2011-09-14 03:42:23 +08:00
|
|
|
//===-- DWARFContext.cpp --------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "DWARFContext.h"
|
2011-09-14 09:09:52 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-09-14 03:42:23 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void DWARFContext::dump(raw_ostream &OS) {
|
2011-09-14 09:09:52 +08:00
|
|
|
OS << ".debug_abbrev contents:\n";
|
2011-09-14 03:42:23 +08:00
|
|
|
getDebugAbbrev()->dump(OS);
|
2011-09-14 09:09:52 +08:00
|
|
|
|
|
|
|
OS << "\n.debug_info contents:\n";
|
2011-09-14 03:42:23 +08:00
|
|
|
for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i)
|
|
|
|
getCompileUnitAtIndex(i)->dump(OS);
|
2011-09-14 09:09:52 +08:00
|
|
|
|
|
|
|
OS << "\n.debug_aranges contents:\n";
|
|
|
|
DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
|
|
|
|
uint32_t offset = 0;
|
|
|
|
DWARFDebugArangeSet set;
|
|
|
|
while (set.extract(arangesData, &offset))
|
|
|
|
set.dump(OS);
|
2011-09-14 03:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {
|
|
|
|
if (Abbrev)
|
|
|
|
return Abbrev.get();
|
|
|
|
|
|
|
|
DataExtractor abbrData(getAbbrevSection(), isLittleEndian(), 0);
|
|
|
|
|
|
|
|
Abbrev.reset(new DWARFDebugAbbrev());
|
|
|
|
Abbrev->parse(abbrData);
|
|
|
|
return Abbrev.get();
|
|
|
|
}
|
|
|
|
|
2011-09-14 09:09:52 +08:00
|
|
|
const DWARFDebugAranges *DWARFContext::getDebugAranges() {
|
|
|
|
if (Aranges)
|
|
|
|
return Aranges.get();
|
|
|
|
|
|
|
|
DataExtractor arangesData(getARangeSection(), isLittleEndian(), 0);
|
|
|
|
|
|
|
|
Aranges.reset(new DWARFDebugAranges());
|
|
|
|
Aranges->extract(arangesData);
|
|
|
|
return Aranges.get();
|
|
|
|
}
|
|
|
|
|
2011-09-14 03:42:23 +08:00
|
|
|
void DWARFContext::parseCompileUnits() {
|
|
|
|
uint32_t offset = 0;
|
|
|
|
const DataExtractor &debug_info_data = DataExtractor(getInfoSection(),
|
|
|
|
isLittleEndian(), 0);
|
|
|
|
while (debug_info_data.isValidOffset(offset)) {
|
|
|
|
CUs.push_back(DWARFCompileUnit(*this));
|
|
|
|
if (!CUs.back().extract(debug_info_data, &offset)) {
|
|
|
|
CUs.pop_back();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = CUs.back().getNextCompileUnitOffset();
|
|
|
|
}
|
|
|
|
}
|