diff --git a/src/framework/debug.cpp b/src/framework/debug.cpp index 4bf6603..cffd54c 100644 --- a/src/framework/debug.cpp +++ b/src/framework/debug.cpp @@ -2,16 +2,12 @@ #include #include -#include #include #include #include "log.h" #include "util/msgbox.h" -const int32_t STACK_ENTRY_STACK_SIZE = 32; -const int32_t STACK_ENTRY_BUFFER_SIZE = 512; -const int32_t STACK_TRACE_BUFFER_SIZE = 2048; const int32_t DEBUG_ASSERT_BUFFER_SIZE = 2048; void DebugInit() @@ -38,16 +34,6 @@ int DebugAssert(const char *expression, const char *file, unsigned long line, co char buffer[DEBUG_ASSERT_BUFFER_SIZE]; int ret = 0; -#ifdef DEBUG_STACK_TRACE - snprintf(buffer, DEBUG_ASSERT_BUFFER_SIZE, - "ASSERT FAILED\n\n" - "EXPRESSION: %s\n" - "FILE: %s\n" - "LINE: %ld\n" - "FUNCTION: %s\n\n" - "STACK TRACE:\n%s\n", - expression, file, line, function, DebugStackTrace()); -#else snprintf(buffer, DEBUG_ASSERT_BUFFER_SIZE, "ASSERT FAILED\n\n" "EXPRESSION: %s\n" @@ -55,7 +41,6 @@ int DebugAssert(const char *expression, const char *file, unsigned long line, co "LINE: %ld\n" "FUNCTION: %s\n", expression, file, line, function); -#endif LOG_ERROR(LOGCAT_DEBUG, buffer); MSGBOX_RESULT result = MsgBox_AbortRetryIgnore(MSGBOX_TYPE_WARNING, buffer, "Assert Failed"); @@ -80,75 +65,3 @@ int DebugAssert(const char *expression, const char *file, unsigned long line, co #endif return ret; } - -const char* DebugStackTrace() -{ -#ifdef DEBUG_STACK_TRACE - return StackTrace::Instance().GetTrace(); -#endif - return ""; -} - -StackTrace::StackTrace() -{ - m_traceBuffer = new char[STACK_TRACE_BUFFER_SIZE]; - m_entryStack = new char*[STACK_ENTRY_STACK_SIZE]; - for (int i = 0; i < STACK_ENTRY_STACK_SIZE; ++i) - m_entryStack[i] = new char[STACK_ENTRY_BUFFER_SIZE]; - m_entryStackPointer = 0; - Clear(); -} - -StackTrace::~StackTrace() -{ - delete[] m_traceBuffer; - for (int i = 0; i < STACK_ENTRY_STACK_SIZE; ++i) - delete[] m_entryStack[i]; - delete[] m_entryStack; - Clear(); -} - -StackTrace& StackTrace::Instance() -{ - static StackTrace stackTrace; - return stackTrace; -} - -void StackTrace::Push(char *entry) -{ - assert(m_entryStackPointer < STACK_ENTRY_STACK_SIZE); - snprintf(m_entryStack[m_entryStackPointer], STACK_ENTRY_BUFFER_SIZE, "%s", entry); - ++m_entryStackPointer; -} - -void StackTrace::Pop() -{ - --m_entryStackPointer; - m_entryStack[m_entryStackPointer][0] = '\0'; -} - -void StackTrace::Clear() -{ - m_entryStackPointer = 0; -} - -char* StackTrace::GetTrace() -{ - *m_traceBuffer = '\0'; - for (int pointer = m_entryStackPointer; pointer >= 0; --pointer) - snprintf(m_traceBuffer, STACK_TRACE_BUFFER_SIZE, "%s%s\n", m_traceBuffer, m_entryStack[pointer]); - - return m_traceBuffer; -} - -StackEntry::StackEntry(const char *file, unsigned long line, const char *function) -{ - static char buffer[STACK_ENTRY_BUFFER_SIZE]; - snprintf(buffer, STACK_ENTRY_BUFFER_SIZE, "%s:%ld:%s", file, line, function); - StackTrace::Instance().Push(buffer); -} - -StackEntry::~StackEntry() -{ - StackTrace::Instance().Pop(); -} diff --git a/src/framework/debug.h b/src/framework/debug.h index 8e348e0..517aaea 100644 --- a/src/framework/debug.h +++ b/src/framework/debug.h @@ -19,20 +19,6 @@ #include #endif -#ifdef DEBUG_STACK_TRACE - /** - * Call stack tracing macro. Simply include this at the top of - * any function to be tracked in the stack history. - */ - #ifdef __GNUC__ - #define STACK_TRACE StackEntry __stackEntry(__FILE__, __LINE__, __PRETTY_FUNCTION__) - #else - #define STACK_TRACE StackEntry __stackEntry(__FILE__, __LINE__, __FUNCSIG__) - #endif -#else - #define STACK_TRACE -#endif - #ifdef DEBUG /** * Toggles a breakpoint in an attached debugger. @@ -92,70 +78,12 @@ */ #define STATIC_ASSERT(exp) typedef int _STATIC_ASSERT_TEST(static_assert_test_var_, __LINE__)[(exp) ? 1 : -1] -/** - * Maintains a list of call stack entries. Entries need to be - * manually pushed/popped off this list. - * - * This class should not be used directly. Instead use the STACK_TRACE - * macro and DebugStackTrace() function. - */ -class StackTrace -{ -public: - static StackTrace& Instance(); - - StackTrace(); - ~StackTrace(); - - /** - * Add new entry onto the top of call stack history. - * @param entry the entry to add - */ - void Push(char *entry); - - /** - * Remove top entry off the call stack history. - */ - void Pop(); - - /** - * Remove all entries from the call stack history. - */ - void Clear(); - - int GetSize() { return m_entryStackPointer + 1; } - - /** - * @return formatted string containing the call stack - * entries top-to-bottom - */ - char* GetTrace(); - -private: - char *m_traceBuffer; - char **m_entryStack; - int m_entryStackPointer; -}; - -/** - * Used by the STACK_TRACE macro to push/pop entries onto the - * actual stack. - * - * This class should not be used directly. - */ -class StackEntry -{ -public: - StackEntry(const char *file, unsigned long line, const char *function); - ~StackEntry(); -}; - /** * Initializes the debug framework. */ void DebugInit(); -/* +/** * Closes up the debug framework. */ void DebugClose(); @@ -171,10 +99,4 @@ void DebugClose(); */ int DebugAssert(const char *expression, const char *file, unsigned long line, const char *function, int *ignore); -/** - * Gets the current call stack as recorded by the STACK_TRACE macros. - * @return formatted string containing the call stack - */ -const char* DebugStackTrace(); - #endif