Pablo Neira Ayuso | fba495e | 2011-03-23 18:08:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2008 by Daniel Willmann <daniel@totalueberwachung.de> |
| 3 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2010 by Nico Golde <nico@ngolde.de> |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 25 | /*! \file backtrace.c |
| 26 | * \brief Routines realted to generating call back traces |
| 27 | */ |
| 28 | |
Pablo Neira Ayuso | fba495e | 2011-03-23 18:08:08 +0100 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <stdlib.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 31 | #include <osmocom/core/utils.h> |
Pablo Neira Ayuso | fba495e | 2011-03-23 18:08:08 +0100 | [diff] [blame] | 32 | #include "config.h" |
| 33 | |
| 34 | #ifdef HAVE_EXECINFO_H |
| 35 | #include <execinfo.h> |
Harald Welte | ba6988b | 2011-08-17 12:46:48 +0200 | [diff] [blame] | 36 | |
| 37 | /*! \brief Generate and print a call back-trace |
| 38 | * |
| 39 | * This function will generate a function call back-trace of the |
| 40 | * current process and print it to stdout |
| 41 | */ |
Harald Welte | 95b2b47 | 2011-07-16 11:58:09 +0200 | [diff] [blame] | 42 | void osmo_generate_backtrace(void) |
Pablo Neira Ayuso | fba495e | 2011-03-23 18:08:08 +0100 | [diff] [blame] | 43 | { |
| 44 | int i, nptrs; |
| 45 | void *buffer[100]; |
| 46 | char **strings; |
| 47 | |
| 48 | nptrs = backtrace(buffer, ARRAY_SIZE(buffer)); |
| 49 | printf("backtrace() returned %d addresses\n", nptrs); |
| 50 | |
| 51 | strings = backtrace_symbols(buffer, nptrs); |
| 52 | if (!strings) |
| 53 | return; |
| 54 | |
| 55 | for (i = 1; i < nptrs; i++) |
| 56 | printf("%s\n", strings[i]); |
| 57 | |
| 58 | free(strings); |
| 59 | } |
Holger Hans Peter Freyther | 3ec5047 | 2011-11-09 12:18:55 +0100 | [diff] [blame] | 60 | #else |
| 61 | void osmo_generate_backtrace(void) |
| 62 | { |
| 63 | } |
Pablo Neira Ayuso | fba495e | 2011-03-23 18:08:08 +0100 | [diff] [blame] | 64 | #endif |