1 /* Functions to deal with the inferior being executed on GDB or
4 Copyright (C) 2019-2020 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdbsupport/common-defs.h"
22 #include "gdbsupport/common-inferior.h"
24 /* See common-inferior.h. */
26 bool startup_with_shell
= true;
28 /* See common-inferior.h. */
31 construct_inferior_arguments (gdb::array_view
<char * const> argv
)
35 if (startup_with_shell
)
38 /* This holds all the characters considered special to the
40 static const char special
[] = "\"!&*|[]{}<>?`~^=;, \t\n";
41 static const char quote
= '"';
43 /* This holds all the characters considered special to the
44 typical Unix shells. We include `^' because the SunOS
45 /bin/sh treats it as a synonym for `|'. */
46 static const char special
[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
47 static const char quote
= '\'';
49 for (int i
= 0; i
< argv
.size (); ++i
)
54 /* Need to handle empty arguments specially. */
55 if (argv
[i
][0] == '\0')
65 if (strpbrk (argv
[i
], special
))
71 for (char *cp
= argv
[i
]; *cp
; ++cp
)
75 /* A newline cannot be quoted with a backslash (it
76 just disappears), only by putting it inside
87 if (strchr (special
, *cp
) != NULL
)
102 /* In this case we can't handle arguments that contain spaces,
103 tabs, or newlines -- see breakup_args(). */
104 for (char *arg
: argv
)
106 char *cp
= strchr (arg
, ' ');
108 cp
= strchr (arg
, '\t');
110 cp
= strchr (arg
, '\n');
112 error (_("can't handle command-line "
113 "argument containing whitespace"));
116 for (int i
= 0; i
< argv
.size (); ++i
)