From c22261528c50f7760dd6a2e29314662b377eebb4 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Thu, 30 Oct 2008 10:07:16 +0000 Subject: [PATCH] * infcmd.c (construct_inferior_arguments): Handle newlines specially. testsuite/: * gdb.base/args.exp: Add tests for newlines. --- gdb/ChangeLog | 5 +++++ gdb/infcmd.c | 20 ++++++++++++++++---- gdb/testsuite/ChangeLog | 4 ++++ gdb/testsuite/gdb.base/args.exp | 8 ++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 389c5fa..0ee7904 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2008-10-30 Andreas Schwab + + * infcmd.c (construct_inferior_arguments): Handle newlines + specially. + 2008-10-30 Joel Brobecker * breakpoint.h (enum bptype): Delete bp_catch_exec. diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 8060af5..607d2b3 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -270,7 +270,7 @@ construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv) /* 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; @@ -290,9 +290,21 @@ construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv) { 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; + } } } } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 5229ff2..9ad4f2d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-10-30 Andreas Schwab + + * gdb.base/args.exp: Add tests for newlines. + 2008-10-30 Joel Brobecker gdb.base/foll-exec.exp: Update the expected output of a couple diff --git a/gdb/testsuite/gdb.base/args.exp b/gdb/testsuite/gdb.base/args.exp index 544fca7..372bfe1 100644 --- a/gdb/testsuite/gdb.base/args.exp +++ b/gdb/testsuite/gdb.base/args.exp @@ -96,4 +96,12 @@ args_test "one empty (with single quotes)" {{1} {''} {3}} 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 -- 2.7.4