Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ EXCEPTION_INT_DIVIDE_BY_ZERO
[4] 0x0000000000403388 qMain(int, char**) at C:\dev\asmCrashReport\build-example-Qt_5_9_1_MinGW_32bit/../example/main.cpp:61
[5] 0x0000000000404592 ?? at qtmain_win.cpp:?
```
Linux (GCC 64bit):
```
asmCrashReportTest v1.0.0
04 янв. 2020 @ 22:46:22

Caught SIGFPE: (integer divide by zero)

/lib/x86_64-linux-gnu/libpthread.so.0(+0x13f40) [0x7f5fc497bf40]
/home/pavelk.ru/Projects/asmCrashReport/build-test-Desktop_Qt_5_12_3_GCC_64bit-Release/asmCrashReportTest(crashTest::_divideByZero(int) у main.cpp:32 (discriminator 6)
/home/pavelk.ru/Projects/asmCrashReport/build-test-Desktop_Qt_5_12_3_GCC_64bit-Release/asmCrashReportTest(crashTest::_function2(int) у main.cpp:40
/home/pavelk.ru/Projects/asmCrashReport/build-test-Desktop_Qt_5_12_3_GCC_64bit-Release/asmCrashReportTest(crashTest::_function1() у main.cpp:45
/home/pavelk.ru/Projects/asmCrashReport/build-test-Desktop_Qt_5_12_3_GCC_64bit-Release/asmCrashReportTest(crashTest::divideByZero() у main.cpp:14
/home/pavelk.ru/Projects/asmCrashReport/build-test-Desktop_Qt_5_12_3_GCC_64bit-Release/asmCrashReportTest(main+0x157) [0x558bdea937f4]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xeb) [0x7f5fc4596b6b]
```

Pull Requests
==
Expand Down
15 changes: 15 additions & 0 deletions asmCrashReport.pri
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ CONFIG (release, release|debug) {
LIBS += "-L$$PWD/Win/WinDebug" -lDbghelp
}

linux {
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO -= -O2
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -O2

QMAKE_CFLAGS_RELEASE += -g -fno-pie -fno-omit-frame-pointer -O0
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -fno-pie -fno-omit-frame-pointer -O0
QMAKE_CXXFLAGS_RELEASE += -g -fno-pie -fno-omit-frame-pointer -O0
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -fno-pie -fno-omit-frame-pointer -O0

QMAKE_LFLAGS_RELEASE += -rdynamic
LIBS += -ldl
}

mac {
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO -= -O2
Expand Down
32 changes: 28 additions & 4 deletions src/asmCrashReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#include <execinfo.h>
#endif

#ifdef Q_OS_LINUX
#include <dlfcn.h>
#endif

#include "asmCrashReport.h"


Expand Down Expand Up @@ -106,17 +110,27 @@ namespace asmCrashReport
"-arch", "x86_64",
cAddrStr
};
#else
#elif defined (Q_OS_WIN)
// Uses addr2line
const QString cProgram = QStringLiteral( "%1/tools/addr2line" ).arg( QCoreApplication::applicationDirPath() );

const QStringList cArguments = {
"-f",
"-p",
"-s",
"-e", inProgramName,
cAddrStr
};
#elif defined (Q_OS_LINUX)
// Uses addr2line
const QString cProgram = QStringLiteral( "addr2line" );
const QStringList cArguments = {
"-f",
"-p",
"-s",
"-C",
"-e", inProgramName,
cAddrStr
};
#endif

sProcess->setProgram( cProgram );
Expand Down Expand Up @@ -314,12 +328,17 @@ namespace asmCrashReport

if ( !cSymbol.isNull() )
{
#ifdef Q_OS_LINUX
Dl_info symbolInfo;
if ( dladdr(sStackTraces[i], &symbolInfo)!=0) {
sStackTraces[i] = reinterpret_cast<void*>(qintptr(sStackTraces[i])-qintptr(symbolInfo.dli_fbase));
}
#endif
QString locationStr = _addressToLine( sProgramName, sStackTraces[i] );

if ( !locationStr.isEmpty() )
{
int matchStart = match.capturedStart( 1 );

message.replace( matchStart, message.length() - matchStart, locationStr );
}
}
Expand Down Expand Up @@ -413,7 +432,10 @@ namespace asmCrashReport
void _posixSetupSignalHandler()
{
// setup alternate stack
stack_t ss{ static_cast<void*>(sAlternateStack), SIGSTKSZ, 0 };
stack_t ss;
ss.ss_sp = static_cast<void*>(sAlternateStack);
ss.ss_size = SIGSTKSZ;
ss.ss_flags = 0;

if ( sigaltstack( &ss, nullptr ) != 0 )
{
Expand All @@ -430,6 +452,8 @@ namespace asmCrashReport
#ifdef __APPLE__
// backtrace() doesn't work on macOS when we use an alternate stack
sigAction.sa_flags = SA_SIGINFO;
#elif defined (Q_OS_LINUX)
sigAction.sa_flags = SA_SIGINFO;
#else
sigAction.sa_flags = SA_SIGINFO | SA_ONSTACK;
#endif
Expand Down