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.
这篇关于您找到段错误原因的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您找到段错误原因的方法是什么?
基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
