使用 gdb 调试 C++
所以我尝试按照本教程来调试我的代码。我告诉 gdb 运行一个可执行文件,它确实运行了,程序崩溃了,给出以下信息:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff907b06e5 in std::string::_Rep::_M_dispose ()
但我没有看到教程谈到的任何方便的 at main.cc:28
内容。
所以我还是继续尝试 backtrace
,这给了我这样的信息:
(gdb) backtrace
#0 0x00007fff907b06e5 in std::string::_Rep::_M_dispose ()
#1 0x00007fff907b12ba in std::string::assign ()
#2 0x00000001000029e4 in Map::insert ()
#3 0x0000000100001ac5 in main ()
仍然没有方便的行号?我应该做什么?
(如果重要的话,我使用的是 Mac OS 10.7,并通过 XCode 安装了默认的 C++ 工具集)
So I am trying to follow this tutorial to debug my code. I tell gdb to run an executable, and it does, and the program crashes, giving this:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff907b06e5 in std::string::_Rep::_M_dispose ()
But I don't see any of the handy at main.cc:28
stuff that the tutorial talks about.
So I continue on anyways and try backtrace
, which gives me this:
(gdb) backtrace
#0 0x00007fff907b06e5 in std::string::_Rep::_M_dispose ()
#1 0x00007fff907b12ba in std::string::assign ()
#2 0x00000001000029e4 in Map::insert ()
#3 0x0000000100001ac5 in main ()
Still no handy line numbers? What should I be doing?
(If it matters, I am using Mac OS 10.7 and installed the default set of C++ tools with XCode)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在构建中打开额外的调试信息。在 gcc 中,您需要
-g
编译器开关。You need to turn on additional debug information in your build. In gcc, you want the
-g
compiler switch.