]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/DebugInfo/DWARF/DWARFTypeUnit.cpp
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r301441, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / DebugInfo / DWARF / DWARFTypeUnit.cpp
1 //===- DWARFTypeUnit.cpp --------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
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/DWARFTypeUnit.h"
14 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
15 #include "llvm/Support/Format.h"
16 #include "llvm/Support/raw_ostream.h"
17 #include <cinttypes>
18
19 using namespace llvm;
20
21 bool DWARFTypeUnit::extractImpl(DataExtractor debug_info,
22                                 uint32_t *offset_ptr) {
23   if (!DWARFUnit::extractImpl(debug_info, offset_ptr))
24     return false;
25   TypeHash = debug_info.getU64(offset_ptr);
26   TypeOffset = debug_info.getU32(offset_ptr);
27   return TypeOffset < getLength();
28 }
29
30 void DWARFTypeUnit::dump(raw_ostream &OS, bool SummarizeTypes) {
31   DWARFDie TD = getDIEForOffset(TypeOffset + getOffset());
32   const char *Name = TD.getName(DINameKind::ShortName);
33
34   if (SummarizeTypes) {
35     OS << "name = '" << Name << "'"
36        << " type_signature = " << format("0x%016" PRIx64, TypeHash)
37        << " length = " << format("0x%08x", getLength()) << '\n';
38     return;
39   }
40
41   OS << format("0x%08x", getOffset()) << ": Type Unit:"
42      << " length = " << format("0x%08x", getLength())
43      << " version = " << format("0x%04x", getVersion());
44   if (getVersion() >= 5)
45     OS << " unit_type = " << dwarf::UnitTypeString(getUnitType());
46   OS << " abbr_offset = " << format("0x%04x", getAbbreviations()->getOffset())
47      << " addr_size = " << format("0x%02x", getAddressByteSize())
48      << " name = '" << Name << "'"
49      << " type_signature = " << format("0x%016" PRIx64, TypeHash)
50      << " type_offset = " << format("0x%04x", TypeOffset)
51      << " (next unit at " << format("0x%08x", getNextUnitOffset()) << ")\n";
52
53   if (DWARFDie TU = getUnitDIE(false))
54     TU.dump(OS, -1U);
55   else
56     OS << "<type unit can't be parsed!>\n\n";
57 }