arm, objdump: print obsolote warning when 26-bit set in instructions
[binutils-gdb.git] / gdb / mi / mi-out.c
blob9ad26e76a30f505de7ce0abf1c9368654b950c7a
1 /* MI Command Set - output generating routines.
3 Copyright (C) 2000-2024 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/>. */
22 #include "mi-out.h"
24 #include <vector>
26 #include "interps.h"
27 #include "ui-out.h"
28 #include "utils.h"
29 #include "gdbsupport/gdb-checked-static-cast.h"
31 /* Mark beginning of a table. */
33 void
34 mi_ui_out::do_table_begin (int nr_cols, int nr_rows,
35 const char *tblid)
37 open (tblid, ui_out_type_tuple);
38 do_field_signed (-1, -1, ui_left, "nr_rows", nr_rows, ui_file_style ());
39 do_field_signed (-1, -1, ui_left, "nr_cols", nr_cols, ui_file_style ());
40 open ("hdr", ui_out_type_list);
43 /* Mark beginning of a table body. */
45 void
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. */
55 void
56 mi_ui_out::do_table_end ()
58 close (ui_out_type_list); /* body */
59 close (ui_out_type_tuple);
62 /* Specify table header. */
64 void
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_signed (0, 0, ui_center, "width", width, ui_file_style ());
71 do_field_signed (0, 0, ui_center, "alignment", alignment, ui_file_style ());
72 do_field_string (0, 0, ui_center, "col_name", col_name.c_str (),
73 ui_file_style ());
74 do_field_string (0, width, alignment, "colhdr", col_hdr.c_str (),
75 ui_file_style ());
76 close (ui_out_type_tuple);
79 /* Mark beginning of a list. */
81 void
82 mi_ui_out::do_begin (ui_out_type type, const char *id)
84 open (id, type);
87 /* Mark end of a list. */
89 void
90 mi_ui_out::do_end (ui_out_type type)
92 close (type);
95 /* Output an int field. */
97 void
98 mi_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
99 const char *fldname, LONGEST value,
100 const ui_file_style &style)
102 do_field_string (fldno, width, alignment, fldname, plongest (value),
103 style);
106 /* Output an unsigned field. */
108 void
109 mi_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
110 const char *fldname, ULONGEST value)
112 do_field_string (fldno, width, alignment, fldname, pulongest (value),
113 ui_file_style ());
116 /* Used to omit a field. */
118 void
119 mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
120 const char *fldname)
124 /* Other specific mi_field_* end up here so alignment and field
125 separators are both handled by mi_field_string. */
127 void
128 mi_ui_out::do_field_string (int fldno, int width, ui_align align,
129 const char *fldname, const char *string,
130 const ui_file_style &style)
132 ui_file *stream = m_streams.back ();
133 field_separator ();
135 if (fldname)
136 gdb_printf (stream, "%s=", fldname);
137 gdb_printf (stream, "\"");
138 if (string)
139 stream->putstr (string, '"');
140 gdb_printf (stream, "\"");
143 void
144 mi_ui_out::do_field_fmt (int fldno, int width, ui_align align,
145 const char *fldname, const ui_file_style &style,
146 const char *format, va_list args)
148 ui_file *stream = m_streams.back ();
149 field_separator ();
151 if (fldname)
152 gdb_printf (stream, "%s=\"", fldname);
153 else
154 gdb_puts ("\"", stream);
155 gdb_vprintf (stream, format, args);
156 gdb_puts ("\"", stream);
159 void
160 mi_ui_out::do_spaces (int numspaces)
164 void
165 mi_ui_out::do_text (const char *string)
169 void
170 mi_ui_out::do_message (const ui_file_style &style,
171 const char *format, va_list args)
175 void
176 mi_ui_out::do_wrap_hint (int indent)
178 m_streams.back ()->wrap_here (indent);
181 void
182 mi_ui_out::do_flush ()
185 gdb_flush (m_streams.back ());
188 void
189 mi_ui_out::do_redirect (ui_file *outstream)
191 if (outstream != NULL)
192 m_streams.push_back (outstream);
193 else
194 m_streams.pop_back ();
197 void
198 mi_ui_out::field_separator ()
200 if (m_suppress_field_separator)
201 m_suppress_field_separator = false;
202 else
203 gdb_putc (',', m_streams.back ());
206 void
207 mi_ui_out::open (const char *name, ui_out_type type)
209 ui_file *stream = m_streams.back ();
211 field_separator ();
212 m_suppress_field_separator = true;
214 if (name)
215 gdb_printf (stream, "%s=", name);
217 switch (type)
219 case ui_out_type_tuple:
220 gdb_putc ('{', stream);
221 break;
223 case ui_out_type_list:
224 gdb_putc ('[', stream);
225 break;
227 default:
228 internal_error (_("bad switch"));
232 void
233 mi_ui_out::close (ui_out_type type)
235 ui_file *stream = m_streams.back ();
237 switch (type)
239 case ui_out_type_tuple:
240 gdb_putc ('}', stream);
241 break;
243 case ui_out_type_list:
244 gdb_putc (']', stream);
245 break;
247 default:
248 internal_error (_("bad switch"));
251 m_suppress_field_separator = false;
254 string_file *
255 mi_ui_out::main_stream ()
257 gdb_assert (m_streams.size () == 1);
259 return (string_file *) m_streams.back ();
262 /* Initialize a progress update to be displayed with
263 mi_ui_out::do_progress_notify. */
265 void
266 mi_ui_out::do_progress_start ()
268 m_progress_info.emplace_back ();
271 /* Indicate that a task described by MSG is in progress. */
273 void
274 mi_ui_out::do_progress_notify (const std::string &msg, const char *unit,
275 double cur, double total)
277 mi_progress_info &info (m_progress_info.back ());
279 if (info.state == progress_update::START)
281 gdb_printf ("%s...\n", msg.c_str ());
282 info.state = progress_update::WORKING;
286 /* Remove the most recent progress update from the progress_info stack. */
288 void
289 mi_ui_out::do_progress_end ()
291 m_progress_info.pop_back ();
294 /* Clear the buffer. */
296 void
297 mi_ui_out::rewind ()
299 main_stream ()->clear ();
302 /* Dump the buffer onto the specified stream. */
304 void
305 mi_ui_out::put (ui_file *where)
307 string_file *mi_stream = main_stream ();
309 where->write (mi_stream->data (), mi_stream->size ());
310 mi_stream->clear ();
313 /* Return the current MI version. */
316 mi_ui_out::version ()
318 return m_mi_version;
321 /* Constructor for an `mi_out_data' object. */
323 mi_ui_out::mi_ui_out (int mi_version)
324 : ui_out (make_flags (mi_version)),
325 m_suppress_field_separator (false),
326 m_suppress_output (false),
327 m_mi_version (mi_version)
329 string_file *stream = new string_file ();
330 m_streams.push_back (stream);
333 mi_ui_out::~mi_ui_out ()
337 /* See mi/mi-out.h. */
339 std::unique_ptr<mi_ui_out>
340 mi_out_new (const char *mi_version)
342 if (streq (mi_version, INTERP_MI4) || streq (mi_version, INTERP_MI))
343 return std::make_unique<mi_ui_out> (4);
345 if (streq (mi_version, INTERP_MI3))
346 return std::make_unique<mi_ui_out> (3);
348 if (streq (mi_version, INTERP_MI2))
349 return std::make_unique<mi_ui_out> (2);
351 return nullptr;
354 /* Helper function to return the given UIOUT as an mi_ui_out. It is an error
355 to call this function with an ui_out that is not an MI. */
357 static mi_ui_out *
358 as_mi_ui_out (ui_out *uiout)
360 return gdb::checked_static_cast<mi_ui_out *> (uiout);
363 void
364 mi_out_put (ui_out *uiout, struct ui_file *stream)
366 return as_mi_ui_out (uiout)->put (stream);
369 void
370 mi_out_rewind (ui_out *uiout)
372 return as_mi_ui_out (uiout)->rewind ();