缺少调用堆栈框架与assert gdb 7.6在mac [英] missing call stack frame with assert for gdb 7.6 on mac

查看:123
本文介绍了缺少调用堆栈框架与assert gdb 7.6在mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当调试一个失败assert的程序时,我无法得到gdb中的调用堆栈。我在Mavericks上使用g ++ 4.8和gdb from Homebrew。

  / usr / local / bin / g ++  - -version 
g ++ 4.8(GCC)4.8.2
/ usr / local / bin / gdb --version
GNU gdb(GDB)7.6.2



以下是重构问题的最小测试

  // test.cpp 
#include< iostream>
#include< cassert>
int main()
{
int i = 42;
std :: cout<< 你好,世界! << i<< std :: endl;
assert(0); //这也发生在abort()其中assert(0)卷起调用
}

编译和使用

  / usr / local / bin / g ++  -  4.8 -g -c test.cpp -o test.o 
/usr/local/bin/g++-4.8 -g test.o -o test
/ usr / local / bin / gdb test
(gdb)r
启动程序: / user / pmelsted / tmp / test / test
Hello World!42
断言失败:(0),函数main,文件test.cpp,第7行。

信号SIGABRT,中止。
0x00007fff9447d866在?? ()
(gdb)其中
#0 0x00007fff9447d866在?? ()
#1 0x00007fff9229835c in? ()
#2 0x0000000000000000 in ?? ()


解决方案

MacOS上的gdb似乎不显示调用堆栈正确(或调用堆栈损坏后的assert()函数调用)为64位程序。这里是稍加修改的程序:

  // test.cpp 
#include< iostream>
#include< cassert>

int foo(){
assert(0);
}
int bar(){
return foo();
}
int main()
{
int i = 42;
std :: cout<< 你好,世界! << i<< std :: endl;
return bar();
}



我已经编译它调用 g ++ -g 15.cpp -m32 命令,并将其运行在ggdb下。 bt full 命令显示调用堆栈如下:

 (gdb)bt full 
#0 0x9843f952 in? ()
无符号表信息可用。
#1 0x96193340 in? ()
无符号表信息可用。
#2 0x9615e43e in? ()
无符号表信息可用。
#3 0x0000216f in foo()at 15.cpp:6
没有本地。
#4 0x0000217b in bar()at 15.cpp:9
没有本地。
#5 0x000021e4在15.cpp的main()中:15
i = 42
(gdb)quit

因此,所有调试符号都显示正确,前3个函数地址被更正,没有名称,因为我的libgcc处于释放模式。



如果我在编译期间不使用 -m32 键,调用堆栈如下:

 (gdb)bt full 
#0 0x00007fff8b442866 in? ()
无符号表信息可用。
#1 0x00007fff8c64735c在?? ()
无符号表信息可用。
#2 0x0000000000000000 in ?? ()
无符号表信息可用。

这是绝对错误的调用堆栈,#2框架函数地址是0x0。所以,根本原因是gdb不能正确显示64位应用程序的调用堆栈。


When debugging a program that fails an assert I can't get the call stack in gdb. I'm using g++4.8 and gdb from Homebrew on Mavericks.

/usr/local/bin/g++-4.8 --version 
g++-4.8 (GCC) 4.8.2
/usr/local/bin/gdb --version
GNU gdb (GDB) 7.6.2

Here is the smallest test to reconstruct the problem

//test.cpp
#include <iostream>
#include <cassert>
int main()
{
  int i = 42;
  std::cout << "Hello World!" << i << std::endl;
  assert(0); // this also happens with abort() which assert(0) winds up calling
}

Compiling and with

/usr/local/bin/g++-4.8 -g -c test.cpp -o test.o
/usr/local/bin/g++-4.8 -g test.o -o test       
/usr/local/bin/gdb test                        
(gdb) r
Starting program: /Users/pmelsted/tmp/test/test 
Hello World!42
Assertion failed: (0), function main, file test.cpp, line 7.

Program received signal SIGABRT, Aborted.
0x00007fff9447d866 in ?? ()
(gdb) where
#0  0x00007fff9447d866 in ?? ()
#1  0x00007fff9229835c in ?? ()
#2  0x0000000000000000 in ?? ()

解决方案

It seems gdb on MacOS don't display call stack correctly (or call stack is corrupted after assert() function call) for 64-bit programs. Here is the program slightly modified:

//test.cpp
#include <iostream>
#include <cassert>

int foo() {
        assert(0);
}
int bar() {
        return foo();
}
int main()
{
        int i = 42;
        std::cout << "Hello World!" << i << std::endl;
        return bar();
}

I have compiled it invoking the g++ -g 15.cpp -m32 command and have ran it under ggdb. The bt full command shows call stack as the following:

(gdb) bt full
#0  0x9843f952 in ?? ()
No symbol table info available.
#1  0x96193340 in ?? ()
No symbol table info available.
#2  0x9615e43e in ?? ()
No symbol table info available.
#3  0x0000216f in foo () at 15.cpp:6
No locals.
#4  0x0000217b in bar () at 15.cpp:9
No locals.
#5  0x000021e4 in main () at 15.cpp:15
        i = 42
(gdb) quit

So, all debug symbols are displayed correctly, first 3 function addresses are corrected and have no name because my libgcc is in release mode.

If I don't use -m32 key during compilation, the call stack is as follows:

(gdb) bt full
#0  0x00007fff8b442866 in ?? ()
No symbol table info available.
#1  0x00007fff8c64735c in ?? ()
No symbol table info available.
#2  0x0000000000000000 in ?? ()
No symbol table info available.

That is definitely wrong call stack, #2 frame function address is 0x0. So, the root cause is gdb can't display call stack correctly for 64-bit applications.

这篇关于缺少调用堆栈框架与assert gdb 7.6在mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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