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" | |
23 | #include "ui-out.h" | |
24 | #include "mi-out.h" | |
4a9d4ea5 | 25 | #include <vector> |
fb40c209 | 26 | |
2b03b41d | 27 | /* Mark beginning of a table. */ |
fb40c209 AC |
28 | |
29 | void | |
112e8700 SM |
30 | mi_ui_out::do_table_begin (int nr_cols, int nr_rows, |
31 | const char *tblid) | |
fb40c209 | 32 | { |
112e8700 SM |
33 | open (tblid, ui_out_type_tuple); |
34 | do_field_int (-1, -1, ui_left, "nr_rows", nr_rows); | |
35 | do_field_int (-1, -1, ui_left, "nr_cols", nr_cols); | |
36 | open ("hdr", ui_out_type_list); | |
fb40c209 AC |
37 | } |
38 | ||
2b03b41d | 39 | /* Mark beginning of a table body. */ |
fb40c209 AC |
40 | |
41 | void | |
112e8700 | 42 | mi_ui_out::do_table_body () |
fb40c209 | 43 | { |
cff22675 | 44 | /* close the table header line if there were any headers */ |
112e8700 SM |
45 | close (ui_out_type_list); |
46 | open ("body", ui_out_type_list); | |
fb40c209 AC |
47 | } |
48 | ||
2b03b41d | 49 | /* Mark end of a table. */ |
fb40c209 AC |
50 | |
51 | void | |
112e8700 | 52 | mi_ui_out::do_table_end () |
fb40c209 | 53 | { |
112e8700 SM |
54 | close (ui_out_type_list); /* body */ |
55 | close (ui_out_type_tuple); | |
fb40c209 AC |
56 | } |
57 | ||
2b03b41d | 58 | /* Specify table header. */ |
fb40c209 AC |
59 | |
60 | void | |
112e8700 SM |
61 | mi_ui_out::do_table_header (int width, ui_align alignment, |
62 | const std::string &col_name, | |
63 | const std::string &col_hdr) | |
fb40c209 | 64 | { |
112e8700 SM |
65 | open (NULL, ui_out_type_tuple); |
66 | do_field_int (0, 0, ui_center, "width", width); | |
67 | do_field_int (0, 0, ui_center, "alignment", alignment); | |
cbe56571 TT |
68 | do_field_string (0, 0, ui_center, "col_name", col_name.c_str (), |
69 | ui_out_style_kind::DEFAULT); | |
70 | do_field_string (0, width, alignment, "colhdr", col_hdr.c_str (), | |
71 | ui_out_style_kind::DEFAULT); | |
112e8700 | 72 | close (ui_out_type_tuple); |
fb40c209 AC |
73 | } |
74 | ||
2b03b41d | 75 | /* Mark beginning of a list. */ |
fb40c209 AC |
76 | |
77 | void | |
112e8700 | 78 | mi_ui_out::do_begin (ui_out_type type, const char *id) |
fb40c209 | 79 | { |
112e8700 | 80 | open (id, type); |
fb40c209 AC |
81 | } |
82 | ||
2b03b41d | 83 | /* Mark end of a list. */ |
fb40c209 AC |
84 | |
85 | void | |
112e8700 | 86 | mi_ui_out::do_end (ui_out_type type) |
fb40c209 | 87 | { |
112e8700 | 88 | close (type); |
fb40c209 AC |
89 | } |
90 | ||
2b03b41d | 91 | /* Output an int field. */ |
fb40c209 | 92 | |
112e8700 SM |
93 | void |
94 | mi_ui_out::do_field_int (int fldno, int width, ui_align alignment, | |
95 | const char *fldname, int value) | |
fb40c209 | 96 | { |
102040f0 | 97 | char buffer[20]; /* FIXME: how many chars long a %d can become? */ |
102040f0 | 98 | |
08850b56 | 99 | xsnprintf (buffer, sizeof (buffer), "%d", value); |
cbe56571 TT |
100 | do_field_string (fldno, width, alignment, fldname, buffer, |
101 | ui_out_style_kind::DEFAULT); | |
fb40c209 AC |
102 | } |
103 | ||
2b03b41d | 104 | /* Used to omit a field. */ |
fb40c209 AC |
105 | |
106 | void | |
112e8700 SM |
107 | mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment, |
108 | const char *fldname) | |
fb40c209 | 109 | { |
fb40c209 AC |
110 | } |
111 | ||
2b03b41d SS |
112 | /* Other specific mi_field_* end up here so alignment and field |
113 | separators are both handled by mi_field_string. */ | |
fb40c209 AC |
114 | |
115 | void | |
112e8700 | 116 | mi_ui_out::do_field_string (int fldno, int width, ui_align align, |
cbe56571 TT |
117 | const char *fldname, const char *string, |
118 | ui_out_style_kind style) | |
fb40c209 | 119 | { |
112e8700 SM |
120 | ui_file *stream = m_streams.back (); |
121 | field_separator (); | |
102040f0 | 122 | |
fb40c209 | 123 | if (fldname) |
4d6cceb4 DE |
124 | fprintf_unfiltered (stream, "%s=", fldname); |
125 | fprintf_unfiltered (stream, "\""); | |
fb40c209 | 126 | if (string) |
4d6cceb4 DE |
127 | fputstr_unfiltered (string, '"', stream); |
128 | fprintf_unfiltered (stream, "\""); | |
fb40c209 AC |
129 | } |
130 | ||
fb40c209 | 131 | void |
112e8700 SM |
132 | mi_ui_out::do_field_fmt (int fldno, int width, ui_align align, |
133 | const char *fldname, const char *format, | |
134 | va_list args) | |
fb40c209 | 135 | { |
112e8700 SM |
136 | ui_file *stream = m_streams.back (); |
137 | field_separator (); | |
102040f0 | 138 | |
fb40c209 | 139 | if (fldname) |
4d6cceb4 | 140 | fprintf_unfiltered (stream, "%s=\"", fldname); |
fb40c209 | 141 | else |
4d6cceb4 DE |
142 | fputs_unfiltered ("\"", stream); |
143 | vfprintf_unfiltered (stream, format, args); | |
144 | fputs_unfiltered ("\"", stream); | |
fb40c209 AC |
145 | } |
146 | ||
147 | void | |
112e8700 | 148 | mi_ui_out::do_spaces (int numspaces) |
fb40c209 AC |
149 | { |
150 | } | |
151 | ||
152 | void | |
112e8700 | 153 | mi_ui_out::do_text (const char *string) |
fb40c209 AC |
154 | { |
155 | } | |
156 | ||
157 | void | |
112e8700 | 158 | mi_ui_out::do_message (const char *format, va_list args) |
fb40c209 AC |
159 | { |
160 | } | |
161 | ||
162 | void | |
112e8700 | 163 | mi_ui_out::do_wrap_hint (const char *identstring) |
fb40c209 AC |
164 | { |
165 | wrap_here (identstring); | |
166 | } | |
167 | ||
168 | void | |
112e8700 | 169 | mi_ui_out::do_flush () |
fb40c209 | 170 | { |
102040f0 | 171 | |
112e8700 | 172 | gdb_flush (m_streams.back ()); |
fb40c209 AC |
173 | } |
174 | ||
7becfd03 | 175 | void |
112e8700 | 176 | mi_ui_out::do_redirect (ui_file *outstream) |
8d3788bd | 177 | { |
8d3788bd | 178 | if (outstream != NULL) |
112e8700 | 179 | m_streams.push_back (outstream); |
4d6cceb4 | 180 | else |
112e8700 | 181 | m_streams.pop_back (); |
8d3788bd VP |
182 | } |
183 | ||
112e8700 SM |
184 | void |
185 | mi_ui_out::field_separator () | |
fb40c209 | 186 | { |
112e8700 SM |
187 | if (m_suppress_field_separator) |
188 | m_suppress_field_separator = false; | |
fb40c209 | 189 | else |
112e8700 | 190 | fputc_unfiltered (',', m_streams.back ()); |
fb40c209 AC |
191 | } |
192 | ||
112e8700 SM |
193 | void |
194 | mi_ui_out::open (const char *name, ui_out_type type) | |
fb40c209 | 195 | { |
112e8700 SM |
196 | ui_file *stream = m_streams.back (); |
197 | ||
198 | field_separator (); | |
199 | m_suppress_field_separator = true; | |
102040f0 | 200 | |
d5e8ba62 | 201 | if (name) |
4d6cceb4 | 202 | fprintf_unfiltered (stream, "%s=", name); |
112e8700 | 203 | |
5a9aa5dc AC |
204 | switch (type) |
205 | { | |
206 | case ui_out_type_tuple: | |
4d6cceb4 | 207 | fputc_unfiltered ('{', stream); |
5a9aa5dc | 208 | break; |
112e8700 | 209 | |
5a9aa5dc | 210 | case ui_out_type_list: |
4d6cceb4 | 211 | fputc_unfiltered ('[', stream); |
5a9aa5dc | 212 | break; |
112e8700 | 213 | |
5a9aa5dc | 214 | default: |
e2e0b3e5 | 215 | internal_error (__FILE__, __LINE__, _("bad switch")); |
5a9aa5dc | 216 | } |
fb40c209 AC |
217 | } |
218 | ||
112e8700 SM |
219 | void |
220 | mi_ui_out::close (ui_out_type type) | |
fb40c209 | 221 | { |
112e8700 | 222 | ui_file *stream = m_streams.back (); |
102040f0 | 223 | |
5a9aa5dc AC |
224 | switch (type) |
225 | { | |
226 | case ui_out_type_tuple: | |
4d6cceb4 | 227 | fputc_unfiltered ('}', stream); |
5a9aa5dc | 228 | break; |
112e8700 | 229 | |
5a9aa5dc | 230 | case ui_out_type_list: |
4d6cceb4 | 231 | fputc_unfiltered (']', stream); |
5a9aa5dc | 232 | break; |
112e8700 | 233 | |
5a9aa5dc | 234 | default: |
e2e0b3e5 | 235 | internal_error (__FILE__, __LINE__, _("bad switch")); |
5a9aa5dc | 236 | } |
112e8700 SM |
237 | |
238 | m_suppress_field_separator = false; | |
fb40c209 AC |
239 | } |
240 | ||
d7e74731 PA |
241 | string_file * |
242 | mi_ui_out::main_stream () | |
243 | { | |
244 | gdb_assert (m_streams.size () == 1); | |
245 | ||
246 | return (string_file *) m_streams.back (); | |
247 | } | |
248 | ||
2b03b41d | 249 | /* Clear the buffer. */ |
fb40c209 AC |
250 | |
251 | void | |
112e8700 | 252 | mi_ui_out::rewind () |
fb40c209 | 253 | { |
d7e74731 | 254 | main_stream ()->clear (); |
fb40c209 AC |
255 | } |
256 | ||
2b03b41d | 257 | /* Dump the buffer onto the specified stream. */ |
fb40c209 | 258 | |
fb40c209 | 259 | void |
d7e74731 | 260 | mi_ui_out::put (ui_file *where) |
fb40c209 | 261 | { |
d7e74731 | 262 | string_file *mi_stream = main_stream (); |
102040f0 | 263 | |
d7e74731 PA |
264 | where->write (mi_stream->data (), mi_stream->size ()); |
265 | mi_stream->clear (); | |
fb40c209 AC |
266 | } |
267 | ||
2b03b41d | 268 | /* Return the current MI version. */ |
c7ec4050 AC |
269 | |
270 | int | |
112e8700 | 271 | mi_ui_out::version () |
c7ec4050 | 272 | { |
112e8700 | 273 | return m_mi_version; |
c7ec4050 AC |
274 | } |
275 | ||
4d6cceb4 DE |
276 | /* Constructor for an `mi_out_data' object. */ |
277 | ||
d7e74731 | 278 | mi_ui_out::mi_ui_out (int mi_version) |
112e8700 SM |
279 | : m_suppress_field_separator (false), |
280 | m_suppress_output (false), | |
281 | m_mi_version (mi_version) | |
4d6cceb4 | 282 | { |
d7e74731 | 283 | string_file *stream = new string_file (); |
112e8700 SM |
284 | m_streams.push_back (stream); |
285 | } | |
4d6cceb4 | 286 | |
112e8700 SM |
287 | mi_ui_out::~mi_ui_out () |
288 | { | |
4d6cceb4 DE |
289 | } |
290 | ||
112e8700 | 291 | /* Initialize private members at startup. */ |
4d6cceb4 | 292 | |
112e8700 SM |
293 | mi_ui_out * |
294 | mi_out_new (int mi_version) | |
4d6cceb4 | 295 | { |
d7e74731 | 296 | return new mi_ui_out (mi_version); |
4d6cceb4 DE |
297 | } |
298 | ||
112e8700 SM |
299 | /* Helper function to return the given UIOUT as an mi_ui_out. It is an error |
300 | to call this function with an ui_out that is not an MI. */ | |
fb40c209 | 301 | |
112e8700 SM |
302 | static mi_ui_out * |
303 | as_mi_ui_out (ui_out *uiout) | |
fb40c209 | 304 | { |
112e8700 SM |
305 | mi_ui_out *mi_uiout = dynamic_cast<mi_ui_out *> (uiout); |
306 | ||
307 | gdb_assert (mi_uiout != NULL); | |
308 | ||
309 | return mi_uiout; | |
310 | } | |
4d6cceb4 | 311 | |
112e8700 SM |
312 | int |
313 | mi_version (ui_out *uiout) | |
314 | { | |
315 | return as_mi_ui_out (uiout)->version (); | |
316 | } | |
317 | ||
318 | void | |
319 | mi_out_put (ui_out *uiout, struct ui_file *stream) | |
320 | { | |
321 | return as_mi_ui_out (uiout)->put (stream); | |
322 | } | |
323 | ||
324 | void | |
325 | mi_out_rewind (ui_out *uiout) | |
326 | { | |
327 | return as_mi_ui_out (uiout)->rewind (); | |
fb40c209 | 328 | } |