1//===----------------------------------------------------------------------===//
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/DWARFExpressionUnit.h"
10#include "DWARFExpressionPrinterImpl.h"
11#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
12#include "llvm/Support/FormatVariadic.h"
13#include <cassert>
14
15using namespace llvm;
16
17static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
18 DIDumpOptions DumpOpts,
19 ArrayRef<uint64_t> Operands,
20 unsigned Operand) {
21 assert(Operand < Operands.size() && "operand out of bounds");
22 auto Die = U->getDIEForOffset(Offset: U->getOffset() + Operands[Operand]);
23 if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
24 OS << " (";
25 if (DumpOpts.Verbose)
26 OS << formatv(Fmt: "{0:x8} -> ", Vals: Operands[Operand]);
27 OS << formatv(Fmt: "{0:x8})", Vals: U->getOffset() + Operands[Operand]);
28 if (auto Name = dwarf::toString(V: Die.find(Attr: dwarf::DW_AT_name)))
29 OS << " \"" << *Name << "\"";
30 } else {
31 OS << formatv(Fmt: " <invalid base_type ref: {0:x}>", Vals: Operands[Operand]);
32 }
33}
34
35void llvm::printDwarfExpression(const DWARFExpression *E, raw_ostream &OS,
36 DIDumpOptions DumpOpts, DWARFUnit *U,
37 bool IsEH) {
38 auto PrintBaseTypeRef = [U](raw_ostream &OS, DIDumpOptions DumpOpts,
39 ArrayRef<uint64_t> Operands, unsigned Operand) {
40 prettyPrintBaseTypeRef(U, OS, DumpOpts, Operands, Operand);
41 };
42 detail::printDwarfExpression(
43 E, OS, DumpOpts,
44 PrintBaseTypeRef: U ? detail::BaseTypeRefPrinter(PrintBaseTypeRef) : nullptr, IsEH);
45}
46
47bool llvm::prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
48 DIDumpOptions DumpOpts, uint8_t Opcode,
49 ArrayRef<uint64_t> Operands) {
50 auto PrintBaseTypeRef = [U](raw_ostream &OS, DIDumpOptions DumpOpts,
51 ArrayRef<uint64_t> Operands, unsigned Operand) {
52 prettyPrintBaseTypeRef(U, OS, DumpOpts, Operands, Operand);
53 };
54 return detail::prettyPrintRegisterOp(
55 PrintBaseTypeRef: U ? detail::BaseTypeRefPrinter(PrintBaseTypeRef) : nullptr, OS, DumpOpts,
56 Opcode, Operands);
57}
58