From 0a48051f27e88ac7477ca5f3752c5ac2e6bf992a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20K=C3=BCmmel?= Date: Mon, 11 Apr 2011 19:39:40 +0000 Subject: [PATCH] add debug function which prints the callstack to stderr, disabled by default git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38334 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/support/debug.cpp | 28 ++++++++++++++++++++++++++++ src/support/debug.h | 3 +++ 2 files changed, 31 insertions(+) diff --git a/src/support/debug.cpp b/src/support/debug.cpp index 0f2cd2dbf4..11dd243e1a 100644 --- a/src/support/debug.cpp +++ b/src/support/debug.cpp @@ -22,6 +22,15 @@ #include #include +//#define LYX_CALLSTACK_PRINTING +#ifdef LYX_CALLSTACK_PRINTING +#include +#include +#include +#endif + + + using namespace std; using namespace lyx::support; @@ -242,4 +251,23 @@ LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &)) // The global instance LyXErr lyxerr; + +void Debug::printCallStack() +{ +#ifdef LYX_CALLSTACK_PRINTING + const int depth = 50; + + // get void*'s for all entries on the stack + void* array[depth]; + size_t size = backtrace(array, depth); + + char** messages = backtrace_symbols(array, size); + + for (size_t i = 0; i < size && messages != NULL; i++) { + fprintf(stderr, "[LyX's bt]: (%d) %s\n", i, messages[i]); + } +#endif +} + + } // namespace lyx diff --git a/src/support/debug.h b/src/support/debug.h index fc7f72eff4..3835242b36 100644 --- a/src/support/debug.h +++ b/src/support/debug.h @@ -124,6 +124,9 @@ namespace Debug { /// Show all the possible tags that can be used for debugging void showTags(std::ostream & os); + /// Print simple callstack to stderr + void printCallStack(); + } // namespace Debug -- 2.39.2