1 //===- DWARFTypeUnit.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/DWARFTypeUnit.h"
10 #include "llvm/DebugInfo/DIContext.h"
11 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
12 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
13 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
14 #include "llvm/Support/Format.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include <cinttypes>
17 
18 using namespace llvm;
19 
20 void DWARFTypeUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
21   DWARFDie TD = getDIEForOffset(getTypeOffset() + getOffset());
22   const char *Name = TD.getName(DINameKind::ShortName);
23   int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat());
24 
25   if (DumpOpts.SummarizeTypes) {
26     OS << "name = '" << Name << "'"
27        << ", type_signature = " << format("0x%016" PRIx64, getTypeHash())
28        << ", length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
29        << '\n';
30     return;
31   }
32 
33   OS << format("0x%08" PRIx64, getOffset()) << ": Type Unit:"
34      << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
35      << ", format = " << dwarf::FormatString(getFormat())
36      << ", version = " << format("0x%04x", getVersion());
37   if (getVersion() >= 5)
38     OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType());
39   OS << ", abbr_offset = " << format("0x%04" PRIx64, getAbbrOffset());
40   if (!getAbbreviations())
41     OS << " (invalid)";
42   OS << ", addr_size = " << format("0x%02x", getAddressByteSize())
43      << ", name = '" << Name << "'"
44      << ", type_signature = " << format("0x%016" PRIx64, getTypeHash())
45      << ", type_offset = " << format("0x%04" PRIx64, getTypeOffset())
46      << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
47      << ")\n";
48 
49   if (DWARFDie TU = getUnitDIE(false))
50     TU.dump(OS, 0, DumpOpts);
51   else
52     OS << "<type unit can't be parsed!>\n\n";
53 }
54