ianlancetaylor / libbacktrace

A C library that may be linked into a C/C++ program to produce symbolic backtraces
Other
947 stars 220 forks source link

please add hints to error message "no debug info in Mach-O executable" #122

Closed bhaible closed 2 months ago

bhaible commented 4 months ago

The error message

libbacktrace: no debug info in Mach-O executable

gives no clue as to how to fix this issue.

Please change the message to

libbacktrace: no debug info in Mach-O executable. Make sure to use option '-g' and to invoke 'dsymutil'.

Rationale: I used libbacktrace in a project with Automake, and it produced this error message. I then spent several hours:

How to reproduce: foo.c.gz

It works in one step:

$ clang -g -O2 -I$HOME/include -L$HOME/lib foo.c -lbacktrace
$ ./a.out
Simple stack trace:
0x1002832e7
Full stack trace (requires debug info):
0x100283303 print_trace
        /Users/haible/foo.c:53
0x100283303 dummy_function
        /Users/haible/foo.c:60
0x100283303 main
        /Users/haible/foo.c:72

But it doesn't work in two steps, until a dsymutil invocation has been performed:

$ clang -g -O2 -I$HOME/include foo.c -c && clang -g -O2 -L$HOME/lib foo.o -lbacktrace
$ ./a.out
Simple stack trace:
0x102bf72e7
Full stack trace (requires debug info):
libbacktrace: no debug info in Mach-O executable
$ dsymutil a.out
$ ./a.out
Simple stack trace:
0x100e3b2e7
Full stack trace (requires debug info):
0x100e3b303 print_trace
        /Users/haible/foo.c:53
0x100e3b303 dummy_function
        /Users/haible/foo.c:60
0x100e3b303 main
        /Users/haible/foo.c:72

References:

If the error message had given me a hint to the missing dsymutil invocation, it would have saved me a lot of time.

ianlancetaylor commented 4 months ago

The intent is that you should not have to run dsymutil. Something is wrong. However, I don't have access to a MacOS system myself to debug this.

bhaible commented 4 months ago

Something is wrong.

Maybe it's related to the test suite failures that I see on macOS 12? I've now reported them at https://github.com/ianlancetaylor/libbacktrace/issues/123 .

The intent is that you should not have to run dsymutil.

Oh, you mean, libbacktrace is supposed to look at the file names stored in the executable (nm -pa a.out | grep OSO) and read the debugging information found in these files? This approach would only suffice in 1 out of 3 cases.

There are 3 cases:

In case a), dsymutil is not needed, if libbacktrace reads the debugging information from each of the .o files.

In case b) and c), dsymutil is needed. Therefore, for these cases, it is worth to improve the error message.

In case c) the user needs also to install the executable.dSYM directory; I hope they will understand this when they know about dsymutil.

cooljeanius commented 3 months ago

Related: GCC bug 97082 and GCC bug 105590

ianlancetaylor commented 2 months ago

Thanks, I improved the error messages slightly.

bhaible commented 2 months ago

Thank you. I appreciate it.