blob: 24613594deed9f6fe2adaed94cd34a2e284ea594 [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/ADT/OwningPtr.h"
18#include "llvm/ADT/SmallVector.h"
Chandler Carrutha1514e22012-12-04 07:12:27 +000019#include "llvm/DebugInfo/DIContext.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000020
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 {
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000028 SmallVector<DWARFCompileUnit, 1> CUs;
29 OwningPtr<DWARFDebugAbbrev> Abbrev;
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000030 OwningPtr<DWARFDebugAranges> Aranges;
Benjamin Kramerb848e972011-09-15 02:12:05 +000031 OwningPtr<DWARFDebugLine> Line;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000032
Craig Topperc2945e42012-09-18 02:01:41 +000033 DWARFContext(DWARFContext &) LLVM_DELETED_FUNCTION;
34 DWARFContext &operator=(DWARFContext &) LLVM_DELETED_FUNCTION;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000035
36 /// Read compile units from the debug_info section and store them in CUs.
37 void parseCompileUnits();
Eric Christopherd1726a42012-11-12 21:40:38 +000038
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000039public:
Eric Christopherd1726a42012-11-12 21:40:38 +000040 DWARFContext() {}
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000041 virtual void dump(raw_ostream &OS);
Eric Christopher806e03d2012-11-07 23:22:07 +000042
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000043 /// 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
56 /// Get a pointer to the parsed DebugAbbrev object.
57 const DWARFDebugAbbrev *getDebugAbbrev();
58
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000059 /// Get a pointer to the parsed DebugAranges object.
60 const DWARFDebugAranges *getDebugAranges();
61
Benjamin Kramerc26ed9b2011-09-15 20:43:18 +000062 /// Get a pointer to a parsed line table corresponding to a compile unit.
63 const DWARFDebugLine::LineTable *
64 getLineTableForCompileUnit(DWARFCompileUnit *cu);
Benjamin Kramerb848e972011-09-15 02:12:05 +000065
Alexey Samsonov38a63812012-08-30 07:49:50 +000066 virtual DILineInfo getLineInfoForAddress(uint64_t Address,
67 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Alexey Samsonov5eae90d2012-09-04 08:12:33 +000068 virtual DIInliningInfo getInliningInfoForAddress(uint64_t Address,
69 DILineInfoSpecifier Specifier = DILineInfoSpecifier());
Benjamin Kramer101b1c52011-09-15 20:43:22 +000070
Eric Christopherd1726a42012-11-12 21:40:38 +000071 virtual bool isLittleEndian() const = 0;
72 virtual const RelocAddrMap &relocMap() const = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000073 virtual StringRef getInfoSection() = 0;
74 virtual StringRef getAbbrevSection() = 0;
75 virtual StringRef getARangeSection() = 0;
76 virtual StringRef getLineSection() = 0;
77 virtual StringRef getStringSection() = 0;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +000078 virtual StringRef getRangeSection() = 0;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000079
80 static bool isSupportedVersion(unsigned version) {
81 return version == 2 || version == 3;
82 }
Alexey Samsonov38a63812012-08-30 07:49:50 +000083private:
84 /// Return the compile unit that includes an offset (relative to .debug_info).
85 DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000086
Alexey Samsonov38a63812012-08-30 07:49:50 +000087 /// Return the compile unit which contains instruction with provided
88 /// address.
89 DWARFCompileUnit *getCompileUnitForAddress(uint64_t Address);
Alexey Samsonov38a63812012-08-30 07:49:50 +000090};
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000091
92/// DWARFContextInMemory is the simplest possible implementation of a
93/// DWARFContext. It assumes all content is available in memory and stores
94/// pointers to it.
95class DWARFContextInMemory : public DWARFContext {
David Blaikie2d24e2a2011-12-20 02:50:00 +000096 virtual void anchor();
Eric Christopherd1726a42012-11-12 21:40:38 +000097 bool IsLittleEndian;
98 RelocAddrMap RelocMap;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000099 StringRef InfoSection;
100 StringRef AbbrevSection;
101 StringRef ARangeSection;
102 StringRef LineSection;
103 StringRef StringSection;
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000104 StringRef RangeSection;
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000105public:
Eric Christopherd1726a42012-11-12 21:40:38 +0000106 DWARFContextInMemory(object::ObjectFile *);
107 virtual bool isLittleEndian() const { return IsLittleEndian; }
108 virtual const RelocAddrMap &relocMap() const { return RelocMap; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000109 virtual StringRef getInfoSection() { return InfoSection; }
110 virtual StringRef getAbbrevSection() { return AbbrevSection; }
111 virtual StringRef getARangeSection() { return ARangeSection; }
112 virtual StringRef getLineSection() { return LineSection; }
113 virtual StringRef getStringSection() { return StringSection; }
Alexey Samsonoveceb5b92012-08-27 07:17:47 +0000114 virtual StringRef getRangeSection() { return RangeSection; }
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +0000115};
116
117}
118
119#endif