1 /* Functions to deal with the inferior being executed on GDB or
4 Copyright (C) 2019-2024 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-inferior.h"
23 /* See common-inferior.h. */
25 bool startup_with_shell
= true;
27 /* See common-inferior.h. */
30 construct_inferior_arguments (gdb::array_view
<char * const> argv
)
34 if (startup_with_shell
)
37 /* This holds all the characters considered special to the
39 static const char special
[] = "\"!&*|[]{}<>?`~^=;, \t\n";
40 static const char quote
= '"';
42 /* This holds all the characters considered special to the
43 typical Unix shells. We include `^' because the SunOS
44 /bin/sh treats it as a synonym for `|'. */
45 static const char special
[] = "\"!#$&*()\\|[]{}<>?'`~^; \t\n";
46 static const char quote
= '\'';
48 for (int i
= 0; i
< argv
.size (); ++i
)
53 /* Need to handle empty arguments specially. */
54 if (argv
[i
][0] == '\0')
64 if (strpbrk (argv
[i
], special
))
70 for (char *cp
= argv
[i
]; *cp
; ++cp
)
74 /* A newline cannot be quoted with a backslash (it
75 just disappears), only by putting it inside
86 if (strchr (special
, *cp
) != NULL
)
101 /* In this case we can't handle arguments that contain spaces,
102 tabs, or newlines -- see breakup_args(). */
103 for (char *arg
: argv
)
105 char *cp
= strchr (arg
, ' ');
107 cp
= strchr (arg
, '\t');
109 cp
= strchr (arg
, '\n');
111 error (_("can't handle command-line "
112 "argument containing whitespace"));
115 for (int i
= 0; i
< argv
.size (); ++i
)