* gdb --args mishandles empty arguments
@ 2002-12-02 6:42 Andreas Schwab
2002-12-02 18:23 ` Daniel Jacobowitz
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2002-12-02 6:42 UTC (permalink / raw)
To: gdb-patches
With the intruduction of --args it is possible to construct empty
arguments that need to be transformed to ''.
Andreas.
2002-12-02 Andreas Schwab <schwab@suse.de>
* infcmd.c (construct_inferior_arguments): Handle empty arguments.
--- gdb/infcmd.c.~1.64.~ 2002-12-02 11:00:11.000000000 +0100
+++ gdb/infcmd.c 2002-12-02 14:52:12.000000000 +0100
@@ -278,7 +278,7 @@ construct_inferior_arguments (struct gdb
/* We over-compute the size. It shouldn't matter. */
for (i = 0; i < argc; ++i)
- length += 2 * strlen (argv[i]) + 1;
+ length += 2 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
result = (char *) xmalloc (length);
out = result;
@@ -288,11 +288,20 @@ construct_inferior_arguments (struct gdb
if (i > 0)
*out++ = ' ';
- for (cp = argv[i]; *cp; ++cp)
+ /* Need to handle empty arguments specially. */
+ if (argv[i][0] == '\0')
{
- if (strchr (special, *cp) != NULL)
- *out++ = '\\';
- *out++ = *cp;
+ *out++ = '\'';
+ *out++ = '\'';
+ }
+ else
+ {
+ for (cp = argv[i]; *cp; ++cp)
+ {
+ if (strchr (special, *cp) != NULL)
+ *out++ = '\\';
+ *out++ = *cp;
+ }
}
}
*out = '\0';
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: gdb --args mishandles empty arguments 2002-12-02 6:42 gdb --args mishandles empty arguments Andreas Schwab @ 2002-12-02 18:23 ` Daniel Jacobowitz 2002-12-02 18:46 ` Andrew Cagney 0 siblings, 1 reply; 5+ messages in thread From: Daniel Jacobowitz @ 2002-12-02 18:23 UTC (permalink / raw) To: Andreas Schwab; +Cc: gdb-patches On Mon, Dec 02, 2002 at 03:42:18PM +0100, Andreas Schwab wrote: > With the intruduction of --args it is possible to construct empty > arguments that need to be transformed to ''. > > Andreas. > > 2002-12-02 Andreas Schwab <schwab@suse.de> > > * infcmd.c (construct_inferior_arguments): Handle empty arguments. This patch is OK. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: gdb --args mishandles empty arguments 2002-12-02 18:23 ` Daniel Jacobowitz @ 2002-12-02 18:46 ` Andrew Cagney 2002-12-02 20:00 ` Daniel Jacobowitz 0 siblings, 1 reply; 5+ messages in thread From: Andrew Cagney @ 2002-12-02 18:46 UTC (permalink / raw) To: Daniel Jacobowitz, Andreas Schwab; +Cc: gdb-patches > On Mon, Dec 02, 2002 at 03:42:18PM +0100, Andreas Schwab wrote: > >> With the intruduction of --args it is possible to construct empty >> arguments that need to be transformed to ''. >> >> Andreas. >> >> 2002-12-02 Andreas Schwab <schwab@suse.de> >> >> * infcmd.c (construct_inferior_arguments): Handle empty arguments. > > > This patch is OK. btw, is there a test case? actually, is this tested at all? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: gdb --args mishandles empty arguments 2002-12-02 18:46 ` Andrew Cagney @ 2002-12-02 20:00 ` Daniel Jacobowitz 2003-01-03 22:46 ` Elena Zannoni 0 siblings, 1 reply; 5+ messages in thread From: Daniel Jacobowitz @ 2002-12-02 20:00 UTC (permalink / raw) To: Andrew Cagney; +Cc: Andreas Schwab, gdb-patches On Mon, Dec 02, 2002 at 09:45:57PM -0500, Andrew Cagney wrote: > >On Mon, Dec 02, 2002 at 03:42:18PM +0100, Andreas Schwab wrote: > > > >>With the intruduction of --args it is possible to construct empty > >>arguments that need to be transformed to ''. > >> > >>Andreas. > >> > >>2002-12-02 Andreas Schwab <schwab@suse.de> > >> > >> * infcmd.c (construct_inferior_arguments): Handle empty arguments. > > > > > >This patch is OK. > > > btw, is there a test case? actually, is this tested at all? No, I don't think --args is... a test case if someone feels like putting one together: gdb --args /bin/echo '' a (gdb) run should produce '^ a$' -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: gdb --args mishandles empty arguments 2002-12-02 20:00 ` Daniel Jacobowitz @ 2003-01-03 22:46 ` Elena Zannoni 0 siblings, 0 replies; 5+ messages in thread From: Elena Zannoni @ 2003-01-03 22:46 UTC (permalink / raw) To: Daniel Jacobowitz; +Cc: Andrew Cagney, Andreas Schwab, gdb-patches Daniel Jacobowitz writes: > On Mon, Dec 02, 2002 at 09:45:57PM -0500, Andrew Cagney wrote: > > >On Mon, Dec 02, 2002 at 03:42:18PM +0100, Andreas Schwab wrote: > > > > > >>With the intruduction of --args it is possible to construct empty > > >>arguments that need to be transformed to ''. > > >> > > >>Andreas. > > >> > > >>2002-12-02 Andreas Schwab <schwab@suse.de> > > >> > > >> * infcmd.c (construct_inferior_arguments): Handle empty arguments. > > > > > > > > >This patch is OK. > > > > > > btw, is there a test case? actually, is this tested at all? > > No, I don't think --args is... a test case if someone feels like > putting one together: > > gdb --args /bin/echo '' a > (gdb) run > > should produce '^ a$' Since I have a bug open against the current RH rawhide for this, I might as well create a test. How's this? (I'll send a formal RFA) ------args.c-------- #include <stdio.h> int main (int argc, char **argv) { int i = 0; printf ("%d\n", argc); while (i < argc) printf ("%s\n", argv[i++]); return 0; } ------args.exp-------- # Copyright 2003 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@prep.ai.mit.edu # This is a test for the gdb invocation option --args. if $tracelevel then { strace $tracelevel } global GDBFLAGS set testfile "args" set srcfile ${testfile}.c set binfile ${objdir}/${subdir}/${testfile} if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } { gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." } # # Test that the --args are processed correctly. # set GDBFLAGS "--args $binfile 1 3" gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_test "run" \ "Starting program.*args 1 3.*3\r\n.*args\r\n1\r\n3.*Program exited normally." \ "correct args printed" # # Test that the --args are processed correctly even if one of them is empty. # set GDBFLAGS "--args $binfile 1 '' 3" gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_test "run" \ "Starting program.*args 1 \\\\'\\\\' 3.*4\r\n.*args\r\n1\r\n''\r\n3.*Program exited normally." \ "correct args printed (one empty)" # # try with 2 empty args # set GDBFLAGS "--args $binfile 1 '' '' 3" gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_test "run" \ "Starting program.*args 1 \\\\'\\\\' \\\\'\\\\' 3.*5\r\n.*args\r\n1\r\n''\r\n''\r\n3.*Program exited normally." \ "correct args printed (two empty)" ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2003-01-03 22:46 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-12-02 6:42 gdb --args mishandles empty arguments Andreas Schwab 2002-12-02 18:23 ` Daniel Jacobowitz 2002-12-02 18:46 ` Andrew Cagney 2002-12-02 20:00 ` Daniel Jacobowitz 2003-01-03 22:46 ` Elena Zannoni
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox