BumpPtrAllocator: use uintptr_t when aligning addresses to avoid undefined behaviour
[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/Object/ObjectFile.h"
21 #include "llvm/Object/RelocVisitor.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/DataTypes.h"
24
25 #include <string>
26
27 namespace llvm {
28
29 class raw_ostream;
30
31 /// DILineInfo - a format-neutral container for source line information.
32 struct DILineInfo {
33   std::string FileName;
34   std::string FunctionName;
35   uint32_t Line;
36   uint32_t Column;
37
38   DILineInfo()
39       : FileName("<invalid>"), FunctionName("<invalid>"), Line(0), Column(0) {}
40
41   bool operator==(const DILineInfo &RHS) const {
42     return Line == RHS.Line && Column == RHS.Column &&
43            FileName == RHS.FileName && FunctionName == RHS.FunctionName;
44   }
45   bool operator!=(const DILineInfo &RHS) const {
46     return !(*this == RHS);
47   }
48 };
49
50 typedef SmallVector<std::pair<uint64_t, DILineInfo>, 16> DILineInfoTable;
51
52 /// DIInliningInfo - a format-neutral container for inlined code description.
53 class DIInliningInfo {
54   SmallVector<DILineInfo, 4> Frames;
55  public:
56   DIInliningInfo() {}
57   DILineInfo getFrame(unsigned Index) const {
58     assert(Index < Frames.size());
59     return Frames[Index];
60   }
61   uint32_t getNumberOfFrames() const {
62     return Frames.size();
63   }
64   void addFrame(const DILineInfo &Frame) {
65     Frames.push_back(Frame);
66   }
67 };
68
69 /// DILineInfoSpecifier - controls which fields of DILineInfo container
70 /// should be filled with data.
71 struct DILineInfoSpecifier {
72   enum class FileLineInfoKind { None, Default, AbsoluteFilePath };
73   enum class FunctionNameKind { None, ShortName, LinkageName };
74
75   FileLineInfoKind FLIKind;
76   FunctionNameKind FNKind;
77
78   DILineInfoSpecifier(FileLineInfoKind FLIKind = FileLineInfoKind::Default,
79                       FunctionNameKind FNKind = FunctionNameKind::None)
80       : FLIKind(FLIKind), FNKind(FNKind) {}
81 };
82
83 /// Selects which debug sections get dumped.
84 enum DIDumpType {
85   DIDT_Null,
86   DIDT_All,
87   DIDT_Abbrev,
88   DIDT_AbbrevDwo,
89   DIDT_Aranges,
90   DIDT_Frames,
91   DIDT_Info,
92   DIDT_InfoDwo,
93   DIDT_Types,
94   DIDT_TypesDwo,
95   DIDT_Line,
96   DIDT_LineDwo,
97   DIDT_Loc,
98   DIDT_LocDwo,
99   DIDT_Ranges,
100   DIDT_Pubnames,
101   DIDT_Pubtypes,
102   DIDT_GnuPubnames,
103   DIDT_GnuPubtypes,
104   DIDT_Str,
105   DIDT_StrDwo,
106   DIDT_StrOffsetsDwo
107 };
108
109 // In place of applying the relocations to the data we've read from disk we use
110 // a separate mapping table to the side and checking that at locations in the
111 // dwarf where we expect relocated values. This adds a bit of complexity to the
112 // dwarf parsing/extraction at the benefit of not allocating memory for the
113 // entire size of the debug info sections.
114 typedef DenseMap<uint64_t, std::pair<uint8_t, int64_t> > RelocAddrMap;
115
116 class DIContext {
117 public:
118   enum DIContextKind {
119     CK_DWARF
120   };
121   DIContextKind getKind() const { return Kind; }
122
123   DIContext(DIContextKind K) : Kind(K) {}
124   virtual ~DIContext();
125
126   /// getDWARFContext - get a context for binary DWARF data.
127   static DIContext *getDWARFContext(object::ObjectFile &);
128
129   virtual void dump(raw_ostream &OS, DIDumpType DumpType = DIDT_All) = 0;
130
131   virtual DILineInfo getLineInfoForAddress(uint64_t Address,
132       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
133   virtual DILineInfoTable getLineInfoForAddressRange(uint64_t Address,
134       uint64_t Size, DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
135   virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
136       DILineInfoSpecifier Specifier = DILineInfoSpecifier()) = 0;
137 private:
138   const DIContextKind Kind;
139 };
140
141 }
142
143 #endif