如何让 GDB 告诉我是哪个地址导致了段错误? [英] How can I get GDB to tell me what address caused a segfault?

查看:18
本文介绍了如何让 GDB 告诉我是哪个地址导致了段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的程序是在访问 NULL 指针还是过时的内存.

回溯如下所示:

<上一页>程序收到信号 SIGSEGV,分段错误.[切换到线程 0x2b0fa4c8 (LWP 1333)]来自/lib/libpthread.so.0 的 pthread_mutex_lock () 中的 0x299a6ad4(gdb) BT#0 0x299a6ad4 in pthread_mutex_lock () from/lib/libpthread.so.0#1 0x0058e900 在??()

解决方案

使用 GDB 7 及更高版本,您可以检查信号发生时填写的 $_siginfo 结构,并确定故障地址:

(gdb) p $_siginfo._sifields._sigfault.si_addr

如果它显示 (void *) 0x0(或一个小数字),那么你有一个 NULL 指针取消引用.

I'd like to know if my program is accessing NULL pointers or stale memory.

The backtrace looks like this:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x2b0fa4c8 (LWP 1333)]
0x299a6ad4 in pthread_mutex_lock () from /lib/libpthread.so.0
(gdb) bt
#0  0x299a6ad4 in pthread_mutex_lock () from /lib/libpthread.so.0
#1  0x0058e900 in ?? ()

解决方案

With GDB 7 and higher, you can examine the $_siginfo structure that is filled out when the signal occurs, and determine the faulting address:

(gdb) p $_siginfo._sifields._sigfault.si_addr

If it shows (void *) 0x0 (or a small number) then you have a NULL pointer dereference.

这篇关于如何让 GDB 告诉我是哪个地址导致了段错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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