30
30
namespace llvm {
31
31
namespace symbolize {
32
32
33
+ void PlainPrinterBase::printHeader (uint64_t Address) {
34
+ if (Config.PrintAddress ) {
35
+ OS << " 0x" ;
36
+ OS.write_hex (Address);
37
+ StringRef Delimiter = Config.Pretty ? " : " : " \n " ;
38
+ OS << Delimiter;
39
+ }
40
+ }
41
+
33
42
// Prints source code around in the FileName the Line.
34
- void DIPrinter ::printContext (const std::string & FileName, int64_t Line) {
35
- if (PrintSourceContext <= 0 )
43
+ void PlainPrinterBase ::printContext (StringRef FileName, int64_t Line) {
44
+ if (Config. SourceContextLines <= 0 )
36
45
return ;
37
46
38
47
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
@@ -42,8 +51,8 @@ void DIPrinter::printContext(const std::string &FileName, int64_t Line) {
42
51
43
52
std::unique_ptr<MemoryBuffer> Buf = std::move (BufOrErr.get ());
44
53
int64_t FirstLine =
45
- std::max (static_cast <int64_t >(1 ), Line - PrintSourceContext / 2 );
46
- int64_t LastLine = FirstLine + PrintSourceContext ;
54
+ std::max (static_cast <int64_t >(1 ), Line - Config. SourceContextLines / 2 );
55
+ int64_t LastLine = FirstLine + Config. SourceContextLines ;
47
56
size_t MaxLineNumberWidth = std::ceil (std::log10 (LastLine));
48
57
49
58
for (line_iterator I = line_iterator (*Buf, false );
@@ -60,97 +69,145 @@ void DIPrinter::printContext(const std::string &FileName, int64_t Line) {
60
69
}
61
70
}
62
71
63
- void DIPrinter::print (const DILineInfo &Info, bool Inlined) {
64
- if (PrintFunctionNames) {
65
- std::string FunctionName = Info.FunctionName ;
72
+ void PlainPrinterBase::printFunctionName (StringRef FunctionName, bool Inlined) {
73
+ if (Config.PrintFunctions ) {
66
74
if (FunctionName == DILineInfo::BadString)
67
75
FunctionName = DILineInfo::Addr2LineBadString;
68
-
69
- StringRef Delimiter = PrintPretty ? " at " : " \n " ;
70
- StringRef Prefix = (PrintPretty && Inlined) ? " (inlined by) " : " " ;
76
+ StringRef Delimiter = Config.Pretty ? " at " : " \n " ;
77
+ StringRef Prefix = (Config.Pretty && Inlined) ? " (inlined by) " : " " ;
71
78
OS << Prefix << FunctionName << Delimiter;
72
79
}
73
- std::string Filename = Info.FileName ;
74
- if (Filename == DILineInfo::BadString)
75
- Filename = DILineInfo::Addr2LineBadString;
76
- if (!Verbose) {
77
- OS << Filename << " :" << Info.Line ;
78
- if (Style == OutputStyle::LLVM)
79
- OS << " :" << Info.Column ;
80
- else if (Style == OutputStyle::GNU && Info.Discriminator != 0 )
81
- OS << " (discriminator " << Info.Discriminator << " )" ;
82
- OS << " \n " ;
83
- printContext (Filename, Info.Line );
84
- return ;
85
- }
86
- OS << " Filename: " << Filename << " \n " ;
80
+ }
81
+
82
+ void LLVMPrinter::printSimpleLocation (StringRef Filename,
83
+ const DILineInfo &Info) {
84
+ OS << Filename << ' :' << Info.Line << ' :' << Info.Column << ' \n ' ;
85
+ printContext (Filename, Info.Line );
86
+ }
87
+
88
+ void GNUPrinter::printSimpleLocation (StringRef Filename,
89
+ const DILineInfo &Info) {
90
+ OS << Filename << ' :' << Info.Line ;
91
+ if (Info.Discriminator )
92
+ OS << " (discriminator " << Info.Discriminator << ' )' ;
93
+ OS << ' \n ' ;
94
+ printContext (Filename, Info.Line );
95
+ }
96
+
97
+ void PlainPrinterBase::printVerbose (StringRef Filename,
98
+ const DILineInfo &Info) {
99
+ OS << " Filename: " << Filename << ' \n ' ;
87
100
if (Info.StartLine ) {
88
- OS << " Function start filename: " << Info.StartFileName << " \n " ;
89
- OS << " Function start line: " << Info.StartLine << " \n " ;
101
+ OS << " Function start filename: " << Info.StartFileName << ' \n ' ;
102
+ OS << " Function start line: " << Info.StartLine << ' \n ' ;
90
103
}
91
- OS << " Line: " << Info.Line << " \n " ;
92
- OS << " Column: " << Info.Column << " \n " ;
104
+ OS << " Line: " << Info.Line << ' \n ' ;
105
+ OS << " Column: " << Info.Column << ' \n ' ;
93
106
if (Info.Discriminator )
94
- OS << " Discriminator: " << Info.Discriminator << " \n " ;
107
+ OS << " Discriminator: " << Info.Discriminator << ' \n ' ;
108
+ }
109
+
110
+ void LLVMPrinter::printFooter () { OS << ' \n ' ; }
111
+
112
+ void PlainPrinterBase::print (const DILineInfo &Info, bool Inlined) {
113
+ printFunctionName (Info.FunctionName , Inlined);
114
+ StringRef Filename = Info.FileName ;
115
+ if (Filename == DILineInfo::BadString)
116
+ Filename = DILineInfo::Addr2LineBadString;
117
+ if (Config.Verbose )
118
+ printVerbose (Filename, Info);
119
+ else
120
+ printSimpleLocation (Filename, Info);
95
121
}
96
122
97
- DIPrinter &DIPrinter::operator <<(const DILineInfo &Info) {
123
+ void PlainPrinterBase::print (const Request &Request, const DILineInfo &Info) {
124
+ printHeader (Request.Address );
98
125
print (Info, false );
99
- return * this ;
126
+ printFooter () ;
100
127
}
101
128
102
- DIPrinter &DIPrinter::operator <<(const DIInliningInfo &Info) {
129
+ void PlainPrinterBase::print (const Request &Request,
130
+ const DIInliningInfo &Info) {
131
+ printHeader (Request.Address );
103
132
uint32_t FramesNum = Info.getNumberOfFrames ();
104
- if (FramesNum == 0 ) {
133
+ if (FramesNum == 0 )
105
134
print (DILineInfo (), false );
106
- return *this ;
107
- }
108
- for (uint32_t i = 0 ; i < FramesNum; i++)
109
- print (Info.getFrame (i), i > 0 );
110
- return *this ;
135
+ else
136
+ for (uint32_t I = 0 ; I < FramesNum; ++I)
137
+ print (Info.getFrame (I), I > 0 );
138
+ printFooter ();
111
139
}
112
140
113
- DIPrinter &DIPrinter::operator <<(const DIGlobal &Global) {
114
- std::string Name = Global.Name ;
141
+ void PlainPrinterBase::print (const Request &Request, const DIGlobal &Global) {
142
+ printHeader (Request.Address );
143
+ StringRef Name = Global.Name ;
115
144
if (Name == DILineInfo::BadString)
116
145
Name = DILineInfo::Addr2LineBadString;
117
146
OS << Name << " \n " ;
118
147
OS << Global.Start << " " << Global.Size << " \n " ;
119
- return * this ;
148
+ printFooter () ;
120
149
}
121
150
122
- DIPrinter &DIPrinter::operator <<(const DILocal &Local) {
123
- if (Local.FunctionName .empty ())
124
- OS << " ??\n " ;
151
+ void PlainPrinterBase::print (const Request &Request,
152
+ const std::vector<DILocal> &Locals) {
153
+ printHeader (Request.Address );
154
+ if (Locals.empty ())
155
+ OS << DILineInfo::Addr2LineBadString << ' \n ' ;
125
156
else
126
- OS << Local.FunctionName << ' \n ' ;
157
+ for (const DILocal &L : Locals) {
158
+ if (L.FunctionName .empty ())
159
+ OS << DILineInfo::Addr2LineBadString;
160
+ else
161
+ OS << L.FunctionName ;
162
+ OS << ' \n ' ;
127
163
128
- if (Local.Name .empty ())
129
- OS << " ??\n " ;
130
- else
131
- OS << Local.Name << ' \n ' ;
164
+ if (L.Name .empty ())
165
+ OS << DILineInfo::Addr2LineBadString;
166
+ else
167
+ OS << L.Name ;
168
+ OS << ' \n ' ;
132
169
133
- if (Local.DeclFile .empty ())
134
- OS << " ??" ;
135
- else
136
- OS << Local.DeclFile ;
137
- OS << ' :' << Local.DeclLine << ' \n ' ;
170
+ if (L.DeclFile .empty ())
171
+ OS << DILineInfo::Addr2LineBadString;
172
+ else
173
+ OS << L.DeclFile ;
138
174
139
- if (Local.FrameOffset )
140
- OS << *Local.FrameOffset << ' ' ;
141
- else
142
- OS << " ?? " ;
175
+ OS << ' :' << L.DeclLine << ' \n ' ;
143
176
144
- if (Local.Size )
145
- OS << *Local.Size << ' ' ;
146
- else
147
- OS << " ?? " ;
177
+ if (L.FrameOffset )
178
+ OS << *L.FrameOffset ;
179
+ else
180
+ OS << DILineInfo::Addr2LineBadString;
181
+ OS << ' ' ;
148
182
149
- if (Local.TagOffset )
150
- OS << *Local.TagOffset << ' \n ' ;
151
- else
152
- OS << " ??\n " ;
153
- return *this ;
183
+ if (L.Size )
184
+ OS << *L.Size ;
185
+ else
186
+ OS << DILineInfo::Addr2LineBadString;
187
+ OS << ' ' ;
188
+
189
+ if (L.TagOffset )
190
+ OS << *L.TagOffset ;
191
+ else
192
+ OS << DILineInfo::Addr2LineBadString;
193
+ OS << ' \n ' ;
194
+ }
195
+ printFooter ();
196
+ }
197
+
198
+ void PlainPrinterBase::printInvalidCommand (const Request &Request,
199
+ const ErrorInfoBase &ErrorInfo) {
200
+ OS << ErrorInfo.message () << ' \n ' ;
201
+ }
202
+
203
+ bool PlainPrinterBase::printError (const Request &Request,
204
+ const ErrorInfoBase &ErrorInfo,
205
+ StringRef ErrorBanner) {
206
+ ES << ErrorBanner;
207
+ ErrorInfo.log (ES);
208
+ ES << ' \n ' ;
209
+ // Print an empty struct too.
210
+ return true ;
154
211
}
155
212
156
213
} // end namespace symbolize
0 commit comments