From: Patrik Gornicz Date: Sun, 31 May 2009 02:49:44 +0000 (-0400) Subject: added a printTrace function to print out the current stack X-Git-Tag: libbear-premerge~79 X-Git-Url: http://gitweb.pgornicz.com/?a=commitdiff_plain;h=5777586d16372f451229a716eea9272bf075ed45;p=libbear.git added a printTrace function to print out the current stack --- diff --git a/inc/debug.h b/inc/debug.h index 90ab59e..fb5ac94 100644 --- a/inc/debug.h +++ b/inc/debug.h @@ -26,6 +26,8 @@ namespace bear { void init(); void fini(); + + void printTrace(); } void DASSERT(bool fAssert); diff --git a/src/debug.cpp b/src/debug.cpp index 8d523dd..ffdfa47 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -23,6 +23,7 @@ using std::cout; using std::endl; #include +#include #include "Lock.h" #include "Autolock.h" @@ -34,13 +35,6 @@ using namespace bear; Lock muDPF; -void bear::DPF(int iLevel, const char* pstr) -{ - Autolock lock(&muDPF); - - cout << pstr << endl; -} - void bear::debug::init() { muDPF.init(); @@ -51,6 +45,39 @@ void bear::debug::fini() muDPF.fini(); } +void bear::debug::printTrace() +{ + int size; + char** strings; + + { + void* array[50]; + + size = backtrace (array, 50); + strings = backtrace_symbols (array, size); + } + + { + Autolock lock(&muDPF); + + cout << "Obtained " << size << " stack frames." << endl; + + for (int i = 0; i < size; i++) + { + cout << strings[i] << endl; + } + } + + free (strings); +} + +void bear::DPF(int iLevel, const char* pstr) +{ + Autolock lock(&muDPF); + + cout << pstr << endl; +} + void bear::DASSERT(bool fAssert) { assert(fAssert);