aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-11-02 17:35:14 +0000
committerAndrew Burgess <aburgess@redhat.com>2025-03-18 13:03:07 +0000
commit512ca2fca4b6674d51706d0d7fe21ed72f733fb5 (patch)
tree150acf6f90fb06b0f09477f2edc332d5243bd541 /gdb
parent710f7df7da31dc6b81cdbdd7256005c51798260a (diff)
downloadbinutils-512ca2fca4b6674d51706d0d7fe21ed72f733fb5.zip
binutils-512ca2fca4b6674d51706d0d7fe21ed72f733fb5.tar.gz
binutils-512ca2fca4b6674d51706d0d7fe21ed72f733fb5.tar.bz2
gdb: split up construct_inferior_arguments
The function construct_inferior_arguments (gdbsupport/common-inferior.cc) currently escapes all special shell characters. After this commit there will be two "levels" of quoting: 1. The current "full" quoting, where all posix shell special characters are quoted, and 2. a new "reduced" quoting, where only the characters that GDB sees as special (quotes and whitespace) are quoted. After this, almost all construct_inferior_arguments calls will use the "full" quoting, which is the current quoting. The "reduced" quoting will be used in this commit to restore the behaviour that was lost in the previous commit (more details below). In the future, the reduced quoting will be useful for some additional inferior argument that I have planned. I already posted my full inferior argument work here: https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com But that series is pretty long, and wasn't getting reviewed, so I'm posted the series in parts now. Before the previous commit, GDB behaved like this: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "$FOO". Notice that with 'startup-with-shell' off, the argument was left as just '$FOO'. But after the previous commit, this changed to: $ gdb -eiex 'set startup-with-shell off' --args /tmp/exec '$FOO' (gdb) show args Argument list to give program being debugged when it is started is "\$FOO". Now the '$' is escaped with a backslash. This commit restores the original behaviour, as this is (currently) the only way to unquoted shell special characters into arguments from the GDB command line. The series that I listed above includes a new command line option for GDB which provides a better approach for controlling the quoting of special shell characters, but that work requires these patches to be merged first. I've split out the core of construct_inferior_arguments into the new function escape_characters, which takes a set of characters to escape. Then the two functions escape_shell_characters and escape_gdb_characters call escape_characters with the appropriate character sets. Finally, construct_inferior_arguments, now takes a boolean which indicates if we should perform full shell escaping, or just perform the reduced escaping. I've updated all uses of construct_inferior_arguments to pass a suitable value to indicate what escaping to perform (mostly just 'true', but one case in main.c is different), also I've updated inferior::set_args to take the same boolean flag, and pass it through to construct_inferior_arguments. Tested-By: Guinevere Larsen <guinevere@redhat.com>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/corelow.c2
-rw-r--r--gdb/inferior.c5
-rw-r--r--gdb/inferior.h7
-rw-r--r--gdb/main.c3
-rw-r--r--gdb/python/py-inferior.c2
5 files changed, 12 insertions, 7 deletions
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 4662b5c..567ecd5 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -1174,7 +1174,7 @@ core_target_open (const char *arg, int from_tty)
for (const gdb::unique_xmalloc_ptr<char> &a : ctx.args ())
argv.push_back (a.get ());
gdb::array_view<char * const> view (argv.data (), argv.size ());
- current_inferior ()->set_args (view);
+ current_inferior ()->set_args (view, true);
/* And now copy the environment. */
current_inferior ()->environment = ctx.environment ();
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 67d70c5..6472d49 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -167,9 +167,10 @@ inferior::tty ()
/* See inferior.h. */
void
-inferior::set_args (gdb::array_view<char * const> args)
+inferior::set_args (gdb::array_view<char * const> args,
+ bool escape_shell_char)
{
- set_args (construct_inferior_arguments (args));
+ set_args (construct_inferior_arguments (args, escape_shell_char));
}
void
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 3d9f86c..327a474 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -522,8 +522,11 @@ public:
m_args = std::move (args);
};
- /* Set the argument string from some strings. */
- void set_args (gdb::array_view<char * const> args);
+ /* Set the argument string from some strings in ARGS. When
+ ESCAPE_SHELL_CHAR is true all special shell characters in ARGS are
+ escaped, When false only the characters that GDB sees as special will
+ be escaped. See construct_inferior_arguments for more details. */
+ void set_args (gdb::array_view<char * const> args, bool escape_shell_char);
/* Get the argument string to use when running this inferior.
diff --git a/gdb/main.c b/gdb/main.c
index 27043b7..d126e98 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -1078,7 +1078,8 @@ captured_main_1 (struct captured_main_args *context)
execarg = argv[optind];
++optind;
current_inferior ()->set_args
- (gdb::array_view<char * const> (&argv[optind], argc - optind));
+ (gdb::array_view<char * const> (&argv[optind], argc - optind),
+ startup_with_shell);
}
else
{
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index d11ca9e..356961c 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -929,7 +929,7 @@ infpy_set_args (PyObject *self, PyObject *value, void *closure)
for (const auto &arg : args)
argvec.push_back (arg.get ());
gdb::array_view<char * const> view (argvec.data (), argvec.size ());
- inf->inferior->set_args (view);
+ inf->inferior->set_args (view, true);
}
else
{