]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Unify gdb putc functions
authorTom Tromey <tom@tromey.com>
Sun, 2 Jan 2022 18:42:07 +0000 (11:42 -0700)
committerTom Tromey <tom@tromey.com>
Tue, 29 Mar 2022 18:46:24 +0000 (12:46 -0600)
Now that filtered and unfiltered output can be treated identically, we
can unify the putc family of functions.  This is done under the name
"gdb_putc".  Most of this patch was written by script.

26 files changed:
gdb/arm-tdep.c
gdb/break-catch-sig.c
gdb/breakpoint.c
gdb/c-lang.c
gdb/cli-out.c
gdb/compile/compile-cplus-types.c
gdb/dwarf2/loc.c
gdb/f-valprint.c
gdb/guile/scm-ports.c
gdb/guile/scm-pretty-print.c
gdb/hppa-tdep.c
gdb/linux-fork.c
gdb/mep-tdep.c
gdb/mi/mi-console.c
gdb/mi/mi-out.c
gdb/mips-tdep.c
gdb/p-typeprint.c
gdb/remote.c
gdb/rust-lang.c
gdb/s12z-tdep.c
gdb/serial.c
gdb/target.c
gdb/ui-file.c
gdb/utils.c
gdb/utils.h
gdb/valprint.c

index 5cd5b160534614570a7acb02cb1662496d0253ac..a87affe17a8b238fa83c539852cefae3c57b48a0 100644 (file)
@@ -4024,7 +4024,7 @@ print_fpu_flags (struct ui_file *file, int flags)
     gdb_puts ("UFL ", file);
   if (flags & (1 << 4))
     gdb_puts ("INX ", file);
-  fputc_filtered ('\n', file);
+  gdb_putc ('\n', file);
 }
 
 /* Print interesting information about the floating point processor
index e268a102891bf80ccde139dd956e1ce4cf6cbb7a..b41a9083ccdcbe6163508d0e576b7ff83c06ce64 100644 (file)
@@ -296,7 +296,7 @@ signal_catchpoint_print_recreate (struct breakpoint *b, struct ui_file *fp)
     }
   else if (c->catch_all)
     fprintf_unfiltered (fp, " all");
-  fputc_unfiltered ('\n', fp);
+  gdb_putc ('\n', fp);
 }
 
 /* Implement the "explains_signal" breakpoint_ops method for signal
index ebcefdee54d107a9ffb5f5bf33f1e6504eea3221..60d343ec55a4742f3ad6fdbdaae19cb78470fb44 100644 (file)
@@ -11069,7 +11069,7 @@ clear_command (const char *arg, int from_tty)
       delete_breakpoint (iter);
     }
   if (from_tty)
-    putchar_filtered ('\n');
+    gdb_putc ('\n');
 }
 \f
 /* Delete breakpoint in BS if they are `delete' breakpoints and
index 2fd86ec101973a4648de49afe0c1e54dca1de165..014dbefb8e2029ce89aa09e2211dec1f7912b9df 100644 (file)
@@ -167,19 +167,19 @@ language_defn::printchar (int c, struct type *type,
     case C_CHAR:
       break;
     case C_WIDE_CHAR:
-      fputc_filtered ('L', stream);
+      gdb_putc ('L', stream);
       break;
     case C_CHAR_16:
-      fputc_filtered ('u', stream);
+      gdb_putc ('u', stream);
       break;
     case C_CHAR_32:
-      fputc_filtered ('U', stream);
+      gdb_putc ('U', stream);
       break;
     }
 
-  fputc_filtered ('\'', stream);
+  gdb_putc ('\'', stream);
   emitchar (c, type, stream, '\'');
-  fputc_filtered ('\'', stream);
+  gdb_putc ('\'', stream);
 }
 
 /* Print the character string STRING, printing at most LENGTH
index 0c87a820568d81e9f064b06723fb7b7395b922c5..47b256bd97ec86b91784fa99a6dcfd5fed2e8818 100644 (file)
@@ -381,9 +381,9 @@ void
 cli_ui_out::field_separator ()
 {
   if (test_flags (unfiltered_output))
-    fputc_unfiltered (' ', m_streams.back ());
+    gdb_putc (' ', m_streams.back ());
   else
-    fputc_filtered (' ', m_streams.back ());
+    gdb_putc (' ', m_streams.back ());
 }
 
 /* Constructor for cli_ui_out.  */
