blob: d3e9470a849666d77e5e88511a163cb573cb6d77 [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"
Alexey Samsonoveceb5b92012-08-27 07:17:47 +000016#include "DWARFDebugRangeList.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000017#include "llvm/DebugInfo/DIContext.h"
18#include "llvm/ADT/OwningPtr.h"
19#include "llvm/ADT/SmallVector.h"
20
21namespace llvm {
22
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000023/// DWARFContext
24/// This data structure is the top level entity that deals with dwarf debug
25/// information parsing. The actual data is supplied through pure virtual
26/// methods that a concrete implementation provides.
27class DWARFContext : public DIContext {
28 bool IsLittleEndian;
Alexey Samsonov4c0ae902012-11-12 14:25:36 +000029 const RelocAddrMap *RelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000030
31 SmallVector<DWARFCompileUnit, 1> CUs;
32 OwningPtr<DWARFDebugAbbrev> Abbrev;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000033 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramerb848e972011-09-15 02:12:05 +000034 OwningPtr<DWARFDebugLine> Line;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000035
Craig Topperc2945e42012-09-18 02:01:41 +000036 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
37 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000038
39 /// Read compile units from the debug_info section and store them in CUs.
40 void parseCompileUnits();
41protected:
Alexey Samsonov4c0ae902012-11-12 14:25:36 +000042 DWARFContext(bool isLittleEndian, const RelocAddrMap *Map) :
Eric Christopher806e03d2012-11-07 23:22:07 +000043 IsLittleEndian(isLittleEndian), RelocMap(Map) {}
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000044public:
45 virtual void dump(raw_ostream &OS);
Eric Christopher806e03d2012-11-07 23:22:07 +000046
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000047 /// Get the number of compile units in this context.
48 unsigned getNumCompileUnits() {
49 if (CUs.empty())
50 parseCompileUnits();
51 return CUs.size();
52 }
53 /// Get the compile unit at the specified index for this compile unit.
54 DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
55 if (CUs.empty())
56 parseCompileUnits();
57 return &CUs[index];
58 }
59
60 /// Get a pointer to the parsed DebugAbbrev object.
61 const DWARFDebugAbbrev *getDebugAbbrev();
62
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000063 /// Get a pointer to the parsed DebugAranges object.
64 const DWARFDebugAranges *getDebugAranges();
65
Benjamin Kramerc26ed9b2011-09-15 20:43:18 +000066 /// Get a pointer to a parsed line table corresponding to a compile unit.
67 const DWARFDebugLine::LineTable *
68 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramerb848e972011-09-15 02:12:05 +000069
Alexey Samsonov38a63812012-08-30 07:49:50 +000070 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
71 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000072 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
73 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer101b1c52011-09-15 20:43:22 +000074
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000075 bool isLittleEndian() const { return IsLittleEndian; }
Alexey Samsonov4c0ae902012-11-12 14:25:36 +000076 const RelocAddrMap *relocMap() const { return RelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000077
78 virtual StringRef getInfoSection() = 0;
79 virtual StringRef getAbbrevSection() = 0;
80 virtual StringRef getARangeSection() = 0;
81 virtual StringRef getLineSection() = 0;
82 virtual StringRef getStringSection() = 0;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +000083 virtual StringRef getRangeSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000084
85 static bool isSupportedVersion(unsigned version) {
86 return version == 2 || version == 3;
87 }
Alexey Samsonov38a63812012-08-30 07:49:50 +000088private:
89 /// Return the compile unit that includes an offset (relative to .debug_info).
90 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000091
Alexey Samsonov38a63812012-08-30 07:49:50 +000092 /// Return the compile unit which contains instruction with provided
93 /// address.
94 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +000095};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000096
97/// DWARFContextInMemory is the simplest possible implementation of a
98/// DWARFContext. It assumes all content is available in memory and stores
99/// pointers to it.
100class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000101 virtual void anchor();
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000102 StringRef InfoSection;
103 StringRef AbbrevSection;
104 StringRef ARangeSection;
105 StringRef LineSection;
106 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000107 StringRef RangeSection;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000108public:
109 DWARFContextInMemory(bool isLittleEndian,
110 StringRef infoSection,
111 StringRef abbrevSection,
112 StringRef aRangeSection,
113 StringRef lineSection,
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000114 StringRef stringSection,
Eric Christopher806e03d2012-11-07 23:22:07 +0000115 StringRef rangeSection,
Alexey Samsonov4c0ae902012-11-12 14:25:36 +0000116 const RelocAddrMap *Map = 0)
Eric Christopher806e03d2012-11-07 23:22:07 +0000117 : DWARFContext(isLittleEndian, Map),
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000118 InfoSection(infoSection),
119 AbbrevSection(abbrevSection),
120 ARangeSection(aRangeSection),
121 LineSection(lineSection),
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000122 StringSection(stringSection),
123 RangeSection(rangeSection)
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000124 {}
125
126 virtual StringRef getInfoSection() { return InfoSection; }
127 virtual StringRef getAbbrevSection() { return AbbrevSection; }
128 virtual StringRef getARangeSection() { return ARangeSection; }
129 virtual StringRef getLineSection() { return LineSection; }
130 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000131 virtual StringRef getRangeSection() { return RangeSection; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000132};
133
134}
135
136#endif