option(DISABLE_WERROR "Build without -Werror" FALSE)
option(ENABLE_SIGNALS "Build with UNIX signals" TRUE)
+option(ENABLE_STACKTRACE "Enable stack trace when crashing" FALSE)
option(ENABLE_DECODE "Build with libsigrokdecode" TRUE)
option(ENABLE_TESTS "Enable unit tests" TRUE)
option(STATIC_PKGDEPS_LIBS "Statically link to (pkg-config) libraries" FALSE)
if(ENABLE_TESTS)
list(APPEND BOOSTCOMPS unit_test_framework)
endif()
-find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
+
+if(ENABLE_STACKTRACE)
+ find_package(Boost 1.65.1 COMPONENTS ${BOOSTCOMPS} REQUIRED)
+else()
+ find_package(Boost 1.55 COMPONENTS ${BOOSTCOMPS} REQUIRED)
+endif()
# Find the platform's thread library (needed for C++11 threads).
# This will set ${CMAKE_THREAD_LIBS_INIT} to the correct, OS-specific value.
add_definitions(-DENABLE_SIGNALS)
endif()
+if(ENABLE_STACKTRACE)
+ add_definitions(-DENABLE_STACKTRACE)
+endif()
+
#===============================================================================
#= Global Include Directories
#-------------------------------------------------------------------------------
list(APPEND PULSEVIEW_LINK_LIBS ${QT5ALL_LDFLAGS})
endif()
+if(ENABLE_STACKTRACE)
+ # Needed to resolve dladdr.
+ list(APPEND PULSEVIEW_LINK_LIBS "-ldl")
+endif()
+
if(ANDROID)
list(APPEND PULSEVIEW_LINK_LIBS "-llog")
endif()
#include "signalhandler.hpp"
#endif
+#ifdef ENABLE_STACKTRACE
+#include <signal.h>
+#include <boost/stacktrace.hpp>
+#include <QStandardPaths>
+#endif
+
#include "pv/application.hpp"
#include "pv/devicemanager.hpp"
#include "pv/mainwindow.hpp"
#include "pv/session.hpp"
+
#ifdef ANDROID
#include <libsigrokandroidutils/libsigrokandroidutils.h>
#include "android/assetreader.hpp"
using std::shared_ptr;
using std::string;
+#if ENABLE_STACKTRACE
+QString stacktrace_filename;
+
+void signal_handler(int signum)
+{
+ ::signal(signum, SIG_DFL);
+ boost::stacktrace::safe_dump_to(stacktrace_filename.toLocal8Bit().data());
+ ::raise(SIGABRT);
+}
+#endif
+
void usage()
{
fprintf(stdout,
context = sigrok::Context::create();
pv::Session::sr_context = context;
+#if ENABLE_STACKTRACE
+ QString temp_path = QStandardPaths::standardLocations(
+ QStandardPaths::TempLocation).at(0);
+ stacktrace_filename = temp_path + "/pv_stacktrace.dmp";
+ qDebug() << "Stack trace file is" << stacktrace_filename;
+
+ ::signal(SIGSEGV, &signal_handler);
+ ::signal(SIGABRT, &signal_handler);
+#endif
+
#ifdef ANDROID
context->set_resource_reader(&asset_reader);
#endif
srd_decoder_load_all();
#endif
+#ifndef ENABLE_STACKTRACE
try {
- // Create the device manager, initialise the drivers
- pv::DeviceManager device_manager(context, driver, do_scan);
+#endif
- // Initialise the main window
- pv::MainWindow w(device_manager);
- w.show();
+ // Create the device manager, initialise the drivers
+ pv::DeviceManager device_manager(context, driver, do_scan);
- if (restore_sessions)
- w.restore_sessions();
+ // Initialise the main window
+ pv::MainWindow w(device_manager);
+ w.show();
- if (!open_file.empty())
- w.add_session_with_file(open_file, open_file_format);
- else
- w.add_default_session();
+ if (restore_sessions)
+ w.restore_sessions();
+
+ if (!open_file.empty())
+ w.add_session_with_file(open_file, open_file_format);
+ else
+ w.add_default_session();
#ifdef ENABLE_SIGNALS
- if (SignalHandler::prepare_signals()) {
- SignalHandler *const handler =
- new SignalHandler(&w);
- QObject::connect(handler,
- SIGNAL(int_received()),
- &w, SLOT(close()));
- QObject::connect(handler,
- SIGNAL(term_received()),
- &w, SLOT(close()));
- } else {
- qWarning() <<
- "Could not prepare signal handler.";
- }
+ if (SignalHandler::prepare_signals()) {
+ SignalHandler *const handler = new SignalHandler(&w);
+ QObject::connect(handler, SIGNAL(int_received()),
+ &w, SLOT(close()));
+ QObject::connect(handler, SIGNAL(term_received()),
+ &w, SLOT(close()));
+ } else
+ qWarning() << "Could not prepare signal handler.";
#endif
- // Run the application
- ret = a.exec();
+ // Run the application
+ ret = a.exec();
+#ifndef ENABLE_STACKTRACE
} catch (exception& e) {
- qDebug() << e.what();
+ qDebug() << "Exception:" << e.what();
}
+#endif
#ifdef ENABLE_DECODE
// Destroy libsigrokdecode