From 6def39bfec04962f03babd1d270028645cdddb81 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 15 May 2019 20:53:39 +0000 Subject: [PATCH] [codeview] Finish support for reading and writing S_ANNOTATION records Implement dumping via llvm-pdbutil and llvm-readobj. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360813 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../llvm/DebugInfo/CodeView/CodeViewSymbols.def | 2 +- include/llvm/DebugInfo/CodeView/SymbolRecord.h | 15 +++- lib/DebugInfo/CodeView/SymbolDumper.cpp | 12 +++ lib/DebugInfo/CodeView/SymbolRecordMapping.cpp | 12 +++ lib/ObjectYAML/CodeViewYAMLSymbols.cpp | 6 ++ test/DebugInfo/PDB/Inputs/unknown-symbol.yaml | 2 +- test/DebugInfo/PDB/annotation.test | 88 ++++++++++++++++++++++ test/DebugInfo/PDB/pdb-unknown-symbol.test | 2 +- tools/llvm-pdbutil/MinimalSymbolDumper.cpp | 9 +++ 9 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 test/DebugInfo/PDB/annotation.test diff --git a/include/llvm/DebugInfo/CodeView/CodeViewSymbols.def b/include/llvm/DebugInfo/CodeView/CodeViewSymbols.def index e36d8046613..4f8ccfdd16a 100644 --- a/include/llvm/DebugInfo/CodeView/CodeViewSymbols.def +++ b/include/llvm/DebugInfo/CodeView/CodeViewSymbols.def @@ -102,7 +102,6 @@ CV_SYMBOL(S_LPROCIA64_ST , 0x1015) CV_SYMBOL(S_GPROCIA64_ST , 0x1016) CV_SYMBOL(S_LOCALSLOT_ST , 0x1017) CV_SYMBOL(S_PARAMSLOT_ST , 0x1018) -CV_SYMBOL(S_ANNOTATION , 0x1019) CV_SYMBOL(S_GMANPROC_ST , 0x101a) CV_SYMBOL(S_LMANPROC_ST , 0x101b) CV_SYMBOL(S_RESERVED1 , 0x101c) @@ -254,6 +253,7 @@ SYMBOL_RECORD(S_LTHREAD32 , 0x1112, ThreadLocalDataSym) SYMBOL_RECORD_ALIAS(S_GTHREAD32 , 0x1113, GlobalTLS, ThreadLocalDataSym) SYMBOL_RECORD(S_UNAMESPACE , 0x1124, UsingNamespaceSym) +SYMBOL_RECORD(S_ANNOTATION , 0x1019, AnnotationSym) #undef CV_SYMBOL #undef SYMBOL_RECORD diff --git a/include/llvm/DebugInfo/CodeView/SymbolRecord.h b/include/llvm/DebugInfo/CodeView/SymbolRecord.h index ac7b106e7b9..b98ada221a4 100644 --- a/include/llvm/DebugInfo/CodeView/SymbolRecord.h +++ b/include/llvm/DebugInfo/CodeView/SymbolRecord.h @@ -973,7 +973,7 @@ class UsingNamespaceSym : public SymbolRecord { public: explicit UsingNamespaceSym(SymbolRecordKind Kind) : SymbolRecord(Kind) {} explicit UsingNamespaceSym(uint32_t RecordOffset) - : SymbolRecord(SymbolRecordKind::RegRelativeSym), + : SymbolRecord(SymbolRecordKind::UsingNamespaceSym), RecordOffset(RecordOffset) {} StringRef Name; @@ -982,6 +982,19 @@ public: }; // 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 Strings; + + uint32_t RecordOffset; +}; using CVSymbol = CVRecord; using CVSymbolArray = VarStreamArray; diff --git a/lib/DebugInfo/CodeView/SymbolDumper.cpp b/lib/DebugInfo/CodeView/SymbolDumper.cpp index 783b85409f7..44ce04a49e9 100644 --- a/lib/DebugInfo/CodeView/SymbolDumper.cpp +++ b/lib/DebugInfo/CodeView/SymbolDumper.cpp @@ -630,6 +630,18 @@ Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, return Error::success(); } +Error CVSymbolDumperImpl::visitKnownRecord(CVSymbol &CVR, + AnnotationSym &Annot) { + W.printHex("Offset", Annot.CodeOffset); + W.printHex("Segment", Annot.Segment); + + ListScope S(W, "Strings"); + for (StringRef Str : Annot.Strings) + W.printString(Str); + + return Error::success(); +} + Error CVSymbolDumperImpl::visitUnknownSymbol(CVSymbol &CVR) { W.printNumber("Length", CVR.length()); return Error::success(); diff --git a/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp b/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp index 36d77965daf..70889839ef4 100644 --- a/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp +++ b/lib/DebugInfo/CodeView/SymbolRecordMapping.cpp @@ -471,6 +471,18 @@ Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, return Error::success(); } +Error SymbolRecordMapping::visitKnownRecord(CVSymbol &CVR, + AnnotationSym &Annot) { + + error(IO.mapInteger(Annot.CodeOffset)); + error(IO.mapInteger(Annot.Segment)); + error(IO.mapVectorN( + Annot.Strings, + [](CodeViewRecordIO &IO, StringRef &S) { return IO.mapStringZ(S); })); + + return Error::success(); +} + RegisterId codeview::decodeFramePtrReg(EncodedFramePtrReg EncodedReg, CPUType CPU) { assert(unsigned(EncodedReg) < 4); diff --git a/lib/ObjectYAML/CodeViewYAMLSymbols.cpp b/lib/ObjectYAML/CodeViewYAMLSymbols.cpp index 301ef4c2334..bbaa5ed75ad 100644 --- a/lib/ObjectYAML/CodeViewYAMLSymbols.cpp +++ b/lib/ObjectYAML/CodeViewYAMLSymbols.cpp @@ -553,6 +553,12 @@ template <> void SymbolRecordImpl::map(IO &IO) { IO.mapRequired("Namespace", Symbol.Name); } +template <> void SymbolRecordImpl::map(IO &IO) { + IO.mapOptional("Offset", Symbol.CodeOffset, 0U); + IO.mapOptional("Segment", Symbol.Segment, uint16_t(0)); + IO.mapRequired("Strings", Symbol.Strings); +} + } // end namespace detail } // end namespace CodeViewYAML } // end namespace llvm diff --git a/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml b/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml index a2966c43787..83bc20c45da 100644 --- a/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml +++ b/test/DebugInfo/PDB/Inputs/unknown-symbol.yaml @@ -4,7 +4,7 @@ DbiStream: - Module: unknown-symbol.yaml Modi: Records: - - Kind: S_ANNOTATION + - Kind: S_RESERVED1 UnknownSym: Data: 123456789ABCDEF0 ... diff --git a/test/DebugInfo/PDB/annotation.test b/test/DebugInfo/PDB/annotation.test new file mode 100644 index 00000000000..ba6bd14061e --- /dev/null +++ b/test/DebugInfo/PDB/annotation.test @@ -0,0 +1,88 @@ +# RUN: yaml2obj < %s > %t.obj +# RUN: llvm-pdbutil dump --symbols %t.obj | FileCheck %s +# RUN: llvm-readobj -codeview %t.obj | FileCheck %s --check-prefix=READOBJ + +# CHECK: S_ANNOTATION [size = 20] +# CHECK-NEXT: addr = 0001:0042 +# CHECK-NEXT: strings = [ +# CHECK-NEXT: foo +# CHECK-NEXT: bar] + +# READOBJ: AnnotationSym { +# READOBJ-NEXT: Kind: S_ANNOTATION (0x1019) +# READOBJ-NEXT: Offset: 0x2A +# READOBJ-NEXT: Segment: 0x1 +# READOBJ-NEXT: Strings [ +# READOBJ-NEXT: foo +# READOBJ-NEXT: bar +# READOBJ-NEXT: ] +# READOBJ-NEXT: } + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: CD2C0F0B + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 0 + ObjectName: 'SimpleFunction.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 14 + FrontendBuild: 26433 + FrontendQFE: 0 + BackendMajor: 19 + BackendMinor: 14 + BackendBuild: 26433 + BackendQFE: 0 + Version: 'Microsoft (R) Optimizing Compiler' + - Kind: S_ANNOTATION + AnnotationSym: + Offset: 42 + Segment: 1 + Strings: + - foo + - bar + - !StringTable + Strings: + - 'SimpleFunction.c' +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 4 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 2772061208 + Number: 1 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 396 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 +... diff --git a/test/DebugInfo/PDB/pdb-unknown-symbol.test b/test/DebugInfo/PDB/pdb-unknown-symbol.test index 3d2547ee51a..14b8cbcf45a 100644 --- a/test/DebugInfo/PDB/pdb-unknown-symbol.test +++ b/test/DebugInfo/PDB/pdb-unknown-symbol.test @@ -1,6 +1,6 @@ ; RUN: llvm-pdbutil yaml2pdb -pdb=%t.pdb %p/Inputs/unknown-symbol.yaml ; RUN: llvm-pdbutil pdb2yaml -minimal -module-syms -no-file-headers %t.pdb | FileCheck %s -CHECK: - Kind: S_ANNOTATION +CHECK: - Kind: S_RESERVED1 CHECK: UnknownSym: CHECK: Data: 123456789ABCDEF0 diff --git a/tools/llvm-pdbutil/MinimalSymbolDumper.cpp b/tools/llvm-pdbutil/MinimalSymbolDumper.cpp index a6f374305fc..50d70c070d2 100644 --- a/tools/llvm-pdbutil/MinimalSymbolDumper.cpp +++ b/tools/llvm-pdbutil/MinimalSymbolDumper.cpp @@ -780,3 +780,12 @@ Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, P.format(" `{0}`", UN.Name); return Error::success(); } + +Error MinimalSymbolDumper::visitKnownRecord(CVSymbol &CVR, + AnnotationSym &Annot) { + AutoIndent Indent(P, 7); + P.formatLine("addr = {0}", formatSegmentOffset(Annot.Segment, Annot.CodeOffset)); + P.formatLine("strings = {0}", typesetStringList(P.getIndentLevel() + 9 + 2, + Annot.Strings)); + return Error::success(); +} -- 2.11.0