]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove excess calls to gdb_flush
authorTom Tromey <tromey@adacore.com>
Tue, 19 Feb 2019 20:36:17 +0000 (13:36 -0700)
committerTom Tromey <tromey@adacore.com>
Tue, 5 Mar 2019 15:55:51 +0000 (08:55 -0700)
A customer noticed some mildly odd MI output, where CLI output was
split into multiple MI strings at unusual boundaries, like this:

    ~"$1 = (b => true"
    ~", p => 0x407260"

This is technically correct according to the MI spec, but still
unusual, in that there's no particular reason for the string to be
split where it is.

I tracked this down to a call to gdb_flush in generic_val_print.
Then, I went through all calls to gdb_flush and removed the ones I
thought were superfluous.  In particular:

* Any call in the value-printing code;
* Likewise the type-printing code (just a single call); and
* Any call that immediately followed a printf that obviously
  ended with a newline, my belief being that gdb's standard output
  streams are line buffered (by inheriting the behavior from stdio)

Regression tested on x86-64 Fedora 29.

I didn't add a new test case.  I tend to think we don't necessarily
want to specify this behavior in the tests.  Let me know what you
think of this.

gdb/ChangeLog
2019-03-05  Tom Tromey  <tromey@adacore.com>

* windows-nat.c (windows_nat_target::attach)
(windows_nat_target::detach): Don't call gdb_flush.
* valprint.c (generic_val_print, val_print, val_print_string):
Don't call gdb_flush.
* utils.c (defaulted_query): Don't call gdb_flush.
* typeprint.c (print_type_scalar): Don't call gdb_flush.
* target.c (target_announce_detach): Don't call gdb_flush.
* sparc64-tdep.c (adi_print_versions): Don't call gdb_flush.
* remote.c (extended_remote_target::attach): Don't call
gdb_flush.
* procfs.c (procfs_target::detach): Don't call gdb_flush.
* printcmd.c (do_examine): Don't call gdb_flush.
(info_display_command): Don't call gdb_flush.
* p-valprint.c (pascal_val_print): Don't call gdb_flush.
* nto-procfs.c (nto_procfs_target::attach): Don't call gdb_flush.
* memattr.c (info_mem_command): Don't call gdb_flush.
* mdebugread.c (mdebug_build_psymtabs): Don't call gdb_flush.
* m2-valprint.c (m2_val_print): Don't call gdb_flush.
* infrun.c (follow_exec, handle_command): Don't call gdb_flush.
* inf-ptrace.c (inf_ptrace_target::attach): Don't call gdb_flush.
* hppa-tdep.c (unwind_command): Don't call gdb_flush.
* gnu-nat.c (gnu_nat_target::attach): Don't call gdb_flush.
(gnu_nat_target::detach): Don't call gdb_flush.
* f-valprint.c (f_val_print): Don't call gdb_flush.
* darwin-nat.c (darwin_nat_target::attach): Don't call gdb_flush.
* cli/cli-script.c (read_command_lines): Don't call gdb_flush.
* cli/cli-cmds.c (shell_escape, print_disassembly): Don't call
gdb_flush.
* c-valprint.c (c_val_print): Don't call gdb_flush.
* ada-valprint.c (ada_print_scalar): Don't call gdb_flush.

25 files changed:
gdb/ChangeLog
gdb/ada-valprint.c
gdb/c-valprint.c
gdb/cli/cli-cmds.c
gdb/cli/cli-script.c
gdb/darwin-nat.c
gdb/f-valprint.c
gdb/gnu-nat.c
gdb/hppa-tdep.c
gdb/inf-ptrace.c
gdb/infrun.c
gdb/m2-valprint.c
gdb/mdebugread.c
gdb/memattr.c
gdb/nto-procfs.c
gdb/p-valprint.c
gdb/printcmd.c
gdb/procfs.c
gdb/remote.c
gdb/sparc64-tdep.c
gdb/target.c
gdb/typeprint.c
gdb/utils.c
gdb/valprint.c
gdb/windows-nat.c

