blob: abd1ad59a9c18d4d1e9f22ae7f38fe275279d12c [file] [log] [blame]
Eugene Zelenko28db7e62017-03-01 01:14:23 +00001//===- DWARFDebugPubTable.cpp ---------------------------------------------===//
George Rimare71e33f2016-12-17 09:10:32 +00002//
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 Song158b2622018-11-11 18:57:28 +000011#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000012#include "llvm/ADT/StringRef.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000013#include "llvm/BinaryFormat/Dwarf.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000014#include "llvm/Support/DataExtractor.h"
George Rimare71e33f2016-12-17 09:10:32 +000015#include "llvm/Support/Format.h"
16#include "llvm/Support/raw_ostream.h"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000017#include <cstdint>
George Rimare71e33f2016-12-17 09:10:32 +000018
19using namespace llvm;
Eugene Zelenko28db7e62017-03-01 01:14:23 +000020using namespace dwarf;
George Rimare71e33f2016-12-17 09:10:32 +000021
Fangrui Song158b2622018-11-11 18:57:28 +000022DWARFDebugPubTable::DWARFDebugPubTable(const DWARFObject &Obj,
23 const DWARFSection &Sec,
24 bool LittleEndian, bool GnuStyle)
George Rimare71e33f2016-12-17 09:10:32 +000025 : GnuStyle(GnuStyle) {
Fangrui Song158b2622018-11-11 18:57:28 +000026 DWARFDataExtractor PubNames(Obj, Sec, LittleEndian, 0);
George Rimare71e33f2016-12-17 09:10:32 +000027 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 Song158b2622018-11-11 18:57:28 +000034 SetData.Offset = PubNames.getRelocatedValue(4, &Offset);
George Rimare71e33f2016-12-17 09:10:32 +000035 SetData.Size = PubNames.getU32(&Offset);
36
Fangrui Song158b2622018-11-11 18:57:28 +000037 while (Offset < Sec.Data.size()) {
George Rimare71e33f2016-12-17 09:10:32 +000038 uint32_t DieRef = PubNames.getU32(&Offset);
39 if (DieRef == 0)
40 break;
41 uint8_t IndexEntryValue = GnuStyle ? PubNames.getU8(&Offset) : 0;
Rui Ueyama0230f7c2018-07-09 22:26:49 +000042 StringRef Name = PubNames.getCStrRef(&Offset);
George Rimare71e33f2016-12-17 09:10:32 +000043 SetData.Entries.push_back(
44 {DieRef, PubIndexEntryDescriptor(IndexEntryValue), Name});
45 }
46 }
47}
48
Adrian Prantl84168022017-09-15 17:39:50 +000049void DWARFDebugPubTable::dump(raw_ostream &OS) const {
George Rimare71e33f2016-12-17 09:10:32 +000050 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 Zelenko28db7e62017-03-01 01:14:23 +000062 GDBIndexEntryLinkageString(E.Descriptor.Linkage);
George Rimare71e33f2016-12-17 09:10:32 +000063 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}