1 /* MI Command Set - output generating routines.
3 Copyright (C) 2000-2019 Free Software Foundation, Inc.
5 Contributed by Cygnus Solutions (a Red Hat company).
7 This file is part of GDB.
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
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 /* Mark beginning of a table. */
34 mi_ui_out::do_table_begin (int nr_cols
, int nr_rows
,
37 open (tblid
, ui_out_type_tuple
);
38 do_field_int (-1, -1, ui_left
, "nr_rows", nr_rows
);
39 do_field_int (-1, -1, ui_left
, "nr_cols", nr_cols
);
40 open ("hdr", ui_out_type_list
);
43 /* Mark beginning of a table body. */
46 mi_ui_out::do_table_body ()
48 /* close the table header line if there were any headers */
49 close (ui_out_type_list
);
50 open ("body", ui_out_type_list
);
53 /* Mark end of a table. */
56 mi_ui_out::do_table_end ()
58 close (ui_out_type_list
); /* body */
59 close (ui_out_type_tuple
);
62 /* Specify table header. */
65 mi_ui_out::do_table_header (int width
, ui_align alignment
,
66 const std::string
&col_name
,
67 const std::string
&col_hdr
)
69 open (NULL
, ui_out_type_tuple
);
70 do_field_int (0, 0, ui_center
, "width", width
);
71 do_field_int (0, 0, ui_center
, "alignment", alignment
);
72 do_field_string (0, 0, ui_center
, "col_name", col_name
.c_str (),
73 ui_out_style_kind::DEFAULT
);
74 do_field_string (0, width
, alignment
, "colhdr", col_hdr
.c_str (),
75 ui_out_style_kind::DEFAULT
);
76 close (ui_out_type_tuple
);
79 /* Mark beginning of a list. */
82 mi_ui_out::do_begin (ui_out_type type
, const char *id
)
87 /* Mark end of a list. */
90 mi_ui_out::do_end (ui_out_type type
)
95 /* Output an int field. */
98 mi_ui_out::do_field_int (int fldno
, int width
, ui_align alignment
,
99 const char *fldname
, int value
)
101 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
103 xsnprintf (buffer
, sizeof (buffer
), "%d", value
);
104 do_field_string (fldno
, width
, alignment
, fldname
, buffer
,
105 ui_out_style_kind::DEFAULT
);
108 /* Output an unsigned field. */
111 mi_ui_out::do_field_unsigned (int fldno
, int width
, ui_align alignment
,
112 const char *fldname
, ULONGEST value
)
114 do_field_string (fldno
, width
, alignment
, fldname
, pulongest (value
),
115 ui_out_style_kind::DEFAULT
);
118 /* Used to omit a field. */
121 mi_ui_out::do_field_skip (int fldno
, int width
, ui_align alignment
,
126 /* Other specific mi_field_* end up here so alignment and field
127 separators are both handled by mi_field_string. */
130 mi_ui_out::do_field_string (int fldno
, int width
, ui_align align
,
131 const char *fldname
, const char *string
,
132 ui_out_style_kind style
)
134 ui_file
*stream
= m_streams
.back ();
138 fprintf_unfiltered (stream
, "%s=", fldname
);
139 fprintf_unfiltered (stream
, "\"");
141 fputstr_unfiltered (string
, '"', stream
);
142 fprintf_unfiltered (stream
, "\"");
146 mi_ui_out::do_field_fmt (int fldno
, int width
, ui_align align
,
147 const char *fldname
, const char *format
,
150 ui_file
*stream
= m_streams
.back ();
154 fprintf_unfiltered (stream
, "%s=\"", fldname
);
156 fputs_unfiltered ("\"", stream
);
157 vfprintf_unfiltered (stream
, format
, args
);
158 fputs_unfiltered ("\"", stream
);
162 mi_ui_out::do_spaces (int numspaces
)
167 mi_ui_out::do_text (const char *string
)
172 mi_ui_out::do_message (const char *format
, va_list args
)
177 mi_ui_out::do_wrap_hint (const char *identstring
)
179 wrap_here (identstring
);
183 mi_ui_out::do_flush ()
186 gdb_flush (m_streams
.back ());
190 mi_ui_out::do_redirect (ui_file
*outstream
)
192 if (outstream
!= NULL
)
193 m_streams
.push_back (outstream
);
195 m_streams
.pop_back ();
199 mi_ui_out::field_separator ()
201 if (m_suppress_field_separator
)
202 m_suppress_field_separator
= false;
204 fputc_unfiltered (',', m_streams
.back ());
208 mi_ui_out::open (const char *name
, ui_out_type type
)
210 ui_file
*stream
= m_streams
.back ();
213 m_suppress_field_separator
= true;
216 fprintf_unfiltered (stream
, "%s=", name
);
220 case ui_out_type_tuple
:
221 fputc_unfiltered ('{', stream
);
224 case ui_out_type_list
:
225 fputc_unfiltered ('[', stream
);
229 internal_error (__FILE__
, __LINE__
, _("bad switch"));
234 mi_ui_out::close (ui_out_type type
)
236 ui_file
*stream
= m_streams
.back ();
240 case ui_out_type_tuple
:
241 fputc_unfiltered ('}', stream
);
244 case ui_out_type_list
:
245 fputc_unfiltered (']', stream
);
249 internal_error (__FILE__
, __LINE__
, _("bad switch"));
252 m_suppress_field_separator
= false;
256 mi_ui_out::main_stream ()
258 gdb_assert (m_streams
.size () == 1);
260 return (string_file
*) m_streams
.back ();
263 /* Clear the buffer. */
268 main_stream ()->clear ();
271 /* Dump the buffer onto the specified stream. */
274 mi_ui_out::put (ui_file
*where
)
276 string_file
*mi_stream
= main_stream ();
278 where
->write (mi_stream
->data (), mi_stream
->size ());
282 /* Return the current MI version. */
285 mi_ui_out::version ()
290 /* Constructor for an `mi_out_data' object. */
292 mi_ui_out::mi_ui_out (int mi_version
)
293 : ui_out (mi_version
>= 3
294 ? fix_multi_location_breakpoint_output
: (ui_out_flag
) 0),
295 m_suppress_field_separator (false),
296 m_suppress_output (false),
297 m_mi_version (mi_version
)
299 string_file
*stream
= new string_file ();
300 m_streams
.push_back (stream
);
303 mi_ui_out::~mi_ui_out ()
307 /* See mi/mi-out.h. */
310 mi_out_new (const char *mi_version
)
312 if (streq (mi_version
, INTERP_MI3
) || streq (mi_version
, INTERP_MI
))
313 return new mi_ui_out (3);
315 if (streq (mi_version
, INTERP_MI2
))
316 return new mi_ui_out (2);
318 if (streq (mi_version
, INTERP_MI1
))
319 return new mi_ui_out (1);
324 /* Helper function to return the given UIOUT as an mi_ui_out. It is an error
325 to call this function with an ui_out that is not an MI. */
328 as_mi_ui_out (ui_out
*uiout
)
330 mi_ui_out
*mi_uiout
= dynamic_cast<mi_ui_out
*> (uiout
);
332 gdb_assert (mi_uiout
!= NULL
);
338 mi_version (ui_out
*uiout
)
340 return as_mi_ui_out (uiout
)->version ();
344 mi_out_put (ui_out
*uiout
, struct ui_file
*stream
)
346 return as_mi_ui_out (uiout
)->put (stream
);
350 mi_out_rewind (ui_out
*uiout
)
352 return as_mi_ui_out (uiout
)->rewind ();