index 18cf7b6333819c070fe2784ddc36b6f2ea09cef2..2b1b01e8d037d0236d2342602c7dd3117e18e301 100644 (file)
@@ -1267,7 +1267,7 @@ static void
 compile_cplus_debug_output (T arg, Targs... Args)
 {
   compile_cplus_debug_output_1 (arg);
-  fputc_unfiltered (' ', gdb_stdlog);
+  gdb_putc (' ', gdb_stdlog);
   compile_cplus_debug_output (Args...);
 }
 
@@ -1277,7 +1277,7 @@ compile_cplus_debug_output (T arg, Targs... Args)
     {                                            \
       gdb_puts (": ", gdb_stdlog);               \
       compile_cplus_debug_output (R);            \
-      fputc_unfiltered ('\n', gdb_stdlog);       \
+      gdb_putc ('\n', gdb_stdlog);               \
     }                                            \
 
 #define GCC_METHOD0(R, N)                        \
index 09455e2e952c39f10af29fce45d620db426f9177..9cd21572f782a4cfa2abf2a11a57e60745897b28 100644 (file)
@@ -877,7 +877,7 @@ chain_candidate (struct gdbarch *gdbarch,
          fprintf_unfiltered (gdb_stdlog, "tailcall: initial:");
          for (idx = 0; idx < length; idx++)
            tailcall_dump (gdbarch, result->call_site[idx]);
-         fputc_unfiltered ('\n', gdb_stdlog);
+         gdb_putc ('\n', gdb_stdlog);
        }
 
       return;
@@ -888,7 +888,7 @@ chain_candidate (struct gdbarch *gdbarch,
       fprintf_unfiltered (gdb_stdlog, "tailcall: compare:");
       for (idx = 0; idx < length; idx++)
        tailcall_dump (gdbarch, chain[idx]);
-      fputc_unfiltered ('\n', gdb_stdlog);
+      gdb_putc ('\n', gdb_stdlog);
     }
 
   /* Intersect callers.  */
@@ -922,7 +922,7 @@ chain_candidate (struct gdbarch *gdbarch,
        tailcall_dump (gdbarch,
                       (*resultp)->call_site[(*resultp)->length
                                             - (*resultp)->callees + idx]);
-      fputc_unfiltered ('\n', gdb_stdlog);
+      gdb_putc ('\n', gdb_stdlog);
     }
 
   if ((*resultp)->callers == 0 && (*resultp)->callees == 0)
@@ -3655,7 +3655,7 @@ disassemble_dwarf_expression (struct ui_file *stream,
        case DW_OP_entry_value:
        case DW_OP_GNU_entry_value:
          data = safe_read_uleb128 (data, end, &ul);
-         fputc_filtered ('\n', stream);
+         gdb_putc ('\n', stream);
          disassemble_dwarf_expression (stream, arch, addr_size, offset_size,
                                        start, data, data + ul, indent + 2,
                                        all, per_cu, per_objfile);
index e56815c2813fe6aeac4df244c282574aca61fc20..e10d4718833b57521ca8ec14c6ab9931057b9cce 100644 (file)
@@ -621,7 +621,7 @@ info_common_command_for_block (const struct block *block, const char *comname,
          continue;
 
        if (*any_printed)
-         putchar_filtered ('\n');
+         gdb_putc ('\n');
        else
          *any_printed = 1;
        if (sym->print_name ())
@@ -650,7 +650,7 @@ info_common_command_for_block (const struct block *block, const char *comname,
                                except.what ());
              }
 
-           putchar_filtered ('\n');
+           gdb_putc ('\n');
          }
       }
 }
index c61ca1dafc411348c22ecce85b18e46213e1d56e..946859aa1f3e8df930969175e9dc83fe12d9451d 100644 (file)
@@ -204,7 +204,7 @@ fputsn_filtered (const char *s, size_t size, struct ui_file *stream)
       if (s[i] == '\0')
        gdb_puts ("\\000", stream);
       else
-       fputc_filtered (s[i], stream);
+       gdb_putc (s[i], stream);
     }
 }
 
index 8a5c02d0adb0fa9ad1868c3dd77e036db730bcfb..707ef4be4e48c037fcff333263865921a8935950 100644 (file)
@@ -689,7 +689,7 @@ ppscm_print_string_repr (SCM printer, enum display_hint hint,
              if (string.get ()[i] == '\0')
                gdb_puts ("\\000", stream);
              else
-               fputc_filtered (string.get ()[i], stream);
+               gdb_putc (string.get ()[i], stream);
            }
        }
       result = STRING_REPR_OK;