index bb94ae250630fa40077f11ac9fd562e3e947c75f..563cda6d38818f385b6e83f1178c7a32f56ef5ed 100644 (file)
@@ -1,3 +1,36 @@
+2019-03-05  Tom Tromey  <tromey@adacore.com>
+
+       * windows-nat.c (windows_nat_target::attach)
+       (windows_nat_target::detach): Don't call gdb_flush.
+       * valprint.c (generic_val_print, val_print, val_print_string):
+       Don't call gdb_flush.
+       * utils.c (defaulted_query): Don't call gdb_flush.
+       * typeprint.c (print_type_scalar): Don't call gdb_flush.
+       * target.c (target_announce_detach): Don't call gdb_flush.
+       * sparc64-tdep.c (adi_print_versions): Don't call gdb_flush.
+       * remote.c (extended_remote_target::attach): Don't call
+       gdb_flush.
+       * procfs.c (procfs_target::detach): Don't call gdb_flush.
+       * printcmd.c (do_examine): Don't call gdb_flush.
+       (info_display_command): Don't call gdb_flush.
+       * p-valprint.c (pascal_val_print): Don't call gdb_flush.
+       * nto-procfs.c (nto_procfs_target::attach): Don't call gdb_flush.
+       * memattr.c (info_mem_command): Don't call gdb_flush.
+       * mdebugread.c (mdebug_build_psymtabs): Don't call gdb_flush.
+       * m2-valprint.c (m2_val_print): Don't call gdb_flush.
+       * infrun.c (follow_exec, handle_command): Don't call gdb_flush.
+       * inf-ptrace.c (inf_ptrace_target::attach): Don't call gdb_flush.
+       * hppa-tdep.c (unwind_command): Don't call gdb_flush.
+       * gnu-nat.c (gnu_nat_target::attach): Don't call gdb_flush.
+       (gnu_nat_target::detach): Don't call gdb_flush.
+       * f-valprint.c (f_val_print): Don't call gdb_flush.
+       * darwin-nat.c (darwin_nat_target::attach): Don't call gdb_flush.
+       * cli/cli-script.c (read_command_lines): Don't call gdb_flush.
+       * cli/cli-cmds.c (shell_escape, print_disassembly): Don't call
+       gdb_flush.
+       * c-valprint.c (c_val_print): Don't call gdb_flush.
+       * ada-valprint.c (ada_print_scalar): Don't call gdb_flush.
+
 2019-03-05  Tom Tromey  <tromey@adacore.com>
 
        * varobj.c (update_dynamic_varobj_children): Update.
index f2aed32cc8635dea16b5fa160cafc9343bfa505d..d4661e1f1d4c451220092ad9958a900b8b0a831a 100644 (file)
@@ -465,7 +465,6 @@ ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     default:
       error (_("Invalid type code in symbol table."));
     }
-  gdb_flush (stream);
 }
 
 /* Print the character string STRING, printing at most LENGTH characters.
index 7a1de70f6a13ad11d725cb16a0d77ee496d4c16b..d5ddd3ece7a01e15ea7f486dabe2ae83a952ef3b 100644 (file)
@@ -564,7 +564,6 @@ c_val_print (struct type *type,
                         &c_decorations);
       break;
     }
-  gdb_flush (stream);
 }
 \f
 void
index fa99503b0ca9ad1e4f2f85cabbfabffeb9f3940b..5dc94a5361af9a15131159ac48452cc036a0b40b 100644 (file)
@@ -709,16 +709,10 @@ shell_escape (const char *arg, int from_tty)
     arg = "inferior shell";
 
   if (rc == -1)
-    {
-      fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
-                         safe_strerror (errno));
-      gdb_flush (gdb_stderr);
-    }
+    fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
+                       safe_strerror (errno));
   else if (rc)
-    {
-      fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
-      gdb_flush (gdb_stderr);
-    }
+    fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
 #ifdef GLOBAL_CURDIR
   /* Make sure to return to the directory GDB thinks it is, in case
      the shell command we just ran changed it.  */
@@ -743,7 +737,6 @@ shell_escape (const char *arg, int from_tty)
 
       fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
                          safe_strerror (errno));
-      gdb_flush (gdb_stderr);
       _exit (0177);
     }
 
