backtrace and sentry.io support

This commit is contained in:
Justin Hammond 2019-12-31 17:18:48 +08:00
parent d8ea87468e
commit 5daa58db6a
3 changed files with 137 additions and 12 deletions

View file

@ -13,7 +13,7 @@ TEMPLATE = lib
VERSION = 1.0.0
CONFIG += silent file_copies
CONFIG += silent file_copies force_debug_info
!versionAtLeast(QT_VERSION, 5.11.2):error("Use at least Qt version 5.11.2")
include(../qt-openzwave.pri)
@ -87,8 +87,10 @@ COPIES += copyrepheaders
unix {
target.path = /usr/local/lib
INSTALLS += target
QMAKE_CXXFLAGS += -g1
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS += -g
QMAKE_LFLAGS += -rdynamic
QMAKE_STRIP = echo
}
#LIBS += -L../../open-zwave -lopenzwave
@ -97,6 +99,13 @@ macx {
QMAKE_POST_LINK=$$top_srcdir/updaterpath.sh $(TARGET)
}
QMAKE_CFLAGS_RELEASE -= -O
QMAKE_CFLAGS_RELEASE -= -O1
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE -= -O
QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2
message(" ")
message("Summary:")
message(" OpenZWave Path: $$OZW_LIB_PATH")

View file

@ -1,3 +1,10 @@
#ifdef BP_LINUX
#include "client/linux/handler/exception_handler.h"
#include "common/linux/http_upload.h"
#define HAVE_BP
#endif
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
@ -11,11 +18,89 @@
#include "mqttpublisher.h"
#endif
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <cxxabi.h>
void backtrace(int sig = 0)
{
Q_UNUSED(sig);
unw_cursor_t cursor;
unw_context_t context;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
int n=0;
while ( unw_step(&cursor) ) {
unw_word_t ip, sp, off;
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
char symbol[256] = {"<unknown>"};
char *name = symbol;
if ( !unw_get_proc_name(&cursor, symbol, sizeof(symbol), &off) ) {
int status;
if ( (name = abi::__cxa_demangle(symbol, NULL, NULL, &status)) == 0 )
name = symbol;
}
printf("#%-2d 0x%016" PRIxPTR " sp=0x%016" PRIxPTR " %s + 0x%" PRIxPTR "\n",
++n,
static_cast<uintptr_t>(ip),
static_cast<uintptr_t>(sp),
name,
static_cast<uintptr_t>(off));
if ( name != symbol )
free(name);
}
#ifndef HAVE_BP
exit(-1);
#endif
}
void crash() { volatile int* a = (int*)(NULL); *a = 1; }
#ifdef HAVE_BP
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor,
void* context, bool succeeded) {
Q_UNUSED(context);
printf("Dump path: %s\n", descriptor.path());
if (succeeded == true) {
std::map<string, string> parameters;
std::map<string, string> files;
std::string proxy_host;
std::string proxy_userpasswd;
std::string url("https://sentry.io/api/1868130/minidump/?sentry_key=e086ba93030843199aab391947d205da");
// Add any attributes to the parameters map.
// Note that several attributes are automatically extracted.
parameters["product_name"] = QCoreApplication::applicationName().toStdString();
parameters["release"] = QCoreApplication::applicationVersion().toStdString();
qtozwdaemon *daemon = static_cast<qtozwdaemon *>(context);
parameters["OpenZWave_Version"] = daemon->getManager()->getVersionAsString().toStdString();
parameters["QTOpenZWave_Version"] = daemon->getQTOpenZWave()->getVersion().toStdString();
parameters["QT_Version"] = qVersion();
files["upload_file_minidump"] = descriptor.path();
std::string response, error;
//bool success = google_breakpad::HTTPUpload::SendRequest(url, parameters, files, proxy_host, proxy_userpasswd, "", &response, NULL, &error);
//printf("%d - %s\n", success, response.c_str());
}
backtrace();
return succeeded;
}
#endif
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QCoreApplication::setApplicationName("ozwdaemon");
QCoreApplication::setApplicationVersion("0.1");
@ -192,7 +277,23 @@ int main(int argc, char *argv[])
mqttpublisher mqttpublisher(&settings);
mqttpublisher.setOZWDaemon(&daemon);
#endif
#ifdef HAVE_BP
QString bppath = QString::fromLocal8Bit(qgetenv("BP_DB_PATH"));
if (bppath.isEmpty())
bppath = QStandardPaths::standardLocations(QStandardPaths::TempLocation).at(0);
google_breakpad::MinidumpDescriptor descriptor(bppath.toStdString());
google_breakpad::ExceptionHandler eh(descriptor, NULL, dumpCallback, static_cast<void *>(&daemon), true, -1);
#else
signal(SIGSEGV, backtrace);
signal(SIGABRT, backtrace);
#endif
daemon.setSerialPort(parser.value(serialPort));
daemon.startOZW();
assert(0);
crash();
return a.exec();
}

View file

@ -6,7 +6,7 @@ TARGET = ../ozwdaemon
VERSION = 0.1.0
CONFIG += c++11 console link_pkgconfig silent
CONFIG += c++11 console link_pkgconfig silent force_debug_info
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
@ -15,11 +15,6 @@ CONFIG -= app_bundle
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS QT_MESSAGELOGCONTEXT APP_VERSION=$$VERSION
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
qtHaveModule(mqtt) {
PKGCONFIG += RapidJSON
QT += mqtt
@ -121,19 +116,34 @@ HEADERS += \
qtozwdaemon.h \
include(../qt-openzwave.pri)
INCLUDEPATH += ../qt-openzwave/include/
BreakPad {
exists( $$top_srcdir/../breakpad/src/src/client/linux/libbreakpad_client.a) {
INCLUDEPATH += $$top_srcdir/../breakpad/src/src/
SOURCES += $$top_srcdir/../breakpad/src/src/common/linux/http_upload.cc
LIBS += $$top_srcdir/../breakpad/src/src/client/linux/libbreakpad_client.a -ldl
DEFINES += BP_LINUX
message("Building with BreakPad");
} else {
error("Can't find BreakPad Library");
}
}
unix {
# Default rules for deployment.
target.path = /usr/local/bin
INSTALLS += target
PKGCONFIG += libunwind libcurl
LIBS += -lresolv -L../qt-openzwave/ -lqt-openzwave -L../qt-openzwavedatabase/ -lqt-openzwavedatabase
INCLUDEPATH += ../qt-openzwavedatabase/include/
QMAKE_CXXFLAGS += -g1
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS += -g
QMAKE_LFLAGS += -rdynamic
QMAKE_STRIP = echo
}
@ -146,4 +156,9 @@ macx {
QMAKE_POST_LINK=$$top_srcdir/updaterpath.sh $(TARGET)
}
QMAKE_CFLAGS_RELEASE -= -O
QMAKE_CFLAGS_RELEASE -= -O1
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE -= -O
QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2