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