mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
Add backtrace function. May only work on Linux but still very useful.
This commit is contained in:
parent
384a41ed5b
commit
1b864b5527
3 changed files with 22 additions and 1 deletions
|
@ -20,7 +20,7 @@ ifeq ($(MEMDEBUG),TRUE)
|
|||
DEFINES = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING -DNUMBER_KEY_AS_INDEX
|
||||
DEFINES += -DCOMMS_CHECKSUM
|
||||
CFLAGS += -g $(GPROFFLAG) -Wall -Wunused-parameter -Wcast-align -Werror -O0
|
||||
CFLAGS += -DDEBUG_TS
|
||||
CFLAGS += -DDEBUG_TS -rdynamic
|
||||
PLATFORM = obj_linux_memdbg
|
||||
else
|
||||
DEFINES =
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h> /* BAD: use glib to support utf8 */
|
||||
#ifdef DEBUG
|
||||
# include <execinfo.h> /* for backtrace */
|
||||
#endif
|
||||
|
||||
#include "linuxutl.h"
|
||||
#include "main.h"
|
||||
|
@ -54,6 +57,21 @@ linux_debugf( const char* format, ... )
|
|||
|
||||
fprintf( stderr, "%s\n", buf );
|
||||
}
|
||||
|
||||
void
|
||||
linux_backtrace( void )
|
||||
{
|
||||
void* buffer[128];
|
||||
int nFound = backtrace( buffer, VSIZE(buffer) );
|
||||
XP_ASSERT( nFound < VSIZE(buffer) );
|
||||
char** traces = backtrace_symbols( buffer, nFound );
|
||||
|
||||
XP_U16 ii;
|
||||
for ( ii = 0; ii < nFound; ++ii ) {
|
||||
XP_LOGF( "trace[%.2d]: %s", ii, traces[ii] );
|
||||
}
|
||||
free( traces );
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef MEM_DEBUG
|
||||
|
|
|
@ -115,8 +115,11 @@ void linux_lowerstr( XP_UCHAR* str );
|
|||
|
||||
#ifdef DEBUG
|
||||
# define XP_ASSERT(b) assert(b)
|
||||
void linux_backtrace( void );
|
||||
# define XP_BACKTRACE linux_backtrace
|
||||
#else
|
||||
# define XP_ASSERT(b)
|
||||
# define XP_BACKTRACE
|
||||
#endif
|
||||
|
||||
#define DGRAM_TYPE SOCK_DGRAM
|
||||
|
|
Loading…
Add table
Reference in a new issue