blob: d2e763a87a45469e2e1891c9dfc72cfd3f4cfd31 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- DWARFContext.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#ifndef LLVM_DEBUGINFO_DWARFCONTEXT_H
11#define LLVM_DEBUGINFO_DWARFCONTEXT_H
12
13#include "DWARFCompileUnit.h"
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000014#include "DWARFDebugAranges.h"
Benjamin Kramerb848e972011-09-15 02:12:05 +000015#include "DWARFDebugLine.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000016#include "llvm/DebugInfo/DIContext.h"
17#include "llvm/ADT/OwningPtr.h"
18#include "llvm/ADT/SmallVector.h"
19
20namespace llvm {
21
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000022/// DWARFContext
23/// This data structure is the top level entity that deals with dwarf debug
24/// information parsing. The actual data is supplied through pure virtual
25/// methods that a concrete implementation provides.
26class DWARFContext : public DIContext {
27 bool IsLittleEndian;
28
29 SmallVector<DWARFCompileUnit, 1> CUs;
30 OwningPtr<DWARFDebugAbbrev> Abbrev;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000031 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramerb848e972011-09-15 02:12:05 +000032 OwningPtr<DWARFDebugLine> Line;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000033
34 DWARFContext(DWARFContext &); // = delete
35 DWARFContext &operator=(DWARFContext &); // = delete
36
37 /// Read compile units from the debug_info section and store them in CUs.
38 void parseCompileUnits();
39protected:
40 DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
41public:
42 virtual void dump(raw_ostream &OS);
43 /// Get the number of compile units in this context.
44 unsigned getNumCompileUnits() {
45 if (CUs.empty())
46 parseCompileUnits();
47 return CUs.size();
48 }
49 /// Get the compile unit at the specified index for this compile unit.
50 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
51 if (CUs.empty())
52 parseCompileUnits();
53 return &CUs[index];
54 }
55
Benjamin Kramer101b1c52011-09-15 20:43:22 +000056 /// Return the compile unit that includes an offset (relative to .debug_info).
57 DWARFCompileUnit *getCompileUnitForOffset(uint32_t offset);
58
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000059 /// Get a pointer to the parsed DebugAbbrev object.
60 const DWARFDebugAbbrev *getDebugAbbrev();
61
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000062 /// Get a pointer to the parsed DebugAranges object.
63 const DWARFDebugAranges *getDebugAranges();
64
Benjamin Kramerc26ed9b2011-09-15 20:43:18 +000065 /// Get a pointer to a parsed line table corresponding to a compile unit.
66 const DWARFDebugLine::LineTable *
67 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramerb848e972011-09-15 02:12:05 +000068
Benjamin Kramer101b1c52011-09-15 20:43:22 +000069 virtual DILineInfo getLineInfoForAddress(uint64_t address);
70
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000071 bool isLittleEndian() const { return IsLittleEndian; }
72
73 virtual StringRef getInfoSection() = 0;
74 virtual StringRef getAbbrevSection() = 0;
75 virtual StringRef getARangeSection() = 0;
76 virtual StringRef getLineSection() = 0;
77 virtual StringRef getStringSection() = 0;
78
79 static bool isSupportedVersion(unsigned version) {
80 return version == 2 || version == 3;
81 }
82};
83
84
85/// DWARFContextInMemory is the simplest possible implementation of a
86/// DWARFContext. It assumes all content is available in memory and stores
87/// pointers to it.
88class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +000089 virtual void anchor();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000090 StringRef InfoSection;
91 StringRef AbbrevSection;
92 StringRef ARangeSection;
93 StringRef LineSection;
94 StringRef StringSection;
95public:
96 DWARFContextInMemory(bool isLittleEndian,
97 StringRef infoSection,
98 StringRef abbrevSection,
99 StringRef aRangeSection,
100 StringRef lineSection,
101 StringRef stringSection)
102 : DWARFContext(isLittleEndian),
103 InfoSection(infoSection),
104 AbbrevSection(abbrevSection),
105 ARangeSection(aRangeSection),
106 LineSection(lineSection),
107 StringSection(stringSection)
108 {}
109
110 virtual StringRef getInfoSection() { return InfoSection; }
111 virtual StringRef getAbbrevSection() { return AbbrevSection; }
112 virtual StringRef getARangeSection() { return ARangeSection; }
113 virtual StringRef getLineSection() { return LineSection; }
114 virtual StringRef getStringSection() { return StringSection; }
115};
116
117}
118
119#endif