LLVM 20.0.0git
DIPrinter.h
Go to the documentation of this file.
1//===- llvm/DebugInfo/Symbolize/DIPrinter.h ---------------------*- C++ -*-===//
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// This file declares the DIPrinter class, which is responsible for printing
10// structures defined in DebugInfo/DIContext.h
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
15#define LLVM_DEBUGINFO_SYMBOLIZE_DIPRINTER_H
16
17#include "llvm/ADT/StringRef.h"
18#include "llvm/Support/JSON.h"
19#include <memory>
20#include <vector>
21
22namespace llvm {
23struct DILineInfo;
24class DIInliningInfo;
25struct DIGlobal;
26struct DILocal;
27class ErrorInfoBase;
28class raw_ostream;
29
30namespace symbolize {
31
32class SourceCode;
33
34struct Request {
36 std::optional<uint64_t> Address;
38};
39
40class DIPrinter {
41public:
42 DIPrinter() = default;
43 virtual ~DIPrinter() = default;
44
45 virtual void print(const Request &Request, const DILineInfo &Info) = 0;
46 virtual void print(const Request &Request, const DIInliningInfo &Info) = 0;
47 virtual void print(const Request &Request, const DIGlobal &Global) = 0;
48 virtual void print(const Request &Request,
49 const std::vector<DILocal> &Locals) = 0;
50 virtual void print(const Request &Request,
51 const std::vector<DILineInfo> &Locations) = 0;
52
53 virtual bool printError(const Request &Request,
54 const ErrorInfoBase &ErrorInfo) = 0;
55
56 virtual void listBegin() = 0;
57 virtual void listEnd() = 0;
58};
59
63 bool Pretty;
64 bool Verbose;
66};
67
69
71protected:
75
76 void print(const DILineInfo &Info, bool Inlined);
77 void printFunctionName(StringRef FunctionName, bool Inlined);
78 virtual void printSimpleLocation(StringRef Filename,
79 const DILineInfo &Info) = 0;
81 void printVerbose(StringRef Filename, const DILineInfo &Info);
82 virtual void printStartAddress(const DILineInfo &Info) {}
83 virtual void printFooter() {}
84
85private:
86 void printHeader(std::optional<uint64_t> Address);
87
88public:
90 : OS(OS), ErrHandler(EH), Config(Config) {}
91
92 void print(const Request &Request, const DILineInfo &Info) override;
93 void print(const Request &Request, const DIInliningInfo &Info) override;
94 void print(const Request &Request, const DIGlobal &Global) override;
95 void print(const Request &Request,
96 const std::vector<DILocal> &Locals) override;
97 void print(const Request &Request,
98 const std::vector<DILineInfo> &Locations) override;
99
100 bool printError(const Request &Request,
101 const ErrorInfoBase &ErrorInfo) override;
102
103 void listBegin() override {}
104 void listEnd() override {}
105};
106
108private:
109 void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override;
110 void printStartAddress(const DILineInfo &Info) override;
111 void printFooter() override;
112
113public:
115 : PlainPrinterBase(OS, EH, Config) {}
116};
117
119private:
120 void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override;
121
122public:
124 : PlainPrinterBase(OS, EH, Config) {}
125
126};
127
128class JSONPrinter : public DIPrinter {
129private:
130 raw_ostream &OS;
131 PrinterConfig Config;
132 std::unique_ptr<json::Array> ObjectList;
133
134 void printJSON(const json::Value &V) {
135 json::OStream JOS(OS, Config.Pretty ? 2 : 0);
136 JOS.value(V);
137 OS << '\n';
138 }
139
140public:
142 : OS(OS), Config(Config) {}
143
144 void print(const Request &Request, const DILineInfo &Info) override;
145 void print(const Request &Request, const DIInliningInfo &Info) override;
146 void print(const Request &Request, const DIGlobal &Global) override;
147 void print(const Request &Request,
148 const std::vector<DILocal> &Locals) override;
149 void print(const Request &Request,
150 const std::vector<DILineInfo> &Locations) override;
151
152 bool printError(const Request &Request,
153 const ErrorInfoBase &ErrorInfo) override;
154
155 void listBegin() override;
156 void listEnd() override;
157};
158} // namespace symbolize
159} // namespace llvm
160
161#endif
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
RelaxConfig Config
Definition: ELF_riscv.cpp:506
This file supports working with JSON data.
raw_pwrite_stream & OS
A format-neutral container for inlined code description.
Definition: DIContext.h:94
Base class for error info classes.
Definition: Error.h:45
Base class for user error types.
Definition: Error.h:355
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
Definition: JSON.h:979
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
Definition: JSON.cpp:754
A Value is an JSON value of unknown type.
Definition: JSON.h:288
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
virtual void print(const Request &Request, const std::vector< DILocal > &Locals)=0
virtual void listBegin()=0
virtual void print(const Request &Request, const DIGlobal &Global)=0
virtual void listEnd()=0
virtual void print(const Request &Request, const DILineInfo &Info)=0
virtual ~DIPrinter()=default
virtual void print(const Request &Request, const DIInliningInfo &Info)=0
virtual bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo)=0
virtual void print(const Request &Request, const std::vector< DILineInfo > &Locations)=0
GNUPrinter(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
Definition: DIPrinter.h:123
void print(const Request &Request, const DILineInfo &Info) override
Definition: DIPrinter.cpp:324
JSONPrinter(raw_ostream &OS, PrinterConfig &Config)
Definition: DIPrinter.h:141
bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo) override
Definition: DIPrinter.cpp:401
LLVMPrinter(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
Definition: DIPrinter.h:114
void printContext(SourceCode SourceCode)
Definition: DIPrinter.cpp:118
virtual void printStartAddress(const DILineInfo &Info)
Definition: DIPrinter.h:82
bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo) override
Definition: DIPrinter.cpp:281
PlainPrinterBase(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
Definition: DIPrinter.h:89
virtual void printSimpleLocation(StringRef Filename, const DILineInfo &Info)=0
void printVerbose(StringRef Filename, const DILineInfo &Info)
Definition: DIPrinter.cpp:154
void printFunctionName(StringRef FunctionName, bool Inlined)
Definition: DIPrinter.cpp:122
void print(const DILineInfo &Info, bool Inlined)
Definition: DIPrinter.cpp:180
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Global
Append to llvm.global_dtors.
Container for description of a global variable.
Definition: DIContext.h:120
A format-neutral container for source line information.
Definition: DIContext.h:32
std::optional< uint64_t > Address
Definition: DIPrinter.h:36