1 //===-- DWARFCompileUnit.cpp ----------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
10 #include "llvm/DebugInfo/DIContext.h"
11 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
13 #include "llvm/Support/Format.h"
14 #include "llvm/Support/raw_ostream.h"
18 void DWARFCompileUnit::dump(raw_ostream
&OS
, DIDumpOptions DumpOpts
) {
19 if (DumpOpts
.SummarizeTypes
)
21 int OffsetDumpWidth
= 2 * dwarf::getDwarfOffsetByteSize(getFormat());
22 OS
<< format("0x%08" PRIx64
, getOffset()) << ": Compile Unit:"
23 << " length = " << format("0x%0*" PRIx64
, OffsetDumpWidth
, getLength())
24 << ", format = " << dwarf::FormatString(getFormat())
25 << ", version = " << format("0x%04x", getVersion());
26 if (getVersion() >= 5)
27 OS
<< ", unit_type = " << dwarf::UnitTypeString(getUnitType());
28 OS
<< ", abbr_offset = " << format("0x%04" PRIx64
, getAbbrOffset());
29 if (!getAbbreviations())
31 OS
<< ", addr_size = " << format("0x%02x", getAddressByteSize());
32 if (getVersion() >= 5 && (getUnitType() == dwarf::DW_UT_skeleton
||
33 getUnitType() == dwarf::DW_UT_split_compile
))
34 OS
<< ", DWO_id = " << format("0x%016" PRIx64
, *getDWOId());
35 OS
<< " (next unit at " << format("0x%08" PRIx64
, getNextUnitOffset())
38 if (DWARFDie CUDie
= getUnitDIE(false)) {
39 CUDie
.dump(OS
, 0, DumpOpts
);
40 if (DumpOpts
.DumpNonSkeleton
) {
41 DWARFDie NonSkeletonCUDie
= getNonSkeletonUnitDIE(false);
42 if (NonSkeletonCUDie
&& CUDie
!= NonSkeletonCUDie
)
43 NonSkeletonCUDie
.dump(OS
, 0, DumpOpts
);
46 OS
<< "<compile unit can't be parsed!>\n\n";
51 DWARFCompileUnit::~DWARFCompileUnit() = default;