mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-12-19 01:19:41 +08:00
With the quoted filename completion work that I did last year the deprecated_filename_completer function will now only complete a single word as a filename, for example: (gdb) save breakpoints /tm<TAB> The 'save breakpoints' command uses the deprecated_filename_completer completion function. In the above '/tm' will complete to '/tmp/' as expected. However, if you try this: (gdb) save breakpoints /tmp/ /tm<TAB> The second '/tm' will not complete for GDB 16.x, but will complete with GDB 15.x as GDB 15.x is before my changes were merged. What's actually happening here is that, before my changes, the filename completion was breaking words on white space, so in the above the first '/tmp/' and the second '/tm' are seen as separate words for completion, the second word is therefore seen as the start of a new filename. After my changes, deprecated_filename_completer allows spaces to be part of the filename, so in the above, GDB is actually trying to complete a filename '/tmp/ /tm' which likely doesn't exist, and so completion stops. This change for how deprecated_filename_completer works makes sense, commands like 'save breakpoints' take their complete command arguments and treat it as a single filename, so given this: (gdb) save breakpoints /tmp/ /tm<ENTER> GDB really will try to save breakpoints to a file called '/tmp/ /tm', weird as that may seem. How GDB interprets the command arguments didn't change with my completion patches, I simply brought completion into line with how GDB interprets the arguments. The patches I'm talking about here are this set: *4076f962e8gdb: split apart two different types of filename completion *dc22ab49e9gdb: deprecated filename_completer and associated functions *3503687591gdb: improve escaping when completing filenames *1d1df75397gdb: move display of completion results into completion_result class *bbbfe4af4fgdb: simplify completion_result::print_matches *2bebc9ee27gdb: add match formatter mechanism for 'complete' command output *f2f866c6cagdb: apply escaping to filenames in 'complete' results *8f87fcb1dagdb: improve gdb_rl_find_completion_word for quoted words *67b8e30af9gdb: implement readline rl_directory_rewrite_hook callback *1be3b2e82fgdb: extend completion of quoted filenames to work in brkchars phase *9dedc2ac71gdb: fix for completing a second filename for a command *4339a3ffc3gdb: fix filename completion in the middle of a line Bug PR gdb/32982 identifies a problem with the shell command; completion broke between 15.x and 16.x. The shell command also uses deprecated_filename_completer for completion. But consider a shell command line: (gdb) shell ls /tm<TAB> The arguments to the shell command are 'ls /tm' at the point <TAB> is pressed. Under the old 15.x completion GDB would split the words on white space and then try to complete '/tm' as a filename. Under the 16.x model, GDB completes all the arguments as a single filename, that is 'ls /tm', which is unlikely to match any filenames, and so completion fails. The fix is to write a custom completion function for the shell_command function (cli/cli-cmds.c), this custom completion function will skip forward to find the last word in the arguments, and then try to complete that, so in the above example, GDB will skip over 'ls ', and then tries to complete '/tm', which is exactly what we want. Given that the filenames passed to the shell command are forwarded to an actual shell, I have switched over the new quoted filename completion function for the shell command, this means that white space within a filename will be escaped with a backslash by the completion function, which is likely what the user wants, this means the filename will arrive in the (actual) shell as a single word, rather than splitting on white space and arriving as two words. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32982 Reviewed-By: Tom Tromey <tom@tromey.com>