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