Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 1 | //===-- 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 Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 11 | #include "llvm/Support/raw_ostream.h" |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 12 | using namespace llvm; |
| 13 | |
| 14 | void DWARFContext::dump(raw_ostream &OS) { |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 15 | OS << ".debug_abbrev contents:\n"; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 16 | getDebugAbbrev()->dump(OS); |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 17 | |
| 18 | OS << "\n.debug_info contents:\n"; |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 19 | for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) |
| 20 | getCompileUnitAtIndex(i)->dump(OS); |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 21 | |
| 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 Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | const 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 Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 41 | const 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); |
Benjamin Kramer | 10df806 | 2011-09-14 20:52:27 +0000 | [diff] [blame^] | 49 | if (Aranges->isEmpty()) // No aranges in file, generate them from the DIEs. |
| 50 | Aranges->generate(this); |
Benjamin Kramer | 358f4fd | 2011-09-14 01:09:52 +0000 | [diff] [blame] | 51 | return Aranges.get(); |
| 52 | } |
| 53 | |
Benjamin Kramer | 72c0d7f | 2011-09-13 19:42:23 +0000 | [diff] [blame] | 54 | void DWARFContext::parseCompileUnits() { |
| 55 | uint32_t offset = 0; |
| 56 | const DataExtractor &debug_info_data = DataExtractor(getInfoSection(), |
| 57 | isLittleEndian(), 0); |
| 58 | while (debug_info_data.isValidOffset(offset)) { |
| 59 | CUs.push_back(DWARFCompileUnit(*this)); |
| 60 | if (!CUs.back().extract(debug_info_data, &offset)) { |
| 61 | CUs.pop_back(); |
| 62 | break; |
| 63 | } |
| 64 | |
| 65 | offset = CUs.back().getNextCompileUnitOffset(); |
| 66 | } |
| 67 | } |