[Interest] Stack trace on Windows
rollastre at gmail.com
rollastre at gmail.com
Wed Apr 3 09:38:36 CEST 2019
Hi.
I use this
in the PRO file
windows {
LIBS+=-ldbghelp#beabletoprintthestacktrace
}
then
intmain(intargc,char*argv[])
{
//0.somepreliminarystuff
//printstacktraceuponSegmentationFault
signal(SIGSEGV,os_signal_print_stack_trace);/*segmentviolation*/ // you could do the same on other OS signals. E.g.
//signal(SIGINT,os_signal_print_stack_trace);/*interrupt*/
//signal(SIGILL,os_signal_print_stack_trace);/*illegalinstruction-invalidfunctionimage*/
//signal(SIGFPE,os_signal_print_stack_trace);/*floatingpointexception*/
... }
and then
#if(defined(__OS__MACOSX__)||defined(__OS__LINUX__))
#include<execinfo.h>
#include<signal.h>
#include<stdlib.h>
voidos_signal_print_stack_trace(intsig)
{
void*array[10];
size_tsize;
//getvoid*'sforallentriesonthestack
size=backtrace(array,10);
//printoutalltheframestostderr
fprintf(stderr,"Error:signal%d:\n",sig);
backtrace_symbols_fd(array,size,2);
system_crash_event();
log_fatal("["__OS__":"__RUNTIME__":"__LIB_BUILD_TYPE__"]:programfoundanunrecoverableerrorandmustquit");
exit(-10);
}
#elifdefined(__OS__WINDOWS__)
#include<DbgHelp.h>
#include<sstream>
voidos_signal_print_stack_trace(intsig)
{
//AllDbgHelpfunctions,suchasthisone,aresinglethreaded.Therefore,callsfrommorethan
//onethreadtothisfunctionwilllikelyresultinunexpectedbehaviorormemorycorruption.To
//avoidthis,youmustsynchronizeallconcurrentcallsfrommorethanonethreadtothisfunction.
unsignedinti;
void*stack[100];
unsignedshortframes;
SYMBOL_INFO*symbol;
HANDLEprocess;
process=GetCurrentProcess();
SymInitialize(process,NULL,TRUE);
frames=CaptureStackBackTrace(0,100,stack,NULL);
symbol=(SYMBOL_INFO*)calloc(sizeof(SYMBOL_INFO)+256*sizeof(char),1);
symbol->MaxNameLen=255;
symbol->SizeOfStruct=sizeof(SYMBOL_INFO);
for(i=0;i<frames;i++)
{
SymFromAddr(process,(DWORD64)(stack[i]),0,symbol);
std::stringstreamss;
ss<<frames-i-1<<":"<<symbol->Name<<"-0x"<<std::hex<<symbol->Address<<std::dec;
log_error(ss.str());
}
free(symbol);
log_fatal("["__OS__":"__RUNTIME__":"__LIB_BUILD_TYPE__"]:programfoundanunrecoverableerrorandmustquit");
exit(-10);
}
Regards.
On 02/04/2019 19:39, Boris Ralchenko wrote:
> Hello,
>
> Question to Windows gurus - what is the best way to get stack trace
> after crash? Say Qt/QML application runs in QA environment, not
> development. MacOS creates log with the stack trace, I am looking to
> something similar on Windows.
>
>
> Regards,
> Boris Ralchenko.
>
>
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
On 02/04/2019 19:39, Boris Ralchenko wrote:
> Hello,
>
> Question to Windows gurus - what is the best way to get stack trace
> after crash? Say Qt/QML application runs in QA environment, not
> development. MacOS creates log with the stack trace, I am looking to
> something similar on Windows.
>
>
> Regards,
> Boris Ralchenko.
>
>
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190403/2dc26623/attachment.html>
More information about the Interest
mailing list