blob: 023671c2ceda31dfaa55c1b90efbe73e684da690 [file] [log] [blame]
Pablo Neira Ayusofba495e2011-03-23 18:08:08 +01001/*
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 Welteba6988b2011-08-17 12:46:48 +020025/*! \file backtrace.c
26 * \brief Routines realted to generating call back traces
27 */
28
Pablo Neira Ayusofba495e2011-03-23 18:08:08 +010029#include <stdio.h>
30#include <stdlib.h>
Pablo Neira Ayuso83419342011-03-22 16:36:13 +010031#include <osmocom/core/utils.h>
Pablo Neira Ayusofba495e2011-03-23 18:08:08 +010032#include "config.h"
33
34#ifdef HAVE_EXECINFO_H
35#include <execinfo.h>
Harald Welteba6988b2011-08-17 12:46:48 +020036
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 Welte95b2b472011-07-16 11:58:09 +020042void osmo_generate_backtrace(void)
Pablo Neira Ayusofba495e2011-03-23 18:08:08 +010043{
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 Freyther3ec50472011-11-09 12:18:55 +010060#else
61void osmo_generate_backtrace(void)
62{
63}
Pablo Neira Ayusofba495e2011-03-23 18:08:08 +010064#endif