From 552c04a7423afb694bd4948e8896b3c4cc4be816 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 22 Nov 2001 00:23:13 +0000 Subject: Fix for PR gdb/209, PR gdb/156: * gdbarch.c, gdbarch.h: Rebuilt. * gdbarch.sh: Added `construct_inferior_arguments'. * cli/cli-decode.h (cmd_list_element): Added pre_show_hook. Typo fix. * cli/cli-setshow.c (do_setshow_command): Call the pre_show_hook. * infcmd.c (_initialize_infcmd): Set sfunc on `set args' command. (inferior_argc, inferior_argv): New globals. (notice_args_set): New function. (set_inferior_args): Clear inferior_argc and inferior_argv. (set_inferior_args_vector): New function. (get_inferior_args): Handle inferior argument vector. (run_command): Use get_inferior_args(). (notice_args_read): New function. (_initialize_infcmd): Don't call set_inferior_args. * command.h: Typo fix. (cmd_list_element): Added pre_show_hook. * main.c (captured_main): Added --args option. (print_gdb_help): Document --args. * inferior.h (construct_inferior_arguments): Declare. (set_inferior_args_vector): Likewise. * fork-child.c (construct_inferior_arguments): New function. --- gdb/fork-child.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'gdb/fork-child.c') diff --git a/gdb/fork-child.c b/gdb/fork-child.c index 21e508939b6..24cd00a5b1d 100644 --- a/gdb/fork-child.c +++ b/gdb/fork-child.c @@ -568,3 +568,74 @@ startup_inferior (int ntraps) #endif /* STARTUP_INFERIOR */ stop_soon_quietly = 0; } + +/* 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; +} -- cgit v1.2.1