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