index cf84555a28cc75115a4b53bcd1456b7b4165182d..80cea7e732241245853a3a4dc382e2d9ca410a7d 100644 (file)
@@ -2596,7 +2596,7 @@ unwind_command (const char *exp, int from_tty)
   pif (Large_frame);
   pif (alloca_frame);
 
-  putchar_filtered ('\n');
+  gdb_putc ('\n');
 
 #define pin(FLD) printf_filtered ("\t"#FLD" = 0x%x\n", u->FLD);
 
index e7e25b5eae6e1c96a847537b4126a5686f56fced..8cea33d793f286e213ac338fa500a09977ffd3b4 100644 (file)
@@ -597,7 +597,7 @@ info_checkpoints_command (const char *arg, int from_tty)
            printf_filtered (", <%s>", msym.minsym->linkage_name ());
        }
 
-      putchar_filtered ('\n');
+      gdb_putc ('\n');
     }
   if (printed == NULL)
     {
index 11d79a0e9e74c441ae088e07392ba9e62183622e..696d9c63bce978f72107111d78a7495130a023f9 100644 (file)
@@ -2369,7 +2369,7 @@ mep_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
          const char *file_endianness
            = bfd_big_endian (info.abfd) ? "big" : "little";
          
-         fputc_unfiltered ('\n', gdb_stderr);
+         gdb_putc ('\n', gdb_stderr);
          if (module_name)
            warning (_("the MeP module '%s' is %s-endian, but the executable\n"
                       "%s is %s-endian."),
index 5043e9b475def16c803b7fd714426bbb1aa50b41..5cdb486be5e31a7b7d336d1528f0a699101a4eda 100644 (file)
@@ -79,15 +79,15 @@ mi_console_file::flush ()
       gdb_puts (m_prefix, m_raw);
       if (m_quote)
        {
-         fputc_unfiltered (m_quote, m_raw);
+         gdb_putc (m_quote, m_raw);
          m_raw->putstrn (buf, length_buf, m_quote);
-         fputc_unfiltered (m_quote, m_raw);
-         fputc_unfiltered ('\n', m_raw);
+         gdb_putc (m_quote, m_raw);
+         gdb_putc ('\n', m_raw);
        }
       else
        {
          m_raw->putstrn (buf, length_buf, 0);
-         fputc_unfiltered ('\n', m_raw);
+         gdb_putc ('\n', m_raw);
        }
       gdb_flush (m_raw);
     }
index ff93cb3ba10d72264a416db6b2712277902cf1d6..c84cc55e4c17f5ffb79ee3d6ff66bc25926d149e 100644 (file)
@@ -199,7 +199,7 @@ mi_ui_out::field_separator ()
   if (m_suppress_field_separator)
     m_suppress_field_separator = false;
   else
-    fputc_unfiltered (',', m_streams.back ());
+    gdb_putc (',', m_streams.back ());
 }
 
 void
