1//===-- DWARFCompileUnit.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/DWARFCompileUnit.h"
10#include "llvm/DebugInfo/DIContext.h"
11#include "llvm/DebugInfo/DWARF/DWARFDie.h"
12
13#include "llvm/Support/FormatAdapters.h"
14#include "llvm/Support/FormatVariadic.h"
15#include "llvm/Support/raw_ostream.h"
16
17using namespace llvm;
18
19void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
20 if (DumpOpts.SummarizeTypes)
21 return;
22 int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(Format: getFormat());
23 OS << formatv(Fmt: "{0:x+8}", Vals: getOffset()) << ": Compile Unit:"
24 << " length = "
25 << formatv(Fmt: "0x{0:x-}",
26 Vals: fmt_align(Item: getLength(), Where: AlignStyle::Right, Amount: OffsetDumpWidth, Fill: '0'))
27 << ", format = " << dwarf::FormatString(Format: getFormat())
28 << ", version = " << formatv(Fmt: "{0:x+4}", Vals: getVersion());
29
30 if (getVersion() >= 5)
31 OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType());
32 OS << ", abbr_offset = " << formatv(Fmt: "{0:x+4}", Vals: getAbbrOffset());
33 if (!getAbbreviations())
34 OS << " (invalid)";
35 OS << ", addr_size = " << formatv(Fmt: "{0:x+2}", Vals: getAddressByteSize());
36 if (getVersion() >= 5 && (getUnitType() == dwarf::DW_UT_skeleton ||
37 getUnitType() == dwarf::DW_UT_split_compile))
38 OS << ", DWO_id = " << formatv(Fmt: "{0:x+16}", Vals: *getDWOId());
39 OS << " (next unit at " << formatv(Fmt: "{0:x+8}", Vals: getNextUnitOffset()) << ")\n";
40
41 if (DWARFDie CUDie = getUnitDIE(ExtractUnitDIEOnly: false)) {
42 CUDie.dump(OS, indent: 0, DumpOpts);
43 if (DumpOpts.DumpNonSkeleton) {
44 DWARFDie NonSkeletonCUDie = getNonSkeletonUnitDIE(ExtractUnitDIEOnly: false);
45 if (NonSkeletonCUDie && CUDie != NonSkeletonCUDie)
46 NonSkeletonCUDie.dump(OS, indent: 0, DumpOpts);
47 }
48 } else {
49 OS << "<compile unit can't be parsed!>\n\n";
50 }
51}
52
53// VTable anchor.
54DWARFCompileUnit::~DWARFCompileUnit() = default;
55