blob: c034bb369638fa4356724840712671612413c307 [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 Kramer72c0d7f2011-09-13 19:42:23 +000028}
29
30const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
31 if (Abbrev)
32 return Abbrev.get();
33
34 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
35
36 Abbrev.reset(new DWARFDebugAbbrev());
37 Abbrev->parse(abbrData);
38 return Abbrev.get();
39}
40
Benjamin Kramer358f4fd2011-09-14 01:09:52 +000041const DWARFDebugAranges *DWARFContext::getDebugAranges() {
42 if (Aranges)
43 return Aranges.get();
44
45 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
46
47 Aranges.reset(new DWARFDebugAranges());
48 Aranges->extract(arangesData);
49 return Aranges.get();
50}
51
Benjamin Kramer72c0d7f2011-09-13 19:42:23 +000052void DWARFContext::parseCompileUnits() {
53 uint32_t offset = 0;
54 const DataExtractor &debug_info_data = DataExtractor(getInfoSection(),
55 isLittleEndian(), 0);
56 while (debug_info_data.isValidOffset(offset)) {
57 CUs.push_back(DWARFCompileUnit(*this));
58 if (!CUs.back().extract(debug_info_data, &offset)) {
59 CUs.pop_back();
60 break;
61 }
62
63 offset = CUs.back().getNextCompileUnitOffset();
64 }
65}