summaryrefslogtreecommitdiff
path: root/gdb/infcmd.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2001-11-27 03:09:44 +0000
committerTom Tromey <tromey@redhat.com>2001-11-27 03:09:44 +0000
commit4ac8d3a044746aaecafe6e2bc5ac35f91acfca41 (patch)
tree57d8ede8b6fd4dbbef3a93f3311121b2c1cadc89 /gdb/infcmd.c
parent3a5681a458483da2d4c1752cd314f35342167280 (diff)
downloadgdb-4ac8d3a044746aaecafe6e2bc5ac35f91acfca41.tar.gz
* NEWS: Update for --args.
* infcmd.c (construct_inferior_arguments): Moved from ... * fork-child.c: ... here.
Diffstat (limited to 'gdb/infcmd.c')
-rw-r--r--gdb/infcmd.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index b0d74eede2f..f05da5aef9b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -257,6 +257,77 @@ notice_args_read (struct cmd_list_element *c)
}
+/* Compute command-line string given argument vector. This does the
+ same shell processing as fork_inferior. */
+/* ARGSUSED */
+char *
+construct_inferior_arguments (struct gdbarch *gdbarch, int argc, char **argv)
+{
+ char *result;
+
+ if (STARTUP_WITH_SHELL)
+ {
+ /* This holds all the characters considered special to the
+ typical Unix shells. We include `^' because the SunOS
+ /bin/sh treats it as a synonym for `|'. */
+ char *special = "\"!#$&*()\\|[]{}<>?'\"`~^; \t\n";
+ int i;
+ int length = 0;
+ char *out, *cp;
+
+ /* We over-compute the size. It shouldn't matter. */
+ for (i = 0; i < argc; ++i)
+ length += 2 * strlen (argv[i]) + 1;
+
+ result = (char *) xmalloc (length);
+ out = result;
+
+ for (i = 0; i < argc; ++i)
+ {
+ if (i > 0)
+ *out++ = ' ';
+
+ for (cp = argv[i]; *cp; ++cp)
+ {
+ if (strchr (special, *cp) != NULL)
+ *out++ = '\\';
+ *out++ = *cp;
+ }
+ }
+ *out = '\0';
+ }
+ else
+ {
+ /* In this case we can't handle arguments that contain spaces,
+ tabs, or newlines -- see breakup_args(). */
+ int i;
+ int length = 0;
+
+ for (i = 0; i < argc; ++i)
+ {
+ char *cp = strchr (argv[i], ' ');
+ if (cp == NULL)
+ cp = strchr (argv[i], '\t');
+ if (cp == NULL)
+ cp = strchr (argv[i], '\n');
+ if (cp != NULL)
+ error ("can't handle command-line argument containing whitespace");
+ length += strlen (argv[i]) + 1;
+ }
+
+ result = (char *) xmalloc (length);
+ result[0] = '\0';
+ for (i = 0; i < argc; ++i)
+ {
+ if (i > 0)
+ strcat (result, " ");
+ strcat (result, argv[i]);
+ }
+ }
+
+ return result;
+}
+
/* This function detects whether or not a '&' character (indicating
background execution) has been added as *the last* of the arguments ARGS