From 9b8c0657d644440e3625167baf327d6b06f5b546 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Tue, 22 Nov 2011 20:35:24 +0000 Subject: (C_backtrace) introduce it in order to get a better GDB trace --- perl-install/c/stuff.xs.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'perl-install/c') diff --git a/perl-install/c/stuff.xs.pl b/perl-install/c/stuff.xs.pl index 1dbc9686a..d3dfd41ab 100755 --- a/perl-install/c/stuff.xs.pl +++ b/perl-install/c/stuff.xs.pl @@ -37,6 +37,7 @@ print ' #include #include #include +#include // for ethtool structs: typedef unsigned long long u64; @@ -701,6 +702,34 @@ disk_add_partition(char * device_path, double start, double length, const char * OUTPUT: RETVAL +#define BACKTRACE_DEPTH 20 + + +char* +C_backtrace() + CODE: + static char buf[1024]; + int nAddresses, i; + unsigned long idx = 0; + void * addresses[BACKTRACE_DEPTH]; + char ** symbols = NULL; + nAddresses = backtrace(addresses, BACKTRACE_DEPTH); + symbols = backtrace_symbols(addresses, nAddresses); + if (symbols == NULL) { + idx += sprintf(buf+idx, "ERROR: Retrieving symbols failed.\n"); + } else { + fprintf(stderr, "HERE 5\n"); + /* dump stack trace */ + for (i = 0; i < nAddresses; ++i) + idx += sprintf(buf+idx, "%d: %s\n", i, symbols[i]); + } + RETVAL = strdup(buf); + OUTPUT: + RETVAL + + + + '; @macros = ( -- cgit v1.2.1