LLVM API Documentation
00001 //===-- DIContext.h ---------------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines DIContext, an abstract data structure that holds 00011 // debug information data. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_DEBUGINFO_DICONTEXT_H 00016 #define LLVM_DEBUGINFO_DICONTEXT_H 00017 00018 #include "llvm/ADT/DenseMap.h" 00019 #include "llvm/ADT/SmallVector.h" 00020 #include "llvm/Object/ObjectFile.h" 00021 #include "llvm/Object/RelocVisitor.h" 00022 #include "llvm/Support/Casting.h" 00023 #include "llvm/Support/DataTypes.h" 00024 00025 #include <string> 00026 00027 namespace llvm { 00028 00029 class raw_ostream; 00030 00031 /// DILineInfo - a format-neutral container for source line information. 00032 struct DILineInfo { 00033 std::string FileName; 00034 std::string FunctionName; 00035 uint32_t Line; 00036 uint32_t Column; 00037 00038 DILineInfo() 00039 : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {} 00040 00041 bool operator==(const DILineInfo &RHS) const { 00042 return Line == RHS.Line && Column == RHS.Column && 00043 FileName == RHS.FileName && FunctionName == RHS.FunctionName; 00044 } 00045 bool operator!=(const DILineInfo &RHS) const { 00046 return !(*this == RHS); 00047 } 00048 }; 00049 00050 typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable; 00051 00052 /// DIInliningInfo - a format-neutral container for inlined code description. 00053 class DIInliningInfo { 00054 SmallVector<DILineInfo, 4> Frames; 00055 public: 00056 DIInliningInfo() {} 00057 DILineInfo getFrame(unsigned Index) const { 00058 assert(Index < Frames.size()); 00059 return Frames[Index]; 00060 } 00061 uint32_t getNumberOfFrames() const { 00062 return Frames.size(); 00063 } 00064 void addFrame(const DILineInfo &Frame) { 00065 Frames.push_back(Frame); 00066 } 00067 }; 00068 00069 /// DILineInfoSpecifier - controls which fields of DILineInfo container 00070 /// should be filled with data. 00071 struct DILineInfoSpecifier { 00072 enum class FileLineInfoKind { None, Default, AbsoluteFilePath }; 00073 enum class FunctionNameKind { None, ShortName, LinkageName }; 00074 00075 FileLineInfoKind FLIKind; 00076 FunctionNameKind FNKind; 00077 00078 DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default, 00079 FunctionNameKind FNKind = FunctionNameKind::None) 00080 : FLIKind(FLIKind), FNKind(FNKind) {} 00081 }; 00082 00083 /// Selects which debug sections get dumped. 00084 enum DIDumpType { 00085 DIDT_Null, 00086 DIDT_All, 00087 DIDT_Abbrev, 00088 DIDT_AbbrevDwo, 00089 DIDT_Aranges, 00090 DIDT_Frames, 00091 DIDT_Info, 00092 DIDT_InfoDwo, 00093 DIDT_Types, 00094 DIDT_TypesDwo, 00095 DIDT_Line, 00096 DIDT_LineDwo, 00097 DIDT_Loc, 00098 DIDT_LocDwo, 00099 DIDT_Ranges, 00100 DIDT_Pubnames, 00101 DIDT_Pubtypes, 00102 DIDT_GnuPubnames, 00103 DIDT_GnuPubtypes, 00104 DIDT_Str, 00105 DIDT_StrDwo, 00106 DIDT_StrOffsetsDwo 00107 }; 00108 00109 // In place of applying the relocations to the data we've read from disk we use 00110 // a separate mapping table to the side and checking that at locations in the 00111 // dwarf where we expect relocated values. This adds a bit of complexity to the 00112 // dwarf parsing/extraction at the benefit of not allocating memory for the 00113 // entire size of the debug info sections. 00114 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap; 00115 00116 class DIContext { 00117 public: 00118 enum DIContextKind { 00119 CK_DWARF 00120 }; 00121 DIContextKind getKind() const { return Kind; } 00122 00123 DIContext(DIContextKind K) : Kind(K) {} 00124 virtual ~DIContext(); 00125 00126 /// getDWARFContext - get a context for binary DWARF data. 00127 static DIContext *getDWARFContext(object::ObjectFile &); 00128 00129 virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0; 00130 00131 virtual DILineInfo getLineInfoForAddress(uint64_t Address, 00132 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; 00133 virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, 00134 uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; 00135 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, 00136 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0; 00137 private: 00138 const DIContextKind Kind; 00139 }; 00140 00141 } 00142 00143 #endif