Introduce field_unsigned
[deliverable/binutils-gdb.git] / gdb / mi / mi-out.c
CommitLineData
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
33void
112e8700
SM
34mi_ui_out::do_table_begin (int nr_cols, int nr_rows,
35 const char *tblid)
fb40c209 36{
112e8700
SM
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);
fb40c209
AC
41}
42
2b03b41d 43/* Mark beginning of a table body. */
fb40c209
AC
44
45void
112e8700 46mi_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
55void
112e8700 56mi_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
64void
112e8700
SM
65mi_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
SM
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);
cbe56571
TT
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);
112e8700 76 close (ui_out_type_tuple);
fb40c209
AC
77}
78
2b03b41d 79/* Mark beginning of a list. */
fb40c209
AC
80
81void
112e8700 82mi_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
89void
112e8700 90mi_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
SM
97void
98mi_ui_out::do_field_int (int fldno, int width, ui_align alignment,
99 const char *fldname, int value)
fb40c209 100{
102040f0 101 char buffer[20]; /* FIXME: how many chars long a %d can become? */
102040f0 102
08850b56 103 xsnprintf (buffer, sizeof (buffer), "%d", value);
cbe56571
TT
104 do_field_string (fldno, width, alignment, fldname, buffer,
105 ui_out_style_kind::DEFAULT);
fb40c209
AC
106}
107
1f77b012
TT
108/* Output an unsigned field. */
109
110void
111mi_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
112 const char *fldname, ULONGEST value)
113{
114 do_field_string (fldno, width, alignment, fldname, pulongest (value),
115 ui_out_style_kind::DEFAULT);
116}
117
2b03b41d 118/* Used to omit a field. */
fb40c209
AC
119
120void
112e8700
SM
121mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
122 const char *fldname)
fb40c209 123{
fb40c209
AC
124}
125
2b03b41d
SS
126/* Other specific mi_field_* end up here so alignment and field
127 separators are both handled by mi_field_string. */
fb40c209
AC
128
129void
112e8700 130mi_ui_out::do_field_string (int fldno, int width, ui_align align,
cbe56571
TT
131 const char *fldname, const char *string,
132 ui_out_style_kind style)
fb40c209 133{
112e8700
SM
134 ui_file *stream = m_streams.back ();
135 field_separator ();
102040f0 136
fb40c209 137 if (fldname)
4d6cceb4
DE
138 fprintf_unfiltered (stream, "%s=", fldname);
139 fprintf_unfiltered (stream, "\"");
fb40c209 140 if (string)
4d6cceb4
DE
141 fputstr_unfiltered (string, '"', stream);
142 fprintf_unfiltered (stream, "\"");
fb40c209
AC
143}
144
fb40c209 145void
112e8700
SM
146mi_ui_out::do_field_fmt (int fldno, int width, ui_align align,
147 const char *fldname, const char *format,
148 va_list args)
fb40c209 149{
112e8700
SM
150 ui_file *stream = m_streams.back ();
151 field_separator ();
102040f0 152
fb40c209 153 if (fldname)
4d6cceb4 154 fprintf_unfiltered (stream, "%s=\"", fldname);
fb40c209 155 else
4d6cceb4
DE
156 fputs_unfiltered ("\"", stream);
157 vfprintf_unfiltered (stream, format, args);
158 fputs_unfiltered ("\"", stream);
fb40c209
AC
159}
160
161void
112e8700 162mi_ui_out::do_spaces (int numspaces)
fb40c209
AC
163{
164}
165
166void
112e8700 167mi_ui_out::do_text (const char *string)
fb40c209
AC
168{
169}
170
171void
112e8700 172mi_ui_out::do_message (const char *format, va_list args)
fb40c209
AC
173{
174}
175
176void
112e8700 177mi_ui_out::do_wrap_hint (const char *identstring)
fb40c209
AC
178{
179 wrap_here (identstring);
180}
181
182void
112e8700 183mi_ui_out::do_flush ()
fb40c209 184{
102040f0 185
112e8700 186 gdb_flush (m_streams.back ());
fb40c209
AC
187}
188
7becfd03 189void
112e8700 190mi_ui_out::do_redirect (ui_file *outstream)
8d3788bd 191{
8d3788bd 192 if (outstream != NULL)
112e8700 193 m_streams.push_back (outstream);
4d6cceb4 194 else
112e8700 195 m_streams.pop_back ();
8d3788bd
VP
196}
197
112e8700
SM
198void
199mi_ui_out::field_separator ()
fb40c209 200{
112e8700
SM
201 if (m_suppress_field_separator)
202 m_suppress_field_separator = false;
fb40c209 203 else
112e8700 204 fputc_unfiltered (',', m_streams.back ());
fb40c209
AC
205}
206
112e8700
SM
207void
208mi_ui_out::open (const char *name, ui_out_type type)
fb40c209 209{
112e8700
SM
210 ui_file *stream = m_streams.back ();
211
212 field_separator ();
213 m_suppress_field_separator = true;
102040f0 214
d5e8ba62 215 if (name)
4d6cceb4 216 fprintf_unfiltered (stream, "%s=", name);
112e8700 217
5a9aa5dc
AC
218 switch (type)
219 {
220 case ui_out_type_tuple:
4d6cceb4 221 fputc_unfiltered ('{', stream);
5a9aa5dc 222 break;
112e8700 223
5a9aa5dc 224 case ui_out_type_list:
4d6cceb4 225 fputc_unfiltered ('[', stream);
5a9aa5dc 226 break;
112e8700 227
5a9aa5dc 228 default:
e2e0b3e5 229 internal_error (__FILE__, __LINE__, _("bad switch"));
5a9aa5dc 230 }
fb40c209
AC
231}
232
112e8700
SM
233void
234mi_ui_out::close (ui_out_type type)
fb40c209 235{
112e8700 236 ui_file *stream = m_streams.back ();
102040f0 237
5a9aa5dc
AC
238 switch (type)
239 {
240 case ui_out_type_tuple:
4d6cceb4 241 fputc_unfiltered ('}', stream);
5a9aa5dc 242 break;
112e8700 243
5a9aa5dc 244 case ui_out_type_list:
4d6cceb4 245 fputc_unfiltered (']', stream);
5a9aa5dc 246 break;
112e8700 247
5a9aa5dc 248 default:
e2e0b3e5 249 internal_error (__FILE__, __LINE__, _("bad switch"));
5a9aa5dc 250 }
112e8700
SM
251
252 m_suppress_field_separator = false;
fb40c209
AC
253}
254
d7e74731
PA
255string_file *
256mi_ui_out::main_stream ()
257{
258 gdb_assert (m_streams.size () == 1);
259
260 return (string_file *) m_streams.back ();
261}
262
2b03b41d 263/* Clear the buffer. */
fb40c209
AC
264
265void
112e8700 266mi_ui_out::rewind ()
fb40c209 267{
d7e74731 268 main_stream ()->clear ();
fb40c209
AC
269}
270
2b03b41d 271/* Dump the buffer onto the specified stream. */
fb40c209 272
fb40c209 273void
d7e74731 274mi_ui_out::put (ui_file *where)
fb40c209 275{
d7e74731 276 string_file *mi_stream = main_stream ();
102040f0 277
d7e74731
PA
278 where->write (mi_stream->data (), mi_stream->size ());
279 mi_stream->clear ();
fb40c209
AC
280}
281
2b03b41d 282/* Return the current MI version. */
c7ec4050
AC
283
284int
112e8700 285mi_ui_out::version ()
c7ec4050 286{
112e8700 287 return m_mi_version;
c7ec4050
AC
288}
289
4d6cceb4
DE
290/* Constructor for an `mi_out_data' object. */
291
d7e74731 292mi_ui_out::mi_ui_out (int mi_version)
13674803
SM
293: ui_out (mi_version >= 3
294 ? fix_multi_location_breakpoint_output : (ui_out_flag) 0),
295 m_suppress_field_separator (false),
112e8700
SM
296 m_suppress_output (false),
297 m_mi_version (mi_version)
4d6cceb4 298{
d7e74731 299 string_file *stream = new string_file ();
112e8700
SM
300 m_streams.push_back (stream);
301}
4d6cceb4 302
112e8700
SM
303mi_ui_out::~mi_ui_out ()
304{
4d6cceb4
DE
305}
306
8e5e5494 307/* See mi/mi-out.h. */
4d6cceb4 308
112e8700 309mi_ui_out *
8e5e5494 310mi_out_new (const char *mi_version)
4d6cceb4 311{
b4be1b06 312 if (streq (mi_version, INTERP_MI3) || streq (mi_version, INTERP_MI))
8e5e5494
SM
313 return new mi_ui_out (3);
314
b4be1b06 315 if (streq (mi_version, INTERP_MI2))
8e5e5494
SM
316 return new mi_ui_out (2);
317
318 if (streq (mi_version, INTERP_MI1))
319 return new mi_ui_out (1);
320
321 return nullptr;
4d6cceb4
DE
322}
323
112e8700
SM
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. */
fb40c209 326
112e8700
SM
327static mi_ui_out *
328as_mi_ui_out (ui_out *uiout)
fb40c209 329{
112e8700
SM
330 mi_ui_out *mi_uiout = dynamic_cast<mi_ui_out *> (uiout);
331
332 gdb_assert (mi_uiout != NULL);
333
334 return mi_uiout;
335}
4d6cceb4 336
112e8700
SM
337int
338mi_version (ui_out *uiout)
339{
340 return as_mi_ui_out (uiout)->version ();
341}
342
343void
344mi_out_put (ui_out *uiout, struct ui_file *stream)
345{
346 return as_mi_ui_out (uiout)->put (stream);
347}
348
349void
350mi_out_rewind (ui_out *uiout)
351{
352 return as_mi_ui_out (uiout)->rewind ();
fb40c209 353}
This page took 1.689403 seconds and 4 git commands to generate.