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/FormatAdapters.h"
13#include "llvm/Support/FormatVariadic.h"
14#include "llvm/Support/raw_ostream.h"
15
16using namespace llvm;
17
18void 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 = " << formatv(Fmt: "{0:x16}", Vals: getTypeHash())
26 << ", length = "
27 << formatv(Fmt: "0x{0:x-}", Vals: fmt_align(Item: getLength(), Where: AlignStyle::Right,
28 Amount: OffsetDumpWidth, Fill: '0'))
29 << '\n';
30 return;
31 }
32
33 OS << formatv(Fmt: "{0:x8}", Vals: getOffset()) << ": Type Unit:"
34 << " length = "
35 << formatv(Fmt: "0x{0:x-}",
36 Vals: fmt_align(Item: getLength(), Where: AlignStyle::Right, Amount: OffsetDumpWidth, Fill: '0'))
37 << ", format = " << dwarf::FormatString(Format: getFormat())
38 << ", version = " << formatv(Fmt: "{0:x4}", Vals: getVersion());
39 if (getVersion() >= 5)
40 OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType());
41 OS << ", abbr_offset = " << formatv(Fmt: "{0:x4}", Vals: getAbbrOffset());
42 if (!getAbbreviations())
43 OS << " (invalid)";
44 OS << ", addr_size = " << formatv(Fmt: "{0:x2}", Vals: getAddressByteSize())
45 << ", name = '" << Name << "'"
46 << ", type_signature = " << formatv(Fmt: "{0:x16}", Vals: getTypeHash())
47 << ", type_offset = " << formatv(Fmt: "{0:x4}", Vals: getTypeOffset())
48 << " (next unit at " << formatv(Fmt: "{0:x8}", Vals: getNextUnitOffset()) << ")\n";
49
50 if (DWARFDie TU = getUnitDIE(ExtractUnitDIEOnly: false))
51 TU.dump(OS, indent: 0, DumpOpts);
52 else
53 OS << "<type unit can't be parsed!>\n\n";
54}
55