我怎样才能得到GDB告诉我什么地址造成了段错误? [英] How can I get GDB to tell me what address caused a segfault?

查看:340
本文介绍了我怎样才能得到GDB告诉我什么地址造成了段错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果我的程序正在访问NULL指针或陈旧的记忆。

回溯看起来是这样的:


计划接收信号SIGSEGV,分割过错。
[切换主题0x2b0fa4c8(LWP 1333)]
从/lib/libpthread.so.0 0x299a6ad4在pthread_mutex_lock()的
(GDB)BT
从/lib/libpthread.so.0#0 0x299a6ad4在pthread_mutex_lock()的
#1 0x0058e900的? ()


解决方案

通过GDB 7及更高版本,可以检查所填写的信号时, $ _ SIGINFO 结构发生,并确定故障地址:

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

如果它显示(无效*)为0x0 (或少数),那么你有一个空指针引用。

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天全站免登陆