Rewrite DIContext interface to take an object. Update all callers.
[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/Object/ObjectFile.h"
23 #include "llvm/Object/RelocVisitor.h"
24 #include "llvm/Support/DataTypes.h"
25
26 namespace llvm {
27
28 class raw_ostream;
29
30 /// DILineInfo - a format-neutral container for source line information.
31 class DILineInfo {
32   SmallString<16> FileName;
33   SmallString<16> FunctionName;
34   uint32_t Line;
35   uint32_t Column;
36 public:
37   DILineInfo()
38     : FileName("<invalid>"), FunctionName("<invalid>"),
39       Line(0), Column(0) {}
40   DILineInfo(const SmallString<16> &fileName,
41              const SmallString<16> &functionName,
42              uint32_t line, uint32_t column)
43     : FileName(fileName), FunctionName(functionName),
44       Line(line), 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
61 /// DIInliningInfo - a format-neutral container for inlined code description.
62 class DIInliningInfo {
63   SmallVector<DILineInfo, 4> Frames;
64  public:
65   DIInliningInfo() {}
66   DILineInfo getFrame(unsigned Index) const {
67     assert(Index < Frames.size());
68     return Frames[Index];
69   }
70   uint32_t getNumberOfFrames() const {
71     return Frames.size();
72   }
73   void addFrame(const DILineInfo &Frame) {
74     Frames.push_back(Frame);
75   }
76 };
77
78 /// DILineInfoSpecifier - controls which fields of DILineInfo container
79 /// should be filled with data.
80 class DILineInfoSpecifier {
81   const uint32_t Flags;  // Or'ed flags that set the info we want to fetch.
82 public:
83   enum Specification {
84     FileLineInfo = 1 << 0,
85     AbsoluteFilePath = 1 << 1,
86     FunctionName = 1 << 2
87   };
88   // Use file/line info by default.
89   DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
90   bool needs(Specification spec) const {
91     return (Flags & spec) > 0;
92   }
93 };
94
95 // In place of applying the relocations to the data we've read from disk we use
96 // a separate mapping table to the side and checking that at locations in the
97 // dwarf where we expect relocated values. This adds a bit of complexity to the
98 // dwarf parsing/extraction at the benefit of not allocating memory for the
99 // entire size of the debug info sections.
100 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
101
102 class DIContext {
103 public:
104   virtual ~DIContext();
105
106   /// getDWARFContext - get a context for binary DWARF data.
107   static DIContext *getDWARFContext(object::ObjectFile *);
108
109   virtual void dump(raw_ostream &OS) = 0;
110
111   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
112       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
113   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
114       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
115 };
116
117 }
118
119 #endif