1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
| //===- SymbolRecord.h -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFO_CODEVIEW_SYMBOLRECORD_H
#define LLVM_DEBUGINFO_CODEVIEW_SYMBOLRECORD_H
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/DebugInfo/CodeView/CVRecord.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/RecordSerialization.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/Support/BinaryStreamArray.h"
#include "llvm/Support/Endian.h"
#include <cstdint>
#include <vector>
namespace llvm {
namespace codeview {
class SymbolRecord {
protected:
explicit SymbolRecord(SymbolRecordKind Kind) : Kind(Kind) {}
public:
SymbolRecordKind getKind() const { return Kind; }
SymbolRecordKind Kind;
};
// S_GPROC32, S_LPROC32, S_GPROC32_ID, S_LPROC32_ID, S_LPROC32_DPC or
// S_LPROC32_DPC_ID
class ProcSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 32;
public:
explicit ProcSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
ProcSym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t Parent = 0;
uint32_t End = 0;
uint32_t Next = 0;
uint32_t CodeSize = 0;
uint32_t DbgStart = 0;
uint32_t DbgEnd = 0;
TypeIndex FunctionType;
uint32_t CodeOffset = 0;
uint16_t Segment = 0;
ProcSymFlags Flags = ProcSymFlags::None;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_THUNK32
class Thunk32Sym : public SymbolRecord {
public:
explicit Thunk32Sym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
Thunk32Sym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
uint32_t Parent = 0;
uint32_t End = 0;
uint32_t Next = 0;
uint32_t Offset = 0;
uint16_t Segment = 0;
uint16_t Length = 0;
ThunkOrdinal Thunk;
StringRef Name;
ArrayRef<uint8_t> VariantData;
uint32_t RecordOffset = 0;
};
// S_TRAMPOLINE
class TrampolineSym : public SymbolRecord {
public:
explicit TrampolineSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
TrampolineSym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
TrampolineType Type;
uint16_t Size = 0;
uint32_t ThunkOffset = 0;
uint32_t TargetOffset = 0;
uint16_t ThunkSection = 0;
uint16_t TargetSection = 0;
uint32_t RecordOffset = 0;
};
// S_SECTION
class SectionSym : public SymbolRecord {
public:
explicit SectionSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
SectionSym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
uint16_t SectionNumber = 0;
uint8_t Alignment = 0;
uint32_t Rva = 0;
uint32_t Length = 0;
uint32_t Characteristics = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_COFFGROUP
class CoffGroupSym : public SymbolRecord {
public:
explicit CoffGroupSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
CoffGroupSym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
uint32_t Size = 0;
uint32_t Characteristics = 0;
uint32_t Offset = 0;
uint16_t Segment = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
class ScopeEndSym : public SymbolRecord {
public:
explicit ScopeEndSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
ScopeEndSym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
uint32_t RecordOffset = 0;
};
class CallerSym : public SymbolRecord {
public:
explicit CallerSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
CallerSym(SymbolRecordKind Kind, uint32_t RecordOffset)
: SymbolRecord(Kind), RecordOffset(RecordOffset) {}
std::vector<TypeIndex> Indices;
uint32_t RecordOffset = 0;
};
struct DecodedAnnotation {
StringRef Name;
ArrayRef<uint8_t> Bytes;
BinaryAnnotationsOpCode OpCode;
uint32_t U1 = 0;
uint32_t U2 = 0;
int32_t S1 = 0;
};
struct BinaryAnnotationIterator
: public iterator_facade_base<BinaryAnnotationIterator,
std::forward_iterator_tag,
DecodedAnnotation> {
BinaryAnnotationIterator() = default;
BinaryAnnotationIterator(ArrayRef<uint8_t> Annotations) : Data(Annotations) {}
BinaryAnnotationIterator(const BinaryAnnotationIterator &Other)
: Data(Other.Data) {}
bool operator==(BinaryAnnotationIterator Other) const {
return Data == Other.Data;
}
BinaryAnnotationIterator &operator=(const BinaryAnnotationIterator Other) {
Data = Other.Data;
return *this;
}
BinaryAnnotationIterator &operator++() {
if (!ParseCurrentAnnotation()) {
*this = BinaryAnnotationIterator();
return *this;
}
Data = Next;
Next = ArrayRef<uint8_t>();
Current.reset();
return *this;
}
const DecodedAnnotation &operator*() {
ParseCurrentAnnotation();
return Current.getValue();
}
private:
static uint32_t GetCompressedAnnotation(ArrayRef<uint8_t> &Annotations) {
if (Annotations.empty())
return -1;
uint8_t FirstByte = Annotations.front();
Annotations = Annotations.drop_front();
if ((FirstByte & 0x80) == 0x00)
return FirstByte;
if (Annotations.empty())
return -1;
uint8_t SecondByte = Annotations.front();
Annotations = Annotations.drop_front();
if ((FirstByte & 0xC0) == 0x80)
return ((FirstByte & 0x3F) << 8) | SecondByte;
if (Annotations.empty())
return -1;
uint8_t ThirdByte = Annotations.front();
Annotations = Annotations.drop_front();
if (Annotations.empty())
return -1;
uint8_t FourthByte = Annotations.front();
Annotations = Annotations.drop_front();
if ((FirstByte & 0xE0) == 0xC0)
return ((FirstByte & 0x1F) << 24) | (SecondByte << 16) |
(ThirdByte << 8) | FourthByte;
return -1;
}
static int32_t DecodeSignedOperand(uint32_t Operand) {
if (Operand & 1)
return -(Operand >> 1);
return Operand >> 1;
}
static int32_t DecodeSignedOperand(ArrayRef<uint8_t> &Annotations) {
return DecodeSignedOperand(GetCompressedAnnotation(Annotations));
}
bool ParseCurrentAnnotation() {
if (Current.hasValue())
return true;
Next = Data;
uint32_t Op = GetCompressedAnnotation(Next);
DecodedAnnotation Result;
Result.OpCode = static_cast<BinaryAnnotationsOpCode>(Op);
switch (Result.OpCode) {
case BinaryAnnotationsOpCode::Invalid:
Result.Name = "Invalid";
Next = ArrayRef<uint8_t>();
break;
case BinaryAnnotationsOpCode::CodeOffset:
Result.Name = "CodeOffset";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeCodeOffsetBase:
Result.Name = "ChangeCodeOffsetBase";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeCodeOffset:
Result.Name = "ChangeCodeOffset";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeCodeLength:
Result.Name = "ChangeCodeLength";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeFile:
Result.Name = "ChangeFile";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeLineEndDelta:
Result.Name = "ChangeLineEndDelta";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeRangeKind:
Result.Name = "ChangeRangeKind";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeColumnStart:
Result.Name = "ChangeColumnStart";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeColumnEnd:
Result.Name = "ChangeColumnEnd";
Result.U1 = GetCompressedAnnotation(Next);
break;
case BinaryAnnotationsOpCode::ChangeLineOffset:
Result.Name = "ChangeLineOffset";
Result.S1 = DecodeSignedOperand(Next);
break;
case BinaryAnnotationsOpCode::ChangeColumnEndDelta:
Result.Name = "ChangeColumnEndDelta";
Result.S1 = DecodeSignedOperand(Next);
break;
case BinaryAnnotationsOpCode::ChangeCodeOffsetAndLineOffset: {
Result.Name = "ChangeCodeOffsetAndLineOffset";
uint32_t Annotation = GetCompressedAnnotation(Next);
Result.S1 = DecodeSignedOperand(Annotation >> 4);
Result.U1 = Annotation & 0xf;
break;
}
case BinaryAnnotationsOpCode::ChangeCodeLengthAndCodeOffset: {
Result.Name = "ChangeCodeLengthAndCodeOffset";
Result.U1 = GetCompressedAnnotation(Next);
Result.U2 = GetCompressedAnnotation(Next);
break;
}
}
Result.Bytes = Data.take_front(Data.size() - Next.size());
Current = Result;
return true;
}
Optional<DecodedAnnotation> Current;
ArrayRef<uint8_t> Data;
ArrayRef<uint8_t> Next;
};
// S_INLINESITE
class InlineSiteSym : public SymbolRecord {
public:
explicit InlineSiteSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit InlineSiteSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::InlineSiteSym),
RecordOffset(RecordOffset) {}
iterator_range<BinaryAnnotationIterator> annotations() const {
return make_range(BinaryAnnotationIterator(AnnotationData),
BinaryAnnotationIterator());
}
uint32_t Parent = 0;
uint32_t End = 0;
TypeIndex Inlinee;
std::vector<uint8_t> AnnotationData;
uint32_t RecordOffset = 0;
};
// S_PUB32
class PublicSym32 : public SymbolRecord {
public:
PublicSym32() : SymbolRecord(SymbolRecordKind::PublicSym32) {}
explicit PublicSym32(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit PublicSym32(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::PublicSym32),
RecordOffset(RecordOffset) {}
PublicSymFlags Flags = PublicSymFlags::None;
uint32_t Offset = 0;
uint16_t Segment = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_REGISTER
class RegisterSym : public SymbolRecord {
public:
explicit RegisterSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit RegisterSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::RegisterSym),
RecordOffset(RecordOffset) {}
TypeIndex Index;
RegisterId Register;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_PROCREF, S_LPROCREF
class ProcRefSym : public SymbolRecord {
public:
explicit ProcRefSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit ProcRefSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::ProcRefSym), RecordOffset(RecordOffset) {
}
uint32_t SumName = 0;
uint32_t SymOffset = 0;
uint16_t Module = 0;
StringRef Name;
uint16_t modi() const { return Module - 1; }
uint32_t RecordOffset = 0;
};
// S_LOCAL
class LocalSym : public SymbolRecord {
public:
explicit LocalSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit LocalSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::LocalSym), RecordOffset(RecordOffset) {}
TypeIndex Type;
LocalSymFlags Flags;
StringRef Name;
uint32_t RecordOffset = 0;
};
struct LocalVariableAddrRange {
uint32_t OffsetStart;
uint16_t ISectStart;
uint16_t Range;
};
struct LocalVariableAddrGap {
uint16_t GapStartOffset;
uint16_t Range;
};
enum : uint16_t { MaxDefRange = 0xf000 };
// S_DEFRANGE
class DefRangeSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 8;
public:
explicit DefRangeSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit DefRangeSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t Program = 0;
LocalVariableAddrRange Range;
std::vector<LocalVariableAddrGap> Gaps;
uint32_t RecordOffset = 0;
};
// S_DEFRANGE_SUBFIELD
class DefRangeSubfieldSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 12;
public:
explicit DefRangeSubfieldSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit DefRangeSubfieldSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeSubfieldSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t Program = 0;
uint16_t OffsetInParent = 0;
LocalVariableAddrRange Range;
std::vector<LocalVariableAddrGap> Gaps;
uint32_t RecordOffset = 0;
};
struct DefRangeRegisterHeader {
ulittle16_t Register;
ulittle16_t MayHaveNoName;
};
// S_DEFRANGE_REGISTER
class DefRangeRegisterSym : public SymbolRecord {
public:
explicit DefRangeRegisterSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit DefRangeRegisterSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeRegisterSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const { return RecordOffset + sizeof(DefRangeRegisterHeader); }
DefRangeRegisterHeader Hdr;
LocalVariableAddrRange Range;
std::vector<LocalVariableAddrGap> Gaps;
uint32_t RecordOffset = 0;
};
struct DefRangeSubfieldRegisterHeader {
ulittle16_t Register;
ulittle16_t MayHaveNoName;
ulittle32_t OffsetInParent;
};
// S_DEFRANGE_SUBFIELD_REGISTER
class DefRangeSubfieldRegisterSym : public SymbolRecord {
public:
explicit DefRangeSubfieldRegisterSym(SymbolRecordKind Kind)
: SymbolRecord(Kind) {}
explicit DefRangeSubfieldRegisterSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeSubfieldRegisterSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const { return RecordOffset + sizeof(DefRangeSubfieldRegisterHeader); }
DefRangeSubfieldRegisterHeader Hdr;
LocalVariableAddrRange Range;
std::vector<LocalVariableAddrGap> Gaps;
uint32_t RecordOffset = 0;
};
struct DefRangeFramePointerRelHeader {
little32_t Offset;
};
// S_DEFRANGE_FRAMEPOINTER_REL
class DefRangeFramePointerRelSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 8;
public:
explicit DefRangeFramePointerRelSym(SymbolRecordKind Kind)
: SymbolRecord(Kind) {}
explicit DefRangeFramePointerRelSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeFramePointerRelSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
DefRangeFramePointerRelHeader Hdr;
LocalVariableAddrRange Range;
std::vector<LocalVariableAddrGap> Gaps;
uint32_t RecordOffset = 0;
};
struct DefRangeRegisterRelHeader {
ulittle16_t Register;
ulittle16_t Flags;
little32_t BasePointerOffset;
};
// S_DEFRANGE_REGISTER_REL
class DefRangeRegisterRelSym : public SymbolRecord {
public:
explicit DefRangeRegisterRelSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit DefRangeRegisterRelSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeRegisterRelSym),
RecordOffset(RecordOffset) {}
// The flags implement this notional bitfield:
// uint16_t IsSubfield : 1;
// uint16_t Padding : 3;
// uint16_t OffsetInParent : 12;
enum : uint16_t {
IsSubfieldFlag = 1,
OffsetInParentShift = 4,
};
bool hasSpilledUDTMember() const { return Hdr.Flags & IsSubfieldFlag; }
uint16_t offsetInParent() const { return Hdr.Flags >> OffsetInParentShift; }
uint32_t getRelocationOffset() const { return RecordOffset + sizeof(DefRangeRegisterRelHeader); }
DefRangeRegisterRelHeader Hdr;
LocalVariableAddrRange Range;
std::vector<LocalVariableAddrGap> Gaps;
uint32_t RecordOffset = 0;
};
// S_DEFRANGE_FRAMEPOINTER_REL_FULL_SCOPE
class DefRangeFramePointerRelFullScopeSym : public SymbolRecord {
public:
explicit DefRangeFramePointerRelFullScopeSym(SymbolRecordKind Kind)
: SymbolRecord(Kind) {}
explicit DefRangeFramePointerRelFullScopeSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DefRangeFramePointerRelFullScopeSym),
RecordOffset(RecordOffset) {}
int32_t Offset = 0;
uint32_t RecordOffset = 0;
};
// S_BLOCK32
class BlockSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 16;
public:
explicit BlockSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit BlockSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::BlockSym), RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t Parent = 0;
uint32_t End = 0;
uint32_t CodeSize = 0;
uint32_t CodeOffset = 0;
uint16_t Segment = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_LABEL32
class LabelSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 4;
public:
explicit LabelSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit LabelSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::LabelSym), RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t CodeOffset = 0;
uint16_t Segment = 0;
ProcSymFlags Flags;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_OBJNAME
class ObjNameSym : public SymbolRecord {
public:
explicit ObjNameSym() : SymbolRecord(SymbolRecordKind::ObjNameSym) {}
explicit ObjNameSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit ObjNameSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::ObjNameSym), RecordOffset(RecordOffset) {
}
uint32_t Signature = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_ENVBLOCK
class EnvBlockSym : public SymbolRecord {
public:
explicit EnvBlockSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit EnvBlockSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::EnvBlockSym),
RecordOffset(RecordOffset) {}
std::vector<StringRef> Fields;
uint32_t RecordOffset = 0;
};
// S_EXPORT
class ExportSym : public SymbolRecord {
public:
explicit ExportSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit ExportSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::ExportSym), RecordOffset(RecordOffset) {}
uint16_t Ordinal = 0;
ExportFlags Flags;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_FILESTATIC
class FileStaticSym : public SymbolRecord {
public:
explicit FileStaticSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit FileStaticSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::FileStaticSym),
RecordOffset(RecordOffset) {}
TypeIndex Index;
uint32_t ModFilenameOffset = 0;
LocalSymFlags Flags;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_COMPILE2
class Compile2Sym : public SymbolRecord {
public:
explicit Compile2Sym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit Compile2Sym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::Compile2Sym),
RecordOffset(RecordOffset) {}
CompileSym2Flags Flags;
CPUType Machine;
uint16_t VersionFrontendMajor = 0;
uint16_t VersionFrontendMinor = 0;
uint16_t VersionFrontendBuild = 0;
uint16_t VersionBackendMajor = 0;
uint16_t VersionBackendMinor = 0;
uint16_t VersionBackendBuild = 0;
StringRef Version;
std::vector<StringRef> ExtraStrings;
uint8_t getLanguage() const { return static_cast<uint32_t>(Flags) & 0xFF; }
uint32_t getFlags() const { return static_cast<uint32_t>(Flags) & ~0xFF; }
uint32_t RecordOffset = 0;
};
// S_COMPILE3
class Compile3Sym : public SymbolRecord {
public:
Compile3Sym() : SymbolRecord(SymbolRecordKind::Compile3Sym) {}
explicit Compile3Sym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit Compile3Sym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::Compile3Sym),
RecordOffset(RecordOffset) {}
CompileSym3Flags Flags;
CPUType Machine;
uint16_t VersionFrontendMajor = 0;
uint16_t VersionFrontendMinor = 0;
uint16_t VersionFrontendBuild = 0;
uint16_t VersionFrontendQFE = 0;
uint16_t VersionBackendMajor = 0;
uint16_t VersionBackendMinor = 0;
uint16_t VersionBackendBuild = 0;
uint16_t VersionBackendQFE = 0;
StringRef Version;
void setLanguage(SourceLanguage Lang) {
Flags = CompileSym3Flags((uint32_t(Flags) & 0xFFFFFF00) | uint32_t(Lang));
}
SourceLanguage getLanguage() const {
return static_cast<SourceLanguage>(static_cast<uint32_t>(Flags) & 0xFF);
}
CompileSym3Flags getFlags() const {
return static_cast<CompileSym3Flags>(static_cast<uint32_t>(Flags) & ~0xFF);
}
bool hasOptimizations() const {
return CompileSym3Flags::None !=
(getFlags() & (CompileSym3Flags::PGO | CompileSym3Flags::LTCG));
}
uint32_t RecordOffset = 0;
};
// S_FRAMEPROC
class FrameProcSym : public SymbolRecord {
public:
explicit FrameProcSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit FrameProcSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::FrameProcSym),
RecordOffset(RecordOffset) {}
uint32_t TotalFrameBytes = 0;
uint32_t PaddingFrameBytes = 0;
uint32_t OffsetToPadding = 0;
uint32_t BytesOfCalleeSavedRegisters = 0;
uint32_t OffsetOfExceptionHandler = 0;
uint16_t SectionIdOfExceptionHandler = 0;
FrameProcedureOptions Flags;
/// Extract the register this frame uses to refer to local variables.
RegisterId getLocalFramePtrReg(CPUType CPU) const {
return decodeFramePtrReg(
EncodedFramePtrReg((uint32_t(Flags) >> 14U) & 0x3U), CPU);
}
/// Extract the register this frame uses to refer to parameters.
RegisterId getParamFramePtrReg(CPUType CPU) const {
return decodeFramePtrReg(
EncodedFramePtrReg((uint32_t(Flags) >> 16U) & 0x3U), CPU);
}
uint32_t RecordOffset = 0;
private:
};
// S_CALLSITEINFO
class CallSiteInfoSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 4;
public:
explicit CallSiteInfoSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit CallSiteInfoSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::CallSiteInfoSym) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t CodeOffset = 0;
uint16_t Segment = 0;
TypeIndex Type;
uint32_t RecordOffset = 0;
};
// S_HEAPALLOCSITE
class HeapAllocationSiteSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 4;
public:
explicit HeapAllocationSiteSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit HeapAllocationSiteSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::HeapAllocationSiteSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t CodeOffset = 0;
uint16_t Segment = 0;
uint16_t CallInstructionSize = 0;
TypeIndex Type;
uint32_t RecordOffset = 0;
};
// S_FRAMECOOKIE
class FrameCookieSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 4;
public:
explicit FrameCookieSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit FrameCookieSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::FrameCookieSym) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
uint32_t CodeOffset = 0;
uint16_t Register = 0;
FrameCookieKind CookieKind;
uint8_t Flags = 0;
uint32_t RecordOffset = 0;
};
// S_UDT, S_COBOLUDT
class UDTSym : public SymbolRecord {
public:
explicit UDTSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit UDTSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::UDTSym) {}
TypeIndex Type;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_BUILDINFO
class BuildInfoSym : public SymbolRecord {
public:
explicit BuildInfoSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit BuildInfoSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::BuildInfoSym),
RecordOffset(RecordOffset) {}
TypeIndex BuildId;
uint32_t RecordOffset = 0;
};
// S_BPREL32
class BPRelativeSym : public SymbolRecord {
public:
explicit BPRelativeSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit BPRelativeSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::BPRelativeSym),
RecordOffset(RecordOffset) {}
int32_t Offset = 0;
TypeIndex Type;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_REGREL32
class RegRelativeSym : public SymbolRecord {
public:
explicit RegRelativeSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit RegRelativeSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::RegRelativeSym),
RecordOffset(RecordOffset) {}
uint32_t Offset = 0;
TypeIndex Type;
RegisterId Register;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_CONSTANT, S_MANCONSTANT
class ConstantSym : public SymbolRecord {
public:
explicit ConstantSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit ConstantSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::ConstantSym),
RecordOffset(RecordOffset) {}
TypeIndex Type;
APSInt Value;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_LDATA32, S_GDATA32, S_LMANDATA, S_GMANDATA
class DataSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 8;
public:
explicit DataSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit DataSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::DataSym), RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
TypeIndex Type;
uint32_t DataOffset = 0;
uint16_t Segment = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_LTHREAD32, S_GTHREAD32
class ThreadLocalDataSym : public SymbolRecord {
static constexpr uint32_t RelocationOffset = 8;
public:
explicit ThreadLocalDataSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit ThreadLocalDataSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::ThreadLocalDataSym),
RecordOffset(RecordOffset) {}
uint32_t getRelocationOffset() const {
return RecordOffset + RelocationOffset;
}
TypeIndex Type;
uint32_t DataOffset = 0;
uint16_t Segment = 0;
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_UNAMESPACE
class UsingNamespaceSym : public SymbolRecord {
public:
explicit UsingNamespaceSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit UsingNamespaceSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::UsingNamespaceSym),
RecordOffset(RecordOffset) {}
StringRef Name;
uint32_t RecordOffset = 0;
};
// S_ANNOTATION
class AnnotationSym : public SymbolRecord {
public:
explicit AnnotationSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {}
explicit AnnotationSym(uint32_t RecordOffset)
: SymbolRecord(SymbolRecordKind::AnnotationSym),
RecordOffset(RecordOffset) {}
uint32_t CodeOffset = 0;
uint16_t Segment = 0;
std::vector<StringRef> Strings;
uint32_t RecordOffset = 0;
};
using CVSymbol = CVRecord<SymbolKind>;
using CVSymbolArray = VarStreamArray<CVSymbol>;
Expected<CVSymbol> readSymbolFromStream(BinaryStreamRef Stream,
uint32_t Offset);
} // end namespace codeview
} // end namespace llvm
#endif // LLVM_DEBUGINFO_CODEVIEW_SYMBOLRECORD_H
|