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