Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 1 | //===- DWARFDebugPubTable.cpp ---------------------------------------------===// |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 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 "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/StringRef.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 12 | #include "llvm/BinaryFormat/Dwarf.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 13 | #include "llvm/Support/DataExtractor.h" |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 14 | #include "llvm/Support/Format.h" |
| 15 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 16 | #include <cstdint> |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace llvm; |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 19 | using namespace dwarf; |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 20 | |
| 21 | DWARFDebugPubTable::DWARFDebugPubTable(StringRef Data, bool LittleEndian, |
| 22 | bool GnuStyle) |
| 23 | : GnuStyle(GnuStyle) { |
| 24 | DataExtractor PubNames(Data, LittleEndian, 0); |
| 25 | uint32_t Offset = 0; |
| 26 | while (PubNames.isValidOffset(Offset)) { |
| 27 | Sets.push_back({}); |
| 28 | Set &SetData = Sets.back(); |
| 29 | |
| 30 | SetData.Length = PubNames.getU32(&Offset); |
| 31 | SetData.Version = PubNames.getU16(&Offset); |
| 32 | SetData.Offset = PubNames.getU32(&Offset); |
| 33 | SetData.Size = PubNames.getU32(&Offset); |
| 34 | |
| 35 | while (Offset < Data.size()) { |
| 36 | uint32_t DieRef = PubNames.getU32(&Offset); |
| 37 | if (DieRef == 0) |
| 38 | break; |
| 39 | uint8_t IndexEntryValue = GnuStyle ? PubNames.getU8(&Offset) : 0; |
Rui Ueyama | 0230f7c | 2018-07-09 22:26:49 +0000 | [diff] [blame] | 40 | StringRef Name = PubNames.getCStrRef(&Offset); |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 41 | SetData.Entries.push_back( |
| 42 | {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name}); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
Adrian Prantl | 8416802 | 2017-09-15 17:39:50 +0000 | [diff] [blame] | 47 | void DWARFDebugPubTable::dump(raw_ostream &OS) const { |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 48 | for (const Set &S : Sets) { |
| 49 | OS << "length = " << format("0x%08x", S.Length); |
| 50 | OS << " version = " << format("0x%04x", S.Version); |
| 51 | OS << " unit_offset = " << format("0x%08x", S.Offset); |
| 52 | OS << " unit_size = " << format("0x%08x", S.Size) << '\n'; |
| 53 | OS << (GnuStyle ? "Offset Linkage Kind Name\n" |
| 54 | : "Offset Name\n"); |
| 55 | |
| 56 | for (const Entry &E : S.Entries) { |
| 57 | OS << format("0x%8.8x ", E.SecOffset); |
| 58 | if (GnuStyle) { |
| 59 | StringRef EntryLinkage = |
Eugene Zelenko | 28db7e6 | 2017-03-01 01:14:23 +0000 | [diff] [blame] | 60 | GDBIndexEntryLinkageString(E.Descriptor.Linkage); |
George Rimar | e71e33f | 2016-12-17 09:10:32 +0000 | [diff] [blame] | 61 | StringRef EntryKind = dwarf::GDBIndexEntryKindString(E.Descriptor.Kind); |
| 62 | OS << format("%-8s", EntryLinkage.data()) << ' ' |
| 63 | << format("%-8s", EntryKind.data()) << ' '; |
| 64 | } |
| 65 | OS << '\"' << E.Name << "\"\n"; |
| 66 | } |
| 67 | } |
| 68 | } |