Consider the following C program for the target program: ``` int foo(void) { return 3; } int bar(void) { return foo(); } int main(void) { bar(); return 0; } ``` Compile it to generate the executable file `./a.out`: ``` gcc -g a.c ``` And then run the following stap oneliner: ``` $ stap -e 'probe oneshot { printf("{%s}\n", sprint_ubacktrace()) }' {foo+0x4 [a.out] bar+0x9 [a.out] main+0x9 [a.out] 0x7ffff7a3b11b [libc-2.27.so+0x2311b]} WARNING: Missing unwind data for a module, rerun with 'stap -d /usr/lib64/libc-2.27.so' ``` The warning can be safely ignored. What's unexpected here is the lack of newline at the end of the last frame in the generated backtrace (between the bytes `]` and `}` in the output above). The current master of the upstream systemtap git repo also has the same problem. We should commit any fixes to the upstream as well for this.
According to the code, it indeed appends a newline to each frame, but the buffer only copies the N - 1 bytes where N is the total byte count (excluding `\0`).
Using `sprint_backtrace()` is the same thing: ``` $ stap -d kernel -e 'probe oneshot { printf("{\%s}\n", sprint_backtrace()) }' {0xffffffffc1d8994b [stap_f56de473ef304e53bfb082b091cabf8_15711+0x894b] 0xffffffffc1d898ca [stap_f56de473ef304e53bfb082b091cabf8_15711+0x88ca] (inexact)} ```
Created attachment 13032 [details] Off-by-one fix
commit fd93cf71df80f