This patch extends the libLLVMDebugInfo which contains a minimalistic DWARF parser:
[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/StringRef.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <cstring>
21
22 namespace llvm {
23
24 class raw_ostream;
25
26 /// DILineInfo - a format-neutral container for source line information.
27 class DILineInfo {
28   const char *FileName;
29   const char *FunctionName;
30   uint32_t Line;
31   uint32_t Column;
32 public:
33   DILineInfo()
34     : FileName("<invalid>"), FunctionName("<invalid>"),
35       Line(0), Column(0) {}
36   DILineInfo(const char *fileName, const char *functionName,
37              uint32_t line, uint32_t column)
38     : FileName(fileName), FunctionName(functionName),
39       Line(line), Column(column) {}
40
41   const char *getFileName() const { return FileName; }
42   const char *getFunctionName() const { return FunctionName; }
43   uint32_t getLine() const { return Line; }
44   uint32_t getColumn() const { return Column; }
45
46   bool operator==(const DILineInfo &RHS) const {
47     return Line == RHS.Line && Column == RHS.Column &&
48            std::strcmp(FileName, RHS.FileName) == 0 &&
49            std::strcmp(FunctionName, RHS.FunctionName) == 0;
50   }
51   bool operator!=(const DILineInfo &RHS) const {
52     return !(*this == RHS);
53   }
54 };
55
56 /// DILineInfoSpecifier - controls which fields of DILineInfo container
57 /// should be filled with data.
58 class DILineInfoSpecifier {
59   const uint32_t Flags;  // Or'ed flags that set the info we want to fetch.
60 public:
61   enum Specification {
62     FileLineInfo = 1 << 0,
63     FunctionName = 1 << 1
64   };
65   // Use file/line info by default.
66   DILineInfoSpecifier(uint32_t flags = FileLineInfo) : Flags(flags) {}
67   bool needs(Specification spec) const {
68     return (Flags & spec) > 0;
69   }
70 };
71
72 class DIContext {
73 public:
74   virtual ~DIContext();
75
76   /// getDWARFContext - get a context for binary DWARF data.
77   static DIContext *getDWARFContext(bool isLittleEndian,
78                                     StringRef infoSection,
79                                     StringRef abbrevSection,
80                                     StringRef aRangeSection = StringRef(),
81                                     StringRef lineSection = StringRef(),
82                                     StringRef stringSection = StringRef());
83
84   virtual void dump(raw_ostream &OS) = 0;
85
86   virtual DILineInfo getLineInfoForAddress(uint64_t address,
87       DILineInfoSpecifier specifier = DILineInfoSpecifier()) = 0;
88 };
89
90 }
91
92 #endif