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