Add a relocation visitor to lib object. This works via caching relocated
[oota-llvm.git] / include / llvm / DebugInfo / DIContext.h
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/SmallVector.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/DataTypes.h"
23
24 namespace llvm {
25
26 class raw_ostream;
27
28 /// DILineInfo - a format-neutral container for source line information.
29 class DILineInfo {
30   SmallString<16> FileName;
31   SmallString<16> FunctionName;
32   uint32_t Line;
33   uint32_t Column;
34 public:
35   DILineInfo()
36     : FileName("<invalid>"), FunctionName("<invalid>"),
37       Line(0), Column(0) {}
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) {}
43
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; }
48
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);
53   }
54   bool operator!=(const DILineInfo &RHS) const {
55     return !(*this == RHS);
56   }
57 };
58
59 /// DIInliningInfo - a format-neutral container for inlined code description.
60 class DIInliningInfo {
61   SmallVector<DILineInfo, 4> Frames;
62  public:
63   DIInliningInfo() {}
64   DILineInfo getFrame(unsigned Index) const {
65     assert(Index < Frames.size());
66     return Frames[Index];
67   }
68   uint32_t getNumberOfFrames() const {
69     return Frames.size();
70   }
71   void addFrame(const DILineInfo &Frame) {
72     Frames.push_back(Frame);
73   }
74 };
75
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.
80 public:
81   enum Specification {
82     FileLineInfo = 1 << 0,
83     AbsoluteFilePath = 1 << 1,
84     FunctionName = 1 << 2
85   };
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;
90   }
91 };
92
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;
99
100 class DIContext {
101 public:
102   virtual ~DIContext();
103
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());
113
114   virtual void dump(raw_ostream &OS) = 0;
115
116   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
117       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
118   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
119       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
120 };
121
122 }
123
124 #endif