From 25f30ba00ae7a5be50724a77bdf7484886726b9b Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 28 Oct 2009 09:12:43 +0100 Subject: misc: Add routine to generate backtrace from within the application E.g. to analyze the subscr_get/subscr_put behavior one can place the generate_backtrace into the functions, recompile and then filter the output with contrib/bt.py to get the function name, file and line. --- openbsc/src/gsm_utils.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'openbsc/src/gsm_utils.c') diff --git a/openbsc/src/gsm_utils.c b/openbsc/src/gsm_utils.c index de18dba26..ddfd7f3de 100644 --- a/openbsc/src/gsm_utils.c +++ b/openbsc/src/gsm_utils.c @@ -23,8 +23,10 @@ #include #include +#include #include #include +#include #include /* GSM 03.38 6.2.1 Charachter packing */ @@ -148,4 +150,21 @@ int ms_pwr_dbm(enum gsm_band band, u_int8_t lvl) return -EINVAL; } +void generate_backtrace() +{ + int i, nptrs; + void *buffer[100]; + char **strings; + + nptrs = backtrace(buffer, ARRAY_SIZE(buffer)); + printf("backtrace() returned %d addresses\n", nptrs); + + strings = backtrace_symbols(buffer, nptrs); + if (!strings) + return; + for (i = 1; i < nptrs; i++) + printf("%s\n", strings[i]); + + free(strings); +} -- cgit v1.2.3