Browse Source

add print backtrace

1.0.2
Georg Hopp 11 years ago
parent
commit
7f825c8af3
  1. 1
      include/Makefile.am
  2. 23
      include/tr/print_trace.h
  3. 1
      include/trbase.h
  4. 1
      src/Makefile.am
  5. 47
      src/print_trace.c

1
include/Makefile.am

@ -4,6 +4,7 @@ nobase_include_HEADERS = trbase.h \
tr/interface.h \
tr/memory.h \
tr/logger.h \
tr/print_trace.h \
tr/sized_data.h \
tr/tree_macros.h \
tr/interface/class.h \

23
include/tr/print_trace.h

@ -0,0 +1,23 @@
/**
* \file
*
* \author The GNU Software Foundation.
*
* \copyright
* Copyright © 2014 The GNU Softare Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
void print_trace (void);

1
include/trbase.h

@ -5,6 +5,7 @@
#include "tr/memory.h"
#include "tr/class.h"
#include "tr/logger.h"
#include "tr/print_trace.h"
#include "tr/sized_data.h"
#include "tr/interface.h"
#include "tr/interface/class.h"

1
src/Makefile.am

@ -6,6 +6,7 @@ AM_CFLAGS += -I../include/
TR_CLASS = memory.c \
interface.c \
logger.c \
print_trace.c \
stderr.c \
syslog.c \
sized_data.c \

47
src/print_trace.c

@ -0,0 +1,47 @@
/**
* \file
*
* \author The GNU Software Foundation.
*
* \copyright
* Copyright © 2014 The GNU Softare Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to stdout. */
void
print_trace (void)
{
void * array[10];
size_t size;
char ** strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}
// vim: set ts=4 sw=4:
Loading…
Cancel
Save