gdb: 'target ...' commands now expect quoted/escaped filenames

This commit changes the 'target ...' commands that accept a filename
to take a quoted or escaped filename rather than a literal filename.

What this means in practice is that if you are specifying a filename
that contains no white space or quote characters, then nothing should
change, e.g.:

  target exec /path/to/some/file

works both before and after this commit.

However, if a user wishes to specify a file containing white space
then either the entire filename needs to be quoted, or the special
white space needs to be escaped.  Before this patch a user could
write:

  target exec /path/to a file/containing spaces

But after this commit the user would have to choose one of:

  target exec "/path/to a file/containing spaces"

or

  target exec /path/to\ a\ file/containing\ spaces

Obviously this is a potentially breaking change.  The benefit of
making this change is consistency.  Commands that take multiple
arguments (one of which is a filename) or in the future, commands that
take filename options, will always need to use quoted/escaped
filenames, so converting all unquoted filename commands to use quoting
or escaping makes the UI more consistent.

Additionally (though this is probably not a common problem), GDB
strips trailing white space from commands that the user enters.  As
such it is not possible to reference any file that ends in white space
unless the quoting / escaping style is used.  Though I suspect very
few users run into this problem!

The downside obviously is that this is a UI breaking change.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
Andrew Burgess
2024-06-19 11:14:08 +01:00
parent e454ae416a
commit 03ad29c86c
8 changed files with 48 additions and 30 deletions

View File

@@ -143,7 +143,10 @@ static void
exec_target_open (const char *args, int from_tty)
{
target_preopen (from_tty);
exec_file_attach (args, from_tty);
std::string filename = extract_single_filename_arg (args);
exec_file_attach (filename.empty () ? nullptr : filename.c_str (),
from_tty);
}
/* This is the target_close implementation. Clears all target
@@ -1120,5 +1123,5 @@ will be loaded as well."),
&setlist, &showlist);
add_target (exec_target_info, exec_target_open,
deprecated_filename_completer);
filename_maybe_quoted_completer);
}