GDB: Question about relative and absolute paths to files in backtraces
Asked Answered
M

1

9

I have question about gdb or gcc (but not firefox).

I see only absolute paths in gdb when i debugging firefox. Example:

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

It's uncomfortable for reading such backtraces. If i try to compile and debug tiny test program i see such backtrace (with relative paths to files):

0  main () at prog.c:5

How can i see only relative paths in backtraces when debugging firefox?

P.S. gcc 4.4.1; gdb 7.0.

Melanite answered 24/6, 2011 at 20:42 Comment(0)
E
3

GDB will show absolute or relative path depending on how the program was compiled. Consider:

$ 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; }

Now the same, but compile source via absolute path:

$ 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; }

And again, this time with relative path that includes directory prefix:

$ 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; }

So, you can get gdb to show relative path if you change the way firefox is built. That may prove to be a very non-trivial proposition.

Etiquette answered 25/6, 2011 at 17:43 Comment(2)
Thank you. I've created new feature for GDB 7.2 ("nopath" argument for "backtrace" command). My patch cuts full path to file in backtraces. Example: (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 I hope that somebody will find it useful. Patch and description here: sourceware.org/ml/gdb-patches/2011-06/msg00385.htmlMelanite
Cool! My patch was approved. Thanks to Jan Kratochvil. My option with Jan's changes is available in gdb 7.6: set filename-displayMelanite

© 2022 - 2024 — McMap. All rights reserved.