Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libbacktrace skip parameter can skip several inlined functions #60

Open
bhaible opened this issue Nov 22, 2020 · 2 comments
Open

libbacktrace skip parameter can skip several inlined functions #60

bhaible opened this issue Nov 22, 2020 · 2 comments

Comments

@bhaible
Copy link

bhaible commented Nov 22, 2020

On Ubuntu 16.04, when I compile a program with "-g" or "-ggdb", for 32-bit mode programs, libbacktrace can infer file and line numbers. For 64-bit mode programs, this does not work.

How to reproduce: Compile this program in 64-bit mode.
backtrace-via-libbacktrace.c.gz

$ gcc -g -O2 -lbacktrace
$ ./a.out
0x7f7b8e38e83f ???
        ???:0
0x401178 ???
        ???:0
0xffffffffffffffff ???
        ???:0

and

$ gcc -ggdb -O2 -lbacktrace
$ ./a.out
0x7f63a997183f ???
        ???:0
0x401178 ???
        ???:0
0xffffffffffffffff ???
        ???:0

gcc is version 5.4.0. gdb does understand the debug info.

@ianlancetaylor
Copy link
Owner

I run libbacktrace on x86_64 all the time. I don't see any problem reading x86_64 debug info.

If I change your program to pass a skip argument of 0 to backtrace_print, it prints a full backtrace. The same is true if the program is compiled without -O2. What is happening with your test program is that all the functions are inlined into main. The skip argument is being applied before considering the inlining. The effect is that the code that skips print_trace also skips dummy_function and main. This does seem like a bug in the handling of the skip parameter.

@ianlancetaylor ianlancetaylor changed the title libbacktrace does not understand the x86_64 debug info libbacktrace skip parameter can skip several inlined functions Nov 22, 2020
@bhaible
Copy link
Author

bhaible commented Nov 22, 2020

If I change your program to pass a skip argument of 0 to backtrace_print, it prints a full backtrace. The same is true if the program is compiled without -O2.

Yes, I reproduce this.

What is happening with your test program is that all the functions are inlined into main.

Not entirely.
Without -O2, there are three stack frames: print_trace, dummy_function, main.
With -O2, dummy_function gets optimized away, and there are two stack frames: print_trace, main. (main contains a call print_trace.) With skip = 0, I get this output:

0x401148 dummy_function
        /media/develdata/devel/GNULIB/old/backtrace-via-libbacktrace.c:18
0x401148 main
        /media/develdata/devel/GNULIB/old/backtrace-via-libbacktrace.c:30
0x7f28b3ee483f ???
        ???:0
0x401178 ???
        ???:0
0xffffffffffffffff ???
        ???:0

The first line here is wrong. It should reflect the frame of print_trace. But instead, it reflects the frame of dummy_function (which has been eliminated), and the frame of print_trace has been lost.

That the frame-skipping logic then, for skip = 1, eliminates two frames instead of one, is understandable (given that both frames show the same code address). But the original problem exists already with skip = 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants