On 16/09/2021 07:44, manuel.serr...@inria.fr wrote:
I have conducted a very quick experiment:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
cat > bt.c <<EOF
#include <backtrace.h>

struct backtrace_state *bt_state;

static int cb(void *data, uintptr_t pc, const char *filename, int lineno, const 
char *function) {
    printf("%s:%d %s\n", filename ? filename : "", lineno, function ? function : 
"");
    return 0;
}

static void cbe(void *data, const char *msg, int errnum) {
    fprintf(stderr, "%s(%)", msg, errnum);
}

long bt_init() {
    bt_state = backtrace_create_state(0L, 0, cbe, 0L);
}

long bt_test() {
    backtrace_full(bt_state, 0, cb, cbe, 0L);
}
EOF
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

Then I grabbed the maze.scm from the bglstone suite and inserted a
call to bt_init at the beginning of the execution and a call to bt_test
in the middle of the benchmark. I have then compiled with:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
gcc -c -I ../include/ -c bt.c
bigloo -unsafe -O3 maze.scm bt.o ../lib/libbacktrace.a -cg -glines
./a.out | demangle
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

I obtained

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
/tmp/BT/libbacktrace/maze.scm:489 print-hexmaze@maze
/tmp/BT/libbacktrace/maze.scm:435 pmaze@maze
/tmp/BT/libbacktrace/maze.scm:805 &<@anonymous:1833>@maze
objs/obj_u/Ieee/port.c:3744 with-output-to-file@__r4_ports_6_10_1
/tmp/BT/libbacktrace/maze.scm:804 do-bench@maze
/tmp/BT/libbacktrace/maze.scm:821 main@maze
/tmp/BT/libbacktrace/maze.scm:1 bigloo_main
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

Which is, I must admit, very nice. I will definitively have to look at
libbacktrace for next Bigloo releases...

Thanks again for having drawn our attention to that library that, personally,
I didn't know.



The caveats are:

 * Unix signals. Ian Lance Taylor worked hard to follow
   signal-safety(7)
   <https://man7.org/linux/man-pages/man7/signal-safety.7.html>, but
   your callbacks to libbacktrace might not follow these rules (in
   particular if you call backtracing routines from inside your signal
   handler)
 * Tail call optimizations done by GCC (not Bigloo!)
 * libbacktrace might not work properly on other OSes....

In practice, compiling on Linux with optimization and DWARF debugging information is helpful. So gcc -O3 -g.


On Linux, dladdr(3) <https://man7.org/linux/man-pages/man3/dladdr.3.html> could be helpful.


Hope this helps.


Cheers

--
Basile Starynkevitch                  <bas...@starynkevitch.net>
(only mine opinions / les opinions sont miennes uniquement)
92340 Bourg-la-Reine, France
web page: starynkevitch.net/Basile/

Reply via email to