@@ -1130,7 +1123,6 @@ print_disassembly (struct gdbarch *gdbarch, const char *name,
            }
        }
       printf_filtered ("End of assembler dump.\n");
-      gdb_flush (gdb_stdout);
     }
 #if defined(TUI)
   else
index 85f00c75b3ff28f039e429382a78efdffd31bfe1..e2fa8807130cf6fa0c4524baeb83de3da2f86944 100644 (file)
@@ -1186,10 +1186,7 @@ read_command_lines (const char *prompt_arg, int from_tty, int parse_commands,
                                             END_MESSAGE);
        }
       else
-       {
-         printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
-         gdb_flush (gdb_stdout);
-       }
+       printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
     }
 
 
index 8c34aa8a3f2cf3a71dfe35f7559bda5eeab7cd4b..0b7cfb69dc805d3e6b565e2a67a5ac1d7d3d6498 100644 (file)
@@ -2056,8 +2056,6 @@ darwin_nat_target::attach (const char *args, int from_tty)
       else
        printf_unfiltered (_("Attaching to %s\n"),
                           target_pid_to_str (ptid_t (pid)));
-
-      gdb_flush (gdb_stdout);
     }
 
   if (pid == 0 || ::kill (pid, 0) < 0)
index d9fe26f1d6a5f4cc3400467ce639c4be0df87a5e..eee0a62fe880657d71b22f1cb42390f747566316 100644 (file)
@@ -366,7 +366,6 @@ f_val_print (struct type *type, int embedded_offset,
                         &f_decorations);
       break;
     }
-  gdb_flush (stream);
 }
 
 static void
index 53f23068a405794c57a2bcf254c3c4f3c034d528..7a0c726c8e943c9072b81b498f3f262984f4d254 100644 (file)
@@ -2217,8 +2217,6 @@ gnu_nat_target::attach (const char *args, int from_tty)
                           exec_file, pid);
       else
        printf_unfiltered ("Attaching to pid %d\n", pid);
-
-      gdb_flush (gdb_stdout);
     }
 
   inf_debug (inf, "attaching to pid: %d", pid);
@@ -2273,7 +2271,6 @@ gnu_nat_target::detach (inferior *inf, int from_tty)
                           exec_file, gnu_current_inf->pid);
       else
        printf_unfiltered ("Detaching from pid %d\n", gnu_current_inf->pid);
-      gdb_flush (gdb_stdout);
     }
 
   pid = gnu_current_inf->pid;
index 7fed349f56d67914ab14b69e3e47a5f30e070d1f..d2b3336cfc7b576fcc07ae74766a3e567b98baad 100644 (file)
@@ -2580,10 +2580,8 @@ unwind_command (const char *exp, int from_tty)
   printf_unfiltered ("unwind_table_entry (%s):\n", host_address_to_string (u));
 
   printf_unfiltered ("\tregion_start = %s\n", hex_string (u->region_start));
-  gdb_flush (gdb_stdout);
 
   printf_unfiltered ("\tregion_end = %s\n", hex_string (u->region_end));
-  gdb_flush (gdb_stdout);
 
 #define pif(FLD) if (u->FLD) printf_unfiltered (" "#FLD);
 
index 0956094c6a452f4b91856ac3c41c600beae8a99b..d4b9a3a646957f0ad66f0057fb947f1dc48e7ee5 100644 (file)
@@ -217,8 +217,6 @@ inf_ptrace_target::attach (const char *args, int from_tty)
       else
        printf_unfiltered (_("Attaching to %s\n"),
                           target_pid_to_str (ptid_t (pid)));
-
-      gdb_flush (gdb_stdout);
     }
 
 #ifdef PT_ATTACH
index b32635fc422da0a22c2e50a3f3d30074ccd61c42..6d1d04ee6952095167ee4c5781101bf9fe671c6b 100644 (file)
@@ -1159,8 +1159,6 @@ follow_exec (ptid_t ptid, char *exec_file_target)
   /* We've followed the inferior through an exec.  Therefore, the
      inferior has essentially been killed & reborn.  */
 
-  gdb_flush (gdb_stdout);
-
   breakpoint_init_inferior (inf_execd);
 
   gdb::unique_xmalloc_ptr<char> exec_file_host
