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