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