1 /* MI Command Set - output generating routines.
3 Copyright (C) 2000-2016 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/>. */
27 /* Mark beginning of a table. */
30 mi_ui_out::do_table_begin (int nr_cols
, int nr_rows
,
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
);
39 /* Mark beginning of a table body. */
42 mi_ui_out::do_table_body ()
44 /* close the table header line if there were any headers */
45 close (ui_out_type_list
);
46 open ("body", ui_out_type_list
);
49 /* Mark end of a table. */
52 mi_ui_out::do_table_end ()
54 close (ui_out_type_list
); /* body */
55 close (ui_out_type_tuple
);
58 /* Specify table header. */
61 mi_ui_out::do_table_header (int width
, ui_align alignment
,
62 const std::string
&col_name
,
63 const std::string
&col_hdr
)
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
);
73 /* Mark beginning of a list. */
76 mi_ui_out::do_begin (ui_out_type type
, const char *id
)
81 /* Mark end of a list. */
84 mi_ui_out::do_end (ui_out_type type
)
89 /* Output an int field. */
92 mi_ui_out::do_field_int (int fldno
, int width
, ui_align alignment
,
93 const char *fldname
, int value
)
95 char buffer
[20]; /* FIXME: how many chars long a %d can become? */
97 xsnprintf (buffer
, sizeof (buffer
), "%d", value
);
98 do_field_string (fldno
, width
, alignment
, fldname
, buffer
);
101 /* Used to omit a field. */
104 mi_ui_out::do_field_skip (int fldno
, int width
, ui_align alignment
,
109 /* Other specific mi_field_* end up here so alignment and field
110 separators are both handled by mi_field_string. */
113 mi_ui_out::do_field_string (int fldno
, int width
, ui_align align
,
114 const char *fldname
, const char *string
)
116 ui_file
*stream
= m_streams
.back ();
120 fprintf_unfiltered (stream
, "%s=", fldname
);
121 fprintf_unfiltered (stream
, "\"");
123 fputstr_unfiltered (string
, '"', stream
);
124 fprintf_unfiltered (stream
, "\"");
127 /* This is the only field function that does not align. */
130 mi_ui_out::do_field_fmt (int fldno
, int width
, ui_align align
,
131 const char *fldname
, const char *format
,
134 ui_file
*stream
= m_streams
.back ();
138 fprintf_unfiltered (stream
, "%s=\"", fldname
);
140 fputs_unfiltered ("\"", stream
);
141 vfprintf_unfiltered (stream
, format
, args
);
142 fputs_unfiltered ("\"", stream
);
146 mi_ui_out::do_spaces (int numspaces
)
151 mi_ui_out::do_text (const char *string
)
156 mi_ui_out::do_message (const char *format
, va_list args
)
161 mi_ui_out::do_wrap_hint (const char *identstring
)
163 wrap_here (identstring
);
167 mi_ui_out::do_flush ()
170 gdb_flush (m_streams
.back ());
174 mi_ui_out::do_redirect (ui_file
*outstream
)
176 if (outstream
!= NULL
)
177 m_streams
.push_back (outstream
);
179 m_streams
.pop_back ();
185 mi_ui_out::field_separator ()
187 if (m_suppress_field_separator
)
188 m_suppress_field_separator
= false;
190 fputc_unfiltered (',', m_streams
.back ());
194 mi_ui_out::open (const char *name
, ui_out_type type
)
196 ui_file
*stream
= m_streams
.back ();
199 m_suppress_field_separator
= true;
202 fprintf_unfiltered (stream
, "%s=", name
);
206 case ui_out_type_tuple
:
207 fputc_unfiltered ('{', stream
);
210 case ui_out_type_list
:
211 fputc_unfiltered ('[', stream
);
215 internal_error (__FILE__
, __LINE__
, _("bad switch"));
220 mi_ui_out::close (ui_out_type type
)
222 ui_file
*stream
= m_streams
.back ();
226 case ui_out_type_tuple
:
227 fputc_unfiltered ('}', stream
);
230 case ui_out_type_list
:
231 fputc_unfiltered (']', stream
);
235 internal_error (__FILE__
, __LINE__
, _("bad switch"));
238 m_suppress_field_separator
= false;
241 /* Clear the buffer. */
246 ui_file_rewind (m_streams
.back ());
249 /* Dump the buffer onto the specified stream. */
252 mi_ui_out::put (ui_file
*stream
)
254 ui_file
*outstream
= m_streams
.back ();
256 ui_file_put (outstream
, ui_file_write_for_put
, stream
);
257 ui_file_rewind (outstream
);
260 /* Return the current MI version. */
263 mi_ui_out::version ()
268 /* Constructor for an `mi_out_data' object. */
270 mi_ui_out::mi_ui_out (int mi_version
, ui_file
*stream
)
271 : m_suppress_field_separator (false),
272 m_suppress_output (false),
273 m_mi_version (mi_version
)
275 gdb_assert (stream
!= NULL
);
277 m_streams
.push_back (stream
);
280 mi_ui_out::~mi_ui_out ()
284 /* Initialize private members at startup. */
287 mi_out_new (int mi_version
)
289 ui_file
*stream
= mem_fileopen ();
291 return new mi_ui_out (mi_version
, stream
);
294 /* Helper function to return the given UIOUT as an mi_ui_out. It is an error
295 to call this function with an ui_out that is not an MI. */
298 as_mi_ui_out (ui_out
*uiout
)
300 mi_ui_out
*mi_uiout
= dynamic_cast<mi_ui_out
*> (uiout
);
302 gdb_assert (mi_uiout
!= NULL
);
308 mi_version (ui_out
*uiout
)
310 return as_mi_ui_out (uiout
)->version ();
314 mi_out_put (ui_out
*uiout
, struct ui_file
*stream
)
316 return as_mi_ui_out (uiout
)->put (stream
);
320 mi_out_rewind (ui_out
*uiout
)
322 return as_mi_ui_out (uiout
)->rewind ();