if (!msg.empty()) {
lyxerr << "\nlyx: " << msg << endl;
// try to make a GUI message
- Alert::error(_("LyX crashed!"), msg);
+ Alert::error(_("LyX crashed!"), msg, true);
}
// Deinstall the signal handlers
/**
* Display a warning to the user. Title should be a short (general) summary.
* Only use this if the user cannot perform some remedial action.
+ * On some systems it is possible to show a backtrace.
*/
-void error(docstring const & title, docstring const & message);
+void error(docstring const & title, docstring const & message, bool backtrace = false);
/**
* Informational message. Use very very sparingly. That is, you must
#include "support/debug.h"
#include "support/docstring.h"
#include "support/lstrings.h"
+#include "support/lassert.h"
#include "support/ProgressInterface.h"
#include <QApplication>
title0, message, askshowagain);
}
-void doError(docstring const & title0, docstring const & message)
+void doError(docstring const & title0, docstring const & message, bool backtrace)
{
lyxerr << "Error: " << title0 << '\n'
<< "----------------------------------------\n"
<< message << endl;
+ QString details;
+ if (backtrace) {
+ details = QString::fromLocal8Bit(to_local8bit(printCallStack()).c_str());
+ }
+
if (!use_gui)
return;
ProgressInterface::instance()->error(
toqstr(title),
- toqstr(message));
+ toqstr(message),
+ details);
qApp->restoreOverrideCursor();
theApp()->startLongOperation();
}
-void error(docstring const & title0, docstring const & message)
+void error(docstring const & title0, docstring const & message, bool backtrace)
{
#ifdef EXPORT_in_THREAD
InGuiThread<void>().call(&doError,
#else
doError(
#endif
- title0, message);
+ title0, message, backtrace);
}
void doInformation(docstring const & title0, docstring const & message)
SLOT(doWarning(QString const &, QString const &)));
connect(this, SIGNAL(toggleWarning(QString const &, QString const &, QString const &)),
SLOT(doToggleWarning(QString const &, QString const &, QString const &)));
- connect(this, SIGNAL(error(QString const &, QString const &)),
- SLOT(doError(QString const &, QString const &)));
+ connect(this, SIGNAL(error(QString const &, QString const &, QString const &)),
+ SLOT(doError(QString const &, QString const &, QString const &)));
connect(this, SIGNAL(information(QString const &, QString const &)),
SLOT(doInformation(QString const &, QString const &)));
connect(this, SIGNAL(triggerFlush()),
}
-void GuiProgress::doError(QString const & title, QString const & message)
+void GuiProgress::doError(QString const & title, QString const & message, QString const & details)
{
- QMessageBox::critical(qApp->focusWidget(), title, message);
+ QMessageBox box(QMessageBox::Critical, title, message, QMessageBox::Ok, qApp->focusWidget());
+ if (!details.isEmpty()) {
+ box.setDetailedText(details);
+ }
+ box.exec();
}
// Alert interface
void warning(QString const & title, QString const & message);
void toggleWarning(QString const & title, QString const & msg, QString const & formatted);
- void error(QString const & title, QString const & message);
+ void error(QString const & title, QString const & message, QString const & details = QString());
void information(QString const & title, QString const & message);
private Q_SLOTS:
void doWarning(QString const &, QString const &);
void doToggleWarning(QString const & title, QString const & msg, QString const & formatted);
- void doError(QString const &, QString const &);
+ void doError(QString const &, QString const &, QString const &);
void doInformation(QString const &, QString const &);
void updateWithLyXErr();
set(support_linkback_headers "")
endif()
+if(UNIX AND CMAKE_COMPILER_IS_GNUCC AND NOT APPLE)
+ add_definitions(-DLYX_CALLSTACK_PRINTING)
+endif()
+
add_subdirectory(tests)
# needed to compile tex2lyx in merged mode
/// Alert interface
virtual void warning(QString const & title, QString const & message) = 0;
virtual void toggleWarning(QString const & title, QString const & msg, QString const & formatted) = 0;
- virtual void error(QString const & title, QString const & message) = 0;
+ virtual void error(QString const & title, QString const & message, QString const & details) = 0;
virtual void information(QString const & title, QString const & message) = 0;
virtual int prompt(docstring const & title, docstring const & question,
int default_button, int cancel_button,
void warning(QString const &, QString const &) {}
void toggleWarning(QString const &, QString const &, QString const &) {}
- void error(QString const &, QString const &) {}
+ void error(QString const &, QString const &, QString const &) {}
void information(QString const &, QString const &) {}
int prompt(docstring const &, docstring const &, int default_but, int,
docstring const &, docstring const &) { return default_but; }
#include <boost/assert.hpp>
+#include <QString>
-//#define LYX_CALLSTACK_PRINTING
-// must be linked with -rdynamic
#ifdef LYX_CALLSTACK_PRINTING
#include <cstdio>
#include <cstdlib>
}
-//TODO Return as string, so call stack could be used in dialogs.
-void printCallStack()
+docstring printCallStack()
{
-#ifdef LYX_CALLSTACK_PRINTING
- const int depth = 50;
+#ifndef LYX_CALLSTACK_PRINTING
+ return docstring();
+#else
+ const int depth = 200;
// get void*'s for all entries on the stack
void* array[depth];
char** messages = backtrace_symbols(array, size);
- for (size_t i = 0; i < size && messages != NULL; i++) {
- std::string orig(messages[i]);
- // extract mangled: bin/lyx2.0(_ZN3lyx7support7packageEv+0x32) [0x8a2e02b]
+ docstring bt;
+ for (size_t i = 1; i < size && messages != NULL; i++) {
+ const std::string orig(messages[i]);
char* mangled = 0;
for (char *p = messages[i]; *p; ++p) {
if (*p == '(') {
break;
}
}
- int err = 0;
- char* demangled = abi::__cxa_demangle(mangled, 0, 0, &err);
- if (err == 0) {
- fprintf(stderr, "[bt]: (%d) %s %s\n", i, messages[i], demangled);
- free((void*)demangled);
- } else {
- fprintf(stderr, "[bt]: (%d) %s\n", i, orig.c_str());
- }
+ int status = 0;
+ const char* demangled = abi::__cxa_demangle(mangled, 0, 0, &status);
+ const QByteArray line = QString("(%1) %2: %3\n").arg(i, 3).arg(messages[i])
+ .arg(demangled ? demangled : orig.c_str()).toLocal8Bit();
+ free((void*)demangled);
+
+ fprintf(stderr, "%s", line.constData());
+ bt += from_local8bit(line.constData());
}
+ return bt;
#endif
}
void doAppErr(char const * expr, char const * file, long line);
/// Print demangled callstack to stderr
-void printCallStack();
+docstring printCallStack();
} // namespace lyx