Skip to content

Commit ce62471

Browse files
committed
[llvm-pdbutil] Fix yaml2pdb failing to parse yaml with register enums
1 parent f4c5323 commit ce62471

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

llvm/tools/llvm-pdbutil/PdbYaml.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ void MappingTraits<PdbDbiStream>::mapping(IO &IO, PdbDbiStream &Obj) {
155155
IO.mapOptional("PdbDllRbld", Obj.PdbDllRbld, uint16_t(0U));
156156
IO.mapOptional("Flags", Obj.Flags, uint16_t(1U));
157157
IO.mapOptional("MachineType", Obj.MachineType, PDB_Machine::x86);
158+
// This is a workaround for IO not having document context with the
159+
// machine type. The machine type is needed to properly parse Register enums
160+
// in the PDB.
161+
if (!IO.getContext()) {
162+
Obj.FakeHeader.Machine = static_cast<uint16_t>(Obj.MachineType);
163+
IO.setContext(&Obj.FakeHeader);
164+
}
158165
IO.mapOptional("Modules", Obj.ModInfos);
159166
}
160167

llvm/tools/llvm-pdbutil/PdbYaml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "OutputStyle.h"
1313

14+
#include "llvm/BinaryFormat/COFF.h"
1415
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
1516
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
1617
#include "llvm/DebugInfo/MSF/MSFCommon.h"
@@ -80,6 +81,7 @@ struct PdbDbiStream {
8081
PDB_Machine MachineType = PDB_Machine::x86;
8182

8283
std::vector<PdbDbiModuleInfo> ModInfos;
84+
COFF::header FakeHeader;
8385
};
8486

8587
struct PdbTpiStream {

0 commit comments

Comments
 (0)