@@ -8406,10 +8404,7 @@ Are you sure you want to change it? "),
                      sigs[signum] = 1;
                    }
                  else
-                   {
-                     printf_unfiltered (_("Not confirmed, unchanged.\n"));
-                     gdb_flush (gdb_stdout);
-                   }
+                   printf_unfiltered (_("Not confirmed, unchanged.\n"));
                }
              break;
            case GDB_SIGNAL_0:
index b011d65aed55012a6def9767dea7e8ed909f2656..74f89ee45fb33f70ec54b07b70000aba5b7883ca 100644 (file)
@@ -408,7 +408,6 @@ m2_val_print (struct type *type, int embedded_offset,
       if (TYPE_STUB (elttype))
        {
          fprintf_filtered (stream, _("<incomplete type>"));
-         gdb_flush (stream);
          break;
        }
       else
@@ -499,5 +498,4 @@ m2_val_print (struct type *type, int embedded_offset,
                         &m2_decorations);
       break;
     }
-  gdb_flush (stream);
 }
index accf07c27804bd29f0080b4d14d84d886c44819b..35e7890f3574beda2b4c3579536fbfa8ba28204b 100644 (file)
@@ -377,7 +377,6 @@ mdebug_build_psymtabs (minimal_symbol_reader &reader,
                           objfile->name);
       printf_unfiltered (_("You should compile with -g2 or "
                           "-g3 for best debugging support.\n"));
-      gdb_flush (gdb_stdout);
     }
 #endif
 }
index 0769a80a0672103ff8e609037da20f72f9fb636c..858a41abfb423ac66c1d4f3343682e23b1e62d33 100644 (file)
@@ -459,8 +459,6 @@ info_mem_command (const char *args, int from_tty)
 #endif
 
       printf_filtered ("\n");
-
-      gdb_flush (gdb_stdout);
     }
 }
 \f
index 40959d7715dd82089658d6b184b023166cb9ec11..8108c0e3888eab79596187d40527ab77e1a94a54 100644 (file)
@@ -712,8 +712,6 @@ nto_procfs_target::attach (const char *args, int from_tty)
       else
        printf_unfiltered ("Attaching to %s\n",
                           target_pid_to_str (ptid_t (pid)));
-
-      gdb_flush (gdb_stdout);
     }
   inferior_ptid = do_attach (ptid_t (pid));
   inf = current_inferior ();
index 713a2889493e963fa41c5f723158145bc47a04d5..0e81697718190ee307b844bed038d56881798655 100644 (file)
@@ -349,7 +349,6 @@ pascal_val_print (struct type *type,
       if (TYPE_STUB (elttype))
        {
          fprintf_filtered (stream, "<incomplete type>");
-         gdb_flush (stream);
          break;
        }
       else
@@ -418,7 +417,6 @@ pascal_val_print (struct type *type,
       error (_("Invalid pascal type code %d in symbol table."),
             TYPE_CODE (type));
     }
-  gdb_flush (stream);
 }
 \f
 void
index 03763d577ab2dfd7b15f8ad45f81ba50eb43543f..c442bb4e07ed0b04f9ccb3fa6bdb60bac025b843 100644 (file)
@@ -1098,7 +1098,6 @@ do_examine (struct format_data fmt, struct gdbarch *gdbarch, CORE_ADDR addr)
            count += branch_delay_insns;
        }
       printf_filtered ("\n");
-      gdb_flush (gdb_stdout);
     }
 
   if (need_to_update_next_address)
@@ -2068,7 +2067,6 @@ Num Enb Expression\n"));
       if (d->block && !contained_in (get_selected_block (0), d->block))
        printf_filtered (_(" (cannot be evaluated in the current context)"));
       printf_filtered ("\n");
-      gdb_flush (gdb_stdout);
     }
 }
 
index 0525b76cee506200d7ca48192e7923bddc8a9a81..384ca9bc0b27076ecd24cb76e62cb29a7daafad9 100644 (file)
@@ -1911,7 +1911,6 @@ procfs_target::detach (inferior *inf, int from_tty)
 
       printf_filtered (_("Detaching from program: %s, %s\n"), exec_file,
                       target_pid_to_str (ptid_t (pid)));
