[英]How to debug a segmentation fault
How do I debug a segmentation fault? 如何调试分段错误?
Basically this is what happens: 基本上这是发生的事情:
I run my server in background: ./server &
我在后台运行我的服务器:
./server &
then I run my client: ./client
然后我运行我的客户端:
./client
When I try to login to my server, on correct username and password, everything is okay, but when I type invalid user and password, it results in a segmentation fault. 当我尝试登录我的服务器时,使用正确的用户名和密码,一切正常,但是当我键入无效的用户名和密码时,会导致分段错误。
How do I make the compiler/debugger able to output what error its actually see that causes segmentation core dump. 如何使编译器/调试器能够输出实际看到的导致分段核心转储的错误。
I know gdb but I try using gdb client but it doesn't seem to work. 我知道gdb,但我尝试使用gdb客户端但它似乎不起作用。
A good idea with segmentation faults is to run the program with valgrind
for debugging. 分段错误的一个好主意是使用
valgrind
运行程序进行调试。 That way, you'll often get more detailed information about what caused your segmentation fault. 这样,您将经常获得有关导致细分错误的更多详细信息。 For example, it will tell you if you are reading from uninitialized memory.
例如,它会告诉您是否正在读取未初始化的内存。
If you are using g++ first compile your program using the -g option. 如果您正在使用g ++,请首先使用-g选项编译您的程序。 Then use
然后用
gdb name_of_program core
to run gdb on the core dump you get ( name_of_program
is the name of the executable file you just built with g++). 在你获得的核心转储上运行gdb(
name_of_program
是你刚用g ++构建的可执行文件的名称)。 This link is useful for how to use gdb. 此链接对于如何使用gdb很有用。
http://www.ibm.com/developerworks/library/l-gdb/ http://www.ibm.com/developerworks/library/l-gdb/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.