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
This commit is contained in:
Peter Kümmel 2011-04-11 19:39:40 +00:00
parent 08e69e57bf
commit 0a48051f27
2 changed files with 31 additions and 0 deletions

View File

@ -22,6 +22,15 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
//#define LYX_CALLSTACK_PRINTING
#ifdef LYX_CALLSTACK_PRINTING
#include <stdio.h>
#include <stdlib.h>
#include <execinfo.h>
#endif
using namespace std; using namespace std;
using namespace lyx::support; using namespace lyx::support;
@ -242,4 +251,23 @@ LyXErr & operator<<(LyXErr & l, ios_base &(*t)(ios_base &))
// The global instance // The global instance
LyXErr lyxerr; 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 } // namespace lyx

View File

@ -124,6 +124,9 @@ namespace Debug {
/// Show all the possible tags that can be used for debugging /// Show all the possible tags that can be used for debugging
void showTags(std::ostream & os); void showTags(std::ostream & os);
/// Print simple callstack to stderr
void printCallStack();
} // namespace Debug } // namespace Debug