xref: /freebsd-src/contrib/llvm-project/llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp (revision 7a6dacaca14b62ca4b74406814becb87a3fefac0)
10b57cec5SDimitry Andric //===-- DWARFCompileUnit.cpp ----------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
1081ad6265SDimitry Andric #include "llvm/DebugInfo/DIContext.h"
110b57cec5SDimitry Andric #include "llvm/DebugInfo/DWARF/DWARFDie.h"
1281ad6265SDimitry Andric 
130b57cec5SDimitry Andric #include "llvm/Support/Format.h"
140b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric using namespace llvm;
170b57cec5SDimitry Andric 
dump(raw_ostream & OS,DIDumpOptions DumpOpts)180b57cec5SDimitry Andric void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
1904eeddc0SDimitry Andric   if (DumpOpts.SummarizeTypes)
2004eeddc0SDimitry Andric     return;
215ffd83dbSDimitry Andric   int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat());
228bcb0991SDimitry Andric   OS << format("0x%08" PRIx64, getOffset()) << ": Compile Unit:"
235ffd83dbSDimitry Andric      << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
245ffd83dbSDimitry Andric      << ", format = " << dwarf::FormatString(getFormat())
255ffd83dbSDimitry Andric      << ", version = " << format("0x%04x", getVersion());
260b57cec5SDimitry Andric   if (getVersion() >= 5)
275ffd83dbSDimitry Andric     OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType());
28e8d8bef9SDimitry Andric   OS << ", abbr_offset = " << format("0x%04" PRIx64, getAbbrOffset());
29e8d8bef9SDimitry Andric   if (!getAbbreviations())
30e8d8bef9SDimitry Andric     OS << " (invalid)";
31e8d8bef9SDimitry Andric   OS << ", addr_size = " << format("0x%02x", getAddressByteSize());
32fe6060f1SDimitry Andric   if (getVersion() >= 5 && (getUnitType() == dwarf::DW_UT_skeleton ||
33fe6060f1SDimitry Andric                             getUnitType() == dwarf::DW_UT_split_compile))
345ffd83dbSDimitry Andric     OS << ", DWO_id = " << format("0x%016" PRIx64, *getDWOId());
358bcb0991SDimitry Andric   OS << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
368bcb0991SDimitry Andric      << ")\n";
370b57cec5SDimitry Andric 
38*7a6dacacSDimitry Andric   if (DWARFDie CUDie = getUnitDIE(false)) {
390b57cec5SDimitry Andric     CUDie.dump(OS, 0, DumpOpts);
40*7a6dacacSDimitry Andric     if (DumpOpts.DumpNonSkeleton) {
41*7a6dacacSDimitry Andric       DWARFDie NonSkeletonCUDie = getNonSkeletonUnitDIE(false);
42*7a6dacacSDimitry Andric       if (NonSkeletonCUDie && CUDie != NonSkeletonCUDie)
43*7a6dacacSDimitry Andric         NonSkeletonCUDie.dump(OS, 0, DumpOpts);
44*7a6dacacSDimitry Andric     }
45*7a6dacacSDimitry Andric   } else {
460b57cec5SDimitry Andric     OS << "<compile unit can't be parsed!>\n\n";
470b57cec5SDimitry Andric   }
48*7a6dacacSDimitry Andric }
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric // VTable anchor.
510b57cec5SDimitry Andric DWARFCompileUnit::~DWARFCompileUnit() = default;
52