Commit | Line | Data |
---|---|---|
fb40c209 | 1 | /* MI Command Set - output generating routines. |
349c5d5f | 2 | |
42a4f53d | 3 | Copyright (C) 2000-2019 Free Software Foundation, Inc. |
349c5d5f | 4 | |
ab91fdd5 | 5 | Contributed by Cygnus Solutions (a Red Hat company). |
fb40c209 AC |
6 | |
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
fb40c209 AC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
fb40c209 AC |
21 | |
22 | #include "defs.h" | |
fb40c209 | 23 | #include "mi-out.h" |
8e5e5494 | 24 | |
4a9d4ea5 | 25 | #include <vector> |
fb40c209 | 26 | |
8e5e5494 SM |
27 | #include "interps.h" |
28 | #include "ui-out.h" | |
29 | #include "utils.h" | |
30 | ||
2b03b41d | 31 | /* Mark beginning of a table. */ |
fb40c209 AC |
32 | |
33 | void | |
112e8700 SM |
34 | mi_ui_out::do_table_begin (int nr_cols, int nr_rows, |
35 | const char *tblid) | |
fb40c209 | 36 | { |
112e8700 | 37 | open (tblid, ui_out_type_tuple); |
381befee TT |
38 | do_field_signed (-1, -1, ui_left, "nr_rows", nr_rows); |
39 | do_field_signed (-1, -1, ui_left, "nr_cols", nr_cols); | |
112e8700 | 40 | open ("hdr", ui_out_type_list); |
fb40c209 AC |
41 | } |
42 | ||
2b03b41d | 43 | /* Mark beginning of a table body. */ |
fb40c209 AC |
44 | |
45 | void | |
112e8700 | 46 | mi_ui_out::do_table_body () |
fb40c209 | 47 | { |
cff22675 | 48 | /* close the table header line if there were any headers */ |
112e8700 SM |
49 | close (ui_out_type_list); |
50 | open ("body", ui_out_type_list); | |
fb40c209 AC |
51 | } |
52 | ||
2b03b41d | 53 | /* Mark end of a table. */ |
fb40c209 AC |
54 | |
55 | void | |
112e8700 | 56 | mi_ui_out::do_table_end () |
fb40c209 | 57 | { |
112e8700 SM |
58 | close (ui_out_type_list); /* body */ |
59 | close (ui_out_type_tuple); | |
fb40c209 AC |
60 | } |
61 | ||
2b03b41d | 62 | /* Specify table header. */ |
fb40c209 AC |
63 | |
64 | void | |
112e8700 SM |
65 | mi_ui_out::do_table_header (int width, ui_align alignment, |
66 | const std::string &col_name, | |
67 | const std::string &col_hdr) | |
fb40c209 | 68 | { |
112e8700 | 69 | open (NULL, ui_out_type_tuple); |
381befee TT |
70 | do_field_signed (0, 0, ui_center, "width", width); |
71 | do_field_signed (0, 0, ui_center, "alignment", alignment); | |
cbe56571 | 72 | do_field_string (0, 0, ui_center, "col_name", col_name.c_str (), |
e43b10e1 | 73 | ui_file_style ()); |
cbe56571 | 74 | do_field_string (0, width, alignment, "colhdr", col_hdr.c_str (), |
e43b10e1 | 75 | ui_file_style ()); |
112e8700 | 76 | close (ui_out_type_tuple); |
fb40c209 AC |
77 | } |
78 | ||
2b03b41d | 79 | /* Mark beginning of a list. */ |
fb40c209 AC |
80 | |
81 | void | |
112e8700 | 82 | mi_ui_out::do_begin (ui_out_type type, const char *id) |
fb40c209 | 83 | { |
112e8700 | 84 | open (id, type); |
fb40c209 AC |
85 | } |
86 | ||
2b03b41d | 87 | /* Mark end of a list. */ |
fb40c209 AC |
88 | |
89 | void | |
112e8700 | 90 | mi_ui_out::do_end (ui_out_type type) |
fb40c209 | 91 | { |
112e8700 | 92 | close (type); |
fb40c209 AC |
93 | } |
94 | ||
2b03b41d | 95 | /* Output an int field. */ |
fb40c209 | 96 | |
112e8700 | 97 | void |
381befee TT |
98 | mi_ui_out::do_field_signed (int fldno, int width, ui_align alignment, |
99 | const char *fldname, LONGEST value) | |
fb40c209 | 100 | { |
07128006 | 101 | do_field_string (fldno, width, alignment, fldname, plongest (value), |
e43b10e1 | 102 | ui_file_style ()); |
fb40c209 AC |
103 | } |
104 | ||
1f77b012 TT |
105 | /* Output an unsigned field. */ |
106 | ||
107 | void | |
108 | mi_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment, | |
109 | const char *fldname, ULONGEST value) | |
110 | { | |
111 | do_field_string (fldno, width, alignment, fldname, pulongest (value), | |
e43b10e1 | 112 | ui_file_style ()); |
1f77b012 TT |
113 | } |
114 | ||
2b03b41d | 115 | /* Used to omit a field. */ |
fb40c209 AC |
116 | |
117 | void | |
112e8700 SM |
118 | mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment, |
119 | const char *fldname) | |
fb40c209 | 120 | { |
fb40c209 AC |
121 | } |
122 | ||
2b03b41d SS |
123 | /* Other specific mi_field_* end up here so alignment and field |
124 | separators are both handled by mi_field_string. */ | |
fb40c209 AC |
125 | |
126 | void | |
112e8700 | 127 | mi_ui_out::do_field_string (int fldno, int width, ui_align align, |
cbe56571 | 128 | const char *fldname, const char *string, |
e43b10e1 | 129 | const ui_file_style &style) |
fb40c209 | 130 | { |
112e8700 SM |
131 | ui_file *stream = m_streams.back (); |
132 | field_separator (); | |
102040f0 | 133 | |
fb40c209 | 134 | if (fldname) |
4d6cceb4 DE |
135 | fprintf_unfiltered (stream, "%s=", fldname); |
136 | fprintf_unfiltered (stream, "\""); | |
fb40c209 | 137 | if (string) |
4d6cceb4 DE |
138 | fputstr_unfiltered (string, '"', stream); |
139 | fprintf_unfiltered (stream, "\""); | |
fb40c209 AC |
140 | } |
141 | ||
fb40c209 | 142 | void |
112e8700 | 143 | mi_ui_out::do_field_fmt (int fldno, int width, ui_align align, |
7f6aba03 TT |
144 | const char *fldname, const ui_file_style &style, |
145 | const char *format, va_list args) | |
fb40c209 | 146 | { |
112e8700 SM |
147 | ui_file *stream = m_streams.back (); |
148 | field_separator (); | |
102040f0 | 149 | |
fb40c209 | 150 | if (fldname) |
4d6cceb4 | 151 | fprintf_unfiltered (stream, "%s=\"", fldname); |
fb40c209 | 152 | else |
4d6cceb4 DE |
153 | fputs_unfiltered ("\"", stream); |
154 | vfprintf_unfiltered (stream, format, args); | |
155 | fputs_unfiltered ("\"", stream); | |
fb40c209 AC |
156 | } |
157 | ||
158 | void | |
112e8700 | 159 | mi_ui_out::do_spaces (int numspaces) |
fb40c209 AC |
160 | { |
161 | } | |
162 | ||
163 | void | |
112e8700 | 164 | mi_ui_out::do_text (const char *string) |
fb40c209 AC |
165 | { |
166 | } | |
167 | ||
168 | void | |
2a3c1174 PA |
169 | mi_ui_out::do_message (const ui_file_style &style, |
170 | const char *format, va_list args) | |
fb40c209 AC |
171 | { |
172 | } | |
173 | ||
174 | void | |
112e8700 | 175 | mi_ui_out::do_wrap_hint (const char *identstring) |
fb40c209 AC |
176 | { |
177 | wrap_here (identstring); | |
178 | } | |
179 | ||
180 | void | |
112e8700 | 181 | mi_ui_out::do_flush () |
fb40c209 | 182 | { |
102040f0 | 183 | |
112e8700 | 184 | gdb_flush (m_streams.back ()); |
fb40c209 AC |
185 | } |
186 | ||
7becfd03 | 187 | void |
112e8700 | 188 | mi_ui_out::do_redirect (ui_file *outstream) |
8d3788bd | 189 | { |
8d3788bd | 190 | if (outstream != NULL) |
112e8700 | 191 | m_streams.push_back (outstream); |
4d6cceb4 | 192 | else |
112e8700 | 193 | m_streams.pop_back (); |
8d3788bd VP |
194 | } |
195 | ||
112e8700 SM |
196 | void |
197 | mi_ui_out::field_separator () | |
fb40c209 | 198 | { |
112e8700 SM |
199 | if (m_suppress_field_separator) |
200 | m_suppress_field_separator = false; | |
fb40c209 | 201 | else |
112e8700 | 202 | fputc_unfiltered (',', m_streams.back ()); |
fb40c209 AC |
203 | } |
204 | ||
112e8700 SM |
205 | void |
206 | mi_ui_out::open (const char *name, ui_out_type type) | |
fb40c209 | 207 | { |
112e8700 SM |
208 | ui_file *stream = m_streams.back (); |
209 | ||
210 | field_separator (); | |
211 | m_suppress_field_separator = true; | |
102040f0 | 212 | |
d5e8ba62 | 213 | if (name) |
4d6cceb4 | 214 | fprintf_unfiltered (stream, "%s=", name); |
112e8700 | 215 | |
5a9aa5dc AC |
216 | switch (type) |
217 | { | |
218 | case ui_out_type_tuple: | |
4d6cceb4 | 219 | fputc_unfiltered ('{', stream); |
5a9aa5dc | 220 | break; |
112e8700 | 221 | |
5a9aa5dc | 222 | case ui_out_type_list: |
4d6cceb4 | 223 | fputc_unfiltered ('[', stream); |
5a9aa5dc | 224 | break; |
112e8700 | 225 | |
5a9aa5dc | 226 | default: |
e2e0b3e5 | 227 | internal_error (__FILE__, __LINE__, _("bad switch")); |
5a9aa5dc | 228 | } |
fb40c209 AC |
229 | } |
230 | ||
112e8700 SM |
231 | void |
232 | mi_ui_out::close (ui_out_type type) | |
fb40c209 | 233 | { |
112e8700 | 234 | ui_file *stream = m_streams.back (); |
102040f0 | 235 | |
5a9aa5dc AC |
236 | switch (type) |
237 | { | |
238 | case ui_out_type_tuple: | |
4d6cceb4 | 239 | fputc_unfiltered ('}', stream); |
5a9aa5dc | 240 | break; |
112e8700 | 241 | |
5a9aa5dc | 242 | case ui_out_type_list: |
4d6cceb4 | 243 | fputc_unfiltered (']', stream); |
5a9aa5dc | 244 | break; |
112e8700 | 245 | |
5a9aa5dc | 246 | default: |
e2e0b3e5 | 247 | internal_error (__FILE__, __LINE__, _("bad switch")); |
5a9aa5dc | 248 | } |
112e8700 SM |
249 | |
250 | m_suppress_field_separator = false; | |
fb40c209 AC |
251 | } |
252 | ||
d7e74731 PA |
253 | string_file * |
254 | mi_ui_out::main_stream () | |
255 | { | |
256 | gdb_assert (m_streams.size () == 1); | |
257 | ||
258 | return (string_file *) m_streams.back (); | |
259 | } | |
260 | ||
2b03b41d | 261 | /* Clear the buffer. */ |
fb40c209 AC |
262 | |
263 | void | |
112e8700 | 264 | mi_ui_out::rewind () |
fb40c209 | 265 | { |
d7e74731 | 266 | main_stream ()->clear (); |
fb40c209 AC |
267 | } |
268 | ||
2b03b41d | 269 | /* Dump the buffer onto the specified stream. */ |
fb40c209 | 270 | |
fb40c209 | 271 | void |
d7e74731 | 272 | mi_ui_out::put (ui_file *where) |
fb40c209 | 273 | { |
d7e74731 | 274 | string_file *mi_stream = main_stream (); |
102040f0 | 275 | |
d7e74731 PA |
276 | where->write (mi_stream->data (), mi_stream->size ()); |
277 | mi_stream->clear (); | |
fb40c209 AC |
278 | } |
279 | ||
2b03b41d | 280 | /* Return the current MI version. */ |
c7ec4050 AC |
281 | |
282 | int | |
112e8700 | 283 | mi_ui_out::version () |
c7ec4050 | 284 | { |
112e8700 | 285 | return m_mi_version; |
c7ec4050 AC |
286 | } |
287 | ||
4d6cceb4 DE |
288 | /* Constructor for an `mi_out_data' object. */ |
289 | ||
d7e74731 | 290 | mi_ui_out::mi_ui_out (int mi_version) |
13674803 SM |
291 | : ui_out (mi_version >= 3 |
292 | ? fix_multi_location_breakpoint_output : (ui_out_flag) 0), | |
293 | m_suppress_field_separator (false), | |
112e8700 SM |
294 | m_suppress_output (false), |
295 | m_mi_version (mi_version) | |
4d6cceb4 | 296 | { |
d7e74731 | 297 | string_file *stream = new string_file (); |
112e8700 SM |
298 | m_streams.push_back (stream); |
299 | } | |
4d6cceb4 | 300 | |
112e8700 SM |
301 | mi_ui_out::~mi_ui_out () |
302 | { | |
4d6cceb4 DE |
303 | } |
304 | ||
8e5e5494 | 305 | /* See mi/mi-out.h. */ |
4d6cceb4 | 306 | |
112e8700 | 307 | mi_ui_out * |
8e5e5494 | 308 | mi_out_new (const char *mi_version) |
4d6cceb4 | 309 | { |
b4be1b06 | 310 | if (streq (mi_version, INTERP_MI3) || streq (mi_version, INTERP_MI)) |
8e5e5494 SM |
311 | return new mi_ui_out (3); |
312 | ||
b4be1b06 | 313 | if (streq (mi_version, INTERP_MI2)) |
8e5e5494 SM |
314 | return new mi_ui_out (2); |
315 | ||
316 | if (streq (mi_version, INTERP_MI1)) | |
317 | return new mi_ui_out (1); | |
318 | ||
319 | return nullptr; | |
4d6cceb4 DE |
320 | } |
321 | ||
112e8700 SM |
322 | /* Helper function to return the given UIOUT as an mi_ui_out. It is an error |
323 | to call this function with an ui_out that is not an MI. */ | |
fb40c209 | 324 | |
112e8700 SM |
325 | static mi_ui_out * |
326 | as_mi_ui_out (ui_out *uiout) | |
fb40c209 | 327 | { |
112e8700 SM |
328 | mi_ui_out *mi_uiout = dynamic_cast<mi_ui_out *> (uiout); |
329 | ||
330 | gdb_assert (mi_uiout != NULL); | |
331 | ||
332 | return mi_uiout; | |
333 | } | |
4d6cceb4 | 334 | |
112e8700 SM |
335 | int |
336 | mi_version (ui_out *uiout) | |
337 | { | |
338 | return as_mi_ui_out (uiout)->version (); | |
339 | } | |
340 | ||
341 | void | |
342 | mi_out_put (ui_out *uiout, struct ui_file *stream) | |
343 | { | |
344 | return as_mi_ui_out (uiout)->put (stream); | |
345 | } | |
346 | ||
347 | void | |
348 | mi_out_rewind (ui_out *uiout) | |
349 | { | |
350 | return as_mi_ui_out (uiout)->rewind (); | |
fb40c209 | 351 | } |