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/Format.h"
12 #include "llvm/Support/raw_ostream.h"
15 void DWARFContext::dump(raw_ostream &OS) {
16 OS << ".debug_abbrev contents:\n";
17 getDebugAbbrev()->dump(OS);
19 OS << "\n.debug_info contents:\n";
20 for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i)
21 getCompileUnitAtIndex(i)->dump(OS);
23 OS << "\n.debug_aranges contents:\n";
24 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
26 DWARFDebugArangeSet set;
27 while (set.extract(arangesData, &offset))
30 OS << "\n.debug_lines contents:\n";
31 // FIXME: must be done per CU.
32 DataExtractor lineData(getLineSection(), isLittleEndian(), /*FIXME*/8);
33 DWARFDebugLine::dump(lineData, OS);
35 OS << "\n.debug_str contents:\n";
36 DataExtractor strData(getStringSection(), isLittleEndian(), 0);
38 uint32_t lastOffset = 0;
39 while (const char *s = strData.getCStr(&offset)) {
40 OS << format("0x%8.8x: \"%s\"\n", lastOffset, s);
45 const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
49 DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
51 Abbrev.reset(new DWARFDebugAbbrev());
52 Abbrev->parse(abbrData);
56 const DWARFDebugAranges *DWARFContext::getDebugAranges() {
60 DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
62 Aranges.reset(new DWARFDebugAranges());
63 Aranges->extract(arangesData);
64 if (Aranges->isEmpty()) // No aranges in file, generate them from the DIEs.
65 Aranges->generate(this);
69 const DWARFDebugLine *DWARFContext::getDebugLine() {
73 DataExtractor lineData(getLineSection(), isLittleEndian(), 0);
75 Line.reset(new DWARFDebugLine());
76 Line->parse(lineData);
80 void DWARFContext::parseCompileUnits() {
82 const DataExtractor &debug_info_data = DataExtractor(getInfoSection(),
84 while (debug_info_data.isValidOffset(offset)) {
85 CUs.push_back(DWARFCompileUnit(*this));
86 if (!CUs.back().extract(debug_info_data, &offset)) {
91 offset = CUs.back().getNextCompileUnitOffset();