This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Handle newlines in args
- From: Andreas Schwab <schwab at suse dot de>
- To: gdb-patches at sourceware dot org
- Date: Fri, 12 Sep 2008 16:30:04 +0200
- Subject: [PATCH] Handle newlines in args
A literal newline cannot be quoted with a backslash, it would just
disappear.
Andreas.
2008-09-12 Andreas Schwab <schwab@suse.de>
* infcmd.c (construct_inferior_arguments): Handle newlines
specially.
testsuite/:
* gdb.base/args.exp: Add tests for newlines.
--- infcmd.c.~1.211.~ 2008-09-12 11:12:15.000000000 +0200
+++ infcmd.c 2008-09-12 16:25:48.000000000 +0200
@@ -271,7 +271,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 + 2 * (argv[i][0] == '\0');
+ length += 3 * strlen (argv[i]) + 1 + 2 * (argv[i][0] == '\0');
result = (char *) xmalloc (length);
out = result;
@@ -291,9 +291,21 @@ construct_inferior_arguments (struct gdb
{
for (cp = argv[i]; *cp; ++cp)
{
- if (strchr (special, *cp) != NULL)
- *out++ = '\\';
- *out++ = *cp;
+ if (*cp == '\n')
+ {
+ /* A newline cannot be quoted with a backslash (it
+ just disappears), only by putting it inside
+ quotes. */
+ *out++ = '\'';
+ *out++ = '\n';
+ *out++ = '\'';
+ }
+ else
+ {
+ if (strchr (special, *cp) != NULL)
+ *out++ = '\\';
+ *out++ = *cp;
+ }
}
}
}
--- testsuite/gdb.base/args.exp.~1.15.~ 2008-08-09 15:44:54.000000000 +0200
+++ testsuite/gdb.base/args.exp 2008-09-12 16:11:20.000000000 +0200
@@ -96,4 +96,12 @@ args_test "one empty (with single quotes
set GDBFLAGS "-nx --args $binfile 1 '' '' 3"
args_test "two empty (with single quotes)" {{1} {''} {''} {3}}
+# try with arguments containing literal newlines.
+
+set GDBFLAGS "-nx --args $binfile 1 {\n} 3"
+args_test "one newline" {{1} {\\n} {3}}
+
+set GDBFLAGS "-nx --args $binfile 1 {\n} {\n} 3"
+args_test "two newlines" {{1} {\\n} {\\n} {3}}
+
set GDBFLAGS $old_gdbflags
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."