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 <string> |
19 | #include <vector> |
20 | |
21 | namespace llvm { |
22 | struct DILineInfo; |
23 | class DIInliningInfo; |
24 | struct DIGlobal; |
25 | struct DILocal; |
26 | class ErrorInfoBase; |
27 | class raw_ostream; |
28 | |
29 | namespace symbolize { |
30 | |
31 | struct Request { |
32 | StringRef ModuleName; |
33 | uint64_t Address = 0; |
34 | }; |
35 | |
36 | class DIPrinter { |
37 | public: |
38 | DIPrinter(){}; |
39 | virtual ~DIPrinter(){}; |
40 | |
41 | virtual void print(const Request &Request, const DILineInfo &Info) = 0; |
42 | virtual void print(const Request &Request, const DIInliningInfo &Info) = 0; |
43 | virtual void print(const Request &Request, const DIGlobal &Global) = 0; |
44 | virtual void print(const Request &Request, |
45 | const std::vector<DILocal> &Locals) = 0; |
46 | |
47 | virtual void printInvalidCommand(const Request &Request, |
48 | const ErrorInfoBase &ErrorInfo) = 0; |
49 | |
50 | virtual bool printError(const Request &Request, |
51 | const ErrorInfoBase &ErrorInfo, |
52 | StringRef ErrorBanner) = 0; |
53 | }; |
54 | |
55 | struct PrinterConfig { |
56 | bool PrintAddress; |
57 | bool PrintFunctions; |
58 | bool Pretty; |
59 | bool Verbose; |
60 | int SourceContextLines; |
61 | }; |
62 | |
63 | class PlainPrinterBase : public DIPrinter { |
64 | protected: |
65 | raw_ostream &OS; |
66 | raw_ostream &ES; |
67 | PrinterConfig Config; |
68 | |
69 | void print(const DILineInfo &Info, bool Inlined); |
70 | void printFunctionName(StringRef FunctionName, bool Inlined); |
71 | virtual void printSimpleLocation(StringRef Filename, |
72 | const DILineInfo &Info) = 0; |
73 | void printContext(StringRef FileName, int64_t Line); |
74 | void printVerbose(StringRef Filename, const DILineInfo &Info); |
75 | virtual void () {} |
76 | |
77 | private: |
78 | void (uint64_t Address); |
79 | |
80 | public: |
81 | PlainPrinterBase(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config) |
82 | : DIPrinter(), OS(OS), ES(ES), Config(Config) {} |
83 | |
84 | void print(const Request &Request, const DILineInfo &Info) override; |
85 | void print(const Request &Request, const DIInliningInfo &Info) override; |
86 | void print(const Request &Request, const DIGlobal &Global) override; |
87 | void print(const Request &Request, |
88 | const std::vector<DILocal> &Locals) override; |
89 | |
90 | void printInvalidCommand(const Request &Request, |
91 | const ErrorInfoBase &ErrorInfo) override; |
92 | |
93 | bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo, |
94 | StringRef ErrorBanner) override; |
95 | }; |
96 | |
97 | class LLVMPrinter : public PlainPrinterBase { |
98 | private: |
99 | void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override; |
100 | void () override; |
101 | |
102 | public: |
103 | LLVMPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config) |
104 | : PlainPrinterBase(OS, ES, Config) {} |
105 | }; |
106 | |
107 | class GNUPrinter : public PlainPrinterBase { |
108 | private: |
109 | void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override; |
110 | |
111 | public: |
112 | GNUPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config) |
113 | : PlainPrinterBase(OS, ES, Config) {} |
114 | }; |
115 | } // namespace symbolize |
116 | } // namespace llvm |
117 | |
118 | #endif |
119 | |