rainers / cv2pdb

converter of DMD CodeView/DWARF debug information to PDB files
Artistic License 2.0
472 stars 109 forks source link

Could you please add the support of DBG files? #25

Closed AlexWhiter closed 6 years ago

AlexWhiter commented 6 years ago

Hi,

For the projects built in Delphi , there's a map2dbg utility that allows for converting the MAP files into DBGs in regular NB09 format. Unfortunately, cv2pdb doesn't look for the external DBG file in case of IMAGE_FILE_DEBUG_STRIPPED flag set in PE header. Is it possible to add such feature? I can try to implement it if you agree to add this functionality.

Thank for the consideration!

rainers commented 6 years ago

Sounds like a worthwhile extension. Do you have an example pair of exe/dbg files so I can have a look how well this might be suited, especially considering the format of the DBG file and the contained CodeView entries?

AlexWhiter commented 6 years ago

Here's an archive with a small sample: https://yadi.sk/d/B9sY97BJ3TsVcV test.exe is just a simple program with recursion (to check if WinDBG can correctly unwind the stack using the resulting PDB), and test.dbg is a corresponding DBG made with map2dbd utility.

I've also added test_with_embedded_DBG.exe file which is test.exe with manually added CV data. cv2pdb can correctly process this file.

I couldn't find any documentation on the DBG file structure, but the headers are documented and declared in WinNT.h, look for IMAGE_SEPARATE_DEBUG_HEADER. The file layout seems to be as follows:

  1. IMAGE_SEPARATE_DEBUG_HEADER
  2. Several IMAGE_SECTION_HEADERs (count = Header.NumberOfSections)
  3. Optional ExportSymbols (size = Header.ExportedNamesSize, usually zero)
  4. One or more IMAGE_DEBUG_DIRECTORY (size = Header.DebugDirectorySize)
  5. The data blocks described by the IMAGE_DEBUG_DIRECTORY entries.
rainers commented 6 years ago

The data looks pretty simple to process. I've added conversion of DBG to PDB (see https://github.com/rainers/cv2pdb/commit/d67da0ec9481ca3ffe878ca68dfb64909040e231), but this still misses embedding the RSDS debug-link into the executable.

If you want to implement it I'll be happy to review and merge.

AlexWhiter commented 6 years ago

Great! I'll try to implement this.

AlexWhiter commented 6 years ago

Seems to be working. Thanks! :)