From 5777586d16372f451229a716eea9272bf075ed45 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Sat, 30 May 2009 22:49:44 -0400 Subject: [PATCH] added a printTrace function to print out the current stack --- inc/debug.h | 2 ++ src/debug.cpp | 41 ++++++++++++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) 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); -- 2.10.2