jrfonseca / drmingw

Postmortem debugging tools for MinGW.
GNU Lesser General Public License v2.1
273 stars 53 forks source link

Help using mgwhelp for stack tracing. #48

Closed MKKnauer closed 4 years ago

MKKnauer commented 4 years ago

I'm trying to use mgwhelp to get a call stack after a Qt assert, but I can't figure out how to get the right context (and no, I don't have a lot of experience with this, so any help would be useful).

The code I've seen used elsewhere (with dbghelp) is this:

    PEXCEPTION_POINTERS pPointers = GetExceptionInformation();
    CONTEXT* context = pPointers->ContextRecord;

But GetExceptionInformation() doesn't seem to be available (or isn't linking correctly for me) in mgwhelp.

I am successfully using exchndl for crash reports, but in the case of these Qt asserts, nothing is generated (I'm assuming this is because Qt is handling them and then exiting instead of having an exception thrown).

jrfonseca commented 4 years ago

Yes, it seems there's no exception per se.

Using DbgHelp API (ditto for MgwHelp) directly requires a lot of work. They are full of subtle quirks. I really don't recommend using them directly unless you're writing general purpose debugging tools/libraries.

I think the most practical way to do this is to:

I don't know if Q_ASSERT() provides some callback that's called when assertions failed. If it did, it would eliminate one step above.

MKKnauer commented 4 years ago

Thanks for the quick reply.

The issue I'm dealing with is Q_ASSERTs inside Qt libraries (ex: ASSERT failure in QList::at: "index out of range") so I'm trying to learn which of my calls to at() passed the bad value. I'll see what I can work out through their assert calls.

Thanks again.

jrfonseca commented 4 years ago

In that case I recommend you use the catchsegv utility that's included with drmingw. It will dump the stack back trace when the program aborts.

So if you run something like

 catchsegv yourapp.exe

it should catch when Q_ASSERT() terminates the process with a non-zero exit code, and dump the stack back trace to stderr.

MKKnauer commented 4 years ago

Thank you again - that does the trick.

I've set it up to redirect the stderr to a file, and it leads me to one final question. After the crash, I do get the stack trace but catchsegv just sort of sits there after that. I end up hitting ctrl-c twice to get it to exit.

I tried setting a timeout to see what that would do and got the following message a little while after the stack dump: catchsegv: time out (60 sec) exceeded catchsegv: error: failed to interrupt target (0x00000005)

If I run my app and exit without crashing, catchsegv exits with no problem.

Any thoughts?

jrfonseca commented 4 years ago

Sometimes catchsegv takes a long time downloading symbols from Microsoft symbol store. Perhaps it's a matter of waiting.

Otherwise it could be a bug. I'll need to repro to investigate it further though

MKKnauer commented 4 years ago

Looks like that was is it. Thanks once more.