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