asmaloney / asmcrashreport Goto Github PK
View Code? Open in Web Editor NEW๐ Installs signal handlers to capture stack traces for MinGW 32 and macOS builds.
License: MIT License
๐ Installs signal handlers to capture stack traces for MinGW 32 and macOS builds.
License: MIT License
Hi Alex,
To make it work on Ubuntu you have to change this line:
sigAction.sa_flags = SA_SIGINFO | SA_ONSTACK;
to:
sigAction.sa_flags = SA_SIGINFO;
Like on MACOS
this part is giving me an error:
// setup alternate stack
stack_t ss{
static_cast<void*>(sAlternateStack),
SIGSTKSZ,
0
};
if ( sigaltstack( &ss, nullptr ) != 0 )
{
err( 1, "sigaltstack" );
}
while this is stting up properly the sigalt:
stack_t ss;
ss.ss_sp = static_cast<void*>(sAlternateStack); //sAlternateStack;
ss.ss_size = SIGSTKSZ;
ss.ss_flags = 0; // Use the default flags (usually 0)
if (sigaltstack(&ss, nullptr) != 0) {
err(1, "sigaltstack");
}
Does it make any sense?
Even tough I am getting this log:
asmCrashReportTest v1.0.0
19 Mar 2024 @ 23:51:55
Caught SIGFPE: (integer divide by zero)
/lib/x86_64-linux-gnu/libpthread.so.0(+0x14420) [0x7fc6cdc00420]
/home/ubuntu/Desktop/__DEV__/asmCrashReport-master/build-test-Desktop_Qt_6_3_0_GCC_64bit-Debug/asmCrashReportTest(+0xad4b) [0x55ef2afe8d4b]
/home/ubuntu/Desktop/__DEV__/asmCrashReport-master/build-test-Desktop_Qt_6_3_0_GCC_64bit-Debug/asmCrashReportTest(+0xadb4) [0x55ef2afe8db4]
/home/ubuntu/Desktop/__DEV__/asmCrashReport-master/build-test-Desktop_Qt_6_3_0_GCC_64bit-Debug/asmCrashReportTest(+0xadd9) [0x55ef2afe8dd9]
/home/ubuntu/Desktop/__DEV__/asmCrashReport-master/build-test-Desktop_Qt_6_3_0_GCC_64bit-Debug/asmCrashReportTest(+0xac12) [0x55ef2afe8c12]
/home/ubuntu/Desktop/__DEV__/asmCrashReport-master/build-test-Desktop_Qt_6_3_0_GCC_64bit-Debug/asmCrashReportTest(+0xa966) [0x55ef2afe8966]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7fc6cd821083]
I am investinating over it...
Hello and thank you for contributing this code, which seems to be the most promising for bug reporting among all the ones I have searched for. In Windows 64-bit and MinGW64 (Obviously), I am not able to retrieve the function names using addr2line.exe.
I always get this kind of result:
[0] 0x00007ff6b8d385d9 ?? ??:0
[1] 0x00007ff6b8d38301 ?? ??:0
[2] 0x00007ff6b8d382ca ?? ??:0
[3] 0x00007ff6b8d384d5 ?? ??:0
[4] 0x00007ff6b8d34073 ?? ??:0
[5] 0x00007ff6b8d35692 ?? ??:0
[6] 0x00007ff6b8d31395 ?? ??:0
[7] 0x00007ff6b8d314c6 ?? ??:0
[8] 0x00007ffaa0bb257d ?? ??:0
[9] 0x00007ffaa226aa58 ?? ??:0
I am using the cygwin64 version, I have tried the version distributed on QT with MinGW and in no case does addr2line.exe return a value to me.
Question: Are memory values like 0x00007ffaa226aa58 (very high) correct?
Another question, why did you import it to work only in Release Mode and not in Debug mode?
I've been trying everything for 4 days but I can't see the light at the end of the tunnel.
Any help is absolutely welcome.
Hi,
After some trial I saw that this does not catch some failure exit like catching a throw.
I am trying to improve example like below.
Am I doing wrong, or should we add a function and get stack trace which will be called at a try catch block ? Maybe with CaptureStackBackTrace
?
#include <QApplication>
#include <QDebug>
#include <QMessageBox>
#include <assert.h>
#ifdef ASM_CRASH_REPORT
#include "asmCrashReport.h"
#endif
class crashTest
{
public:
void crashMe() { function1(); }
void accessViolation( int val )
{
qDebug() << Q_FUNC_INFO;
int * foo = NULL;
*foo = val;
}
void stackoverflow()
{
qDebug() << Q_FUNC_INFO;
int foo[10000];
(void)foo;
stackoverflow();
}
void throwError()
{
qDebug() << Q_FUNC_INFO;
throw "error";
}
void outOfBounds()
{
qDebug() << Q_FUNC_INFO;
std::vector<int> v;
v[0] = 5;
}
private:
void divideByZero( int val )
{
qDebug() << Q_FUNC_INFO << val;
int foo = val / 0;
}
void function2( int val )
{
++val;
divideByZero( val );
}
void function1()
{
function2( 41 );
}
};
int main( int argc, char** argv )
{
QApplication app( argc, argv );
app.setApplicationName( QStringLiteral( "asmCrashReportExample" ) );
app.setApplicationVersion( QStringLiteral( "1.0.0" ) );
#ifdef ASM_CRASH_REPORT
asmCrashReport::setSignalHandler( QString(), [] (const QString &inFileName, bool inSuccess) {
QString message;
if ( inSuccess )
{
message = QStringLiteral( "Sorry, %1 has crashed. A log file was written to:\n\n%2\n\nPlease email this to [email protected]." ).arg( QCoreApplication::applicationName(), inFileName );
}
else
{
message = QStringLiteral( "Sorry, %1 has crashed and we could not write a log file to:\n\n%2\n\nPlease contact [email protected]." ).arg( QCoreApplication::applicationName(), inFileName );
}
QMessageBox::critical( nullptr, QObject::tr( "%1 Crashed" ).arg( QCoreApplication::applicationName() ), message );
});
#endif
int methode = 0;
if (argc > 1)
{
methode = QString(argv[1]).toInt();
}
crashTest ct;
switch (methode) {
case 0:
ct.crashMe();
break;
case 1:
ct.accessViolation(17);
break;
case 2:
ct.stackoverflow();
break;
case 3:
ct.throwError();
break;
case 4:
ct.outOfBounds();
break;
default:
qDebug() << "Invalid methode";
return 1;
}
return app.exec();
}
Hi,
Thanks for this tool, I have compiled it and it's working fine for the example project which is given in the repo.
But what I did is, from mainwindow.cpp I run one class into other thread and used the same function given in the example to crash the application on that thread.
But no log came after application crashes.
I want to use it for a multithreaded application, will this work?
When "Generate separate debug info" is checked in Qt Creator, the atos
lookup fails.
For starters, the .pri file needs QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
and QMAKE_CPPFLAGS_RELEASE_WITH_DEBUGINFO
options modified like the others to turn off optimization.
Then the atos
command needs to be changed to handle the external dSYM file (I think?).
I don't plan to do this, but if someone wants to take a swing at it, please feel free.
Hi,
I tried my development env which is Ubuntu 16.04 64bit, and got some problems. I got prebuilt Qt 5.12 which installed by Qt installer.
First, line endings are not LF. Editing and sending to git may cause problems, so did not try to add a PR.
Could not catch divide by zero, so tried with access violation.
stack_t
have different order than you initialized. Got asmCrashReportExample: sigaltstack: Invalid argument
error. I have fixed by adding a correct ordered initialization.
With SA_ONSTACK
, does not call handler at access violation. Also, cannot catch stack overflow with or without SA_ONSTACK
.
diff --git a/src/asmCrashReport.cpp b/src/asmCrashReport.cpp
index 3799d11..bfbcc89 100644
--- a/src/asmCrashReport.cpp
+++ b/src/asmCrashReport.cpp
@@ -391,7 +391,11 @@ namespace asmCrashReport
void _posixSetupSignalHandler()
{
// setup alternate stack
- stack_t ss{ static_cast<void*>(sAlternateStack), SIGSTKSZ, 0 };
+#ifdef Q_OS_LINUX^M
+ stack_t ss {static_cast<void*>(sAlternateStack), 0, SIGSTKSZ};^M
+#else^M
+ stack_t ss {static_cast<void*>(sAlternateStack), SIGSTKSZ, 0};^M
+#endif^M
if ( sigaltstack( &ss, nullptr ) != 0 )
{
@@ -409,7 +413,8 @@ namespace asmCrashReport
// backtrace() doesn't work on macOS when we use an alternate stack
sigAction.sa_flags = SA_SIGINFO;
#else
- sigAction.sa_flags = SA_SIGINFO | SA_ONSTACK;
+ // sigAction.sa_flags = SA_SIGINFO | SA_ONSTACK; // _posixSignalHandler does not called with SA_ONSTACK^M
+ sigAction.sa_flags = SA_SIGINFO;^M
#endif
if ( sigaction( SIGSEGV, &sigAction, nullptr ) != 0 ) { err( 1, "sigaction" ); }
I have checked sigaction.h
and it seems disable. I tried to add below defines before csignal
but no luck. Also, IDE shows _GNU_SOURCE
already defined.
#define _XOPEN_SOURCE 700
#define _GNU_SOURCE
Here the catched output:
asmCrashReportTest v1.0.0
04 Ara 2019 @ 10:02:19
Caught SIGSEGV: Segmentation Fault
/lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7fefff690390]
/home/hk/p/asmCrashReport/build-test-Desktop_Qt_5_12_5_GCC_64bit-Release/asmCrashReportTest() [0x4028f1]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0) [0x7feffed3d830]
It works quite well when a crash happen in exe.
But, if a crash is in DLL or plugin loaded with QPluginLoader it doesn't get decoded well.
Any suggestion how to catch from DLL or plugin?
Platform: Windows Mingw 64
Here it comes an example:
RTSuite v1.7.0
02 Mar 2020 @ 20:55:02
EXCEPTION_INT_DIVIDE_BY_ZERO
[0] 0x000000006f10501d ?? ??:0
[1] 0x0000000068aa2720 ?? ??:0
[2] 0x0000000068aadb7a ?? ??:0
[3] 0x0000000068aa334b ?? ??:0
[4] 0x00000000013c7c8c ?? ??:0
[5] 0x00000000013ced23 ?? ??:0
[6] 0x0000000068a758c8 ?? ??:0
[7] 0x0000000068ad1344 ?? ??:0
[8] 0x0000000068ad15a2 ?? ??:0
[9] 0x00007ff98f3f5b6d ?? ??:0
[10] 0x00007ff98f3f5562 ?? ??:0
[11] 0x0000000068ad0dcb ?? ??:0
[12] 0x000000006a8fb565 ?? ??:0
[13] 0x0000000068a7395e ?? ??:0
[14] 0x000000000158e109 ?? ??:0
[15] 0x000000006f10b2f1 ?? ??:0
[16] 0x000000006f110202 ?? ??:0
[17] 0x000000006f110343 ?? ??:0
[18] 0x0000000068aa26d3 ?? ??:0
[19] 0x000000000163056f ?? ??:0
[20] 0x0000000001635cff ?? ??:0
[21] 0x0000000068aa2600 ?? ??:0
[22] 0x00000000015df9dd ?? ??:0
[23] 0x0000000001405378 ?? ??:0
[24] 0x000000000149c6ae ?? ??:0
[25] 0x00000000015e862e ?? ??:0
[26] 0x0000000068a74430 ?? ??:0
[27] 0x00000000013c7c65 ?? ??:0
[28] 0x00000000013cfd1a ?? ??:0
[29] 0x0000000068a75a88 ?? ??:0
[30] 0x00000000013ce118 ?? ??:0
[31] 0x0000000001419edd ?? ??:0
[32] 0x000000000141caa3 ?? ??:0
[33] 0x00000000013c7c8c ?? ??:0
[34] 0x00000000013ced23 ?? ??:0
[35] 0x0000000068a75a88 ?? ??:0
[36] 0x0000000061977824 ?? ??:0
[37] 0x00000000619789b5 ?? ??:0
[38] 0x0000000061950f2c ?? ??:0
[39] 0x0000000068ad187a ?? ??:0
[40] 0x00007ff98f3f5b6d ?? ??:0
[41] 0x00007ff98f3f5562 ?? ??:0
[42] 0x0000000068ad0dcb ?? ??:0
[43] 0x000000006a8fb565 ?? ??:0
[44] 0x0000000068a7395e ?? ??:0
[45] 0x0000000068a7cd87 ?? ??:0
[46] 0x0000000000409108 qMain(int, char**) at main.cpp:123
[47] 0x0000000000412610 /tools/addr2line: Dwarf Error: Could not find abbrev number 69.
?? at qtmain_win.cpp:?
[48] 0x00000000004013c7 /tools/addr2line: Dwarf Error: Could not find abbrev number 69.
?? at crtexe.c:?
[49] 0x00000000004014cb /tools/addr2line: Dwarf Error: Could not find abbrev number 69.
?? at crtexe.c:?
[50] 0x00007ff9909b7bd4 ?? ??:0
[51] 0x00007ff990c0ced1 ?? ??:0
HI,
Thank you for your simple and powerfull crash report tool!
It works on my project with MinGW32.
The only thing I noticed is that after importing the asmCrashReport, my exe file in release mode has increased a lot! (same size as in debug mode).
Is it due to a compiler setting or something ?
Thanks for your help.
Hi,
there is no licensing information in the repository, meaning that this is not useable freely as default copyright laws apply.
Could you please add a license to the project ?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.