I'm having issues with getting the line number of a stack frame provided by boost::stacktrace. When printing the task with boost::stacktrace::to_string
it prints the line number but when calling source_line()
it returns 0.
Example:
auto frame = boost::stacktrace::stacktrace()[0];
std::cout << frame << std::endl;
std::cout << frame.source_file() << ":" << frame.source_line();
Outut:
foo::bar() at /some/path/to/file/file.cc:24
/some/path/to/file/file.cc:
Is there any solution or do I have to do some manual string manipulation to get the line number?
I get the same behaviour on Ubuntu 18.04 with full debug info.
Using
strace -f -e execve,clone,fork,waitpid ./sotest
Shows that the command being executed is
[pid 5972] execve("/usr/bin/addr2line", ["/usr/bin/addr2line", "-e", "./sotest", "0x000055EC1854F7FF"], 0x7fff8e99bdd8 /* 82 vars */) = 0
Indeed, manually checking
/usr/bin/addr2line -e ./sotest 0x000055EC1854F7FF
Prints
??:0
I've got no idea why this is, as the debug info is very much there (even at -g -O0 -fno-omit-frame-pointer
):
$ file sotest
sotest: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=53bae8898d711d1946ac4cb805740b11aa1cc045, with debug_info, not stripped
I had more success with the libbacktrace
backend
#define BOOST_STACKTRACE_USE_BACKTRACE
Printing
$ ./sotest
foo::bar() at /home/sehe/Projects/stackoverflow/test.cpp:8
/home/sehe/Projects/stackoverflow/test.cpp:8
Of course this requires linking the backtrace library. but this appears to be part of the standard Ubuntu installation.