ubsan: z8k: index 10 out of bounds for type 'unsigned int const[10]'
[deliverable/binutils-gdb.git] / gdb / mi / mi-out.c
index 3761a5c0e54e1efaa739b1d873269a074275209e..050c05c7e0653a0684e8be8d853236b4451ad4d9 100644 (file)
@@ -1,6 +1,6 @@
 /* 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
@@ -31,8 +35,8 @@ mi_ui_out::do_table_begin (int nr_cols, int nr_rows,
                           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);
 }
 
@@ -63,10 +67,12 @@ mi_ui_out::do_table_header (int width, ui_align alignment,
                            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);
 }
 
@@ -89,13 +95,21 @@ mi_ui_out::do_end (ui_out_type type)
 /* 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.  */
@@ -111,7 +125,8 @@ mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
 
 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 ();
@@ -124,12 +139,10 @@ mi_ui_out::do_field_string (int fldno, int width, ui_align align,
   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 ();
@@ -153,7 +166,8 @@ mi_ui_out::do_text (const char *string)
 }
 
 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)
 {
 }
 
@@ -170,15 +184,13 @@ mi_ui_out::do_flush ()
   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
@@ -238,23 +250,31 @@ mi_ui_out::close (ui_out_type type)
   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.  */
@@ -267,13 +287,14 @@ mi_ui_out::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);
 }
 
@@ -281,14 +302,21 @@ mi_ui_out::~mi_ui_out ()
 {
 }
 
-/* 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
This page took 0.027653 seconds and 4 git commands to generate.