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>
25 #ifdef LYX_CALLSTACK_PRINTING
36 using namespace support;
38 // TODO Should we try to print the call stack in the course of these?
40 void doAssert(char const * expr, char const * file, long line)
42 LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
43 // comment this out if not needed
48 docstring formatHelper(docstring const & msg,
49 char const * expr, char const * file, long line)
51 docstring const d = _("Assertion %1$s violated in\nfile: %2$s, line: %3$s");
52 LYXERR0("ASSERTION " << expr << " VIOLATED IN " << file << ":" << line);
54 return bformat(d, from_ascii(expr), from_ascii(file),
55 convert<docstring>(line)) + '\n' + msg;
59 void doWarnIf(char const * expr, char const * file, long line)
61 docstring const d = _("It should be safe to continue, but you\nmay wish to save your work and restart LyX.");
62 // comment this out if not needed
64 throw ExceptionMessage(WarningException, _("Warning!"),
65 formatHelper(d, expr, file, line));
69 void doBufErr(char const * expr, char const * file, long line)
71 docstring const d = _("There has been an error with this document.\nLyX will attempt to close it safely.");
72 // comment this out if not needed
74 throw ExceptionMessage(BufferException, _("Buffer Error!"),
75 formatHelper(d, expr, file, line));
79 void doAppErr(char const * expr, char const * file, long line)
81 docstring const d = _("LyX has encountered an application error\nand will now shut down.");
82 // comment this out if not needed
84 throw ExceptionMessage(ErrorException, _("Fatal Exception!"),
85 formatHelper(d, expr, file, line));
89 docstring printCallStack()
91 #ifndef LYX_CALLSTACK_PRINTING
94 const int depth = 200;
96 // get void*'s for all entries on the stack
98 size_t size = backtrace(array, depth);
100 char** messages = backtrace_symbols(array, size);
103 for (size_t i = 1; i < size && messages != NULL; i++) {
104 const std::string orig(messages[i]);
106 for (char *p = messages[i]; *p; ++p) {
110 } else if (*p == '+') {
116 const char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
117 const QByteArray line = QString("(%1) %2: %3\n").arg(i, 3).arg(messages[i])
118 .arg(demangled ? demangled : orig.c_str()).toLocal8Bit();
119 free((void*)demangled);
121 fprintf(stderr, "%s", line.constData());
122 bt += from_local8bit(line.constData());