From 1391bd7219f1c9f9e59958d052011e7796dea338 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 27 Aug 2023 11:29:42 +0200 Subject: [PATCH] Enhancement: crash log now is shown in a more reliable way - but less fancy. In addition, a crash log is written 'klayout_crash.log' in the home path and the crash message is printed to error. --- src/lay/lay/laySignalHandler.cc | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/lay/lay/laySignalHandler.cc b/src/lay/lay/laySignalHandler.cc index c4f5075dd..95dbe1175 100644 --- a/src/lay/lay/laySignalHandler.cc +++ b/src/lay/lay/laySignalHandler.cc @@ -27,6 +27,8 @@ #include "tlException.h" #include "tlString.h" #include "tlLog.h" +#include "tlFileUtils.h" +#include "tlStream.h" #ifdef _WIN32 # include @@ -297,16 +299,6 @@ void signal_handler (int signo, siginfo_t *si, void *) lay::Version::name () + " " + lay::Version::version () + " (" + lay::Version::subversion () + ")\n"; - std::unique_ptr msg; - - bool has_gui = s_sh_has_gui && lay::ApplicationBase::instance () && lay::ApplicationBase::instance ()->has_gui (); - - if (has_gui) { - msg.reset (new CrashMessage (0, false, tl::to_qstring (text) + QObject::tr ("\nCollecting backtrace .."))); - msg->show (); - lay::ApplicationBase::instance ()->qapp_gui ()->setOverrideCursor (Qt::WaitCursor); - } - text += std::string ("\nBacktrace:\n"); #if 0 @@ -332,14 +324,6 @@ void signal_handler (int signo, siginfo_t *si, void *) bool has_addr2line = true; for (size_t i = 0; i < nptrs; ++i) { - if (has_gui) { - lay::ApplicationBase::instance ()->qapp_gui ()->processEvents (); - if (msg->is_cancel_pressed ()) { - text += "...\n"; - break; - } - } - Dl_info info; dladdr (array [i], &info); @@ -407,9 +391,25 @@ void signal_handler (int signo, siginfo_t *si, void *) #endif - if (has_gui) { + try { - lay::ApplicationBase::instance ()->qapp_gui ()->setOverrideCursor (QCursor ()); + // write crash log + + std::string crash_log = tl::combine_path (lay::ApplicationBase::instance () ? lay::ApplicationBase::instance ()->appdata_path () : ".", "klayout_crash.log"); + + tl::OutputStream os (crash_log, tl::OutputStream::OM_Plain, true); + os << text; + + text += "\nCrash log written to " + crash_log; + + } catch (...) { + // .. ignore errors + } + + tl::error << text << tl::noendl; + + bool has_gui = s_sh_has_gui && lay::ApplicationBase::instance () && lay::ApplicationBase::instance ()->has_gui (); + if (has_gui) { // YES! I! KNOW! // In a signal handler you shall not do fancy stuff (in particular not @@ -418,8 +418,10 @@ void signal_handler (int signo, siginfo_t *si, void *) // from our stack frames) and everything is better than just core dumping. // Isn't it? - msg->set_text (tl::to_qstring (text)); - msg->set_can_resume (can_resume); + lay::ApplicationBase::instance ()->qapp_gui ()->setOverrideCursor (QCursor ()); + + std::unique_ptr msg; + msg.reset (new CrashMessage (0, can_resume, tl::to_qstring (text))); if (! msg->exec ()) { @@ -438,7 +440,6 @@ void signal_handler (int signo, siginfo_t *si, void *) } else { - tl::error << text << tl::noendl; _exit (signo); }