wbenny / pdbex

pdbex is a utility for reconstructing structures and unions from the PDB into compilable C headers
MIT License
814 stars 160 forks source link

Fix crash with newer Windows PDBs, add char8_t support #21

Closed Mattiwatti closed 3 years ago

Mattiwatti commented 3 years ago

Some of the more recent Windows PDBs use char8_t, which a type that is in the current (VS 19.10) MS DIA SDK, but is not in the known type maps for pdbex. This causes a crash due to a nullptr dereference in UdtFieldDefinition::VisitBaseType (there was already an issue for this - see #12).

This is an input command that caused pdbex to crash for me (most arguments probably unnecessary): pdbex * WinTypes.pdb -o WinTypes.h -d -e i -u _anon_union_ -s _anon_struct_ -m -b -p- where WinTypes.pdb is the PDB for WinTypes.dll 10.0.21390.1, found in C:\Symbols\WinTypes.pdb\383E6861B516E717207B5610F6C0D2F91.

The first commit in this PR fixes the nullptr dereference, should a new type be added to the MS DIA SDK again in future. The non-compilable string <unknown_type> will be printed instead.

The second commit adds the char8_t type to the known type maps so that pdbex knows about it. Example output from the same WinTypes.pdb, which looks correct to me:

struct std::_Codecvt_guard<char16_t,char8_t>
{
  /* 0x0000 */ const char16_t* const& _First1;
  /* 0x0008 */ const char16_t*& _Mid1;
  /* 0x0010 */ char8_t* const& _First2;
  /* 0x0018 */ char8_t*& _Mid2;
}; /* size: 0x0020 */
wbenny commented 3 years ago

Thanks a lot!