diff --git a/llvm/include/llvm/DebugInfo/DIContext.h b/llvm/include/llvm/DebugInfo/DIContext.h --- a/llvm/include/llvm/DebugInfo/DIContext.h +++ b/llvm/include/llvm/DebugInfo/DIContext.h @@ -112,6 +112,16 @@ DIGlobal() : Name("") {} }; +struct DILocal { + std::string FunctionName; + std::string Name; + std::string DeclFile; + uint64_t DeclLine = 0; + Optional FrameOffset; + Optional Size; + Optional TagOffset; +}; + /// A DINameKind is passed to name search methods to specify a /// preference regarding the type of name resolution the caller wants. enum class DINameKind { None, ShortName, LinkageName }; @@ -216,6 +226,9 @@ object::SectionedAddress Address, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; + virtual std::vector + getLocalsForAddress(object::SectionedAddress Address) = 0; + private: const DIContextKind Kind; }; diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h --- a/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h +++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h @@ -331,6 +331,9 @@ object::SectionedAddress Address, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override; + std::vector + getLocalsForAddress(object::SectionedAddress Address) override; + bool isLittleEndian() const { return DObj->isLittleEndian(); } static bool isSupportedVersion(unsigned version) { return version == 2 || version == 3 || version == 4 || version == 5; @@ -374,6 +377,8 @@ /// TODO: change input parameter from "uint64_t Address" /// into "SectionedAddress Address" DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address); + void addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram, DWARFDie Die, + std::vector &Result); }; } // end namespace llvm diff --git a/llvm/include/llvm/DebugInfo/PDB/PDBContext.h b/llvm/include/llvm/DebugInfo/PDB/PDBContext.h --- a/llvm/include/llvm/DebugInfo/PDB/PDBContext.h +++ b/llvm/include/llvm/DebugInfo/PDB/PDBContext.h @@ -52,6 +52,9 @@ object::SectionedAddress Address, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override; + std::vector + getLocalsForAddress(object::SectionedAddress Address) override; + private: std::string getFunctionName(uint64_t Address, DINameKind NameKind) const; std::unique_ptr Session; diff --git a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h --- a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h @@ -20,6 +20,7 @@ struct DILineInfo; class DIInliningInfo; struct DIGlobal; +struct DILocal; namespace symbolize { @@ -51,6 +52,7 @@ DIPrinter &operator<<(const DILineInfo &Info); DIPrinter &operator<<(const DIInliningInfo &Info); DIPrinter &operator<<(const DIGlobal &Global); + DIPrinter &operator<<(const DILocal &Local); }; } } diff --git a/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h b/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h --- a/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/SymbolizableModule.h @@ -32,6 +32,8 @@ FunctionNameKind FNKind, bool UseSymbolTable) const = 0; virtual DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const = 0; + virtual std::vector + symbolizeFrame(object::SectionedAddress ModuleOffset) const = 0; // Return true if this is a 32-bit x86 PE COFF module. virtual bool isWin32Module() const = 0; diff --git a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h --- a/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h +++ b/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h @@ -59,6 +59,9 @@ object::SectionedAddress ModuleOffset); Expected symbolizeData(const std::string &ModuleName, object::SectionedAddress ModuleOffset); + Expected> + symbolizeFrame(const std::string &ModuleName, + object::SectionedAddress ModuleOffset); void flush(); static std::string diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -41,6 +41,7 @@ #include "llvm/Support/DataExtractor.h" #include "llvm/Support/Error.h" #include "llvm/Support/Format.h" +#include "llvm/Support/LEB128.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/TargetRegistry.h" @@ -972,6 +973,116 @@ return FoundResult; } +static Optional getTypeSize(DWARFDie Type, uint64_t PointerSize) { + if (auto SizeAttr = Type.find(DW_AT_byte_size)) + if (Optional Size = SizeAttr->getAsUnsignedConstant()) + return Size; + + switch (Type.getTag()) { + case DW_TAG_pointer_type: + case DW_TAG_reference_type: + case DW_TAG_rvalue_reference_type: + return PointerSize; + case DW_TAG_ptr_to_member_type: + return 2 * PointerSize; + case DW_TAG_const_type: + case DW_TAG_volatile_type: + case DW_TAG_restrict_type: + case DW_TAG_typedef: { + if (DWARFDie BaseType = Type.getAttributeValueAsReferencedDie(DW_AT_type)) + return getTypeSize(BaseType, PointerSize); + break; + } + case DW_TAG_array_type: { + DWARFDie BaseType = Type.getAttributeValueAsReferencedDie(DW_AT_type); + if (!BaseType) + return Optional(); + Optional BaseSize = getTypeSize(BaseType, PointerSize); + if (!BaseSize) + return Optional(); + + for (DWARFDie Child : Type) { + if (Child.getTag() != DW_TAG_subrange_type) + continue; + + if (auto ElemCountAttr = Child.find(DW_AT_count)) + if (Optional ElemCount = + ElemCountAttr->getAsUnsignedConstant()) + return *ElemCount * *BaseSize; + if (auto UpperBoundAttr = Child.find(DW_AT_upper_bound)) + if (Optional UpperBound = + UpperBoundAttr->getAsUnsignedConstant()) + return (*UpperBound + 1) * *BaseSize; + } + break; + } + default: + break; + } + return Optional(); +} + +void DWARFContext::addLocalsForDie(DWARFCompileUnit *CU, DWARFDie Subprogram, + DWARFDie Die, std::vector &Result) { + if (Die.getTag() == DW_TAG_variable || + Die.getTag() == DW_TAG_formal_parameter) { + DILocal Local; + if (auto NameAttr = Subprogram.find(DW_AT_name)) + if (Optional Name = NameAttr->getAsCString()) + Local.FunctionName = *Name; + if (auto LocationAttr = Die.find(DW_AT_location)) + if (Optional> Location = LocationAttr->getAsBlock()) + if (!Location->empty() && (*Location)[0] == DW_OP_fbreg) + Local.FrameOffset = + decodeSLEB128(Location->data() + 1, nullptr, Location->end()); + if (auto TagOffsetAttr = Die.find(DW_AT_LLVM_tag_offset)) + Local.TagOffset = TagOffsetAttr->getAsUnsignedConstant(); + + if (auto Origin = + Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) + Die = Origin; + if (auto NameAttr = Die.find(DW_AT_name)) + if (Optional Name = NameAttr->getAsCString()) + Local.Name = *Name; + if (auto Type = Die.getAttributeValueAsReferencedDie(DW_AT_type)) + Local.Size = getTypeSize(Type, getCUAddrSize()); + if (auto DeclFileAttr = Die.find(DW_AT_decl_file)) { + if (const auto *LT = CU->getContext().getLineTableForUnit(CU)) + LT->getFileNameByIndex( + DeclFileAttr->getAsUnsignedConstant().getValue(), + CU->getCompilationDir(), + DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, + Local.DeclFile); + } + if (auto DeclLineAttr = Die.find(DW_AT_decl_line)) + Local.DeclLine = DeclLineAttr->getAsUnsignedConstant().getValue(); + + Result.push_back(Local); + return; + } + + if (Die.getTag() == DW_TAG_inlined_subroutine) + if (auto Origin = + Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) + Subprogram = Origin; + + for (auto Child : Die) + addLocalsForDie(CU, Subprogram, Child, Result); +} + +std::vector +DWARFContext::getLocalsForAddress(object::SectionedAddress Address) { + std::vector Result; + DWARFCompileUnit *CU = getCompileUnitForAddress(Address.Address); + if (!CU) + return Result; + + DWARFDie Subprogram = CU->getSubroutineForAddress(Address.Address); + if (Subprogram.isValid()) + addLocalsForDie(CU, Subprogram, Subprogram, Result); + return Result; +} + DILineInfo DWARFContext::getLineInfoForAddress(object::SectionedAddress Address, DILineInfoSpecifier Spec) { DILineInfo Result; diff --git a/llvm/lib/DebugInfo/PDB/PDBContext.cpp b/llvm/lib/DebugInfo/PDB/PDBContext.cpp --- a/llvm/lib/DebugInfo/PDB/PDBContext.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBContext.cpp @@ -91,6 +91,11 @@ return InlineInfo; } +std::vector +PDBContext::getLocalsForAddress(object::SectionedAddress Address) { + return std::vector(); +} + std::string PDBContext::getFunctionName(uint64_t Address, DINameKind NameKind) const { if (NameKind == DINameKind::None) diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp --- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp +++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp @@ -122,5 +122,28 @@ return *this; } +DIPrinter &DIPrinter::operator<<(const DILocal &Local) { + OS << Local.FunctionName << '\n'; + OS << Local.Name << '\n'; + if (Local.DeclFile.empty()) + OS << "??"; + else + OS << Local.DeclFile; + OS << ':' << Local.DeclLine << '\n'; + if (Local.FrameOffset) + OS << *Local.FrameOffset << ' '; + else + OS << "?? "; + if (Local.Size) + OS << *Local.Size << ' '; + else + OS << "?? "; + if (Local.TagOffset) + OS << *Local.TagOffset << '\n'; + else + OS << "??\n"; + return *this; +} + } // end namespace symbolize } // end namespace llvm diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h --- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h +++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h @@ -40,6 +40,8 @@ FunctionNameKind FNKind, bool UseSymbolTable) const override; DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override; + std::vector + symbolizeFrame(object::SectionedAddress ModuleOffset) const override; // Return true if this is a 32-bit x86 PE COFF module. bool isWin32Module() const override; diff --git a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp --- a/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp +++ b/llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp @@ -298,6 +298,14 @@ return Res; } +std::vector SymbolizableObjectFile::symbolizeFrame( + object::SectionedAddress ModuleOffset) const { + if (ModuleOffset.SectionIndex == object::SectionedAddress::UndefSection) + ModuleOffset.SectionIndex = + getModuleSectionIndexForAddress(ModuleOffset.Address); + return DebugInfoContext->getLocalsForAddress(ModuleOffset); +} + /// Search for the first occurence of specified Address in ObjectFile. uint64_t SymbolizableObjectFile::getModuleSectionIndexForAddress( uint64_t Address) const { diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -133,6 +133,29 @@ return Global; } +Expected> +LLVMSymbolizer::symbolizeFrame(const std::string &ModuleName, + object::SectionedAddress ModuleOffset) { + SymbolizableModule *Info; + if (auto InfoOrErr = getOrCreateModuleInfo(ModuleName)) + Info = InfoOrErr.get(); + else + return InfoOrErr.takeError(); + + // A null module means an error has already been reported. Return an empty + // result. + if (!Info) + return std::vector(); + + // If the user is giving us relative addresses, add the preferred base of + // the object to the offset before we do the query. It's what DIContext + // expects. + if (Opts.RelativeAddresses) + ModuleOffset.Address += Info->getModulePreferredBase(); + + return Info->symbolizeFrame(ModuleOffset); +} + void LLVMSymbolizer::flush() { ObjectForUBPathAndArch.clear(); BinaryForPath.clear(); diff --git a/llvm/test/tools/llvm-symbolizer/frame-types.s b/llvm/test/tools/llvm-symbolizer/frame-types.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/frame-types.s @@ -0,0 +1,490 @@ +// REQUIRES: x86-registered-target + +// RUN: llvm-mc -filetype=obj -triple=i386-linux-gnu -o %t.o %s +// RUN: echo 'FRAME %t.o 0' | llvm-symbolizer | FileCheck %s + +// CHECK: f +// CHECK-NEXT: a +// CHECK-NEXT: /tmp/frame-types.cpp:4 +// CHECK-NEXT: -1 1 ?? +// CHECK-NEXT: f +// CHECK-NEXT: b +// CHECK-NEXT: /tmp/frame-types.cpp:5 +// CHECK-NEXT: -8 4 ?? +// CHECK-NEXT: f +// CHECK-NEXT: c +// CHECK-NEXT: /tmp/frame-types.cpp:6 +// CHECK-NEXT: -12 4 ?? +// CHECK-NEXT: f +// CHECK-NEXT: d +// CHECK-NEXT: /tmp/frame-types.cpp:7 +// CHECK-NEXT: -16 4 ?? +// CHECK-NEXT: f +// CHECK-NEXT: e +// CHECK-NEXT: /tmp/frame-types.cpp:8 +// CHECK-NEXT: -32 8 ?? +// CHECK-NEXT: f +// CHECK-NEXT: f +// CHECK-NEXT: /tmp/frame-types.cpp:9 +// CHECK-NEXT: -33 1 ?? +// CHECK-NEXT: f +// CHECK-NEXT: g +// CHECK-NEXT: /tmp/frame-types.cpp:10 +// CHECK-NEXT: -34 1 ?? +// CHECK-NEXT: f +// CHECK-NEXT: h +// CHECK-NEXT: /tmp/frame-types.cpp:11 +// CHECK-NEXT: -40 4 ?? +// CHECK-NEXT: f +// CHECK-NEXT: i +// CHECK-NEXT: /tmp/frame-types.cpp:13 +// CHECK-NEXT: -41 1 ?? +// CHECK-NEXT: f +// CHECK-NEXT: j +// CHECK-NEXT: /tmp/frame-types.cpp:14 +// CHECK-NEXT: -53 12 ?? + +// Generated from: +// +// struct S; +// +// void f() { +// char a; +// char *b; +// char &c = a; +// char &&d = 1; +// char (S::*e)(); +// const char f = 2; +// volatile char g; +// char *__restrict h; +// typedef char char_typedef; +// char_typedef i; +// char j[12]; +// } +// +// clang++ --target=i386-linux-gnu frame-types.cpp -g -std=c++11 -S -o frame-types.s + + .text + .file "frame-types.cpp" + .globl _Z1fv # -- Begin function _Z1fv + .p2align 4, 0x90 + .type _Z1fv,@function +_Z1fv: # @_Z1fv +.Lfunc_begin0: + .file 1 "/tmp" "frame-types.cpp" + .loc 1 3 0 # frame-types.cpp:3:0 + .cfi_sections .debug_frame + .cfi_startproc +# %bb.0: # %entry + pushl %ebp + .cfi_def_cfa_offset 8 + .cfi_offset %ebp, -8 + movl %esp, %ebp + .cfi_def_cfa_register %ebp + subl $56, %esp +.Ltmp0: + .loc 1 6 9 prologue_end # frame-types.cpp:6:9 + leal -1(%ebp), %eax +.Ltmp1: + #DEBUG_VALUE: f:a <- [$eax+0] + movl %eax, -12(%ebp) + .loc 1 7 14 # frame-types.cpp:7:14 + movb $1, -17(%ebp) + .loc 1 7 10 is_stmt 0 # frame-types.cpp:7:10 + leal -17(%ebp), %eax +.Ltmp2: + movl %eax, -16(%ebp) + .loc 1 9 14 is_stmt 1 # frame-types.cpp:9:14 + movb $2, -33(%ebp) + .loc 1 15 1 # frame-types.cpp:15:1 + addl $56, %esp + popl %ebp + .cfi_def_cfa %esp, 4 + retl +.Ltmp3: +.Lfunc_end0: + .size _Z1fv, .Lfunc_end0-_Z1fv + .cfi_endproc + # -- End function + .section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "clang version 9.0.0 " # string offset=0 +.Linfo_string1: + .asciz "frame-types.cpp" # string offset=21 +.Linfo_string2: + .asciz "/tmp" # string offset=37 +.Linfo_string3: + .asciz "_Z1fv" # string offset=42 +.Linfo_string4: + .asciz "f" # string offset=48 +.Linfo_string5: + .asciz "a" # string offset=50 +.Linfo_string6: + .asciz "char" # string offset=52 +.Linfo_string7: + .asciz "b" # string offset=57 +.Linfo_string8: + .asciz "c" # string offset=59 +.Linfo_string9: + .asciz "d" # string offset=61 +.Linfo_string10: + .asciz "e" # string offset=63 +.Linfo_string11: + .asciz "S" # string offset=65 +.Linfo_string12: + .asciz "g" # string offset=67 +.Linfo_string13: + .asciz "h" # string offset=69 +.Linfo_string14: + .asciz "i" # string offset=71 +.Linfo_string15: + .asciz "char_typedef" # string offset=73 +.Linfo_string16: + .asciz "j" # string offset=86 +.Linfo_string17: + .asciz "__ARRAY_SIZE_TYPE__" # string offset=88 + .section .debug_abbrev,"",@progbits + .byte 1 # Abbreviation Code + .byte 17 # DW_TAG_compile_unit + .byte 1 # DW_CHILDREN_yes + .byte 37 # DW_AT_producer + .byte 14 # DW_FORM_strp + .byte 19 # DW_AT_language + .byte 5 # DW_FORM_data2 + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 16 # DW_AT_stmt_list + .byte 23 # DW_FORM_sec_offset + .byte 27 # DW_AT_comp_dir + .byte 14 # DW_FORM_strp + .byte 17 # DW_AT_low_pc + .byte 1 # DW_FORM_addr + .byte 18 # DW_AT_high_pc + .byte 6 # DW_FORM_data4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 2 # Abbreviation Code + .byte 46 # DW_TAG_subprogram + .byte 1 # DW_CHILDREN_yes + .byte 17 # DW_AT_low_pc + .byte 1 # DW_FORM_addr + .byte 18 # DW_AT_high_pc + .byte 6 # DW_FORM_data4 + .byte 64 # DW_AT_frame_base + .byte 24 # DW_FORM_exprloc + .byte 110 # DW_AT_linkage_name + .byte 14 # DW_FORM_strp + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 63 # DW_AT_external + .byte 25 # DW_FORM_flag_present + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 3 # Abbreviation Code + .byte 52 # DW_TAG_variable + .byte 0 # DW_CHILDREN_no + .byte 2 # DW_AT_location + .byte 24 # DW_FORM_exprloc + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 4 # Abbreviation Code + .byte 22 # DW_TAG_typedef + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 58 # DW_AT_decl_file + .byte 11 # DW_FORM_data1 + .byte 59 # DW_AT_decl_line + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 5 # Abbreviation Code + .byte 36 # DW_TAG_base_type + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 62 # DW_AT_encoding + .byte 11 # DW_FORM_data1 + .byte 11 # DW_AT_byte_size + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 6 # Abbreviation Code + .byte 15 # DW_TAG_pointer_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 7 # Abbreviation Code + .byte 16 # DW_TAG_reference_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 8 # Abbreviation Code + .byte 66 # DW_TAG_rvalue_reference_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 9 # Abbreviation Code + .byte 31 # DW_TAG_ptr_to_member_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 29 # DW_AT_containing_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 10 # Abbreviation Code + .byte 21 # DW_TAG_subroutine_type + .byte 1 # DW_CHILDREN_yes + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 11 # Abbreviation Code + .byte 5 # DW_TAG_formal_parameter + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 52 # DW_AT_artificial + .byte 25 # DW_FORM_flag_present + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 12 # Abbreviation Code + .byte 19 # DW_TAG_structure_type + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 60 # DW_AT_declaration + .byte 25 # DW_FORM_flag_present + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 13 # Abbreviation Code + .byte 38 # DW_TAG_const_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 14 # Abbreviation Code + .byte 53 # DW_TAG_volatile_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 15 # Abbreviation Code + .byte 55 # DW_TAG_restrict_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 16 # Abbreviation Code + .byte 1 # DW_TAG_array_type + .byte 1 # DW_CHILDREN_yes + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 17 # Abbreviation Code + .byte 33 # DW_TAG_subrange_type + .byte 0 # DW_CHILDREN_no + .byte 73 # DW_AT_type + .byte 19 # DW_FORM_ref4 + .byte 55 # DW_AT_count + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 18 # Abbreviation Code + .byte 36 # DW_TAG_base_type + .byte 0 # DW_CHILDREN_no + .byte 3 # DW_AT_name + .byte 14 # DW_FORM_strp + .byte 11 # DW_AT_byte_size + .byte 11 # DW_FORM_data1 + .byte 62 # DW_AT_encoding + .byte 11 # DW_FORM_data1 + .byte 0 # EOM(1) + .byte 0 # EOM(2) + .byte 0 # EOM(3) + .section .debug_info,"",@progbits +.Lcu_begin0: + .long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit +.Ldebug_info_start0: + .short 4 # DWARF version number + .long .debug_abbrev # Offset Into Abbrev. Section + .byte 4 # Address Size (in bytes) + .byte 1 # Abbrev [1] 0xb:0x11f DW_TAG_compile_unit + .long .Linfo_string0 # DW_AT_producer + .short 4 # DW_AT_language + .long .Linfo_string1 # DW_AT_name + .long .Lline_table_start0 # DW_AT_stmt_list + .long .Linfo_string2 # DW_AT_comp_dir + .long .Lfunc_begin0 # DW_AT_low_pc + .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc + .byte 2 # Abbrev [2] 0x26:0xad DW_TAG_subprogram + .long .Lfunc_begin0 # DW_AT_low_pc + .long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc + .byte 1 # DW_AT_frame_base + .byte 85 + .long .Linfo_string3 # DW_AT_linkage_name + .long .Linfo_string4 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 3 # DW_AT_decl_line + # DW_AT_external + .byte 3 # Abbrev [3] 0x3b:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 127 + .long .Linfo_string5 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 4 # DW_AT_decl_line + .long 211 # DW_AT_type + .byte 3 # Abbrev [3] 0x49:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 120 + .long .Linfo_string7 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 5 # DW_AT_decl_line + .long 218 # DW_AT_type + .byte 3 # Abbrev [3] 0x57:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 116 + .long .Linfo_string8 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 6 # DW_AT_decl_line + .long 223 # DW_AT_type + .byte 3 # Abbrev [3] 0x65:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 112 + .long .Linfo_string9 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 7 # DW_AT_decl_line + .long 228 # DW_AT_type + .byte 3 # Abbrev [3] 0x73:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 96 + .long .Linfo_string10 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 8 # DW_AT_decl_line + .long 233 # DW_AT_type + .byte 3 # Abbrev [3] 0x81:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 95 + .long .Linfo_string4 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 9 # DW_AT_decl_line + .long 263 # DW_AT_type + .byte 3 # Abbrev [3] 0x8f:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 94 + .long .Linfo_string12 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 10 # DW_AT_decl_line + .long 268 # DW_AT_type + .byte 3 # Abbrev [3] 0x9d:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 88 + .long .Linfo_string13 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 11 # DW_AT_decl_line + .long 273 # DW_AT_type + .byte 3 # Abbrev [3] 0xab:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 87 + .long .Linfo_string14 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 13 # DW_AT_decl_line + .long 199 # DW_AT_type + .byte 3 # Abbrev [3] 0xb9:0xe DW_TAG_variable + .byte 2 # DW_AT_location + .byte 145 + .byte 75 + .long .Linfo_string16 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 14 # DW_AT_decl_line + .long 278 # DW_AT_type + .byte 4 # Abbrev [4] 0xc7:0xb DW_TAG_typedef + .long 211 # DW_AT_type + .long .Linfo_string15 # DW_AT_name + .byte 1 # DW_AT_decl_file + .byte 12 # DW_AT_decl_line + .byte 0 # End Of Children Mark + .byte 5 # Abbrev [5] 0xd3:0x7 DW_TAG_base_type + .long .Linfo_string6 # DW_AT_name + .byte 6 # DW_AT_encoding + .byte 1 # DW_AT_byte_size + .byte 6 # Abbrev [6] 0xda:0x5 DW_TAG_pointer_type + .long 211 # DW_AT_type + .byte 7 # Abbrev [7] 0xdf:0x5 DW_TAG_reference_type + .long 211 # DW_AT_type + .byte 8 # Abbrev [8] 0xe4:0x5 DW_TAG_rvalue_reference_type + .long 211 # DW_AT_type + .byte 9 # Abbrev [9] 0xe9:0x9 DW_TAG_ptr_to_member_type + .long 242 # DW_AT_type + .long 258 # DW_AT_containing_type + .byte 10 # Abbrev [10] 0xf2:0xb DW_TAG_subroutine_type + .long 211 # DW_AT_type + .byte 11 # Abbrev [11] 0xf7:0x5 DW_TAG_formal_parameter + .long 253 # DW_AT_type + # DW_AT_artificial + .byte 0 # End Of Children Mark + .byte 6 # Abbrev [6] 0xfd:0x5 DW_TAG_pointer_type + .long 258 # DW_AT_type + .byte 12 # Abbrev [12] 0x102:0x5 DW_TAG_structure_type + .long .Linfo_string11 # DW_AT_name + # DW_AT_declaration + .byte 13 # Abbrev [13] 0x107:0x5 DW_TAG_const_type + .long 211 # DW_AT_type + .byte 14 # Abbrev [14] 0x10c:0x5 DW_TAG_volatile_type + .long 211 # DW_AT_type + .byte 15 # Abbrev [15] 0x111:0x5 DW_TAG_restrict_type + .long 218 # DW_AT_type + .byte 16 # Abbrev [16] 0x116:0xc DW_TAG_array_type + .long 211 # DW_AT_type + .byte 17 # Abbrev [17] 0x11b:0x6 DW_TAG_subrange_type + .long 290 # DW_AT_type + .byte 12 # DW_AT_count + .byte 0 # End Of Children Mark + .byte 18 # Abbrev [18] 0x122:0x7 DW_TAG_base_type + .long .Linfo_string17 # DW_AT_name + .byte 8 # DW_AT_byte_size + .byte 7 # DW_AT_encoding + .byte 0 # End Of Children Mark +.Ldebug_info_end0: + .section .debug_macinfo,"",@progbits + .byte 0 # End Of Macro List Mark + + .ident "clang version 9.0.0 " + .section ".note.GNU-stack","",@progbits + .addrsig + .section .debug_line,"",@progbits +.Lline_table_start0: diff --git a/llvm/test/tools/llvm-symbolizer/frame.s b/llvm/test/tools/llvm-symbolizer/frame.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/frame.s @@ -0,0 +1,430 @@ +// REQUIRES: aarch64-registered-target + +// RUN: llvm-mc -filetype=obj -triple=aarch64-linux-android -o %t.o %s +// RUN: echo 'FRAME %t.o 0' | llvm-symbolizer | FileCheck %s + +// CHECK: f +// CHECK-NEXT: a +// CHECK-NEXT: /tmp/stack.c:9 +// CHECK-NEXT: -96 32 128 +// CHECK-NEXT: g +// CHECK-NEXT: p +// CHECK-NEXT: /tmp/stack.c:3 +// CHECK-NEXT: ?? 8 ?? +// CHECK-NEXT: g +// CHECK-NEXT: b +// CHECK-NEXT: /tmp/stack.c:4 +// CHECK-NEXT: -64 32 0 + +// Generated from: +// +// void h(void *, void *); +// +// static void g(void *p) { +// char b[32]; +// h(b, p); +// } +// +// void f() { +// char a[32]; +// g(a); +// } +// +// clang -S -o - -fsanitize=hwaddress --target=aarch64-linux-android /tmp/stack.c -O -fsanitize-hwaddress-abi=platform -g + + .text + .file "stack.c" + .globl f // -- Begin function f + .p2align 2 + .type f,@function +f: // @f +.Lfunc_begin0: + .file 1 "/tmp" "stack.c" + .loc 1 8 0 // stack.c:8:0 + .cfi_startproc +// %bb.0: // %entry + sub sp, sp, #112 // =112 + str x21, [sp, #64] // 8-byte Folded Spill + stp x20, x19, [sp, #80] // 16-byte Folded Spill + stp x29, x30, [sp, #96] // 16-byte Folded Spill + add x29, sp, #96 // =96 + .cfi_def_cfa w29, 16 + .cfi_offset w30, -8 + .cfi_offset w29, -16 + .cfi_offset w19, -24 + .cfi_offset w20, -32 + .cfi_offset w21, -48 + mrs x8, TPIDR_EL0 + ldr x9, [x8, #48] +.Ltmp0: + adr x10, .Ltmp0 + orr x10, x10, x29, lsl #44 + asr x11, x9, #3 + asr x12, x9, #56 + orr x13, x9, #0xffffffff + str x10, [x9], #8 + bic x9, x9, x12, lsl #12 + add x10, sp, #32 // =32 + str x9, [x8, #48] +.Ltmp1: + .loc 1 4 8 prologue_end // stack.c:4:8 + and w8, w11, #0xff + lsr x19, x10, #4 + add x20, x13, #1 // =1 + bfi w8, w8, #8, #8 + mov x12, sp + strh w8, [x20, x19] +.Ltmp2: + .loc 1 9 3 // stack.c:9:3 + eor x8, x11, #0x80 + orr x1, x12, x8, lsl #56 + and w8, w8, #0xff + lsr x21, x12, #4 +.Ltmp3: + .loc 1 4 8 // stack.c:4:8 + orr x0, x10, x11, lsl #56 +.Ltmp4: + .loc 1 9 3 // stack.c:9:3 + bfi w8, w8, #8, #8 + strh w8, [x20, x21] +.Ltmp5: + //DEBUG_VALUE: g:p <- $x1 + .loc 1 5 3 // stack.c:5:3 + bl h +.Ltmp6: + .loc 1 11 1 // stack.c:11:1 + strh wzr, [x20, x19] + strh wzr, [x20, x21] + ldp x29, x30, [sp, #96] // 16-byte Folded Reload + ldp x20, x19, [sp, #80] // 16-byte Folded Reload + ldr x21, [sp, #64] // 8-byte Folded Reload + add sp, sp, #112 // =112 + ret +.Ltmp7: +.Lfunc_end0: + .size f, .Lfunc_end0-f + .cfi_endproc + // -- End function + .section .text.hwasan.module_ctor,"axG",@progbits,hwasan.module_ctor,comdat + .p2align 2 // -- Begin function hwasan.module_ctor + .type hwasan.module_ctor,@function +hwasan.module_ctor: // @hwasan.module_ctor +.Lfunc_begin1: + .cfi_startproc +// %bb.0: + str x30, [sp, #-16]! // 8-byte Folded Spill + .cfi_def_cfa_offset 16 + .cfi_offset w30, -16 + bl __hwasan_init + ldr x30, [sp], #16 // 8-byte Folded Reload + ret +.Lfunc_end1: + .size hwasan.module_ctor, .Lfunc_end1-hwasan.module_ctor + .cfi_endproc + // -- End function + .section .init_array.0,"aGw",@init_array,hwasan.module_ctor,comdat + .p2align 3 + .xword hwasan.module_ctor + .section .debug_str,"MS",@progbits,1 +.Linfo_string0: + .asciz "clang version 9.0.0 " // string offset=0 +.Linfo_string1: + .asciz "/tmp/stack.c" // string offset=21 +.Linfo_string2: + .asciz "/tmp" // string offset=34 +.Linfo_string3: + .asciz "g" // string offset=39 +.Linfo_string4: + .asciz "p" // string offset=41 +.Linfo_string5: + .asciz "b" // string offset=43 +.Linfo_string6: + .asciz "char" // string offset=45 +.Linfo_string7: + .asciz "__ARRAY_SIZE_TYPE__" // string offset=50 +.Linfo_string8: + .asciz "f" // string offset=70 +.Linfo_string9: + .asciz "a" // string offset=72 + .section .debug_loc,"",@progbits +.Ldebug_loc0: + .xword .Ltmp5-.Lfunc_begin0 + .xword .Ltmp6-.Lfunc_begin0 + .hword 1 // Loc expr size + .byte 81 // DW_OP_reg1 + .xword 0 + .xword 0 + .section .debug_abbrev,"",@progbits + .byte 1 // Abbreviation Code + .byte 17 // DW_TAG_compile_unit + .byte 1 // DW_CHILDREN_yes + .byte 37 // DW_AT_producer + .byte 14 // DW_FORM_strp + .byte 19 // DW_AT_language + .byte 5 // DW_FORM_data2 + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 16 // DW_AT_stmt_list + .byte 23 // DW_FORM_sec_offset + .byte 27 // DW_AT_comp_dir + .byte 14 // DW_FORM_strp + .byte 17 // DW_AT_low_pc + .byte 1 // DW_FORM_addr + .byte 18 // DW_AT_high_pc + .byte 6 // DW_FORM_data4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 2 // Abbreviation Code + .byte 46 // DW_TAG_subprogram + .byte 1 // DW_CHILDREN_yes + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 58 // DW_AT_decl_file + .byte 11 // DW_FORM_data1 + .byte 59 // DW_AT_decl_line + .byte 11 // DW_FORM_data1 + .byte 39 // DW_AT_prototyped + .byte 25 // DW_FORM_flag_present + .byte 32 // DW_AT_inline + .byte 11 // DW_FORM_data1 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 3 // Abbreviation Code + .byte 5 // DW_TAG_formal_parameter + .byte 0 // DW_CHILDREN_no + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 58 // DW_AT_decl_file + .byte 11 // DW_FORM_data1 + .byte 59 // DW_AT_decl_line + .byte 11 // DW_FORM_data1 + .byte 73 // DW_AT_type + .byte 19 // DW_FORM_ref4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 4 // Abbreviation Code + .byte 52 // DW_TAG_variable + .byte 0 // DW_CHILDREN_no + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 58 // DW_AT_decl_file + .byte 11 // DW_FORM_data1 + .byte 59 // DW_AT_decl_line + .byte 11 // DW_FORM_data1 + .byte 73 // DW_AT_type + .byte 19 // DW_FORM_ref4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 5 // Abbreviation Code + .byte 15 // DW_TAG_pointer_type + .byte 0 // DW_CHILDREN_no + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 6 // Abbreviation Code + .byte 1 // DW_TAG_array_type + .byte 1 // DW_CHILDREN_yes + .byte 73 // DW_AT_type + .byte 19 // DW_FORM_ref4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 7 // Abbreviation Code + .byte 33 // DW_TAG_subrange_type + .byte 0 // DW_CHILDREN_no + .byte 73 // DW_AT_type + .byte 19 // DW_FORM_ref4 + .byte 55 // DW_AT_count + .byte 11 // DW_FORM_data1 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 8 // Abbreviation Code + .byte 36 // DW_TAG_base_type + .byte 0 // DW_CHILDREN_no + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 62 // DW_AT_encoding + .byte 11 // DW_FORM_data1 + .byte 11 // DW_AT_byte_size + .byte 11 // DW_FORM_data1 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 9 // Abbreviation Code + .byte 36 // DW_TAG_base_type + .byte 0 // DW_CHILDREN_no + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 11 // DW_AT_byte_size + .byte 11 // DW_FORM_data1 + .byte 62 // DW_AT_encoding + .byte 11 // DW_FORM_data1 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 10 // Abbreviation Code + .byte 46 // DW_TAG_subprogram + .byte 1 // DW_CHILDREN_yes + .byte 17 // DW_AT_low_pc + .byte 1 // DW_FORM_addr + .byte 18 // DW_AT_high_pc + .byte 6 // DW_FORM_data4 + .byte 64 // DW_AT_frame_base + .byte 24 // DW_FORM_exprloc + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 58 // DW_AT_decl_file + .byte 11 // DW_FORM_data1 + .byte 59 // DW_AT_decl_line + .byte 11 // DW_FORM_data1 + .byte 63 // DW_AT_external + .byte 25 // DW_FORM_flag_present + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 11 // Abbreviation Code + .byte 52 // DW_TAG_variable + .byte 0 // DW_CHILDREN_no + .byte 2 // DW_AT_location + .byte 24 // DW_FORM_exprloc + .ascii "\203|" // DW_AT_LLVM_tag_offset + .byte 11 // DW_FORM_data1 + .byte 3 // DW_AT_name + .byte 14 // DW_FORM_strp + .byte 58 // DW_AT_decl_file + .byte 11 // DW_FORM_data1 + .byte 59 // DW_AT_decl_line + .byte 11 // DW_FORM_data1 + .byte 73 // DW_AT_type + .byte 19 // DW_FORM_ref4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 12 // Abbreviation Code + .byte 29 // DW_TAG_inlined_subroutine + .byte 1 // DW_CHILDREN_yes + .byte 49 // DW_AT_abstract_origin + .byte 19 // DW_FORM_ref4 + .byte 85 // DW_AT_ranges + .byte 23 // DW_FORM_sec_offset + .byte 88 // DW_AT_call_file + .byte 11 // DW_FORM_data1 + .byte 89 // DW_AT_call_line + .byte 11 // DW_FORM_data1 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 13 // Abbreviation Code + .byte 5 // DW_TAG_formal_parameter + .byte 0 // DW_CHILDREN_no + .byte 2 // DW_AT_location + .byte 23 // DW_FORM_sec_offset + .byte 49 // DW_AT_abstract_origin + .byte 19 // DW_FORM_ref4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 14 // Abbreviation Code + .byte 52 // DW_TAG_variable + .byte 0 // DW_CHILDREN_no + .byte 2 // DW_AT_location + .byte 24 // DW_FORM_exprloc + .ascii "\203|" // DW_AT_LLVM_tag_offset + .byte 11 // DW_FORM_data1 + .byte 49 // DW_AT_abstract_origin + .byte 19 // DW_FORM_ref4 + .byte 0 // EOM(1) + .byte 0 // EOM(2) + .byte 0 // EOM(3) + .section .debug_info,"",@progbits +.Lcu_begin0: + .word .Ldebug_info_end0-.Ldebug_info_start0 // Length of Unit +.Ldebug_info_start0: + .hword 4 // DWARF version number + .word .debug_abbrev // Offset Into Abbrev. Section + .byte 8 // Address Size (in bytes) + .byte 1 // Abbrev [1] 0xb:0x9e DW_TAG_compile_unit + .word .Linfo_string0 // DW_AT_producer + .hword 12 // DW_AT_language + .word .Linfo_string1 // DW_AT_name + .word .Lline_table_start0 // DW_AT_stmt_list + .word .Linfo_string2 // DW_AT_comp_dir + .xword .Lfunc_begin0 // DW_AT_low_pc + .word .Lfunc_end0-.Lfunc_begin0 // DW_AT_high_pc + .byte 2 // Abbrev [2] 0x2a:0x1f DW_TAG_subprogram + .word .Linfo_string3 // DW_AT_name + .byte 1 // DW_AT_decl_file + .byte 3 // DW_AT_decl_line + // DW_AT_prototyped + .byte 1 // DW_AT_inline + .byte 3 // Abbrev [3] 0x32:0xb DW_TAG_formal_parameter + .word .Linfo_string4 // DW_AT_name + .byte 1 // DW_AT_decl_file + .byte 3 // DW_AT_decl_line + .word 73 // DW_AT_type + .byte 4 // Abbrev [4] 0x3d:0xb DW_TAG_variable + .word .Linfo_string5 // DW_AT_name + .byte 1 // DW_AT_decl_file + .byte 4 // DW_AT_decl_line + .word 74 // DW_AT_type + .byte 0 // End Of Children Mark + .byte 5 // Abbrev [5] 0x49:0x1 DW_TAG_pointer_type + .byte 6 // Abbrev [6] 0x4a:0xc DW_TAG_array_type + .word 86 // DW_AT_type + .byte 7 // Abbrev [7] 0x4f:0x6 DW_TAG_subrange_type + .word 93 // DW_AT_type + .byte 32 // DW_AT_count + .byte 0 // End Of Children Mark + .byte 8 // Abbrev [8] 0x56:0x7 DW_TAG_base_type + .word .Linfo_string6 // DW_AT_name + .byte 8 // DW_AT_encoding + .byte 1 // DW_AT_byte_size + .byte 9 // Abbrev [9] 0x5d:0x7 DW_TAG_base_type + .word .Linfo_string7 // DW_AT_name + .byte 8 // DW_AT_byte_size + .byte 7 // DW_AT_encoding + .byte 10 // Abbrev [10] 0x64:0x44 DW_TAG_subprogram + .xword .Lfunc_begin0 // DW_AT_low_pc + .word .Lfunc_end0-.Lfunc_begin0 // DW_AT_high_pc + .byte 1 // DW_AT_frame_base + .byte 109 + .word .Linfo_string8 // DW_AT_name + .byte 1 // DW_AT_decl_file + .byte 8 // DW_AT_decl_line + // DW_AT_external + .byte 11 // Abbrev [11] 0x79:0x10 DW_TAG_variable + .byte 3 // DW_AT_location + .byte 145 + .ascii "\240\177" + .byte 128 // DW_AT_LLVM_tag_offset + .word .Linfo_string9 // DW_AT_name + .byte 1 // DW_AT_decl_file + .byte 9 // DW_AT_decl_line + .word 74 // DW_AT_type + .byte 12 // Abbrev [12] 0x89:0x1e DW_TAG_inlined_subroutine + .word 42 // DW_AT_abstract_origin + .word .Ldebug_ranges0 // DW_AT_ranges + .byte 1 // DW_AT_call_file + .byte 10 // DW_AT_call_line + .byte 13 // Abbrev [13] 0x94:0x9 DW_TAG_formal_parameter + .word .Ldebug_loc0 // DW_AT_location + .word 50 // DW_AT_abstract_origin + .byte 14 // Abbrev [14] 0x9d:0x9 DW_TAG_variable + .byte 2 // DW_AT_location + .byte 145 + .byte 64 + .byte 0 // DW_AT_LLVM_tag_offset + .word 61 // DW_AT_abstract_origin + .byte 0 // End Of Children Mark + .byte 0 // End Of Children Mark + .byte 0 // End Of Children Mark +.Ldebug_info_end0: + .section .debug_ranges,"",@progbits +.Ldebug_ranges0: + .xword .Ltmp1-.Lfunc_begin0 + .xword .Ltmp2-.Lfunc_begin0 + .xword .Ltmp3-.Lfunc_begin0 + .xword .Ltmp4-.Lfunc_begin0 + .xword .Ltmp5-.Lfunc_begin0 + .xword .Ltmp6-.Lfunc_begin0 + .xword 0 + .xword 0 + .section .debug_macinfo,"",@progbits + .byte 0 // End Of Macro List Mark + + .ident "clang version 9.0.0 " + .section ".note.GNU-stack","",@progbits + .section .debug_line,"",@progbits +.Lline_table_start0: diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -163,17 +163,25 @@ return true; } -static bool parseCommand(StringRef InputString, bool &IsData, +enum class Command { + Code, + Data, + Frame, +}; + +static bool parseCommand(StringRef InputString, Command &Cmd, std::string &ModuleName, uint64_t &ModuleOffset) { const char kDelimiters[] = " \n\r"; ModuleName = ""; if (InputString.consume_front("CODE ")) { - IsData = false; + Cmd = Command::Code; } else if (InputString.consume_front("DATA ")) { - IsData = true; + Cmd = Command::Data; + } else if (InputString.consume_front("FRAME ")) { + Cmd = Command::Frame; } else { // If no cmd, assume it's CODE. - IsData = false; + Cmd = Command::Code; } const char *pos = InputString.data(); // Skip delimiters and parse input filename (if needed). @@ -203,10 +211,10 @@ static void symbolizeInput(StringRef InputString, LLVMSymbolizer &Symbolizer, DIPrinter &Printer) { - bool IsData = false; + Command Cmd; std::string ModuleName; uint64_t Offset = 0; - if (!parseCommand(StringRef(InputString), IsData, ModuleName, Offset)) { + if (!parseCommand(StringRef(InputString), Cmd, ModuleName, Offset)) { outs() << InputString; return; } @@ -218,10 +226,19 @@ outs() << Delimiter; } Offset -= ClAdjustVMA; - if (IsData) { + if (Cmd == Command::Data) { auto ResOrErr = Symbolizer.symbolizeData( ModuleName, {Offset, object::SectionedAddress::UndefSection}); Printer << (error(ResOrErr) ? DIGlobal() : ResOrErr.get()); + } else if (Cmd == Command::Frame) { + auto ResOrErr = Symbolizer.symbolizeFrame( + ModuleName, {Offset, object::SectionedAddress::UndefSection}); + if (!error(ResOrErr)) { + for (DILocal Local : *ResOrErr) + Printer << Local; + if (ResOrErr->empty()) + outs() << "??\n"; + } } else if (ClPrintInlining) { auto ResOrErr = Symbolizer.symbolizeInlinedCode( ModuleName, {Offset, object::SectionedAddress::UndefSection});