Discussion:
Get module where crash happened
(too old to reply)
Richard
2009-09-28 11:15:22 UTC
Permalink
I have a program which loads and executes code in other supplier's DLLs. I
am catching program crashes using SetUnhandledExceptionFilter() and
producing a minidump which can be sent to me for analysis.

However I would like to be able to display some basic information about the
crash to the user - probably in a MessageBox just after calling
MiniDumpWriteDump().

It would be helpful if I could find out the module where the crash occured
and display that in the MessageBox because it would immediately tell me if
the problem is in my code or someone else's DLL.

Is there a way to find the module name (e.g. "fred.dll") from the exception
info that I'm passing to MiniDumpWriteDump() ?
Ben Voigt [C++ MVP]
2009-09-28 21:24:20 UTC
Permalink
http://msdn.microsoft.com/en-us/library/ms681336(VS.85).aspx

Pass in arg->ExceptionRecord->ExceptionAddress, where arg is the parameter
of your unhandled exception filter.
Post by Richard
I have a program which loads and executes code in other supplier's DLLs. I
am catching program crashes using SetUnhandledExceptionFilter() and
producing a minidump which can be sent to me for analysis.
However I would like to be able to display some basic information about
the crash to the user - probably in a MessageBox just after calling
MiniDumpWriteDump().
It would be helpful if I could find out the module where the crash occured
and display that in the MessageBox because it would immediately tell me if
the problem is in my code or someone else's DLL.
Is there a way to find the module name (e.g. "fred.dll") from the
exception info that I'm passing to MiniDumpWriteDump() ?
Richard
2009-10-01 15:21:27 UTC
Permalink
Post by Ben Voigt [C++ MVP]
http://msdn.microsoft.com/en-us/library/ms681336(VS.85).aspx
Pass in arg->ExceptionRecord->ExceptionAddress, where arg is the parameter
of your unhandled exception filter.
I've added this to the start of my handler which now begins:

static LONG WINAPI myfilter(_EXCEPTION_POINTERS *exc_ptr)
{
BOOL q;
q = SymInitialize(GetCurrentProcess(), NULL, FALSE);

IMAGEHLP_MODULE64 modinfo;
modinfo.SizeOfStruct = sizeof(IMAGEHLP_MODULE64);
q = SymGetModuleInfo64(GetCurrentProcess(),
(DWORD64)exc_ptr->ExceptionRecord->ExceptionAddress,
&modinfo);
......

and tested it by dereferencing a NULL pointer in my own code.

SymInitialize returns TRUE, but SymGetModuleInfo64 returns FALSE and error
code 126 (ERROR_MOD_NOT_FOUND).

Bearing in mind that my program will be a Release build on a client's
machine and there will be no symbol file for my own code nor for the other
supplier's DLLs, so in this situation is it even possible to find out the
module name?

Does SymInitialise need access to some symbol files just to find the module
name or pathname with SymGetModuleInfo64 ?
Ben Voigt [C++ MVP]
2009-10-02 18:03:21 UTC
Permalink
Post by Richard
Does SymInitialise need access to some symbol files just to find the
module name or pathname with SymGetModuleInfo64 ?
The relevant information is pretty much all needed for performing
relocations and dynamic unloads (e.g. FreeLibrary), I don't see why you'd
need a symbol file for that.

You're not using any JIT or anything that would put code in dynamically
allocated memory pages, are you?

Does the address in the exception structure match the address in your
debugger's disassembly view? (e.g. turn on first-chance exception handling
in the debugger, copy the address, place breakpoint in your filter, continue
so the filter breakpoint is reached, compare the values)

Loading...