← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Print stacktrace when SIGSEGV or SIGABRT appears

 

Hi Thomas,

I tried to build this on windows and ran into some issues.  It looks
like wxDebugReport only works when wx is built with compilers that
support structured exception handling (SEH) which most likely means
msvc.  I don't think gcc supports SEH yet but I could be wrong.  This
means that you have to wrap the wxHandleFatalExceptions() call in an #if
wxUSE_ON_FATAL_EXCEPTION/#endif block just in case wxWidgets is built
without SEH on windows.  I've attached a patch that fixes this issue.
If gcc does support seh, we will have to change the wxwidgets build
config on msys2 to enable it.  If gcc does not support seh and we want
to provide debug reports on windows, we will have to build kicad with
msvc. :(  Yet one more cross platform joy!  Would one of our macos devs
check to make sure this patch works?

Cheers,

Wayne

On 9/21/2018 11:48 AM, Thomas Pointhuber wrote:
> Hi Wayne,
> 
> thanks for proposing wxDebugReport. I didn't knew about that. I fixed
> the format issues using clang-format, and fixed a little windows bug as
> well (which was found by an wx developer). Furthermore I added some
> preprocessor macro to not overwrite AddContext for wx versions > 3.1.1
> because It's already fixed in upstream since a day and will be included
> in future releases :)
> 
> https://github.com/wxWidgets/wxWidgets/pull/940
> 
> Personally, I only tested this on Linux x64 with wx 3.1
> 
> Regards,
> Thomas
> 
> Am 21.09.18 um 16:01 schrieb Wayne Stambaugh:
>> Hi Thomas,
>>
>> I like this much better than your previous patch.  What platforms have
>> you tested this on?  Also, please fix the coding policy[1] issues in
>> your patch.  You can use uncrustify or clang-format if you don't want to
>> do it by hand.
>>
>> Cheers,
>>
>> Wayne
>>
>> [1]:
>> http://docs.kicad-pcb.org/doxygen/md_Documentation_development_coding-style-policy.html
>>
>> On 9/20/2018 5:49 AM, Thomas Pointhuber wrote:
>>> Hi Tom,
>>>
>>> based on your proposal I fixed the Stack Walker (I think it should also
>>> be fixed upstream). I was required to duplicate quite some wx code and
>>> we probably need to add an additional copyright notice.
>>>
>>> The stack now looks like this, and I verified that I can find the
>>> location of a crash using addr2line:
>>> ```
>>>   <stack>
>>>     <frame level="0" offset="0004752b" address="55aeb750c52b"
>>> module="pcbnew/pcbnew"/>
>>>     <frame level="1" offset="00045e37" address="55aeb750ae37"
>>> module="pcbnew/pcbnew"/>
>>>     <frame level="2" offset="000443dc" address="55aeb75093dc"
>>> module="pcbnew/pcbnew"/>
>>>     <frame level="3" offset="001c830c" address="7f60b12af30c"
>>> module="/usr/lib/libwx_baseu-3.1.so.1"/>
>>>     <frame level="4" offset="000123c0" address="7f60af51a3c0"
>>> module="/usr/lib/libpthread.so.0"/>
>>>     <frame level="5" function="__poll" offset="00000051"
>>> address="7f60af434bb1" module="/usr/lib/libc.so.6"/>
>>>     <frame level="6" offset="0006cee0" address="7f60ae795ee0"
>>> module="/usr/lib/libglib-2.0.so.0"/>
>>>     <frame level="7" function="g_main_loop_run" offset="000000d2"
>>> address="7f60ae796f62" module="/usr/lib/libglib-2.0.so.0"/>
>>>     <frame level="8" function="gtk_dialog_run" offset="0000015e"
>>> address="7f60aedb914e" module="/usr/lib/libgtk-x11-2.0.so.0"/>
>>>     <frame level="9" function="wxMessageDialog::ShowModal()"
>>> offset="00000083" address="7f60b1acc463"
>>> module="/usr/lib/libwx_gtk2u_core-3.1.so.1"/>
>>>     ...
>>> ```
>>>
>>> the current code is more or less a minimal implementation. It would be a
>>> good idea to add the build parameters like displayed in about_config,
>>> configuration files, environment variables,... in the future as well.
>>>
>>> Regards,
>>> Thomas
>>>
>>> Am 19.09.18 um 20:36 schrieb Tomasz Wlostowski:
>>>> On 19/09/18 20:13, Thomas Pointhuber wrote:
>>>>>
>>>>> I rewrote it to use wxDebugReport and wxHandleFatalExceptions. What I
>>>>> noticed (at least for my build setup), the stack-trace is unusable in
>>>>> this version for me because it lacks all kicad internals:
>>>>
>>>> Hi Thomas,
>>>>
>>>> I like a lot your idea of having a builtin crash reporter (especially
>>>> under Windows/OSX where people struggle to get a stack trace, Linux
>>>> users sooner or later are forced to figure out how to use a
>>>> debugger...). I also second Wayne's comment that it must work on all
>>>> platforms, so please no glibc-specific code.
>>>>
>>>> wxDebugReport is IMHO a good starting point, but for some reasons that
>>>> are beyond my understanding, wxWidgets doesn't output raw addresses of
>>>> the functions in the call stack and if there's no symbols in the file
>>>> (and its dependent DLLs), the trace file is indeed useless.
>>>>
>>>> Luckily wxStackFrame contains all the necessary information. The
>>>> function to blame is XmlStackWalker::OnStackFrame(...). A quick hack
>>>> like the one below can add raw addresses to the XML dump:
>>>>
>>>> -- snip --
>>>>
>>>>     if(func.empty())
>>>>     	func = wxT("<unknown>");
>>>>
>>>>     nodeFrame->AddAttribute(wxT("function"), func);
>>>>     HexProperty(nodeFrame, wxT("offset"), frame.GetOffset());
>>>>     HexProperty(nodeFrame, wxT("address"), reinterpret_cast<long
>>>> unsigned int>(frame.GetAddress()));
>>>>
>>>> -- snip --
>>>>
>>>> Cheers,
>>>> Tom
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Mailing list: https://launchpad.net/~kicad-developers
>>>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>>>> Unsubscribe : https://launchpad.net/~kicad-developers
>>>> More help   : https://help.launchpad.net/ListHelp
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>>
>> _______________________________________________
>> Mailing list: https://launchpad.net/~kicad-developers
>> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~kicad-developers
>> More help   : https://help.launchpad.net/ListHelp
diff --git a/common/single_top.cpp b/common/single_top.cpp
index fce8a0b35..b777b4c32 100644
--- a/common/single_top.cpp
+++ b/common/single_top.cpp
@@ -126,7 +126,9 @@ struct APP_SINGLE_TOP : public wxApp
 {
     APP_SINGLE_TOP(): wxApp()
     {
+#if wxUSE_ON_FATAL_EXCEPTION
         wxHandleFatalExceptions();
+#endif
 
 #if defined (__LINUX__)
         // Disable proxy menu in Unity window manager. Only usual menubar works with wxWidgets (at least <= 3.1)
diff --git a/kicad/kicad.cpp b/kicad/kicad.cpp
index c80f66665..25d9a2b57 100644
--- a/kicad/kicad.cpp
+++ b/kicad/kicad.cpp
@@ -220,7 +220,9 @@ struct APP_KICAD : public wxApp
 {
     APP_KICAD(): wxApp()
     {
+#if wxUSE_ON_FATAL_EXCEPTION
         wxHandleFatalExceptions();
+#endif
 
 #if defined (__LINUX__)
         // Disable proxy menu in Unity window manager. Only usual menubar works with

References