3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "support/debug.h"
16 #include <boost/assert.hpp>
19 //#define LYX_CALLSTACK_PRINTING
20 // must be linked with -rdynamic
21 #ifdef LYX_CALLSTACK_PRINTING
31 void doAssert(char const * expr, char const * file, long line)
33 // TODO Should we try to print the call stack before exiting?
35 LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
36 // comment this out if not needed
41 //TODO Return as string, so call stack could be used in dialogs.
44 #ifdef LYX_CALLSTACK_PRINTING
47 // get void*'s for all entries on the stack
49 size_t size = backtrace(array, depth);
51 char** messages = backtrace_symbols(array, size);
53 for (size_t i = 0; i < size && messages != NULL; i++) {
54 std::string orig(messages[i]);
55 // extract mangled: bin/lyx2.0(_ZN3lyx7support7packageEv+0x32) [0x8a2e02b]
57 for (char *p = messages[i]; *p; ++p) {
61 } else if (*p == '+') {
67 char* demangled = abi::__cxa_demangle(mangled, 0, 0, &err);
69 fprintf(stderr, "[bt]: (%d) %s %s\n", i, messages[i], demangled);
70 free((void*)demangled);
72 fprintf(stderr, "[bt]: (%d) %s\n", i, orig.c_str());