1 //===-- DIContext.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines DIContext, an abstract data structure that holds
11 // debug information data.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_DEBUGINFO_DICONTEXT_H
16 #define LLVM_DEBUGINFO_DICONTEXT_H
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/DataTypes.h"
28 /// DILineInfo - a format-neutral container for source line information.
30 SmallString<16> FileName;
31 SmallString<16> FunctionName;
36 : FileName("<invalid>"), FunctionName("<invalid>"),
38 DILineInfo(const SmallString<16> &fileName,
39 const SmallString<16> &functionName,
40 uint32_t line, uint32_t column)
41 : FileName(fileName), FunctionName(functionName),
42 Line(line), Column(column) {}
44 const char *getFileName() { return FileName.c_str(); }
45 const char *getFunctionName() { return FunctionName.c_str(); }
46 uint32_t getLine() const { return Line; }
47 uint32_t getColumn() const { return Column; }
49 bool operator==(const DILineInfo &RHS) const {
50 return Line == RHS.Line && Column == RHS.Column &&
51 FileName.equals(RHS.FileName) &&
52 FunctionName.equals(RHS.FunctionName);
54 bool operator!=(const DILineInfo &RHS) const {
55 return !(*this == RHS);
59 /// DIInliningInfo - a format-neutral container for inlined code description.
60 class DIInliningInfo {
61 SmallVector<DILineInfo, 4> Frames;
64 DILineInfo getFrame(unsigned Index) const {
65 assert(Index < Frames.size());
68 uint32_t getNumberOfFrames() const {
71 void addFrame(const DILineInfo &Frame) {
72 Frames.push_back(Frame);
76 /// DILineInfoSpecifier - controls which fields of DILineInfo container
77 /// should be filled with data.
78 class DILineInfoSpecifier {
79 const uint32_t Flags; // Or'ed flags that set the info we want to fetch.
82 FileLineInfo = 1 << 0,
83 AbsoluteFilePath = 1 << 1,
86 // Use file/line info by default.
87 DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
88 bool needs(Specification spec) const {
89 return (Flags & spec) > 0;
93 // In place of applying the relocations to the data we've read from disk we use
94 // a separate mapping table to the side and checking that at locations in the dwarf
95 // we expec relocated values. This adds a bit of complexity to the dwarf
96 // parsing/extraction at the benefit of not allocating memory for the entire
97 // size of the debug info sections.
98 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
102 virtual ~DIContext();
104 /// getDWARFContext - get a context for binary DWARF data.
105 static DIContext *getDWARFContext(bool isLittleEndian,
106 StringRef infoSection,
107 StringRef abbrevSection,
108 StringRef aRangeSection = StringRef(),
109 StringRef lineSection = StringRef(),
110 StringRef stringSection = StringRef(),
111 StringRef rangeSection = StringRef(),
112 const RelocAddrMap &Map = RelocAddrMap());
114 virtual void dump(raw_ostream &OS) = 0;
116 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
117 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
118 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
119 DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;