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/convert.h"
15 #include "support/debug.h"
16 #include "support/docstring.h"
17 #include "support/ExceptionMessage.h"
18 #include "support/gettext.h"
19 #include "support/lstrings.h"
21 #include <boost/assert.hpp>
24 //#define LYX_CALLSTACK_PRINTING
25 // must be linked with -rdynamic
26 #ifdef LYX_CALLSTACK_PRINTING
37 using namespace support;
39 // TODO Should we try to print the call stack in the course of these?
41 void doAssert(char const * expr, char const * file, long line)
43 LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
44 // comment this out if not needed
49 docstring formatHelper(docstring const & msg,
50 char const * expr, char const * file, long line)
52 docstring const d = _("Assertion %1$s violated in\nfile: %2$s, line: %3$s");
53 LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
55 return bformat(d, from_ascii(expr), from_ascii(file),
56 convert<docstring>(line)) + '\n' + msg;
60 void doWarnIf(char const * expr, char const * file, long line)
62 docstring const d = _("It should be safe to continue, but you\nmay wish to save your work and restart LyX.");
63 // comment this out if not needed
65 throw ExceptionMessage(WarningException, _("Warning!"),
66 formatHelper(d, expr, file, line));
70 void doBufErr(char const * expr, char const * file, long line)
72 docstring const d = _("There has been an error with this document.\nLyX will attempt to close it safely.");
73 // comment this out if not needed
75 throw ExceptionMessage(BufferException, _("Buffer Error!"),
76 formatHelper(d, expr, file, line));
80 void doAppErr(char const * expr, char const * file, long line)
82 docstring const d = _("LyX has encountered an application error\nand will now shut down.");
83 // comment this out if not needed
85 throw ExceptionMessage(ErrorException, _("Fatal Exception!"),
86 formatHelper(d, expr, file, line));
90 //TODO Return as string, so call stack could be used in dialogs.
93 #ifdef LYX_CALLSTACK_PRINTING
96 // get void*'s for all entries on the stack
98 size_t size = backtrace(array, depth);
100 char** messages = backtrace_symbols(array, size);
102 for (size_t i = 0; i < size && messages != NULL; i++) {
103 std::string orig(messages[i]);
104 // extract mangled: bin/lyx2.0(_ZN3lyx7support7packageEv+0x32) [0x8a2e02b]
106 for (char *p = messages[i]; *p; ++p) {
110 } else if (*p == '+') {
116 char* demangled = abi::__cxa_demangle(mangled, 0, 0, &err);
118 fprintf(stderr, "[bt]: (%d) %s %s\n", i, messages[i], demangled);
119 free((void*)demangled);
121 fprintf(stderr, "[bt]: (%d) %s\n", i, orig.c_str());