public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH][PR <gdb/29784>] Fix: Trailing whitespace omitted when using "with" command
@ 2023-09-20 16:51 Sahil Siddiq
  2023-09-21 19:41 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Sahil Siddiq @ 2023-09-20 16:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sahil Siddiq

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(+)

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;
-- 
2.42.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH][PR <gdb/29784>] Fix: Trailing whitespace omitted when using "with" command
  2023-09-20 16:51 [PATCH][PR <gdb/29784>] Fix: Trailing whitespace omitted when using "with" command Sahil Siddiq
@ 2023-09-21 19:41 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-09-21 19:41 UTC (permalink / raw)
  To: Sahil Siddiq via Gdb-patches; +Cc: Sahil Siddiq

>>>>> "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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-09-21 19:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-20 16:51 [PATCH][PR <gdb/29784>] Fix: Trailing whitespace omitted when using "with" command Sahil Siddiq
2023-09-21 19:41 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).