What#39;s your method for finding the cause of a segfault?(您找到段错误原因的方法是什么?)
问题描述
或者只是一般的调试,您喜欢如何查找代码中的错误.特别适用于 C/C++,但一般适用于所有语言.我一直在试图找出这个令人讨厌的段错误的原因,但我希望自己找到它,而不是在网上发布它.你对像我这样的学徒有什么建议吗?
Or just debugging in general, how do you like to go about finding bugs in code. Specifically for C/C++, but all languages in general. I've been trying to find the cause of this nasty segfault, but I'd like the challenge of finding it myself, not posting it online. Do you have any advice for a padawan such as myself?
推荐答案
尝试将你的代码推向糟糕的情况.
Try to push your code into bad situations.
如果您正在编写解析器,请将 BMP、JPG、随机文本扔给它,看看会发生什么.如果你正在编写一个 RPC 协议服务器,用大量并发请求使其超载,向其中写入垃圾,在不知不觉中断开客户端......
If you're writing a parser, throw BMPs, JPGs, random text at it, and see what happens. If you're writing a RPC protocol server, overload it with plenty of concurrent requests, write garbage into it, disconnect the client in the middle of nowhere...
一开始不要狡猾,尽可能地抛出,然后尝试欺骗你的代码.
Don't be subtle at first, throw whatever possible, but then try to trick your code.
这篇关于您找到段错误原因的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您找到段错误原因的方法是什么?
基础教程推荐
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
