Reputation: 4877
I am using strace and SystemTap to obtain stack traces at system calls. What I get currently shows the function name but not the file name and line number. A trace from strace on ls
using -k
option:
> /usr/lib64/libc-2.22.so(_IO_file_close+0xb) [0x7890b]
> /usr/lib64/libc-2.22.so(_IO_file_close_it+0x120) [0x79f40]
> /usr/lib64/libc-2.22.so(fclose+0x183) [0x6db93]
> /code/coreutils/src/ls(close_stream+0x1a) [0x1232a]
> /code/coreutils/src/ls(close_stdout+0x12) [0x9d52]
> /usr/lib64/libc-2.22.so(__run_exit_handlers+0xe8) [0x39658]
> /usr/lib64/libc-2.22.so(exit+0x15) [0x396a5]
> /usr/lib64/libc-2.22.so(__libc_start_main+0xf7) [0x20587]
> /code/coreutils/src/ls(_start+0x29) [0x4629]
Another one from SystemTap again from ls
with a slight modification of strace.stp
in the examples:
0x7f17e06eb607 : munmap+0x7/0x30 [/usr/lib64/libc-2.17.so]
0x7f17e0672882 : _IO_setb+0x62/0x70 [/usr/lib64/libc-2.17.so]
0x7f17e0671030 : _IO_file_close_it@@GLIBC_2.2.5+0xb0/0x180 [/usr/lib64/libc-2.17.so]
0x7f17e0665020 : _IO_fclose@@GLIBC_2.2.5+0x180/0x210 [/usr/lib64/libc-2.17.so]
0x4122ba : close_stream+0x1a/0x80 [/usr/bin/ls]
0x40a8b5 : close_stdout+0x15/0xc0 [/usr/bin/ls]
0x7f17e0632e69 : __run_exit_handlers+0xd9/0x110 [/usr/lib64/libc-2.17.so]
0x7f17e0632eb5 : exit+0x15/0x20 [/usr/lib64/libc-2.17.so]
0x40449c : main+0x1aec/0x2198 [/usr/bin/ls]
0x7f17e061bb15 : __libc_start_main+0xf5/0x1c0 [/usr/lib64/libc-2.17.so]
0x404b71 : _start+0x29/0x38 [/usr/bin/ls]
How do I convert the hexadecimal numbers to get the file names and line numbers?
Upvotes: 0
Views: 509
Reputation: 2790
There are at least two possibilities
addr2line
program (part of binutils). This may be possible to automate, but clumsy; something like this, except one may have to split the hex addresses and process them one by one.{ system(sprintf("addr2line -e /proc/self/exe %s", ubacktrace())) }
[u]symfile
and [u]symline
functions. These functions work by uploading line-record parts of the debuginfo into the systemtap module, which these functions can use to map to kernel|userspace source file/lines.{ hexaddr=tokenize(ubacktrace(), " ") ha=strtol(hexaddr,16) printf("%p %s:%s", ha, usymfile(ha), usymline(ha)) while (1) { hexaddr=tokenize("", " ") // continue tokenizing if (hexaddr=="") break ha=strtol(hexaddr,16) printf("%p %s:%s", ha, usymfile(ha), usymline(ha)) } }
Upvotes: 2