缺少调用堆栈帧与断言gdb 7.6在mac上

 浪奔西安 发布于 2023-02-06 17:53

在调试一个失败的程序时,我无法在gdb中获得调用堆栈.我在Mavericks上使用了Homebrew的g ++ 4.8和gdb.

/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

这是重建问题的最小测试

//test.cpp
#include 
#include 
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
}

编译和使用

/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 ?? ()

小智.. 7

对于64位程序,MacOS上的gdb似乎没有正确显示调用堆栈(或者在assert()函数调用之后调用堆栈已损坏).这是程序略有修改:

//test.cpp
#include 
#include 

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

我编译它调用g ++ -g 15.cpp -m32命令并在ggdb下运行它.该BT全命令显示调用堆栈,如下所示:

(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

因此,所有调试符号都正确显示,前3个函数地址已更正且没有名称,因为我的libgcc处于发布模式.

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

(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.

那肯定是错误的调用栈,#2帧功能地址是0x0.因此,根本原因是gdb无法正确显示64位应用程序的调用堆栈.

1 个回答
  • 对于64位程序,MacOS上的gdb似乎没有正确显示调用堆栈(或者在assert()函数调用之后调用堆栈已损坏).这是程序略有修改:

    //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();
    }
    

    我编译它调用g ++ -g 15.cpp -m32命令并在ggdb下运行它.该BT全命令显示调用堆栈,如下所示:

    (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
    

    因此,所有调试符号都正确显示,前3个函数地址已更正且没有名称,因为我的libgcc处于发布模式.

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

    (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.
    

    那肯定是错误的调用栈,#2帧功能地址是0x0.因此,根本原因是gdb无法正确显示64位应用程序的调用堆栈.

    2023-02-06 17:56 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有