public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] fix for PR gdb/15995
@ 2013-10-07 18:57 Tom Tromey
  2013-10-08 15:53 ` Pedro Alves
  2013-10-17 18:28 ` Tom Tromey
  0 siblings, 2 replies; 3+ messages in thread
From: Tom Tromey @ 2013-10-07 18:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This patch fixes PR gdb/15995.

The bug here is that gdb's printf command does not flush the output
stream.  This makes a printf that is not newline-terminated interleave
incorrectly with other forms of output, such as that generated via a
call to an external program using "shell".

I note that the "output" command already does this flushing.

The fix is to call gdb_flush in printf_command.

Built and regtested on x86-64 Fedora 18.
New test case included.

	PR gdb/15995:
	* printcmd.c (printcmd): Call gdb_flush.

	* gdb.base/printcmds.exp (test_printf): Test printf flushing.
---
 gdb/printcmd.c                       | 1 +
 gdb/testsuite/gdb.base/printcmds.exp | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 751cd2b..9bca6dd 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2458,6 +2458,7 @@ static void
 printf_command (char *arg, int from_tty)
 {
   ui_printf (arg, gdb_stdout);
+  gdb_flush (gdb_stdout);
 }
 
 /* Implement the "eval" command.  */
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 60e4a7f..6d65107 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -740,6 +740,12 @@ proc test_printf {} {
     gdb_test "printf \"% p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
     gdb_test "printf \"%0p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
     gdb_test "printf \"%+p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+
+
+    gdb_test "define hibob\nprintf \"hi bob \"\nshell echo zzz\nprintf \"y\\n\"\nend" \
+	"" \
+	"create hibob command"
+    gdb_test "hibob" "hi bob zzz.*y" "run hibob command"
 }
 
 #Test printing DFP values with printf
-- 
1.8.1.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fix for PR gdb/15995
  2013-10-07 18:57 [PATCH] fix for PR gdb/15995 Tom Tromey
@ 2013-10-08 15:53 ` Pedro Alves
  2013-10-17 18:28 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2013-10-08 15:53 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 10/07/2013 07:57 PM, Tom Tromey wrote:
> This patch fixes PR gdb/15995.
> 
> The bug here is that gdb's printf command does not flush the output
> stream.  This makes a printf that is not newline-terminated interleave
> incorrectly with other forms of output, such as that generated via a
> call to an external program using "shell".
> 
> I note that the "output" command already does this flushing.
> 
> The fix is to call gdb_flush in printf_command.

This is fine with me.

(Though I'm wondering if there aren't more ways to get
to a shell command with no previous newline, and so it'd
make sense for the shell command itself to flush stdout
before forking the shell.)

-- 
Pedro Alves

> 
> Built and regtested on x86-64 Fedora 18.
> New test case included.
> 
> 	PR gdb/15995:
> 	* printcmd.c (printcmd): Call gdb_flush.
> 
> 	* gdb.base/printcmds.exp (test_printf): Test printf flushing.
> ---
>  gdb/printcmd.c                       | 1 +
>  gdb/testsuite/gdb.base/printcmds.exp | 6 ++++++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/gdb/printcmd.c b/gdb/printcmd.c
> index 751cd2b..9bca6dd 100644
> --- a/gdb/printcmd.c
> +++ b/gdb/printcmd.c
> @@ -2458,6 +2458,7 @@ static void
>  printf_command (char *arg, int from_tty)
>  {
>    ui_printf (arg, gdb_stdout);
> +  gdb_flush (gdb_stdout);
>  }
>  
>  /* Implement the "eval" command.  */
> diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
> index 60e4a7f..6d65107 100644
> --- a/gdb/testsuite/gdb.base/printcmds.exp
> +++ b/gdb/testsuite/gdb.base/printcmds.exp
> @@ -740,6 +740,12 @@ proc test_printf {} {
>      gdb_test "printf \"% p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
>      gdb_test "printf \"%0p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
>      gdb_test "printf \"%+p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
> +
> +
> +    gdb_test "define hibob\nprintf \"hi bob \"\nshell echo zzz\nprintf \"y\\n\"\nend" \
> +	"" \
> +	"create hibob command"
> +    gdb_test "hibob" "hi bob zzz.*y" "run hibob command"
>  }
>  
>  #Test printing DFP values with printf
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fix for PR gdb/15995
  2013-10-07 18:57 [PATCH] fix for PR gdb/15995 Tom Tromey
  2013-10-08 15:53 ` Pedro Alves
@ 2013-10-17 18:28 ` Tom Tromey
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2013-10-17 18:28 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@redhat.com> writes:

Tom> This patch fixes PR gdb/15995.

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-17 18:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-07 18:57 [PATCH] fix for PR gdb/15995 Tom Tromey
2013-10-08 15:53 ` Pedro Alves
2013-10-17 18:28 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).