LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DIContext.h
Go to the documentation of this file.
1 //===-- DIContext.h ---------------------------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines DIContext, an abstract data structure that holds
11 // debug information data.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_DEBUGINFO_DICONTEXT_H
16 #define LLVM_DEBUGINFO_DICONTEXT_H
17 
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Support/Casting.h"
25 #include "llvm/Support/DataTypes.h"
26 
27 namespace llvm {
28 
29 class raw_ostream;
30 
31 /// DILineInfo - a format-neutral container for source line information.
32 class DILineInfo {
33  SmallString<16> FileName;
34  SmallString<16> FunctionName;
35  uint32_t Line;
36  uint32_t Column;
37 public:
39  : FileName("<invalid>"), FunctionName("<invalid>"),
40  Line(0), Column(0) {}
41  DILineInfo(StringRef fileName, StringRef functionName, uint32_t line,
42  uint32_t column)
43  : FileName(fileName), FunctionName(functionName), Line(line),
44  Column(column) {}
45 
46  const char *getFileName() { return FileName.c_str(); }
47  const char *getFunctionName() { return FunctionName.c_str(); }
48  uint32_t getLine() const { return Line; }
49  uint32_t getColumn() const { return Column; }
50 
51  bool operator==(const DILineInfo &RHS) const {
52  return Line == RHS.Line && Column == RHS.Column &&
53  FileName.equals(RHS.FileName) &&
54  FunctionName.equals(RHS.FunctionName);
55  }
56  bool operator!=(const DILineInfo &RHS) const {
57  return !(*this == RHS);
58  }
59 };
60 
62 
63 /// DIInliningInfo - a format-neutral container for inlined code description.
66  public:
68  DILineInfo getFrame(unsigned Index) const {
69  assert(Index < Frames.size());
70  return Frames[Index];
71  }
72  uint32_t getNumberOfFrames() const {
73  return Frames.size();
74  }
75  void addFrame(const DILineInfo &Frame) {
76  Frames.push_back(Frame);
77  }
78 };
79 
80 /// DILineInfoSpecifier - controls which fields of DILineInfo container
81 /// should be filled with data.
83  const uint32_t Flags; // Or'ed flags that set the info we want to fetch.
84 public:
86  FileLineInfo = 1 << 0,
87  AbsoluteFilePath = 1 << 1,
88  FunctionName = 1 << 2
89  };
90  // Use file/line info by default.
91  DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
92  bool needs(Specification spec) const {
93  return (Flags & spec) > 0;
94  }
95 };
96 
97 /// Selects which debug sections get dumped.
98 enum DIDumpType {
118 };
119 
120 // In place of applying the relocations to the data we've read from disk we use
121 // a separate mapping table to the side and checking that at locations in the
122 // dwarf where we expect relocated values. This adds a bit of complexity to the
123 // dwarf parsing/extraction at the benefit of not allocating memory for the
124 // entire size of the debug info sections.
126 
127 class DIContext {
128 public:
131  };
132  DIContextKind getKind() const { return Kind; }
133 
134  DIContext(DIContextKind K) : Kind(K) {}
135  virtual ~DIContext();
136 
137  /// getDWARFContext - get a context for binary DWARF data.
139 
140  virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
141 
142  virtual DILineInfo getLineInfoForAddress(uint64_t Address,
143  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
144  virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
145  uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
146  virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
147  DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
148 private:
149  const DIContextKind Kind;
150 };
151 
152 }
153 
154 #endif
uint32_t getColumn() const
Definition: DIContext.h:49
bool operator!=(const DILineInfo &RHS) const
Definition: DIContext.h:56
void addFrame(const DILineInfo &Frame)
Definition: DIContext.h:75
DIContextKind getKind() const
Definition: DIContext.h:132
static DIContext * getDWARFContext(object::ObjectFile *)
getDWARFContext - get a context for binary DWARF data.
Definition: DIContext.cpp:16
virtual DILineInfo getLineInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
virtual ~DIContext()
Definition: DIContext.cpp:14
DILineInfo(StringRef fileName, StringRef functionName, uint32_t line, uint32_t column)
Definition: DIContext.h:41
bool equals(StringRef RHS) const
Definition: SmallString.h:102
uint32_t getNumberOfFrames() const
Definition: DIContext.h:72
bool operator==(const DILineInfo &RHS) const
Definition: DIContext.h:51
DILineInfo getFrame(unsigned Index) const
Definition: DIContext.h:68
DIContext(DIContextKind K)
Definition: DIContext.h:134
DIInliningInfo - a format-neutral container for inlined code description.
Definition: DIContext.h:64
DIDumpType
Selects which debug sections get dumped.
Definition: DIContext.h:98
virtual void dump(raw_ostream &OS, DIDumpType DumpType=DIDT_All)=0
DILineInfo - a format-neutral container for source line information.
Definition: DIContext.h:32
SmallVector< std::pair< uint64_t, DILineInfo >, 16 > DILineInfoTable
Definition: DIContext.h:61
DILineInfoSpecifier(uint32_t flags=FileLineInfo)
Definition: DIContext.h:91
uint32_t getLine() const
Definition: DIContext.h:48
const char * getFileName()
Definition: DIContext.h:46
virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
const char * c_str()
Definition: SmallString.h:273
virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address, DILineInfoSpecifier Specifier=DILineInfoSpecifier())=0
bool needs(Specification spec) const
Definition: DIContext.h:92
DenseMap< uint64_t, std::pair< uint8_t, int64_t > > RelocAddrMap
Definition: DIContext.h:125
const char * getFunctionName()
Definition: DIContext.h:47