【问题标题】:GDB: Question about relative and absolute paths to files in backtracesGDB:关于回溯中文件的相对路径和绝对路径的问题
【发布时间】:2011-06-24 20:42:08
【问题描述】:

我对 gdb 或 gcc(但不是 firefox)有疑问。

我在调试 firefox 时只看到 gdb 中的绝对路径。示例:

5  0x01bb0c52 in nsAppShell::ProcessNextNativeEvent 
    (this=0xb7232ba0, mayWait=1)
    at 
    /media/25b7639d-9a70-42ca-aaa7-28f4d1f417fd/firefox-dev/mozilla-central/widget/src/gtk2/nsAppShell.cpp:144

阅读这样的回溯很不舒服。 如果我尝试编译和调试微型测试程序,我会看到这样的回溯(带有文件的相对路径):

0  main () at prog.c:5

在调试 firefox 时,我如何才能在回溯中只看到相对路径?

附: GCC 4.4.1; gdb 7.0。

【问题讨论】:

    标签: gcc path gdb backtrace


    【解决方案1】:

    GDB 将根据程序的编译方式显示绝对或相对路径。考虑:

    $ cd /tmp
    $ cat t.c
    int main() { return 0; }
    $ gcc -g t.c && gdb -q -ex start -ex quit ./a.out
    Reading symbols from /tmp/a.out...done.
    Temporary breakpoint 1 at 0x4004c8: file t.c, line 1.
    
    Temporary breakpoint 1, main () at t.c:1
    1   int main() { return 0; }
    

    现在一样,但是通过绝对路径编译源代码:

    $ gcc -g /tmp/t.c && gdb -q -ex start -ex quit ./a.out
    Reading symbols from /tmp/a.out...done.
    Temporary breakpoint 1 at 0x4004c8: file /tmp/t.c, line 1.
    
    Temporary breakpoint 1, main () at /tmp/t.c:1
    1   int main() { return 0; }
    

    同样,这次使用包含目录前缀的相对路径:

    $ cd /
    $ gcc -g tmp/t.c -o tmp/a.out && gdb -q -ex start -ex quit tmp/a.out
    Reading symbols from /tmp/a.out...done.
    Temporary breakpoint 1 at 0x4004c8: file tmp/t.c, line 1.
    
    Temporary breakpoint 1, main () at tmp/t.c:1
    1   int main() { return 0; }
    

    所以,你可以让gdb显示相对路径如果你改变了firefox的构建方式。这可能被证明是一个非常重要的命题。

    【讨论】:

    • 谢谢。我为 GDB 7.2 创建了新功能(“backtrace”命令的“nopath”参数)。我的补丁在回溯中削减了文件的完整路径。示例: (gdb) backtrace #0 main (argc=4, argv=0xbffff884) at /media/25b7639d-9a70-42ca-aaa7-28f4d1f417fd/firefox-dev/mozilla-central/browser/app/nsBrowserApp.cpp:204 ( gdb) backtrace nopath #0 main (argc=4, argv=0xbffff884) at nsBrowserApp.cpp:204 我希望有人会发现它有用。补丁和描述在这里:sourceware.org/ml/gdb-patches/2011-06/msg00385.html
    • 酷!我的补丁被批准了。感谢 Jan Kratochvil。我对 Jan 的更改的选项在 gdb 7.6 中可用:设置文件名显示
    猜你喜欢
    • 2010-09-15
    • 2020-07-04
    • 2014-02-06
    • 1970-01-01
    • 2013-07-14
    • 2010-12-17
    • 1970-01-01
    • 2012-10-16
    • 2010-09-05
    相关资源
    最近更新 更多