-      gdb_flush (gdb_stdout);
     }
 
   do_detach ();
index c98c5cb2ebf351cf9aa8cab01a5efe29cf5093dd..bed997c6adf2a7fc0db74fdbde9ebef529e5a078 100644 (file)
@@ -5826,8 +5826,6 @@ extended_remote_target::attach (const char *args, int from_tty)
       else
        printf_unfiltered (_("Attaching to %s\n"),
                           target_pid_to_str (ptid_t (pid)));
-
-      gdb_flush (gdb_stdout);
     }
 
   xsnprintf (rs->buf.data (), get_remote_packet_size (), "vAttach;%x", pid);
index 030850955ace9fff37a5a26ef673249cc5f85e81..5b7d57a21638ddae7c27067edf0e1313e7126bd4 100644 (file)
@@ -406,7 +406,6 @@ adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
           ++v_idx;
         }
       printf_filtered ("\n");
-      gdb_flush (gdb_stdout);
       vaddr += maxelts;
     }
 }
index d5ff932c7483d70fe27a337ef58441864977d99b..fe7cb08b994763f308396baa3aeaf6949648955b 100644 (file)
@@ -3168,7 +3168,6 @@ target_announce_detach (int from_tty)
   pid = inferior_ptid.pid ();
   printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file,
                     target_pid_to_str (ptid_t (pid)));
-  gdb_flush (gdb_stdout);
 }
 
 /* The inferior process has died.  Long live the inferior!  */
index 6c499b6467e13d02e794dc031956e7e0c1b0f4d9..114725bc6959e9422f84c6d978cbb4a1fbae61ae 100644 (file)
@@ -691,7 +691,6 @@ print_type_scalar (struct type *type, LONGEST val, struct ui_file *stream)
     default:
       error (_("Invalid type code in symbol table."));
     }
-  gdb_flush (stream);
 }
 
 /* Dump details of a type specified either directly or indirectly.
index 60af31f2e4fe4d894479d45ba0a07b6dd1dc6b5e..6520f1db2faeb4baa31297463d3454d39558ee9c 100644 (file)
@@ -890,7 +890,6 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
       printf_filtered (_("(%s or %s) [answered %c; "
                         "input not from terminal]\n"),
                       y_string, n_string, def_answer);
-      gdb_flush (gdb_stdout);
 
       return def_value;
     }
index a079c0025a748a3c4002984e0ea48c5f9b6ed4e9..10020901c2df781033c31d6ee27dbaedae6514d1 100644 (file)
@@ -986,7 +986,6 @@ generic_val_print (struct type *type,
       error (_("Unhandled type code %d in symbol table."),
             TYPE_CODE (type));
     }
-  gdb_flush (stream);
 }
 
 /* Print using the given LANGUAGE the data of type TYPE located at
@@ -1032,7 +1031,6 @@ val_print (struct type *type, LONGEST embedded_offset,
   if (TYPE_STUB (real_type))
     {
       fprintf_filtered (stream, _("<incomplete type>"));
-      gdb_flush (stream);
       return;
     }
 
@@ -2860,8 +2858,6 @@ val_print_string (struct type *elttype, const char *encoding,
       fprintf_filtered (stream, ">");
     }
 
-  gdb_flush (stream);
-
   return (bytes_read / width);
 }
 \f
index e47fcb1b40a375690345b393d543631a2c625d60..99bcedcc2cf9f16188cc767c79b66787ef97cd9a 100644 (file)
@@ -2015,8 +2015,6 @@ windows_nat_target::attach (const char *args, int from_tty)
       else
        printf_unfiltered ("Attaching to %s\n",
                           target_pid_to_str (ptid_t (pid)));
-
-      gdb_flush (gdb_stdout);
     }
 
   do_initial_windows_stuff (this, pid, 1);
@@ -2046,7 +2044,6 @@ windows_nat_target::detach (inferior *inf, int from_tty)
        exec_file = "";
       printf_unfiltered ("Detaching from program: %s, Pid %u\n", exec_file,
                         (unsigned) current_event.dwProcessId);
-      gdb_flush (gdb_stdout);
     }
 
   x86_cleanup_dregs ();