182af9438SZachary Turner //===-- DWARFCompileUnit.cpp ----------------------------------------------===//
282af9438SZachary Turner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
682af9438SZachary Turner //
782af9438SZachary Turner //===----------------------------------------------------------------------===//
882af9438SZachary Turner 
982af9438SZachary Turner #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
10*290e4823Sserge-sans-paille #include "llvm/DebugInfo/DIContext.h"
11c8c1032cSGreg Clayton #include "llvm/DebugInfo/DWARF/DWARFDie.h"
12*290e4823Sserge-sans-paille 
1382af9438SZachary Turner #include "llvm/Support/Format.h"
1482af9438SZachary Turner #include "llvm/Support/raw_ostream.h"
1582af9438SZachary Turner 
1682af9438SZachary Turner using namespace llvm;
1782af9438SZachary Turner 
dump(raw_ostream & OS,DIDumpOptions DumpOpts)18318d1195SAdrian Prantl void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
1933529ba0SDavid Blaikie   if (DumpOpts.SummarizeTypes)
2033529ba0SDavid Blaikie     return;
210db1684bSIgor Kudrin   int OffsetDumpWidth = 2 * dwarf::getDwarfOffsetByteSize(getFormat());
22f26a70a5SIgor Kudrin   OS << format("0x%08" PRIx64, getOffset()) << ": Compile Unit:"
230db1684bSIgor Kudrin      << " length = " << format("0x%0*" PRIx64, OffsetDumpWidth, getLength())
24ef7ada04SIgor Kudrin      << ", format = " << dwarf::FormatString(getFormat())
252a7af304SIgor Kudrin      << ", version = " << format("0x%04x", getVersion());
26cddd6044SPaul Robinson   if (getVersion() >= 5)
272a7af304SIgor Kudrin     OS << ", unit_type = " << dwarf::UnitTypeString(getUnitType());
289ceb192eSIgor Kudrin   OS << ", abbr_offset = " << format("0x%04" PRIx64, getAbbrOffset());
299ceb192eSIgor Kudrin   if (!getAbbreviations())
309ceb192eSIgor Kudrin     OS << " (invalid)";
319ceb192eSIgor Kudrin   OS << ", addr_size = " << format("0x%02x", getAddressByteSize());
325a26345fSAlok Kumar Sharma   if (getVersion() >= 5 && (getUnitType() == dwarf::DW_UT_skeleton ||
335a26345fSAlok Kumar Sharma                             getUnitType() == dwarf::DW_UT_split_compile))
342a7af304SIgor Kudrin     OS << ", DWO_id = " << format("0x%016" PRIx64, *getDWOId());
35f26a70a5SIgor Kudrin   OS << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
36f26a70a5SIgor Kudrin      << ")\n";
3782af9438SZachary Turner 
38c8c1032cSGreg Clayton   if (DWARFDie CUDie = getUnitDIE(false))
39d3f9f213SAdrian Prantl     CUDie.dump(OS, 0, DumpOpts);
407a18c061SAlexey Samsonov   else
417a18c061SAlexey Samsonov     OS << "<compile unit can't be parsed!>\n\n";
4282af9438SZachary Turner }
4382af9438SZachary Turner 
4482af9438SZachary Turner // VTable anchor.
45570e39a2SEugene Zelenko DWARFCompileUnit::~DWARFCompileUnit() = default;
46