/* MI Command Set - output generating routines.
- Copyright (C) 2000-2016 Free Software Foundation, Inc.
+ Copyright (C) 2000-2020 Free Software Foundation, Inc.
Contributed by Cygnus Solutions (a Red Hat company).
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
-#include "ui-out.h"
#include "mi-out.h"
+
#include <vector>
+#include "interps.h"
+#include "ui-out.h"
+#include "utils.h"
+
/* Mark beginning of a table. */
void
const char *tblid)
{
open (tblid, ui_out_type_tuple);
- do_field_int (-1, -1, ui_left, "nr_rows", nr_rows);
- do_field_int (-1, -1, ui_left, "nr_cols", nr_cols);
+ do_field_signed (-1, -1, ui_left, "nr_rows", nr_rows);
+ do_field_signed (-1, -1, ui_left, "nr_cols", nr_cols);
open ("hdr", ui_out_type_list);
}
const std::string &col_hdr)
{
open (NULL, ui_out_type_tuple);
- do_field_int (0, 0, ui_center, "width", width);
- do_field_int (0, 0, ui_center, "alignment", alignment);
- do_field_string (0, 0, ui_center, "col_name", col_name.c_str ());
- do_field_string (0, width, alignment, "colhdr", col_hdr.c_str ());
+ do_field_signed (0, 0, ui_center, "width", width);
+ do_field_signed (0, 0, ui_center, "alignment", alignment);
+ do_field_string (0, 0, ui_center, "col_name", col_name.c_str (),
+ ui_file_style ());
+ do_field_string (0, width, alignment, "colhdr", col_hdr.c_str (),
+ ui_file_style ());
close (ui_out_type_tuple);
}
/* Output an int field. */
void
-mi_ui_out::do_field_int (int fldno, int width, ui_align alignment,
- const char *fldname, int value)
+mi_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
+ const char *fldname, LONGEST value)
{
- char buffer[20]; /* FIXME: how many chars long a %d can become? */
+ do_field_string (fldno, width, alignment, fldname, plongest (value),
+ ui_file_style ());
+}
- xsnprintf (buffer, sizeof (buffer), "%d", value);
- do_field_string (fldno, width, alignment, fldname, buffer);
+/* Output an unsigned field. */
+
+void
+mi_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
+ const char *fldname, ULONGEST value)
+{
+ do_field_string (fldno, width, alignment, fldname, pulongest (value),
+ ui_file_style ());
}
/* Used to omit a field. */
void
mi_ui_out::do_field_string (int fldno, int width, ui_align align,
- const char *fldname, const char *string)
+ const char *fldname, const char *string,
+ const ui_file_style &style)
{
ui_file *stream = m_streams.back ();
field_separator ();
fprintf_unfiltered (stream, "\"");
}
-/* This is the only field function that does not align. */
-
void
mi_ui_out::do_field_fmt (int fldno, int width, ui_align align,
- const char *fldname, const char *format,
- va_list args)
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
{
ui_file *stream = m_streams.back ();
field_separator ();
}
void
-mi_ui_out::do_message (const char *format, va_list args)
+mi_ui_out::do_message (const ui_file_style &style,
+ const char *format, va_list args)
{
}
gdb_flush (m_streams.back ());
}
-int
+void
mi_ui_out::do_redirect (ui_file *outstream)
{
if (outstream != NULL)
m_streams.push_back (outstream);
else
m_streams.pop_back ();
-
- return 0;
}
void
m_suppress_field_separator = false;
}
+string_file *
+mi_ui_out::main_stream ()
+{
+ gdb_assert (m_streams.size () == 1);
+
+ return (string_file *) m_streams.back ();
+}
+
/* Clear the buffer. */
void
mi_ui_out::rewind ()
{
- ui_file_rewind (m_streams.back ());
+ main_stream ()->clear ();
}
/* Dump the buffer onto the specified stream. */
void
-mi_ui_out::put (ui_file *stream)
+mi_ui_out::put (ui_file *where)
{
- ui_file *outstream = m_streams.back ();
+ string_file *mi_stream = main_stream ();
- ui_file_put (outstream, ui_file_write_for_put, stream);
- ui_file_rewind (outstream);
+ where->write (mi_stream->data (), mi_stream->size ());
+ mi_stream->clear ();
}
/* Return the current MI version. */
/* Constructor for an `mi_out_data' object. */
-mi_ui_out::mi_ui_out (int mi_version, ui_file *stream)
-: m_suppress_field_separator (false),
+mi_ui_out::mi_ui_out (int mi_version)
+: ui_out (mi_version >= 3
+ ? fix_multi_location_breakpoint_output : (ui_out_flag) 0),
+ m_suppress_field_separator (false),
m_suppress_output (false),
m_mi_version (mi_version)
{
- gdb_assert (stream != NULL);
-
+ string_file *stream = new string_file ();
m_streams.push_back (stream);
}
{
}
-/* Initialize private members at startup. */
+/* See mi/mi-out.h. */
mi_ui_out *
-mi_out_new (int mi_version)
+mi_out_new (const char *mi_version)
{
- ui_file *stream = mem_fileopen ();
+ if (streq (mi_version, INTERP_MI3) || streq (mi_version, INTERP_MI))
+ return new mi_ui_out (3);
+
+ if (streq (mi_version, INTERP_MI2))
+ return new mi_ui_out (2);
+
+ if (streq (mi_version, INTERP_MI1))
+ return new mi_ui_out (1);
- return new mi_ui_out (mi_version, stream);
+ return nullptr;
}
/* Helper function to return the given UIOUT as an mi_ui_out. It is an error