1 //===-- DWARFContext.cpp --------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "DWARFContext.h"
11 #include "llvm/Support/raw_ostream.h"
14 void DWARFContext::dump(raw_ostream &OS) {
15 OS << ".debug_abbrev contents:\n";
16 getDebugAbbrev()->dump(OS);
18 OS << "\n.debug_info contents:\n";
19 for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i)
20 getCompileUnitAtIndex(i)->dump(OS);
22 OS << "\n.debug_aranges contents:\n";
23 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
25 DWARFDebugArangeSet set;
26 while (set.extract(arangesData, &offset))
29 OS << "\n.debug_lines contents:\n";
30 DataExtractor lineData(getLineSection(), isLittleEndian(), 8);
31 DWARFDebugLine::dump(lineData, OS);
34 const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
38 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
40 Abbrev.reset(new DWARFDebugAbbrev());
41 Abbrev->parse(abbrData);
45 const DWARFDebugAranges *DWARFContext::getDebugAranges() {
49 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
51 Aranges.reset(new DWARFDebugAranges());
52 Aranges->extract(arangesData);
53 if (Aranges->isEmpty()) // No aranges in file, generate them from the DIEs.
54 Aranges->generate(this);
58 const DWARFDebugLine *DWARFContext::getDebugLine() {
62 DataExtractor lineData(getLineSection(), isLittleEndian(), 0);
64 Line.reset(new DWARFDebugLine());
65 Line->parse(lineData);
69 void DWARFContext::parseCompileUnits() {
71 const DataExtractor &debug_info_data = DataExtractor(getInfoSection(),
73 while (debug_info_data.isValidOffset(offset)) {
74 CUs.push_back(DWARFCompileUnit(*this));
75 if (!CUs.back().extract(debug_info_data, &offset)) {
80 offset = CUs.back().getNextCompileUnitOffset();