xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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/DWARF/DWARFDebugAbbrev.h"
11 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
12 #include "llvm/Support/Format.h"
13 #include "llvm/Support/raw_ostream.h"
14 
15 using namespace llvm;
16 
17 void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
18   if (DumpOpts.SummarizeTypes)
19     return;
20   int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat());
21   OS << format("0x%08" PRIx64, getOffset()) << ": Compile Unit:"
22      << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
23      << ", format = " << dwarf::FormatString(getFormat())
24      << ", version = " << format("0x%04x", getVersion());
25   if (getVersion() >= 5)
26     OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType());
27   OS << ", abbr_offset = " << format("0x%04" PRIx64, getAbbrOffset());
28   if (!getAbbreviations())
29     OS << " (invalid)";
30   OS << ", addr_size = " << format("0x%02x", getAddressByteSize());
31   if (getVersion() >= 5 && (getUnitType() == dwarf::DW_UT_skeleton ||
32                             getUnitType() == dwarf::DW_UT_split_compile))
33     OS << ", DWO_id = " << format("0x%016" PRIx64, *getDWOId());
34   OS << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
35      << ")\n";
36 
37   if (DWARFDie CUDie = getUnitDIE(false))
38     CUDie.dump(OS, 0, DumpOpts);
39   else
40     OS << "<compile unit can't be parsed!>\n\n";
41 }
42 
43 // VTable anchor.
44 DWARFCompileUnit::~DWARFCompileUnit() = default;
45