aboutsummaryrefslogtreecommitdiff
path: root/gdb/fork-child.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2003-05-08 18:08:57 +0000
committerJoel Brobecker <brobecker@gnat.com>2003-05-08 18:08:57 +0000
commit6037b8306e768248d2a00de918bfb953fa9d8b24 (patch)
tree343e6a422b38cad1ba66ae3c612b8e41cd85c78d /gdb/fork-child.c
parent5d62c8b152e352241b4a904e77f8a74a98d64b80 (diff)
downloadgdb-6037b8306e768248d2a00de918bfb953fa9d8b24.zip
gdb-6037b8306e768248d2a00de918bfb953fa9d8b24.tar.gz
gdb-6037b8306e768248d2a00de918bfb953fa9d8b24.tar.bz2
* fork-child.c (escape_bang_in_quoted_argument): New function.
(fork_inferior): Escape '!' characters in quoted arguments only when needed.
Diffstat (limited to 'gdb/fork-child.c')
-rw-r--r--gdb/fork-child.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/gdb/fork-child.c b/gdb/fork-child.c
index 738898a..e1d32b0 100644
--- a/gdb/fork-child.c
+++ b/gdb/fork-child.c
@@ -88,6 +88,29 @@ breakup_args (char *scratch, char **argv)
}
+/* When executing a command under the given shell, return non-zero
+ if the '!' character should be escaped when embedded in a quoted
+ command-line argument. */
+
+static int
+escape_bang_in_quoted_argument (const char *shell_file)
+{
+ const int shell_file_len = strlen (shell_file);
+
+ /* Bang should be escaped only in C Shells. For now, simply check
+ that the shell name ends with 'csh', which covers at least csh
+ and tcsh. This should be good enough for now. */
+
+ if (shell_file_len < 3)
+ return 0;
+
+ if (shell_file[shell_file_len - 3] == 'c'
+ && shell_file[shell_file_len - 2] == 's'
+ && shell_file[shell_file_len - 1] == 'h')
+ return 1;
+
+ return 0;
+}
/* Start an inferior Unix child process and sets inferior_ptid to its pid.
EXEC_FILE is the file to run.
@@ -171,6 +194,7 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
char *p;
int need_to_quote;
+ const int escape_bang = escape_bang_in_quoted_argument (shell_file);
strcat (shell_command, "exec ");
@@ -215,7 +239,7 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
{
if (*p == '\'')
strcat (shell_command, "'\\''");
- else if (*p == '!')
+ else if (*p == '!' && escape_bang)
strcat (shell_command, "\\!");
else
strncat (shell_command, p, 1);