JochenKalmbach / StackWalker

Walking the callstack in windows applications
BSD 2-Clause "Simplified" License
819 stars 179 forks source link

Invalid IMAGEHLP_MODULE64_V3 structure ending with error 87 #30

Open SoLaRGit opened 6 years ago

SoLaRGit commented 6 years ago

Last version of dbghelp.dll is 6.12.2.633 (released 02/01/2010 | Debugging Tools for Windows 6.12)

https://docs.microsoft.com/en-us/windows/desktop/debug/dbghelp-versions

and current code missing two last fields in IMAGEHLP_MODULE64_V3 structure

    // new element: 15-Jul-2009
    DWORD    MachineType;            // IMAGE_FILE_MACHINE_XXX from ntimage.h and winnt.h
    DWORD    Reserved;               // Padding - don't remove.

When we call this version of dbghelp.dll it fails with error 87. If we extend structure IMAGEHLP_MODULE64_V3 with this two fields code works.

This code assumes there are only 3 versions of this structure, which is not the case.

Also one question, why try to auto detect version available on the system when there is C:\Program Files (x86)\Debugging Tools for Windows (x86)\sdk\ which could be used directly with provided dbghelp.dll, and without any overhead or dynamic instantiation of library, as this topic suggests: https://docs.microsoft.com/en-us/windows/desktop/debug/calling-the-dbghelp-library

JochenKalmbach commented 6 years ago

if this is the case, then this is a bug in the dbghelp.dll... The dbghelp.dll must be able to support all versions of the "IMAGEHLP_MODULE64" structure. This is done by setting the "SizeOfStruct" member before calling any API. See also: https://docs.microsoft.com/de-de/windows/desktop/api/dbghelp/ns-dbghelp-_imagehlp_module64

Can you open a support case at MS?

SoLaRGit commented 6 years ago

Well yes for some structure, and no for the other - that is my experience with Microsoft over 2 decades. I guess that was the main reason behind the article that we should distribute dbghelp.dll with our application, instead of relaying on ones provided on OS.

So can't really report a bug since there is no document explicitly saying that it should work without any ambiguity (without any doubt).

Sure that newer OS will probably have all versions of dbghelp.dll in SxS (Side by Side assemblies) and our applications will work. But older versions of OS will not, so our apps might not work on them. True Microsoft have been dropping support for those old OS's recently more faster, than in years before. But since release of Debugging Tools for Windows 6.12 which I think came with windows 7 sdk, and VS2010, Microsoft has dropped support for Windows 7. So even this version is also outdated and obsolete. I managed to find newer headers on net, still got no chance to look trough Windows 10 SDK's (6 of them) and annotate what version they do have, and how do they work on older OS's need to check this OS cross version support.