您找到段错误原因的方法是什么? [英] What's your method for finding the cause of a segfault?

查看:18
本文介绍了您找到段错误原因的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

或者只是一般的调试,您喜欢如何查找代码中的错误.特别适用于 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.

这篇关于您找到段错误原因的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