@@ -216,11 +216,11 @@ mi_ui_out::open (const char *name, ui_out_type type)
   switch (type)
     {
     case ui_out_type_tuple:
-      fputc_unfiltered ('{', stream);
+      gdb_putc ('{', stream);
       break;
 
     case ui_out_type_list:
-      fputc_unfiltered ('[', stream);
+      gdb_putc ('[', stream);
       break;
 
     default:
@@ -236,11 +236,11 @@ mi_ui_out::close (ui_out_type type)
   switch (type)
     {
     case ui_out_type_tuple:
-      fputc_unfiltered ('}', stream);
+      gdb_putc ('}', stream);
       break;
 
     case ui_out_type_list:
-      fputc_unfiltered (']', stream);
+      gdb_putc (']', stream);
       break;
 
     default:
index d731ecc4938cd12f0e65cd20085fa7e318d65129..cedce6c1abe2308ba6283b2749f8533670e82243 100644 (file)
@@ -6423,7 +6423,7 @@ print_fpu_flags (struct ui_file *file, int flags)
     gdb_puts (" inval", file);
   if (flags & (1 << 5))
     gdb_puts (" unimp", file);
-  fputc_filtered ('\n', file);
+  gdb_putc ('\n', file);
 }
 
 /* Print interesting information about the floating point processor
@@ -6458,7 +6458,7 @@ mips_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
   for (i = 1; i <= 7; i++)
     if (fcs & (1 << (24 + i)))
       fprintf_filtered (file, " %d", i);
-  fputc_filtered ('\n', file);
+  gdb_putc ('\n', file);
 
   gdb_puts ("cause   :", file);
   print_fpu_flags (file, (fcs >> 12) & 0x3f);
@@ -6485,11 +6485,11 @@ mips_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
     gdb_puts (" zero", file);
   if ((fcs & (0xb << 21)) == 0)
     gdb_puts (" no", file);
-  fputc_filtered ('\n', file);
+  gdb_putc ('\n', file);
 
   fprintf_filtered (file, "nan2008 : %s\n", fcs & (1 << 18) ? "yes" : "no");
   fprintf_filtered (file, "abs2008 : %s\n", fcs & (1 << 19) ? "yes" : "no");
-  fputc_filtered ('\n', file);
+  gdb_putc ('\n', file);
 
   default_print_float_info (gdbarch, file, frame, args);
 }
index 98bbee97988bcc9c3310d5e389ca14cb19841562..f8bdf72cf4a7e6ee1407e0b50868f291f2a7a8ae 100644 (file)
@@ -152,7 +152,7 @@ pascal_language::type_print_method_args (const char *physname,
          physname += len;
 
          for (j = 0; j < i; ++j)
-           fputc_filtered (physname[j], stream);
+           gdb_putc (physname[j], stream);
 
          physname += i;
          if (physname[0] != 0)
index 2bad9ee1b361c4884c79627b507e1f7b890d4b25..fb09a9bbc5f02b41aa12f4adfdaabe255510c184 100644 (file)
@@ -11572,7 +11572,7 @@ remote_target::rcmd (const char *command, struct ui_file *outbuf)
        {
          char c = (fromhex (p[0]) << 4) + fromhex (p[1]);
 
-         fputc_unfiltered (c, outbuf);
+         gdb_putc (c, outbuf);
        }
       break;
     }
@@ -11629,7 +11629,7 @@ private:
       {
        gdb_byte c = buf[i];
        if (isprint (c))
-         fputc_unfiltered (c, &stb);
+         gdb_putc (c, &stb);
        else
          fprintf_unfiltered (&stb, "\\x%02x", (unsigned char) c);
       }
index 768924564490e8a317ba25e80d6bd606af5f4d13..6738243ba9bf73929a7dead66dc252ff8581ae89 100644 (file)
@@ -1608,7 +1608,7 @@ rust_language::emitchar (int ch, struct type *chtype,
   else if (ch == '\0')
     gdb_puts ("\\0", stream);
   else if (ch >= 32 && ch <= 127 && isprint (ch))
-    fputc_filtered (ch, stream);
+    gdb_putc (ch, stream);
   else if (ch <= 255)
     fprintf_filtered (stream, "\\x%02x", ch);
   else
index d13d7397057a7ef567311e02bc73b5fe846cab37..77dda56fab0b9924f4d6ee585a7b5b4f80e0e8e2 100644 (file)
@@ -523,23 +523,23 @@ s12z_print_ccw_info (struct gdbarch *gdbarch,
   const int stop_1 = 15;
   const int stop_2 = 17;
   for (int i = 0; i < stop_1 - len; ++i)
-    fputc_filtered (' ', file);
+    gdb_putc (' ', file);
   fprintf_filtered (file, "0x%04x", ccw);
   for (int i = 0; i < stop_2 - len; ++i)
-    fputc_filtered (' ', file);
+    gdb_putc (' ', file);
   for (int b = 15; b >= 0; --b)
     {
       if (ccw & (0x1u << b))
        {
          if (ccw_bits[b] == 0)
-           fputc_filtered ('1', file);
+           gdb_putc ('1', file);
          else
-           fputc_filtered (ccw_bits[b], file);
+           gdb_putc (ccw_bits[b], file);
        }
       else
-       fputc_filtered (tolower (ccw_bits[b]), file);
+       gdb_putc (tolower (ccw_bits[b]), file);
     }
-  fputc_filtered ('\n', file);
+  gdb_putc ('\n', file);
 }
 
 static void
index 347ab2e098f580a36a48a687438838ebcbab46b3..1508c5de2c3b581ae0a13c0d95b333efadd702a8 100644 (file)
@@ -70,7 +70,7 @@ serial_logchar (struct ui_file *stream, int ch_type, int ch, int timeout)
     }
 
   if (serial_logbase != logbase_ascii)
-    fputc_unfiltered (' ', stream);
+    gdb_putc (' ', stream);
 
   switch (ch)
     {
index 0a4f892a9ee67c973c5a20458056e5041f798d3c..8216ee930b9cb12350e73e96f638a3349b962226 100644 (file)
@@ -1786,7 +1786,7 @@ target_xfer_partial (struct target_ops *ops,
            }
        }
 
-      fputc_unfiltered ('\n', gdb_stdlog);
+      gdb_putc ('\n', gdb_stdlog);
     }
 
   /* Check implementations of to_xfer_partial update *XFERED_LEN
index ec441a73a8c82f6791cea790496b3b0875108f25..afb12b408f5f154eb71ca872971e84bf2f484ebd 100644 (file)
@@ -63,7 +63,9 @@ ui_file::putstrn (const char *str, int n, int quoter, bool async_safe)
 int
 ui_file::putc (int c)
 {
-  return fputc_unfiltered (c, this);
+  char copy = (char) c;
+  write (&copy, 1);
+  return c;
 }
 
 void
index 2124b4bdfc34b70d6a97234b10bed1db81fd1e89..21fb7d6e9b1a8d9fc098d3006cec123e71fd6027 100644 (file)
@@ -1765,7 +1765,7 @@ fputs_highlighted (const char *str, const compiled_regex &highlight,
       /* Output the part before pmatch with current style.  */
       while (pmatch.rm_so > 0)
        {
-         fputc_filtered (*str, stream);
+         gdb_putc (*str, stream);
          pmatch.rm_so--;
          str++;
        }
@@ -1774,7 +1774,7 @@ fputs_highlighted (const char *str, const compiled_regex &highlight,
       stream->emit_style_escape (highlight_style.style ());
       while (n_highlight > 0)
        {
-         fputc_filtered (*str, stream);
+         gdb_putc (*str, stream);
          n_highlight--;
          str++;
        }
@@ -1790,31 +1790,15 @@ fputs_highlighted (const char *str, const compiled_regex &highlight,
    May return nonlocally.  */
 
 int
-putchar_filtered (int c)
+gdb_putc (int c)
 {
-  return fputc_filtered (c, gdb_stdout);
+  return gdb_stdout->putc (c);
 }
 
 int
-fputc_unfiltered (int c, struct ui_file *stream)
+gdb_putc (int c, struct ui_file *stream)
 {
-  char buf[2];
-
-  buf[0] = c;
-  buf[1] = 0;
-  gdb_puts (buf, stream);
-  return c;
-}
-
-int
-fputc_filtered (int c, struct ui_file *stream)
-{
-  char buf[2];
-
-  buf[0] = c;
-  buf[1] = 0;
-  gdb_puts (buf, stream);
-  return c;
+  return stream->putc (c);
 }
 
 void
index dc76da468c31a753139063ba08759d0fd022110a..26c35bc545155bb9b862a937901e19462cae5884 100644 (file)
@@ -235,11 +235,9 @@ extern void set_screen_width_and_height (int width, int height);
 
 extern void gdb_puts (const char *, struct ui_file *);
 
-extern int fputc_filtered (int c, struct ui_file *);
+extern int gdb_putc (int c, struct ui_file *);
 
-extern int fputc_unfiltered (int c, struct ui_file *);
-
-extern int putchar_filtered (int c);
+extern int gdb_putc (int c);
 
 extern void gdb_puts (const char *);
 
index 43ba08d5ef23cf88edabd44dfb42bd94268db2c6..3a07c98ceb48e6a47195826cfd72dc18f6f2db39 100644 (file)
@@ -1389,7 +1389,7 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
                b = '0';
 
              if (zero_pad || seen_a_one || b == '1')
-               fputc_filtered (b, stream);
+               gdb_putc (b, stream);
              if (b == '1')
                seen_a_one = true;
            }
@@ -1409,7 +1409,7 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
                b = '0';
 
              if (zero_pad || seen_a_one || b == '1')
-               fputc_filtered (b, stream);
+               gdb_putc (b, stream);
              if (b == '1')
                seen_a_one = true;
            }
@@ -1419,7 +1419,7 @@ print_binary_chars (struct ui_file *stream, const gdb_byte *valaddr,
   /* When not zero-padding, ensure that something is printed when the
      input is 0.  */
   if (!zero_pad && !seen_a_one)
-    fputc_filtered ('0', stream);
+    gdb_putc ('0', stream);
 }
 
 /* A helper for print_octal_chars that emits a single octal digit,