aarch64, testsuite: Fixed recently added cssc.d
[binutils-gdb.git] / gdbsupport / common-inferior.cc
blob7e1a5b6fa447c21b2a8ae1c8315c965447b7cffb
1 /* Functions to deal with the inferior being executed on GDB or
2 GDBserver.
4 Copyright (C) 2019-2022 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. */
30 std::string
31 construct_inferior_arguments (gdb::array_view<char * const> argv)
33 std::string result;
35 if (startup_with_shell)
37 #ifdef __MINGW32__
38 /* This holds all the characters considered special to the
39 Windows shells. */
40 static const char special[] = "\"!&*|[]{}<>?`~^=;, \t\n";
41 static const char quote = '"';
42 #else
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 = '\'';
48 #endif
49 for (int i = 0; i < argv.size (); ++i)
51 if (i > 0)
52 result += ' ';
54 /* Need to handle empty arguments specially. */
55 if (argv[i][0] == '\0')
57 result += quote;
58 result += quote;
60 else
62 #ifdef __MINGW32__
63 bool quoted = false;
65 if (strpbrk (argv[i], special))
67 quoted = true;
68 result += quote;
70 #endif
71 for (char *cp = argv[i]; *cp; ++cp)
73 if (*cp == '\n')
75 /* A newline cannot be quoted with a backslash (it
76 just disappears), only by putting it inside
77 quotes. */
78 result += quote;
79 result += '\n';
80 result += quote;
82 else
84 #ifdef __MINGW32__
85 if (*cp == quote)
86 #else
87 if (strchr (special, *cp) != NULL)
88 #endif
89 result += '\\';
90 result += *cp;
93 #ifdef __MINGW32__
94 if (quoted)
95 result += quote;
96 #endif
100 else
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, ' ');
107 if (cp == NULL)
108 cp = strchr (arg, '\t');
109 if (cp == NULL)
110 cp = strchr (arg, '\n');
111 if (cp != NULL)
112 error (_("can't handle command-line "
113 "argument containing whitespace"));
116 for (int i = 0; i < argv.size (); ++i)
118 if (i > 0)
119 result += " ";
120 result += argv[i];
124 return result;