1 | //===- DWARFTypeUnit.cpp --------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h" |
10 | #include "llvm/DebugInfo/DIContext.h" |
11 | #include "llvm/DebugInfo/DWARF/DWARFDie.h" |
12 | #include "llvm/Support/Format.h" |
13 | #include "llvm/Support/raw_ostream.h" |
14 | #include <cinttypes> |
15 | |
16 | using namespace llvm; |
17 | |
18 | void DWARFTypeUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) { |
19 | DWARFDie TD = getDIEForOffset(Offset: getTypeOffset() + getOffset()); |
20 | const char *Name = TD.getName(Kind: DINameKind::ShortName); |
21 | int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(Format: getFormat()); |
22 | |
23 | if (DumpOpts.SummarizeTypes) { |
24 | OS << "name = '" << Name << "'" |
25 | << ", type_signature = " << format(Fmt: "0x%016" PRIx64, Vals: getTypeHash()) |
26 | << ", length = " << format(Fmt: "0x%0*" PRIx64, Vals: OffsetDumpWidth, Vals: getLength()) |
27 | << '\n'; |
28 | return; |
29 | } |
30 | |
31 | OS << format(Fmt: "0x%08" PRIx64, Vals: getOffset()) << ": Type Unit:" |
32 | << " length = " << format(Fmt: "0x%0*" PRIx64, Vals: OffsetDumpWidth, Vals: getLength()) |
33 | << ", format = " << dwarf::FormatString(Format: getFormat()) |
34 | << ", version = " << format(Fmt: "0x%04x" , Vals: getVersion()); |
35 | if (getVersion() >= 5) |
36 | OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType()); |
37 | OS << ", abbr_offset = " << format(Fmt: "0x%04" PRIx64, Vals: getAbbrOffset()); |
38 | if (!getAbbreviations()) |
39 | OS << " (invalid)" ; |
40 | OS << ", addr_size = " << format(Fmt: "0x%02x" , Vals: getAddressByteSize()) |
41 | << ", name = '" << Name << "'" |
42 | << ", type_signature = " << format(Fmt: "0x%016" PRIx64, Vals: getTypeHash()) |
43 | << ", type_offset = " << format(Fmt: "0x%04" PRIx64, Vals: getTypeOffset()) |
44 | << " (next unit at " << format(Fmt: "0x%08" PRIx64, Vals: getNextUnitOffset()) |
45 | << ")\n" ; |
46 | |
47 | if (DWARFDie TU = getUnitDIE(ExtractUnitDIEOnly: false)) |
48 | TU.dump(OS, indent: 0, DumpOpts); |
49 | else |
50 | OS << "<type unit can't be parsed!>\n\n" ; |
51 | } |
52 | |