For me, backtrace_symbols() does not show line-numbers. Is this the
intended behaviour?
I'm using:
OpenBSD jules-obsd 6.7 GENERIC.MP#182 amd64
libexecinfo-0.3p2v0
With 'cc -g -Wl,--export-dynamic', i'm getting backtraces like:
0x69854ee369 <bar+41> at ./foo.c.exe
0x69854ee477 <foo+23> at ./foo.c.exe
0x69854ee4be <main+30> at ./foo.c.exe
0x69854ee13b <__start+315> at ./foo.c.exe
[gdb can show line numbers on the same executable, so the information
is definitely in the executable somewhere.]
I'm testing with this code:
====
#include <err.h>
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
void bar()
{
void* bt[20];
char** strings;
int i;
int d;
d = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
if (d == -1)
errx(1, "backtrace");
strings = backtrace_symbols(bt, d);
if (strings == NULL)
errx(1, "backtrace_symbols");
for (i = 0; i < d; i++)
printf(" %s\n", strings[i]);
free(strings);
}
void foo(void)
{
bar();
}
int main(void)
{
foo();
return 0;
}
===
Build with:
cc -g -o foo.c.exe foo.c -I /usr/local/include -g -L /usr/local/lib
-lexecinfo -Wl,--export-dynamic
Run:
./foo.c.exe
Output:
0x69854ee369 <bar+41> at ./foo.c.exe
0x69854ee477 <foo+23> at ./foo.c.exe
0x69854ee4be <main+30> at ./foo.c.exe
0x69854ee13b <__start+315> at ./foo.c.exe
====
Also, here's a small diff for /usr/local/man/man3/backtrace.3, which
makes the code example more directly usable and fixes a misprint of
'\n':
--- /usr/local/man/man3/backtrace.3 Fri May 8 19:49:25 2020
+++ backtrace.3 Fri Jul 17 11:09:15 2020
@@ -63,14 +63,17 @@
The following code fragment illustrates the use of the backtrace
functionality:
.Bd -literal -offset indent
+#include <execinfo.h>
+#include <err.h>
+
void
print_backtrace(void)
{
- void *bt[BT_MAX_DEPTH];
+ void *bt[20];
char **strings;
int i, d;
- d = backtrace(bt, BT_MAX_DEPTH);
+ d = backtrace(bt, sizeof(bt) / sizeof(bt[0]));
if (d == -1)
errx(1, "backtrace");
@@ -80,7 +83,7 @@
errx(1, "backtrace_symbols");
for (i = 0; i < d; i++)
- printf("%s\n", strings[i]);
+ printf("%s\\n", strings[i]);
free(strings);
}
Thanks,
- Jules
--
http://op59.net