On Fri, 11 Feb 2011, Ozkan Sezer wrote:

On Fri, Feb 11, 2011 at 11:35 AM, Kai Tietz <[email protected]> wrote:
2011/2/11 Joel Dice <[email protected]>:
Hi all,

My application uses AddVectoredExceptionHandler to register an exception
handler which, if it can't handle the exception, tries to create a mini
dump file for later analysis.  This involves using MiniDumpWriteDump from
dbghelp.dll, which accepts a pointer to a MINIDUMP_EXCEPTION_INFORMATION
instance which wraps the LPEXCEPTION_POINTERS instance provided to the
exception handler by the OS.

All this works great on 32-bit systems, but crashes on 64-bit ones.  To
find out why, I ran my app in WinDbg and found that code in
MiniDumpWriteDump was triggering an EXCEPTION_ACCESS_VIOLATION.  Tracing
through the disassembled code revealed that MiniDumpWriteDump is looking
for the ExceptionPointers field at a four byte offset from the beginning
of the MINIDUMP_EXCEPTION_INFORMATION instance I passed as a parameter.
However, the natural alignment of that field is 8 bytes, so GCC added
padding after the first field (ThreadId) to achieve that alignment.

Once I realized what was happening, I defined my own version of
MINIDUMP_EXCEPTION_INFORMATION with __attribute__ ((__packed__)) to
eliminate the padding, and this fixed the crash.

Should MINIDUMP_EXCEPTION_INFORMATION be declared with __attribute__
((__packed__)) in dbghelp.h?  Are there other structures in that header
that should be similarly declared?

Thanks.

Joel,

thanks for the report. Feel free to provide a patch for this
adjustment. Nevertheless I am a bit curious, as those structures in
dbghelp.h have a packing of 4 bytes (see pshpack4.h).

Maybe we should see how the header is included along
with some other defines etc. in the relevant source ?

That was good advice, since it made me notice that the problem was entirely on my end to begin with. The version of MingGW32 I was using before I switched to MinGW-W64 did not have dbghelp.h at all, so I had been declaring all the structures I needed myself based on the MSDN documentation. I had totally forgotten about that until I took a closer look at my source code.

Anyway, I've switched over to using MinGW-W64's dbghelp.h and it's working perfectly. Thanks for your help, and sorry for the noise.

Thanks also for all the good work put into this project; it's very much appreciated.



Thanks,
Kai

PS: Please sign-up to ML before posting to it.

--
O.S.
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to