LLVM  14.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/Optional.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/JSON.h"
20 #include <memory>
21 #include <vector>
22 
23 namespace llvm {
24 struct DILineInfo;
25 class DIInliningInfo;
26 struct DIGlobal;
27 struct DILocal;
28 class ErrorInfoBase;
29 class raw_ostream;
30 
31 namespace symbolize {
32 
33 class SourceCode;
34 
35 struct Request {
38 };
39 
40 class DIPrinter {
41 public:
42  DIPrinter() {}
43  virtual ~DIPrinter() {}
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 
51  virtual void printInvalidCommand(const Request &Request,
52  StringRef Command) = 0;
53 
54  virtual bool printError(const Request &Request,
55  const ErrorInfoBase &ErrorInfo,
56  StringRef ErrorBanner) = 0;
57 
58  virtual void listBegin() = 0;
59  virtual void listEnd() = 0;
60 };
61 
62 struct PrinterConfig {
65  bool Pretty;
66  bool Verbose;
68 };
69 
70 class PlainPrinterBase : public DIPrinter {
71 protected:
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 
85 private:
86  void printHeader(uint64_t Address);
87 
88 public:
90  : DIPrinter(), OS(OS), ES(ES), 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 
98  void printInvalidCommand(const Request &Request, StringRef Command) override;
99 
100  bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo,
101  StringRef ErrorBanner) override;
102 
103  void listBegin() override {}
104  void listEnd() override {}
105 };
106 
108 private:
109  void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override;
110  void printStartAddress(const DILineInfo &Info) override;
111  void printFooter() override;
112 
113 public:
115  : PlainPrinterBase(OS, ES, Config) {}
116 };
117 
118 class GNUPrinter : public PlainPrinterBase {
119 private:
120  void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override;
121 
122 public:
124  : PlainPrinterBase(OS, ES, Config) {}
125 };
126 
127 class JSONPrinter : public DIPrinter {
128 private:
129  raw_ostream &OS;
130  PrinterConfig Config;
131  std::unique_ptr<json::Array> ObjectList;
132 
133  void printJSON(const json::Value &V) {
134  json::OStream JOS(OS, Config.Pretty ? 2 : 0);
135  JOS.value(V);
136  OS << '\n';
137  }
138 
139 public:
141  : DIPrinter(), OS(OS), Config(Config) {}
142 
143  void print(const Request &Request, const DILineInfo &Info) override;
144  void print(const Request &Request, const DIInliningInfo &Info) override;
145  void print(const Request &Request, const DIGlobal &Global) override;
146  void print(const Request &Request,
147  const std::vector<DILocal> &Locals) override;
148 
149  void printInvalidCommand(const Request &Request, StringRef Command) override;
150 
151  bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo,
152  StringRef ErrorBanner) override;
153 
154  void listBegin() override;
155  void listEnd() override;
156 };
157 } // namespace symbolize
158 } // namespace llvm
159 
160 #endif
llvm::symbolize::DIPrinter::printError
virtual bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo, StringRef ErrorBanner)=0
llvm::json::Value
A Value is an JSON value of unknown type.
Definition: JSON.h:289
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
Optional.h
llvm::symbolize::PlainPrinterBase::printInvalidCommand
void printInvalidCommand(const Request &Request, StringRef Command) override
Definition: DIPrinter.cpp:261
llvm::symbolize::PlainPrinterBase::printContext
void printContext(SourceCode SourceCode)
Definition: DIPrinter.cpp:120
llvm::DIInliningInfo
A format-neutral container for inlined code description.
Definition: DIContext.h:87
llvm::symbolize::PlainPrinterBase
Definition: DIPrinter.h:70
StringRef.h
llvm::symbolize::JSONPrinter::listBegin
void listBegin() override
Definition: DIPrinter.cpp:386
llvm::symbolize::PlainPrinterBase::Config
PrinterConfig Config
Definition: DIPrinter.h:74
llvm::symbolize::DIPrinter
Definition: DIPrinter.h:40
llvm::symbolize::PlainPrinterBase::listEnd
void listEnd() override
Definition: DIPrinter.h:104
llvm::symbolize::PlainPrinterBase::OS
raw_ostream & OS
Definition: DIPrinter.h:72
llvm::symbolize::PlainPrinterBase::print
void print(const DILineInfo &Info, bool Inlined)
Definition: DIPrinter.cpp:175
llvm::Optional< uint64_t >
llvm::symbolize::PlainPrinterBase::printFooter
virtual void printFooter()
Definition: DIPrinter.h:83
llvm::symbolize::JSONPrinter::print
void print(const Request &Request, const DILineInfo &Info) override
Definition: DIPrinter.cpp:289
llvm::symbolize::DIPrinter::listBegin
virtual void listBegin()=0
llvm::symbolize::Request::Address
Optional< uint64_t > Address
Definition: DIPrinter.h:37
llvm::symbolize::PrinterConfig::PrintAddress
bool PrintAddress
Definition: DIPrinter.h:63
llvm::symbolize::PlainPrinterBase::printStartAddress
virtual void printStartAddress(const DILineInfo &Info)
Definition: DIPrinter.h:82
llvm::symbolize::JSONPrinter::JSONPrinter
JSONPrinter(raw_ostream &OS, PrinterConfig &Config)
Definition: DIPrinter.h:140
llvm::symbolize::DIPrinter::listEnd
virtual void listEnd()=0
llvm::symbolize::PrinterConfig
Definition: DIPrinter.h:62
llvm::symbolize::JSONPrinter::printInvalidCommand
void printInvalidCommand(const Request &Request, StringRef Command) override
Definition: DIPrinter.cpp:367
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
JSON.h
llvm::symbolize::PrinterConfig::PrintFunctions
bool PrintFunctions
Definition: DIPrinter.h:64
llvm::symbolize::Request::ModuleName
StringRef ModuleName
Definition: DIPrinter.h:36
llvm::ErrorInfoBase
Base class for error info classes.
Definition: Error.h:48
llvm::symbolize::DIPrinter::~DIPrinter
virtual ~DIPrinter()
Definition: DIPrinter.h:43
llvm::symbolize::PrinterConfig::SourceContextLines
int SourceContextLines
Definition: DIPrinter.h:67
llvm::symbolize::PlainPrinterBase::listBegin
void listBegin() override
Definition: DIPrinter.h:103
llvm::json::OStream
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
Definition: JSON.h:920
uint64_t
llvm::symbolize::PrinterConfig::Verbose
bool Verbose
Definition: DIPrinter.h:66
llvm::DILineInfo
A format-neutral container for source line information.
Definition: DIContext.h:31
llvm::symbolize::DIPrinter::print
virtual void print(const Request &Request, const DILineInfo &Info)=0
llvm::symbolize::GNUPrinter::GNUPrinter
GNUPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
Definition: DIPrinter.h:123
llvm::symbolize::PlainPrinterBase::PlainPrinterBase
PlainPrinterBase(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
Definition: DIPrinter.h:89
llvm::symbolize::JSONPrinter
Definition: DIPrinter.h:127
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:349
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::symbolize::PrinterConfig::Pretty
bool Pretty
Definition: DIPrinter.h:65
llvm::symbolize::LLVMPrinter::LLVMPrinter
LLVMPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
Definition: DIPrinter.h:114
llvm::DIGlobal
Container for description of a global variable.
Definition: DIContext.h:111
llvm::symbolize::PlainPrinterBase::printVerbose
void printVerbose(StringRef Filename, const DILineInfo &Info)
Definition: DIPrinter.cpp:151
llvm::symbolize::Request
Definition: DIPrinter.h:35
llvm::symbolize::GNUPrinter
Definition: DIPrinter.h:118
llvm::json::OStream::value
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
Definition: JSON.cpp:742
llvm::symbolize::PlainPrinterBase::printSimpleLocation
virtual void printSimpleLocation(StringRef Filename, const DILineInfo &Info)=0
llvm::symbolize::JSONPrinter::listEnd
void listEnd() override
Definition: DIPrinter.cpp:391
llvm::symbolize::SourceCode
Definition: DIPrinter.cpp:33
llvm::symbolize::PlainPrinterBase::ES
raw_ostream & ES
Definition: DIPrinter.h:73
llvm::symbolize::LLVMPrinter
Definition: DIPrinter.h:107
llvm::symbolize::PlainPrinterBase::printError
bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo, StringRef ErrorBanner) override
Definition: DIPrinter.cpp:266
llvm::symbolize::DIPrinter::printInvalidCommand
virtual void printInvalidCommand(const Request &Request, StringRef Command)=0
llvm::symbolize::JSONPrinter::printError
bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo, StringRef ErrorBanner) override
Definition: DIPrinter.cpp:375
llvm::symbolize::PlainPrinterBase::printFunctionName
void printFunctionName(StringRef FunctionName, bool Inlined)
Definition: DIPrinter.cpp:124
llvm::symbolize::DIPrinter::DIPrinter
DIPrinter()
Definition: DIPrinter.h:42