Bug 11345 - printf "%%\n" does not print the '%' character
Summary: printf "%%\n" does not print the '%' character
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 7.1
: P2 normal
Target Milestone: 7.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-03 15:01 UTC by Dainis Jonitis
Modified: 2010-03-03 18:24 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2010-03-03 16:48:10


Attachments
Fix. Change fputs_unfiltered to fprintf_unfiltered (499 bytes, patch)
2010-03-03 15:16 UTC, Dainis Jonitis
Details | Diff
Fix. Change puts_unfiltered to fprintf_unfiltered (497 bytes, patch)
2010-03-03 15:19 UTC, Dainis Jonitis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dainis Jonitis 2010-03-03 15:01:27 UTC
printf command parses the format string and prints arguments one by one. If it
happens that you want to print just a "%%" and there are no arguments anymore
(or there were no any arguments) then the remainder of format string is printed
with puts_filtered (last_arg); 
puts does not know anything about special escape sequence for "%%" and instead
of printing just one '%' it prints both of them.

The fix is trivial. Just replace:

  puts_filtered (last_arg);

with:

  printf_filtered (last_arg);

in gdb/printcmd.c printf_command()

Test like this:

printf "%% %d %%\n", 1

Should produce:

% 1 %

The same problem was in 6.8.
Comment 1 Dainis Jonitis 2010-03-03 15:16:19 UTC
Created attachment 4640 [details]
Fix. Change fputs_unfiltered to fprintf_unfiltered
Comment 2 Dainis Jonitis 2010-03-03 15:19:38 UTC
Created attachment 4641 [details]
Fix. Change puts_unfiltered to fprintf_unfiltered
Comment 3 Tom Tromey 2010-03-03 16:48:10 UTC
I'm handling this.
The patch looks fine to me.
I'm writing a regression test & testing it, then I'll commit it.
Comment 4 Sourceware Commits 2010-03-03 18:05:24 UTC
Subject: Bug 11345

CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2010-03-03 18:05:05

Modified files:
	gdb            : ChangeLog printcmd.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.base: printcmds.exp 

Log message:
	gdb
	2010-03-03  Dainis Jonitis  <jonitis@gmail.com>
	PR gdb/11345:
	* printcmd.c (printf_command): Print end of format string using
	printf_filtered.
	gdb/testsuite
	2010-03-03  Tom Tromey  <tromey@redhat.com>
	PR gdb/11345:
	* gdb.base/printcmds.exp (test_printf): Add test.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11417&r2=1.11418
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/printcmd.c.diff?cvsroot=src&r1=1.170&r2=1.171
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2159&r2=1.2160
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.base/printcmds.exp.diff?cvsroot=src&r1=1.29&r2=1.30

Comment 5 Tom Tromey 2010-03-03 18:07:34 UTC
Fixed in CVS.
Comment 6 Sourceware Commits 2010-03-03 18:23:25 UTC
Subject: Bug 11345

CVSROOT:	/cvs/src
Module name:	src
Branch: 	gdb_7_1-branch
Changes by:	tromey@sourceware.org	2010-03-03 18:22:59

Modified files:
	gdb            : ChangeLog printcmd.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.base: printcmds.exp 

Log message:
	gdb
	2010-03-03  Dainis Jonitis  <jonitis@gmail.com>
	PR gdb/11345:
	* printcmd.c (printf_command): Print end of format string using
	printf_filtered.
	gdb/testsuite
	2010-03-03  Tom Tromey  <tromey@redhat.com>
	PR gdb/11345:
	* gdb.base/printcmds.exp (test_printf): Add test.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&only_with_tag=gdb_7_1-branch&r1=1.11378.2.14&r2=1.11378.2.15
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/printcmd.c.diff?cvsroot=src&only_with_tag=gdb_7_1-branch&r1=1.170&r2=1.170.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&only_with_tag=gdb_7_1-branch&r1=1.2147.2.1&r2=1.2147.2.2
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.base/printcmds.exp.diff?cvsroot=src&only_with_tag=gdb_7_1-branch&r1=1.29&r2=1.29.2.1

Comment 7 Tom Tromey 2010-03-03 18:24:19 UTC
I also pushed it into the 7.1 branch