Add support for fetching inlining context (stack of source code locations)
[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/SmallVector.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/Support/DataTypes.h"
22
23 namespace llvm {
24
25 class raw_ostream;
26
27 /// DILineInfo - a format-neutral container for source line information.
28 class DILineInfo {
29   SmallString<16> FileName;
30   SmallString<16> FunctionName;
31   uint32_t Line;
32   uint32_t Column;
33 public:
34   DILineInfo()
35     : FileName("<invalid>"), FunctionName("<invalid>"),
36       Line(0), Column(0) {}
37   DILineInfo(const SmallString<16> &fileName,
38              const SmallString<16> &functionName,
39              uint32_t line, uint32_t column)
40     : FileName(fileName), FunctionName(functionName),
41       Line(line), Column(column) {}
42
43   const char *getFileName() { return FileName.c_str(); }
44   const char *getFunctionName() { return FunctionName.c_str(); }
45   uint32_t getLine() const { return Line; }
46   uint32_t getColumn() const { return Column; }
47
48   bool operator==(const DILineInfo &RHS) const {
49     return Line == RHS.Line && Column == RHS.Column &&
50            FileName.equals(RHS.FileName) &&
51            FunctionName.equals(RHS.FunctionName);
52   }
53   bool operator!=(const DILineInfo &RHS) const {
54     return !(*this == RHS);
55   }
56 };
57
58 /// DIInliningInfo - a format-neutral container for inlined code description.
59 class DIInliningInfo {
60   SmallVector<DILineInfo, 4> Frames;
61  public:
62   DIInliningInfo() {}
63   DILineInfo getFrame(unsigned Index) const {
64     assert(Index < Frames.size());
65     return Frames[Index];
66   }
67   uint32_t getNumberOfFrames() const {
68     return Frames.size();
69   }
70   void addFrame(const DILineInfo &Frame) {
71     Frames.push_back(Frame);
72   }
73 };
74
75 /// DILineInfoSpecifier - controls which fields of DILineInfo container
76 /// should be filled with data.
77 class DILineInfoSpecifier {
78   const uint32_t Flags;  // Or'ed flags that set the info we want to fetch.
79 public:
80   enum Specification {
81     FileLineInfo = 1 << 0,
82     AbsoluteFilePath = 1 << 1,
83     FunctionName = 1 << 2
84   };
85   // Use file/line info by default.
86   DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
87   bool needs(Specification spec) const {
88     return (Flags & spec) > 0;
89   }
90 };
91
92 class DIContext {
93 public:
94   virtual ~DIContext();
95
96   /// getDWARFContext - get a context for binary DWARF data.
97   static DIContext *getDWARFContext(bool isLittleEndian,
98                                     StringRef infoSection,
99                                     StringRef abbrevSection,
100                                     StringRef aRangeSection = StringRef(),
101                                     StringRef lineSection = StringRef(),
102                                     StringRef stringSection = StringRef(),
103                                     StringRef rangeSection = StringRef());
104
105   virtual void dump(raw_ostream &OS) = 0;
106
107   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
108       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
109   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
110       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
111 };
112
113 }
114
115 #endif