[PR,<gdb/29784>] Fix: Trailing whitespace omitted when using "with" command

Message ID 20230920165125.1394193-1-icegambit91@gmail.com
State New
Headers
Series [PR,<gdb/29784>] Fix: Trailing whitespace omitted when using "with" command |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Sahil Siddiq Sept. 20, 2023, 4:51 p.m. UTC
  Consider the following usage of the "complete" command (<SP>
represents a whitespace):

    (gdb) complete set architecture<SP>
    set architecture auto
    set architecture i386
    set architecture i386:intel
    set architecture i386:x64-32
    set architecture i386:x64-32:intel
    set architecture i386:x86-64
    set architecture i386:x86-64:intel
    set architecture i8086

The trailing whitespace is not dropped.

However, using the "with" command alongside "complete" drops the
trailing whitespace.

    (gdb) with max-completions unlimited -- complete set architecture<SP>
    set architecture

The execute_command() function in "gdb/top.c" is responsible for this.
It checks if the command is "complete" or "set". If it isn't, then the
trailing whitespace is cleared.

The syntax of the "with" command is:

    with SETTING [VALUE] [-- COMMAND]

Given that the "with" command is used to temporarily change the value of
a setting before running a specific command, execute_command() should
not clear trailing spaces until it evaluates the COMMAND to be run
following the "--" delimiter.

Changes:
* gdb/top.c (execute_command):
  Fix trailing whitespace omission for "with" command.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29784
Signed-off-by: Sahil Siddiq <icegambit91@gmail.com>
---
 gdb/top.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Tom Tromey Sept. 21, 2023, 7:41 p.m. UTC | #1
>>>>> "Sahil" == Sahil Siddiq via Gdb-patches <gdb-patches@sourceware.org> writes:

Sahil> Consider the following usage of the "complete" command (<SP>
Sahil> represents a whitespace):
[...]

Thank you for the patch.

Sahil> Given that the "with" command is used to temporarily change the value of
Sahil> a setting before running a specific command, execute_command() should
Sahil> not clear trailing spaces until it evaluates the COMMAND to be run
Sahil> following the "--" delimiter.

I agree there's a bug here.

I am not completely sure about the fix.  It seems like it could do the
wrong thing when completing "with" where the "sub-command" is not
"complete".

I think a test case is required as well.  It can probably be added to
some existing test.

Sahil> +	  && strcmp(c->name, "with")

gdb style is a space before the paren and an explicit "!= 0".
Or you can use "!streq".

thanks,
Tom
  

Patch

diff --git a/gdb/top.c b/gdb/top.c
index 2322e55f1db..dbe528d671b 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -525,6 +525,7 @@  execute_command (const char *p, int from_tty)
       std::string without_whitespace;
       if (arg
 	  && c->type != set_cmd
+	  && strcmp(c->name, "with")
 	  && !is_complete_command (c))
 	{
 	  const char *old_end = arg + strlen (arg) - 1;