blob: 3eca9524b5940bc390046ffb96f5780934a5fd12 [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 Kramer72c0d7f2011-09-13 19:42:23 +000015#include "llvm/DebugInfo/DIContext.h"
16#include "llvm/ADT/OwningPtr.h"
17#include "llvm/ADT/SmallVector.h"
18
19namespace llvm {
20
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000021/// DWARFContext
22/// This data structure is the top level entity that deals with dwarf debug
23/// information parsing. The actual data is supplied through pure virtual
24/// methods that a concrete implementation provides.
25class DWARFContext : public DIContext {
26 bool IsLittleEndian;
27
28 SmallVector<DWARFCompileUnit, 1> CUs;
29 OwningPtr<DWARFDebugAbbrev> Abbrev;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000030 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000031
32 DWARFContext(DWARFContext &); // = delete
33 DWARFContext &operator=(DWARFContext &); // = delete
34
35 /// Read compile units from the debug_info section and store them in CUs.
36 void parseCompileUnits();
37protected:
38 DWARFContext(bool isLittleEndian) : IsLittleEndian(isLittleEndian) {}
39public:
40 virtual void dump(raw_ostream &OS);
41 /// Get the number of compile units in this context.
42 unsigned getNumCompileUnits() {
43 if (CUs.empty())
44 parseCompileUnits();
45 return CUs.size();
46 }
47 /// Get the compile unit at the specified index for this compile unit.
48 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
49 if (CUs.empty())
50 parseCompileUnits();
51 return &CUs[index];
52 }
53
54 /// Get a pointer to the parsed DebugAbbrev object.
55 const DWARFDebugAbbrev *getDebugAbbrev();
56
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000057 /// Get a pointer to the parsed DebugAranges object.
58 const DWARFDebugAranges *getDebugAranges();
59
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000060 bool isLittleEndian() const { return IsLittleEndian; }
61
62 virtual StringRef getInfoSection() = 0;
63 virtual StringRef getAbbrevSection() = 0;
64 virtual StringRef getARangeSection() = 0;
65 virtual StringRef getLineSection() = 0;
66 virtual StringRef getStringSection() = 0;
67
68 static bool isSupportedVersion(unsigned version) {
69 return version == 2 || version == 3;
70 }
71};
72
73
74/// DWARFContextInMemory is the simplest possible implementation of a
75/// DWARFContext. It assumes all content is available in memory and stores
76/// pointers to it.
77class DWARFContextInMemory : public DWARFContext {
78 StringRef InfoSection;
79 StringRef AbbrevSection;
80 StringRef ARangeSection;
81 StringRef LineSection;
82 StringRef StringSection;
83public:
84 DWARFContextInMemory(bool isLittleEndian,
85 StringRef infoSection,
86 StringRef abbrevSection,
87 StringRef aRangeSection,
88 StringRef lineSection,
89 StringRef stringSection)
90 : DWARFContext(isLittleEndian),
91 InfoSection(infoSection),
92 AbbrevSection(abbrevSection),
93 ARangeSection(aRangeSection),
94 LineSection(lineSection),
95 StringSection(stringSection)
96 {}
97
98 virtual StringRef getInfoSection() { return InfoSection; }
99 virtual StringRef getAbbrevSection() { return AbbrevSection; }
100 virtual StringRef getARangeSection() { return ARangeSection; }
101 virtual StringRef getLineSection() { return LineSection; }
102 virtual StringRef getStringSection() { return StringSection; }
103};
104
105}
106
107#endif