blob: 68f58d90319d1810dcacdfa72c3259002e025f63 [file] [log] [blame]
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +00001//===-- DWARFContext.cpp --------------------------------------------------===//
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#include "DWARFContext.h"
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000011#include "llvm/Support/raw_ostream.h"
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000012using namespace llvm;
13
14void DWARFContext::dump(raw_ostream &OS) {
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000015 OS << ".debug_abbrev contents:\n";
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000016 getDebugAbbrev()->dump(OS);
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000017
18 OS << "\n.debug_info contents:\n";
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000019 for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i)
20 getCompileUnitAtIndex(i)->dump(OS);
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000021
22 OS << "\n.debug_aranges contents:\n";
23 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
24 uint32_t offset = 0;
25 DWARFDebugArangeSet set;
26 while (set.extract(arangesData, &offset))
27 set.dump(OS);
Benjamin Kramerb848e972011-09-15 02:12:05 +000028
29 OS << "\n.debug_lines contents:\n";
30 DataExtractor lineData(getLineSection(), isLittleEndian(), 8);
31 DWARFDebugLine::dump(lineData, OS);
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000032}
33
34const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
35 if (Abbrev)
36 return Abbrev.get();
37
38 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
39
40 Abbrev.reset(new DWARFDebugAbbrev());
41 Abbrev->parse(abbrData);
42 return Abbrev.get();
43}
44
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000045const DWARFDebugAranges *DWARFContext::getDebugAranges() {
46 if (Aranges)
47 return Aranges.get();
48
49 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
50
51 Aranges.reset(new DWARFDebugAranges());
52 Aranges->extract(arangesData);
Benjamin Kramer10df8062011-09-14 20:52:27 +000053 if (Aranges->isEmpty()) // No aranges in file, generate them from the DIEs.
54 Aranges->generate(this);
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000055 return Aranges.get();
56}
57
Benjamin Kramerb848e972011-09-15 02:12:05 +000058const DWARFDebugLine *DWARFContext::getDebugLine() {
59 if (Line)
60 return Line.get();
61
62 DataExtractor lineData(getLineSection(), isLittleEndian(), 0);
63
64 Line.reset(new DWARFDebugLine());
65 Line->parse(lineData);
66 return Line.get();
67}
68
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000069void DWARFContext::parseCompileUnits() {
70 uint32_t offset = 0;
71 const DataExtractor &debug_info_data = DataExtractor(getInfoSection(),
72 isLittleEndian(), 0);
73 while (debug_info_data.isValidOffset(offset)) {
74 CUs.push_back(DWARFCompileUnit(*this));
75 if (!CUs.back().extract(debug_info_data, &offset)) {
76 CUs.pop_back();
77 break;
78 }
79
80 offset = CUs.back().getNextCompileUnitOffset();
81 }
82}