xref: /src/contrib/llvm-project/llvm/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1b915e9e0SDimitry Andric //===- SymbolRecordMapping.cpp -----------------------------------*- C++-*-===//
2b915e9e0SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6b915e9e0SDimitry Andric //
7b915e9e0SDimitry Andric //===----------------------------------------------------------------------===//
8b915e9e0SDimitry Andric 
9b915e9e0SDimitry Andric #include "llvm/DebugInfo/CodeView/SymbolRecordMapping.h"
10b915e9e0SDimitry Andric 
11b915e9e0SDimitry Andric using namespace llvm;
12b915e9e0SDimitry Andric using namespace llvm::codeview;
13b915e9e0SDimitry Andric 
14b915e9e0SDimitry Andric #define error(X)                                                               \
15b915e9e0SDimitry Andric   if (auto EC = X)                                                             \
16b915e9e0SDimitry Andric     return EC;
17b915e9e0SDimitry Andric 
18b915e9e0SDimitry Andric namespace {
19b915e9e0SDimitry Andric struct MapGap {
operator ()__anon5b47c5ed0111::MapGap20b915e9e0SDimitry Andric   Error operator()(CodeViewRecordIO &IO, LocalVariableAddrGap &Gap) const {
21b915e9e0SDimitry Andric     error(IO.mapInteger(Gap.GapStartOffset));
22b915e9e0SDimitry Andric     error(IO.mapInteger(Gap.Range));
23b915e9e0SDimitry Andric     return Error::success();
24b915e9e0SDimitry Andric   }
25b915e9e0SDimitry Andric };
26b915e9e0SDimitry Andric }
27b915e9e0SDimitry Andric 
mapLocalVariableAddrRange(CodeViewRecordIO & IO,LocalVariableAddrRange & Range)28b915e9e0SDimitry Andric static Error mapLocalVariableAddrRange(CodeViewRecordIO &IO,
29b915e9e0SDimitry Andric                                        LocalVariableAddrRange &Range) {
30b915e9e0SDimitry Andric   error(IO.mapInteger(Range.OffsetStart));
31b915e9e0SDimitry Andric   error(IO.mapInteger(Range.ISectStart));
32b915e9e0SDimitry Andric   error(IO.mapInteger(Range.Range));
33b915e9e0SDimitry Andric   return Error::success();
34b915e9e0SDimitry Andric }
35b915e9e0SDimitry Andric 
visitSymbolBegin(CVSymbol & Record)36b915e9e0SDimitry Andric Error SymbolRecordMapping::visitSymbolBegin(CVSymbol &Record) {
37b915e9e0SDimitry Andric   error(IO.beginRecord(MaxRecordLength - sizeof(RecordPrefix)));
38b915e9e0SDimitry Andric   return Error::success();
39b915e9e0SDimitry Andric }
40b915e9e0SDimitry Andric 
visitSymbolEnd(CVSymbol & Record)41b915e9e0SDimitry Andric Error SymbolRecordMapping::visitSymbolEnd(CVSymbol &Record) {
42d288ef4cSDimitry Andric   error(IO.padToAlignment(alignOf(Container)));
43b915e9e0SDimitry Andric   error(IO.endRecord());
44b915e9e0SDimitry Andric   return Error::success();
45b915e9e0SDimitry Andric }
46b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,BlockSym & Block)47b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, BlockSym &Block) {
48b915e9e0SDimitry Andric 
49b915e9e0SDimitry Andric   error(IO.mapInteger(Block.Parent));
50b915e9e0SDimitry Andric   error(IO.mapInteger(Block.End));
51b915e9e0SDimitry Andric   error(IO.mapInteger(Block.CodeSize));
52b915e9e0SDimitry Andric   error(IO.mapInteger(Block.CodeOffset));
53b915e9e0SDimitry Andric   error(IO.mapInteger(Block.Segment));
54b915e9e0SDimitry Andric   error(IO.mapStringZ(Block.Name));
55b915e9e0SDimitry Andric 
56b915e9e0SDimitry Andric   return Error::success();
57b915e9e0SDimitry Andric }
58b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,Thunk32Sym & Thunk)59b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, Thunk32Sym &Thunk) {
60b915e9e0SDimitry Andric 
61b915e9e0SDimitry Andric   error(IO.mapInteger(Thunk.Parent));
62b915e9e0SDimitry Andric   error(IO.mapInteger(Thunk.End));
63b915e9e0SDimitry Andric   error(IO.mapInteger(Thunk.Next));
64b915e9e0SDimitry Andric   error(IO.mapInteger(Thunk.Offset));
65b915e9e0SDimitry Andric   error(IO.mapInteger(Thunk.Segment));
66b915e9e0SDimitry Andric   error(IO.mapInteger(Thunk.Length));
67b915e9e0SDimitry Andric   error(IO.mapEnum(Thunk.Thunk));
68b915e9e0SDimitry Andric   error(IO.mapStringZ(Thunk.Name));
69b915e9e0SDimitry Andric   error(IO.mapByteVectorTail(Thunk.VariantData));
70b915e9e0SDimitry Andric 
71b915e9e0SDimitry Andric   return Error::success();
72b915e9e0SDimitry Andric }
73b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,TrampolineSym & Tramp)74b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
75b915e9e0SDimitry Andric                                             TrampolineSym &Tramp) {
76b915e9e0SDimitry Andric 
77b915e9e0SDimitry Andric   error(IO.mapEnum(Tramp.Type));
78b915e9e0SDimitry Andric   error(IO.mapInteger(Tramp.Size));
79b915e9e0SDimitry Andric   error(IO.mapInteger(Tramp.ThunkOffset));
80b915e9e0SDimitry Andric   error(IO.mapInteger(Tramp.TargetOffset));
81b915e9e0SDimitry Andric   error(IO.mapInteger(Tramp.ThunkSection));
82b915e9e0SDimitry Andric   error(IO.mapInteger(Tramp.TargetSection));
83b915e9e0SDimitry Andric 
84b915e9e0SDimitry Andric   return Error::success();
85b915e9e0SDimitry Andric }
86b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,SectionSym & Section)87b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
88b915e9e0SDimitry Andric                                             SectionSym &Section) {
89b915e9e0SDimitry Andric   uint8_t Padding = 0;
90b915e9e0SDimitry Andric 
91b915e9e0SDimitry Andric   error(IO.mapInteger(Section.SectionNumber));
92b915e9e0SDimitry Andric   error(IO.mapInteger(Section.Alignment));
93b915e9e0SDimitry Andric   error(IO.mapInteger(Padding));
94b915e9e0SDimitry Andric   error(IO.mapInteger(Section.Rva));
95b915e9e0SDimitry Andric   error(IO.mapInteger(Section.Length));
96b915e9e0SDimitry Andric   error(IO.mapInteger(Section.Characteristics));
97b915e9e0SDimitry Andric   error(IO.mapStringZ(Section.Name));
98b915e9e0SDimitry Andric 
99b915e9e0SDimitry Andric   return Error::success();
100b915e9e0SDimitry Andric }
101b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,CoffGroupSym & CoffGroup)102b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
103b915e9e0SDimitry Andric                                             CoffGroupSym &CoffGroup) {
104b915e9e0SDimitry Andric 
105b915e9e0SDimitry Andric   error(IO.mapInteger(CoffGroup.Size));
106b915e9e0SDimitry Andric   error(IO.mapInteger(CoffGroup.Characteristics));
107b915e9e0SDimitry Andric   error(IO.mapInteger(CoffGroup.Offset));
108b915e9e0SDimitry Andric   error(IO.mapInteger(CoffGroup.Segment));
109b915e9e0SDimitry Andric   error(IO.mapStringZ(CoffGroup.Name));
110b915e9e0SDimitry Andric 
111b915e9e0SDimitry Andric   return Error::success();
112b915e9e0SDimitry Andric }
113b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,BPRelativeSym & BPRel)114b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
115b915e9e0SDimitry Andric                                             BPRelativeSym &BPRel) {
116b915e9e0SDimitry Andric 
117b915e9e0SDimitry Andric   error(IO.mapInteger(BPRel.Offset));
118b915e9e0SDimitry Andric   error(IO.mapInteger(BPRel.Type));
119b915e9e0SDimitry Andric   error(IO.mapStringZ(BPRel.Name));
120b915e9e0SDimitry Andric 
121b915e9e0SDimitry Andric   return Error::success();
122b915e9e0SDimitry Andric }
123b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,BuildInfoSym & BuildInfo)124b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
125b915e9e0SDimitry Andric                                             BuildInfoSym &BuildInfo) {
126b915e9e0SDimitry Andric 
127b915e9e0SDimitry Andric   error(IO.mapInteger(BuildInfo.BuildId));
128b915e9e0SDimitry Andric 
129b915e9e0SDimitry Andric   return Error::success();
130b915e9e0SDimitry Andric }
131b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,CallSiteInfoSym & CallSiteInfo)132b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
133b915e9e0SDimitry Andric                                             CallSiteInfoSym &CallSiteInfo) {
134b915e9e0SDimitry Andric   uint16_t Padding = 0;
135b915e9e0SDimitry Andric 
136b915e9e0SDimitry Andric   error(IO.mapInteger(CallSiteInfo.CodeOffset));
137b915e9e0SDimitry Andric   error(IO.mapInteger(CallSiteInfo.Segment));
138b915e9e0SDimitry Andric   error(IO.mapInteger(Padding));
139b915e9e0SDimitry Andric   error(IO.mapInteger(CallSiteInfo.Type));
140b915e9e0SDimitry Andric 
141b915e9e0SDimitry Andric   return Error::success();
142b915e9e0SDimitry Andric }
143b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,EnvBlockSym & EnvBlock)144b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
145b915e9e0SDimitry Andric                                             EnvBlockSym &EnvBlock) {
146b915e9e0SDimitry Andric 
147b915e9e0SDimitry Andric   uint8_t Reserved = 0;
148b915e9e0SDimitry Andric   error(IO.mapInteger(Reserved));
149b915e9e0SDimitry Andric   error(IO.mapStringZVectorZ(EnvBlock.Fields));
150b915e9e0SDimitry Andric 
151b915e9e0SDimitry Andric   return Error::success();
152b915e9e0SDimitry Andric }
153b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,FileStaticSym & FileStatic)154b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
155b915e9e0SDimitry Andric                                             FileStaticSym &FileStatic) {
156b915e9e0SDimitry Andric 
157b915e9e0SDimitry Andric   error(IO.mapInteger(FileStatic.Index));
158b915e9e0SDimitry Andric   error(IO.mapInteger(FileStatic.ModFilenameOffset));
159b915e9e0SDimitry Andric   error(IO.mapEnum(FileStatic.Flags));
160b915e9e0SDimitry Andric   error(IO.mapStringZ(FileStatic.Name));
161b915e9e0SDimitry Andric 
162b915e9e0SDimitry Andric   return Error::success();
163b915e9e0SDimitry Andric }
164b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ExportSym & Export)165b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, ExportSym &Export) {
166b915e9e0SDimitry Andric 
167b915e9e0SDimitry Andric   error(IO.mapInteger(Export.Ordinal));
168b915e9e0SDimitry Andric   error(IO.mapEnum(Export.Flags));
169b915e9e0SDimitry Andric   error(IO.mapStringZ(Export.Name));
170b915e9e0SDimitry Andric 
171b915e9e0SDimitry Andric   return Error::success();
172b915e9e0SDimitry Andric }
173b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,Compile2Sym & Compile2)174b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
175b915e9e0SDimitry Andric                                             Compile2Sym &Compile2) {
176b915e9e0SDimitry Andric 
177b915e9e0SDimitry Andric   error(IO.mapEnum(Compile2.Flags));
178b915e9e0SDimitry Andric   error(IO.mapEnum(Compile2.Machine));
179b915e9e0SDimitry Andric   error(IO.mapInteger(Compile2.VersionFrontendMajor));
180b915e9e0SDimitry Andric   error(IO.mapInteger(Compile2.VersionFrontendMinor));
181b915e9e0SDimitry Andric   error(IO.mapInteger(Compile2.VersionFrontendBuild));
182b915e9e0SDimitry Andric   error(IO.mapInteger(Compile2.VersionBackendMajor));
183b915e9e0SDimitry Andric   error(IO.mapInteger(Compile2.VersionBackendMinor));
184b915e9e0SDimitry Andric   error(IO.mapInteger(Compile2.VersionBackendBuild));
185b915e9e0SDimitry Andric   error(IO.mapStringZ(Compile2.Version));
186b915e9e0SDimitry Andric   error(IO.mapStringZVectorZ(Compile2.ExtraStrings));
187b915e9e0SDimitry Andric 
188b915e9e0SDimitry Andric   return Error::success();
189b915e9e0SDimitry Andric }
190b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,Compile3Sym & Compile3)191b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
192b915e9e0SDimitry Andric                                             Compile3Sym &Compile3) {
193b915e9e0SDimitry Andric 
194b915e9e0SDimitry Andric   error(IO.mapEnum(Compile3.Flags));
195b915e9e0SDimitry Andric   error(IO.mapEnum(Compile3.Machine));
196b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionFrontendMajor));
197b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionFrontendMinor));
198b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionFrontendBuild));
199b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionFrontendQFE));
200b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionBackendMajor));
201b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionBackendMinor));
202b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionBackendBuild));
203b915e9e0SDimitry Andric   error(IO.mapInteger(Compile3.VersionBackendQFE));
204b915e9e0SDimitry Andric   error(IO.mapStringZ(Compile3.Version));
205b915e9e0SDimitry Andric 
206b915e9e0SDimitry Andric   return Error::success();
207b915e9e0SDimitry Andric }
208b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ConstantSym & Constant)209b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
210b915e9e0SDimitry Andric                                             ConstantSym &Constant) {
211b915e9e0SDimitry Andric 
212b915e9e0SDimitry Andric   error(IO.mapInteger(Constant.Type));
213b915e9e0SDimitry Andric   error(IO.mapEncodedInteger(Constant.Value));
214b915e9e0SDimitry Andric   error(IO.mapStringZ(Constant.Name));
215b915e9e0SDimitry Andric 
216b915e9e0SDimitry Andric   return Error::success();
217b915e9e0SDimitry Andric }
218b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DataSym & Data)219b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, DataSym &Data) {
220b915e9e0SDimitry Andric 
221b915e9e0SDimitry Andric   error(IO.mapInteger(Data.Type));
222b915e9e0SDimitry Andric   error(IO.mapInteger(Data.DataOffset));
223b915e9e0SDimitry Andric   error(IO.mapInteger(Data.Segment));
224b915e9e0SDimitry Andric   error(IO.mapStringZ(Data.Name));
225b915e9e0SDimitry Andric 
226b915e9e0SDimitry Andric   return Error::success();
227b915e9e0SDimitry Andric }
228b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeFramePointerRelSym & DefRangeFramePointerRel)229b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
230b915e9e0SDimitry Andric     CVSymbol &CVR, DefRangeFramePointerRelSym &DefRangeFramePointerRel) {
231b915e9e0SDimitry Andric 
2321d5ae102SDimitry Andric   error(IO.mapObject(DefRangeFramePointerRel.Hdr.Offset));
233b915e9e0SDimitry Andric   error(mapLocalVariableAddrRange(IO, DefRangeFramePointerRel.Range));
234b915e9e0SDimitry Andric   error(IO.mapVectorTail(DefRangeFramePointerRel.Gaps, MapGap()));
235b915e9e0SDimitry Andric 
236b915e9e0SDimitry Andric   return Error::success();
237b915e9e0SDimitry Andric }
238b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeFramePointerRelFullScopeSym & DefRangeFramePointerRelFullScope)239b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
240b915e9e0SDimitry Andric     CVSymbol &CVR,
241b915e9e0SDimitry Andric     DefRangeFramePointerRelFullScopeSym &DefRangeFramePointerRelFullScope) {
242b915e9e0SDimitry Andric 
243b915e9e0SDimitry Andric   error(IO.mapInteger(DefRangeFramePointerRelFullScope.Offset));
244b915e9e0SDimitry Andric 
245b915e9e0SDimitry Andric   return Error::success();
246b915e9e0SDimitry Andric }
247b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeRegisterRelSym & DefRangeRegisterRel)248b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
249b915e9e0SDimitry Andric     CVSymbol &CVR, DefRangeRegisterRelSym &DefRangeRegisterRel) {
250b915e9e0SDimitry Andric 
251b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeRegisterRel.Hdr.Register));
252b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeRegisterRel.Hdr.Flags));
253b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeRegisterRel.Hdr.BasePointerOffset));
254b915e9e0SDimitry Andric   error(mapLocalVariableAddrRange(IO, DefRangeRegisterRel.Range));
255b915e9e0SDimitry Andric   error(IO.mapVectorTail(DefRangeRegisterRel.Gaps, MapGap()));
256b915e9e0SDimitry Andric 
257b915e9e0SDimitry Andric   return Error::success();
258b915e9e0SDimitry Andric }
259b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeRegisterSym & DefRangeRegister)260b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
261b915e9e0SDimitry Andric     CVSymbol &CVR, DefRangeRegisterSym &DefRangeRegister) {
262b915e9e0SDimitry Andric 
263b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeRegister.Hdr.Register));
264b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeRegister.Hdr.MayHaveNoName));
265b915e9e0SDimitry Andric   error(mapLocalVariableAddrRange(IO, DefRangeRegister.Range));
266b915e9e0SDimitry Andric   error(IO.mapVectorTail(DefRangeRegister.Gaps, MapGap()));
267b915e9e0SDimitry Andric 
268b915e9e0SDimitry Andric   return Error::success();
269b915e9e0SDimitry Andric }
270b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeSubfieldRegisterSym & DefRangeSubfieldRegister)271b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
272b915e9e0SDimitry Andric     CVSymbol &CVR, DefRangeSubfieldRegisterSym &DefRangeSubfieldRegister) {
273b915e9e0SDimitry Andric 
274b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeSubfieldRegister.Hdr.Register));
275b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeSubfieldRegister.Hdr.MayHaveNoName));
276b915e9e0SDimitry Andric   error(IO.mapObject(DefRangeSubfieldRegister.Hdr.OffsetInParent));
277b915e9e0SDimitry Andric   error(mapLocalVariableAddrRange(IO, DefRangeSubfieldRegister.Range));
278b915e9e0SDimitry Andric   error(IO.mapVectorTail(DefRangeSubfieldRegister.Gaps, MapGap()));
279b915e9e0SDimitry Andric 
280b915e9e0SDimitry Andric   return Error::success();
281b915e9e0SDimitry Andric }
282b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeSubfieldSym & DefRangeSubfield)283b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
284b915e9e0SDimitry Andric     CVSymbol &CVR, DefRangeSubfieldSym &DefRangeSubfield) {
285b915e9e0SDimitry Andric 
286b915e9e0SDimitry Andric   error(IO.mapInteger(DefRangeSubfield.Program));
287b915e9e0SDimitry Andric   error(IO.mapInteger(DefRangeSubfield.OffsetInParent));
288b915e9e0SDimitry Andric   error(mapLocalVariableAddrRange(IO, DefRangeSubfield.Range));
289b915e9e0SDimitry Andric   error(IO.mapVectorTail(DefRangeSubfield.Gaps, MapGap()));
290b915e9e0SDimitry Andric 
291b915e9e0SDimitry Andric   return Error::success();
292b915e9e0SDimitry Andric }
293b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,DefRangeSym & DefRange)294b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
295b915e9e0SDimitry Andric                                             DefRangeSym &DefRange) {
296b915e9e0SDimitry Andric 
297b915e9e0SDimitry Andric   error(IO.mapInteger(DefRange.Program));
298b915e9e0SDimitry Andric   error(mapLocalVariableAddrRange(IO, DefRange.Range));
299b915e9e0SDimitry Andric   error(IO.mapVectorTail(DefRange.Gaps, MapGap()));
300b915e9e0SDimitry Andric 
301b915e9e0SDimitry Andric   return Error::success();
302b915e9e0SDimitry Andric }
303b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,FrameCookieSym & FrameCookie)304b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
305b915e9e0SDimitry Andric                                             FrameCookieSym &FrameCookie) {
306b915e9e0SDimitry Andric 
307b915e9e0SDimitry Andric   error(IO.mapInteger(FrameCookie.CodeOffset));
308b915e9e0SDimitry Andric   error(IO.mapInteger(FrameCookie.Register));
3097c7aba6eSDimitry Andric   error(IO.mapEnum(FrameCookie.CookieKind));
310b915e9e0SDimitry Andric   error(IO.mapInteger(FrameCookie.Flags));
311b915e9e0SDimitry Andric 
312b915e9e0SDimitry Andric   return Error::success();
313b915e9e0SDimitry Andric }
314b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,FrameProcSym & FrameProc)315b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
316b915e9e0SDimitry Andric                                             FrameProcSym &FrameProc) {
317b915e9e0SDimitry Andric   error(IO.mapInteger(FrameProc.TotalFrameBytes));
318b915e9e0SDimitry Andric   error(IO.mapInteger(FrameProc.PaddingFrameBytes));
319b915e9e0SDimitry Andric   error(IO.mapInteger(FrameProc.OffsetToPadding));
320b915e9e0SDimitry Andric   error(IO.mapInteger(FrameProc.BytesOfCalleeSavedRegisters));
321b915e9e0SDimitry Andric   error(IO.mapInteger(FrameProc.OffsetOfExceptionHandler));
322b915e9e0SDimitry Andric   error(IO.mapInteger(FrameProc.SectionIdOfExceptionHandler));
323b915e9e0SDimitry Andric   error(IO.mapEnum(FrameProc.Flags));
324b915e9e0SDimitry Andric 
325b915e9e0SDimitry Andric   return Error::success();
326b915e9e0SDimitry Andric }
327b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,HeapAllocationSiteSym & HeapAllocSite)328b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(
329b915e9e0SDimitry Andric     CVSymbol &CVR, HeapAllocationSiteSym &HeapAllocSite) {
330b915e9e0SDimitry Andric 
331b915e9e0SDimitry Andric   error(IO.mapInteger(HeapAllocSite.CodeOffset));
332b915e9e0SDimitry Andric   error(IO.mapInteger(HeapAllocSite.Segment));
333b915e9e0SDimitry Andric   error(IO.mapInteger(HeapAllocSite.CallInstructionSize));
334b915e9e0SDimitry Andric   error(IO.mapInteger(HeapAllocSite.Type));
335b915e9e0SDimitry Andric 
336b915e9e0SDimitry Andric   return Error::success();
337b915e9e0SDimitry Andric }
338b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,InlineSiteSym & InlineSite)339b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
340b915e9e0SDimitry Andric                                             InlineSiteSym &InlineSite) {
341b915e9e0SDimitry Andric 
342b915e9e0SDimitry Andric   error(IO.mapInteger(InlineSite.Parent));
343b915e9e0SDimitry Andric   error(IO.mapInteger(InlineSite.End));
344b915e9e0SDimitry Andric   error(IO.mapInteger(InlineSite.Inlinee));
345b915e9e0SDimitry Andric   error(IO.mapByteVectorTail(InlineSite.AnnotationData));
346b915e9e0SDimitry Andric 
347b915e9e0SDimitry Andric   return Error::success();
348b915e9e0SDimitry Andric }
349b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,RegisterSym & Register)350b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
351b915e9e0SDimitry Andric                                             RegisterSym &Register) {
352b915e9e0SDimitry Andric 
353b915e9e0SDimitry Andric   error(IO.mapInteger(Register.Index));
354b915e9e0SDimitry Andric   error(IO.mapEnum(Register.Register));
355b915e9e0SDimitry Andric   error(IO.mapStringZ(Register.Name));
356b915e9e0SDimitry Andric 
357b915e9e0SDimitry Andric   return Error::success();
358b915e9e0SDimitry Andric }
359b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,PublicSym32 & Public)360b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
361b915e9e0SDimitry Andric                                             PublicSym32 &Public) {
362b915e9e0SDimitry Andric 
36308bbd35aSDimitry Andric   error(IO.mapEnum(Public.Flags));
364b915e9e0SDimitry Andric   error(IO.mapInteger(Public.Offset));
365b915e9e0SDimitry Andric   error(IO.mapInteger(Public.Segment));
366b915e9e0SDimitry Andric   error(IO.mapStringZ(Public.Name));
367b915e9e0SDimitry Andric 
368b915e9e0SDimitry Andric   return Error::success();
369b915e9e0SDimitry Andric }
370b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ProcRefSym & ProcRef)371b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
372b915e9e0SDimitry Andric                                             ProcRefSym &ProcRef) {
373b915e9e0SDimitry Andric 
374b915e9e0SDimitry Andric   error(IO.mapInteger(ProcRef.SumName));
375b915e9e0SDimitry Andric   error(IO.mapInteger(ProcRef.SymOffset));
376b915e9e0SDimitry Andric   error(IO.mapInteger(ProcRef.Module));
377b915e9e0SDimitry Andric   error(IO.mapStringZ(ProcRef.Name));
378b915e9e0SDimitry Andric 
379b915e9e0SDimitry Andric   return Error::success();
380b915e9e0SDimitry Andric }
381b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,LabelSym & Label)382b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, LabelSym &Label) {
383b915e9e0SDimitry Andric 
384b915e9e0SDimitry Andric   error(IO.mapInteger(Label.CodeOffset));
385b915e9e0SDimitry Andric   error(IO.mapInteger(Label.Segment));
386b915e9e0SDimitry Andric   error(IO.mapEnum(Label.Flags));
387b915e9e0SDimitry Andric   error(IO.mapStringZ(Label.Name));
388b915e9e0SDimitry Andric 
389b915e9e0SDimitry Andric   return Error::success();
390b915e9e0SDimitry Andric }
391b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,LocalSym & Local)392b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, LocalSym &Local) {
393b915e9e0SDimitry Andric   error(IO.mapInteger(Local.Type));
394b915e9e0SDimitry Andric   error(IO.mapEnum(Local.Flags));
395b915e9e0SDimitry Andric   error(IO.mapStringZ(Local.Name));
396b915e9e0SDimitry Andric 
397b915e9e0SDimitry Andric   return Error::success();
398b915e9e0SDimitry Andric }
399b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ObjNameSym & ObjName)400b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
401b915e9e0SDimitry Andric                                             ObjNameSym &ObjName) {
402b915e9e0SDimitry Andric 
403b915e9e0SDimitry Andric   error(IO.mapInteger(ObjName.Signature));
404b915e9e0SDimitry Andric   error(IO.mapStringZ(ObjName.Name));
405b915e9e0SDimitry Andric 
406b915e9e0SDimitry Andric   return Error::success();
407b915e9e0SDimitry Andric }
408b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ProcSym & Proc)409b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, ProcSym &Proc) {
410b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.Parent));
411b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.End));
412b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.Next));
413b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.CodeSize));
414b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.DbgStart));
415b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.DbgEnd));
416b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.FunctionType));
417b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.CodeOffset));
418b915e9e0SDimitry Andric   error(IO.mapInteger(Proc.Segment));
419b915e9e0SDimitry Andric   error(IO.mapEnum(Proc.Flags));
420b915e9e0SDimitry Andric   error(IO.mapStringZ(Proc.Name));
421b915e9e0SDimitry Andric   return Error::success();
422b915e9e0SDimitry Andric }
423b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ScopeEndSym & ScopeEnd)424b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
425b915e9e0SDimitry Andric                                             ScopeEndSym &ScopeEnd) {
426b915e9e0SDimitry Andric   return Error::success();
427b915e9e0SDimitry Andric }
428b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,CallerSym & Caller)429b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, CallerSym &Caller) {
430b915e9e0SDimitry Andric   error(IO.mapVectorN<uint32_t>(
431b915e9e0SDimitry Andric       Caller.Indices,
432b915e9e0SDimitry Andric       [](CodeViewRecordIO &IO, TypeIndex &N) { return IO.mapInteger(N); }));
433b915e9e0SDimitry Andric   return Error::success();
434b915e9e0SDimitry Andric }
435b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,RegRelativeSym & RegRel)436b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
437b915e9e0SDimitry Andric                                             RegRelativeSym &RegRel) {
438b915e9e0SDimitry Andric 
439b915e9e0SDimitry Andric   error(IO.mapInteger(RegRel.Offset));
440b915e9e0SDimitry Andric   error(IO.mapInteger(RegRel.Type));
4417c7aba6eSDimitry Andric   error(IO.mapEnum(RegRel.Register));
442b915e9e0SDimitry Andric   error(IO.mapStringZ(RegRel.Name));
443b915e9e0SDimitry Andric 
444b915e9e0SDimitry Andric   return Error::success();
445b915e9e0SDimitry Andric }
446b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,ThreadLocalDataSym & Data)447b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
448b915e9e0SDimitry Andric                                             ThreadLocalDataSym &Data) {
449b915e9e0SDimitry Andric 
450b915e9e0SDimitry Andric   error(IO.mapInteger(Data.Type));
451b915e9e0SDimitry Andric   error(IO.mapInteger(Data.DataOffset));
452b915e9e0SDimitry Andric   error(IO.mapInteger(Data.Segment));
453b915e9e0SDimitry Andric   error(IO.mapStringZ(Data.Name));
454b915e9e0SDimitry Andric 
455b915e9e0SDimitry Andric   return Error::success();
456b915e9e0SDimitry Andric }
457b915e9e0SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,UDTSym & UDT)458b915e9e0SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, UDTSym &UDT) {
459b915e9e0SDimitry Andric 
460b915e9e0SDimitry Andric   error(IO.mapInteger(UDT.Type));
461b915e9e0SDimitry Andric   error(IO.mapStringZ(UDT.Name));
462b915e9e0SDimitry Andric 
463b915e9e0SDimitry Andric   return Error::success();
464b915e9e0SDimitry Andric }
465b7eb8e35SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,UsingNamespaceSym & UN)466b7eb8e35SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
467b7eb8e35SDimitry Andric                                             UsingNamespaceSym &UN) {
468b7eb8e35SDimitry Andric 
469b7eb8e35SDimitry Andric   error(IO.mapStringZ(UN.Name));
470b7eb8e35SDimitry Andric 
471b7eb8e35SDimitry Andric   return Error::success();
472b7eb8e35SDimitry Andric }
473d8e91e46SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,AnnotationSym & Annot)474e6d15924SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
475e6d15924SDimitry Andric                                             AnnotationSym &Annot) {
476e6d15924SDimitry Andric 
477e6d15924SDimitry Andric   error(IO.mapInteger(Annot.CodeOffset));
478e6d15924SDimitry Andric   error(IO.mapInteger(Annot.Segment));
479e6d15924SDimitry Andric   error(IO.mapVectorN<uint16_t>(
480e6d15924SDimitry Andric       Annot.Strings,
481e6d15924SDimitry Andric       [](CodeViewRecordIO &IO, StringRef &S) { return IO.mapStringZ(S); }));
482e6d15924SDimitry Andric 
483e6d15924SDimitry Andric   return Error::success();
484e6d15924SDimitry Andric }
485e6d15924SDimitry Andric 
visitKnownRecord(CVSymbol & CVR,JumpTableSym & JumpTable)486b1c73532SDimitry Andric Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR,
487b1c73532SDimitry Andric                                             JumpTableSym &JumpTable) {
488b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.BaseOffset));
489b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.BaseSegment));
490b1c73532SDimitry Andric   error(IO.mapEnum(JumpTable.SwitchType));
491b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.BranchOffset));
492b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.TableOffset));
493b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.BranchSegment));
494b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.TableSegment));
495b1c73532SDimitry Andric   error(IO.mapInteger(JumpTable.EntriesCount));
496b1c73532SDimitry Andric   return Error::success();
497b1c73532SDimitry Andric }
498b1c73532SDimitry Andric 
decodeFramePtrReg(EncodedFramePtrReg EncodedReg,CPUType CPU)499d8e91e46SDimitry Andric RegisterId codeview::decodeFramePtrReg(EncodedFramePtrReg EncodedReg,
500d8e91e46SDimitry Andric                                        CPUType CPU) {
501d8e91e46SDimitry Andric   assert(unsigned(EncodedReg) < 4);
502d8e91e46SDimitry Andric   switch (CPU) {
503d8e91e46SDimitry Andric   // FIXME: Add ARM and AArch64 variants here.
504d8e91e46SDimitry Andric   default:
505d8e91e46SDimitry Andric     break;
506d8e91e46SDimitry Andric   case CPUType::Intel8080:
507d8e91e46SDimitry Andric   case CPUType::Intel8086:
508d8e91e46SDimitry Andric   case CPUType::Intel80286:
509d8e91e46SDimitry Andric   case CPUType::Intel80386:
510d8e91e46SDimitry Andric   case CPUType::Intel80486:
511d8e91e46SDimitry Andric   case CPUType::Pentium:
512d8e91e46SDimitry Andric   case CPUType::PentiumPro:
513d8e91e46SDimitry Andric   case CPUType::Pentium3:
514d8e91e46SDimitry Andric     switch (EncodedReg) {
515d8e91e46SDimitry Andric     case EncodedFramePtrReg::None:     return RegisterId::NONE;
516d8e91e46SDimitry Andric     case EncodedFramePtrReg::StackPtr: return RegisterId::VFRAME;
517d8e91e46SDimitry Andric     case EncodedFramePtrReg::FramePtr: return RegisterId::EBP;
518d8e91e46SDimitry Andric     case EncodedFramePtrReg::BasePtr:  return RegisterId::EBX;
519d8e91e46SDimitry Andric     }
520d8e91e46SDimitry Andric     llvm_unreachable("bad encoding");
521d8e91e46SDimitry Andric   case CPUType::X64:
522d8e91e46SDimitry Andric     switch (EncodedReg) {
523d8e91e46SDimitry Andric     case EncodedFramePtrReg::None:     return RegisterId::NONE;
524d8e91e46SDimitry Andric     case EncodedFramePtrReg::StackPtr: return RegisterId::RSP;
525d8e91e46SDimitry Andric     case EncodedFramePtrReg::FramePtr: return RegisterId::RBP;
526d8e91e46SDimitry Andric     case EncodedFramePtrReg::BasePtr:  return RegisterId::R13;
527d8e91e46SDimitry Andric     }
528d8e91e46SDimitry Andric     llvm_unreachable("bad encoding");
529d8e91e46SDimitry Andric   }
530d8e91e46SDimitry Andric   return RegisterId::NONE;
531d8e91e46SDimitry Andric }
532d8e91e46SDimitry Andric 
encodeFramePtrReg(RegisterId Reg,CPUType CPU)533d8e91e46SDimitry Andric EncodedFramePtrReg codeview::encodeFramePtrReg(RegisterId Reg, CPUType CPU) {
534d8e91e46SDimitry Andric   switch (CPU) {
535d8e91e46SDimitry Andric   // FIXME: Add ARM and AArch64 variants here.
536d8e91e46SDimitry Andric   default:
537d8e91e46SDimitry Andric     break;
538d8e91e46SDimitry Andric   case CPUType::Intel8080:
539d8e91e46SDimitry Andric   case CPUType::Intel8086:
540d8e91e46SDimitry Andric   case CPUType::Intel80286:
541d8e91e46SDimitry Andric   case CPUType::Intel80386:
542d8e91e46SDimitry Andric   case CPUType::Intel80486:
543d8e91e46SDimitry Andric   case CPUType::Pentium:
544d8e91e46SDimitry Andric   case CPUType::PentiumPro:
545d8e91e46SDimitry Andric   case CPUType::Pentium3:
546d8e91e46SDimitry Andric     switch (Reg) {
547d8e91e46SDimitry Andric     case RegisterId::VFRAME:
548d8e91e46SDimitry Andric       return EncodedFramePtrReg::StackPtr;
549d8e91e46SDimitry Andric     case RegisterId::EBP:
550d8e91e46SDimitry Andric       return EncodedFramePtrReg::FramePtr;
551d8e91e46SDimitry Andric     case RegisterId::EBX:
552d8e91e46SDimitry Andric       return EncodedFramePtrReg::BasePtr;
553d8e91e46SDimitry Andric     default:
554d8e91e46SDimitry Andric       break;
555d8e91e46SDimitry Andric     }
556d8e91e46SDimitry Andric     break;
557d8e91e46SDimitry Andric   case CPUType::X64:
558d8e91e46SDimitry Andric     switch (Reg) {
559d8e91e46SDimitry Andric     case RegisterId::RSP:
560d8e91e46SDimitry Andric       return EncodedFramePtrReg::StackPtr;
561d8e91e46SDimitry Andric     case RegisterId::RBP:
562d8e91e46SDimitry Andric       return EncodedFramePtrReg::FramePtr;
563d8e91e46SDimitry Andric     case RegisterId::R13:
564d8e91e46SDimitry Andric       return EncodedFramePtrReg::BasePtr;
565d8e91e46SDimitry Andric     default:
566d8e91e46SDimitry Andric       break;
567d8e91e46SDimitry Andric     }
568d8e91e46SDimitry Andric     break;
569d8e91e46SDimitry Andric   }
570d8e91e46SDimitry Andric   return EncodedFramePtrReg::None;
571d8e91e46SDimitry Andric }
572