public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
To: Pedro Alves <pedro@palves.net>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: "simark@simark.ca" <simark@simark.ca>
Subject: RE: [PATCH v4 2/2] gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition
Date: Tue, 10 Nov 2020 19:33:38 +0000	[thread overview]
Message-ID: <SN6PR11MB2893E685964964948497A5D7C4E90@SN6PR11MB2893.namprd11.prod.outlook.com> (raw)
In-Reply-To: <aa4f7358-55f0-9ba3-c8b4-a2e5c4982a0e@palves.net>

On Thursday, October 29, 2020 6:30 PM, Pedro Alves wrote:
> On 10/13/20 1:25 PM, Tankut Baris Aktemur via Gdb-patches wrote:
> > @@ -9192,10 +9207,25 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
> >        if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
> >  	{
> >  	  tok = cond_start = end_tok + 1;
> > -	  parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
> > +	  try
> > +	    {
> > +	      parse_exp_1 (&tok, pc, block_for_pc (pc), 0);
> > +	    }
> > +	  catch (const gdb_exception_error &)
> > +	    {
> > +	      if (!force)
> > +		throw;
> > +	      else
> > +		tok = tok + strlen (tok);
> > +	    }
> >  	  cond_end = tok;
> >  	  *cond_string = savestring (cond_start, cond_end - cond_start);
> >  	}
> > +      else if (toklen >= 1 && strncmp (tok, "-force-condition", toklen) == 0)
> > +	{
> > +	  tok = cond_start = end_tok + 1;
> > +	  force = true;
> > +	}
> >        else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
> >  	{
> >  	  const char *tmptok;
> 
> Is it important to handle "-force-condition" in this position, as opposed
> to making it another option handled by string_to_explicit_location ?

I have mixed feelings about this.  On one hand, it feels more natural to me that
"-force-condition" belongs to the keywords group (i.e. 'thread', 'task', 'if')
because it's about defining the condition rather than the location.  On the other
hand, I agree that having it start with "-" gives it a flexible option feeling.
We could handle "-force-condition" like an option, but then this would not work:

  (gdb) break main thread 1 -force-condition if foo

Once we start typing keywords (in this case, 'thread'), no more options are expected.
Perhaps making "thread" and "task" also start with "-" and converting them to an
option would improve consistency and flexibility.

> As is, this doesn't work, for example:
> 
>  (gdb) b -function main -force<TAB>

This is a bug.  I propose a patch to fix it.  Please see below.

> 
> nor does:
> 
>  (gdb) b -force-condition main if 0
>  invalid explicit location argument, "-force-condition"

Based on the current implementation, this is expected because 
'-force-condition' is considered a keyword.

> IMO, ideally all '-' options would be handled in the same place.

Like I wrote above, this is a trade-off.  It gives more flexibility but also
brings some limitations.
 
> At some point, I think it would be nice to convert the
> "break" command to use gdb::option, but it isn't trivial.

Converting all keywords except "if" (currently "thread", "task", and "-force-condition")
to '-' options is IMHO a sweet-spot solution here.  It's likely to be easier than
gdb::option, but also improves positional flexibility.  However, backwards compatibility
would be a bit of pain.

Thanks.
-Baris


From 35c23da750cb4aa7fa6a6e1919a180fb13901fda Mon Sep 17 00:00:00 2001
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Date: Tue, 10 Nov 2020 16:09:15 +0100
Subject: [PATCH] gdb/completer: improve tab completion to consider the
 '-force-condition' flag

The commit

  commit 733d554a4625db4ffb89b7a20e1cf27ab071ef4d
  Author: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
  Date:   Tue Oct 27 10:56:03 2020 +0100

  gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition

introduced the '-force-condition' flag to the 'break' command.  This
flag was defined as a keyword like 'thread', 'task', and 'if'.
However, it starts with '-'.  This difference caused an uncovered case
when tab-completing a seemingly complete linespec.

Below, we see "-force-condition" in the completion list, where both
the options and the keywords are listed:

  (gdb) break -function main <TAB>
  -force-condition  -function  -label  -line  -qualified
  -source           if         task    thread

But tab-completing '-' lists only options:

  (gdb) break -function main -<TAB>
  -function   -label      -line       -qualified  -source

This patch fixes the problem by adding keywords to the completion
list, so that we see:

  (gdb) break -function main -<TAB>
  -force-condition  -function  -label  -line  -qualified  -source

gdb/ChangeLog:
2020-11-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* completer.c (complete_explicit_location): Also add keywords
	that start with '-' to the completion list.

gdb/testsuite/ChangeLog:
2020-11-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* gdb.linespec/explicit.exp: Extend with a test to check completing
	'-' after seemingly complete options.
---
 gdb/completer.c                         |  6 +++++-
 gdb/testsuite/gdb.linespec/explicit.exp | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gdb/completer.c b/gdb/completer.c
index 262c8556bf6..cf8c14e7828 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -892,7 +892,11 @@ complete_explicit_location (completion_tracker &tracker,
   int keyword = skip_keyword (tracker, explicit_options, &text);
 
   if (keyword == -1)
-    complete_on_enum (tracker, explicit_options, text, text);
+    {
+      complete_on_enum (tracker, explicit_options, text, text);
+      /* There are keywords that start with "-".   Include them, too.  */
+      complete_on_enum (tracker, linespec_keywords, text, text);
+    }
   else
     {
       /* Completing on value.  */
diff --git a/gdb/testsuite/gdb.linespec/explicit.exp b/gdb/testsuite/gdb.linespec/explicit.exp
index 52a1fce5371..c33ab505e34 100644
--- a/gdb/testsuite/gdb.linespec/explicit.exp
+++ b/gdb/testsuite/gdb.linespec/explicit.exp
@@ -469,6 +469,20 @@ namespace eval $testfile {
 	    }
 	}
 
+	# Test that after a seemingly finished option argument,
+	# completion for "-" matches both the explicit location
+	# options and the linespec keywords that start with "-".
+	with_test_prefix "complete '-' after options" {
+	    test_gdb_complete_multiple "b -function myfunction " "-" "" {
+		"-force-condition"
+		"-function"
+		"-label"
+		"-line"
+		"-qualified"
+		"-source"
+	    }
+	}
+
 	# Tests that ensure that after "if" we complete on expressions
 	# are in cpcompletion.exp.
 
-- 
2.17.1

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

  reply	other threads:[~2020-11-10 19:33 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 15:42 [PATCH 0/2] Breakpoint conditions at locations with differing contexts Tankut Baris Aktemur
     [not found] ` <cover.1596209606.git.tankut.baris.aktemur@intel.com>
2020-07-31 15:42   ` [PATCH 1/2] gdb/breakpoint: disable a bp location if condition is invalid at that location Tankut Baris Aktemur
2020-07-31 15:42   ` [RFC][PATCH 2/2] gdb/breakpoint: add a '-force' flag to the 'condition' command Tankut Baris Aktemur
2020-08-03 10:28     ` Andrew Burgess
2020-08-20 21:24 ` [PATCH v2 0/2] Breakpoint conditions at locations with differing contexts Tankut Baris Aktemur
2020-08-20 21:24   ` [PATCH v2 1/2] gdb/breakpoint: disable a bp location if condition is invalid at that location Tankut Baris Aktemur
2020-09-19  3:05     ` Simon Marchi
2020-09-25 15:49       ` Aktemur, Tankut Baris
2020-09-25 16:10         ` Simon Marchi
2020-09-25 18:15           ` Aktemur, Tankut Baris
2020-10-13 12:24             ` Aktemur, Tankut Baris
2020-08-20 21:24   ` [PATCH v2 2/2] gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition Tankut Baris Aktemur
2020-09-04 11:02   ` [PATCH v2 0/2] Breakpoint conditions at locations with differing contexts Tankut Baris Aktemur
2020-09-11 11:56   ` Tankut Baris Aktemur
2020-09-18 20:36   ` [PING][PATCH " Tankut Baris Aktemur
2020-09-25 15:51 ` [PATCH v3 " Tankut Baris Aktemur
2020-09-25 15:51   ` [PATCH v3 1/2] gdb/breakpoint: disable a bp location if condition is invalid at that location Tankut Baris Aktemur
2020-09-25 15:51   ` [PATCH v3 2/2] gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition Tankut Baris Aktemur
2020-10-13 12:25 ` [PATCH v4 0/2] Breakpoint conditions at locations with differing contexts Tankut Baris Aktemur
2020-10-13 12:25   ` [PATCH v4 1/2] gdb/breakpoint: disable a bp location if condition is invalid at that location Tankut Baris Aktemur
2020-10-13 15:06     ` Eli Zaretskii
2020-10-13 15:17       ` Aktemur, Tankut Baris
2020-10-16 22:20     ` Simon Marchi
2020-10-13 12:25   ` [PATCH v4 2/2] gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition Tankut Baris Aktemur
2020-10-13 15:08     ` Eli Zaretskii
2020-10-13 15:46       ` Aktemur, Tankut Baris
2020-10-13 16:12         ` Eli Zaretskii
2020-10-16 22:45     ` Simon Marchi
2020-10-19 13:58       ` Aktemur, Tankut Baris
2020-10-19 14:07         ` Simon Marchi
2020-10-27 10:13         ` Aktemur, Tankut Baris
2020-10-29 10:10           ` Tom de Vries
2020-10-29 10:30             ` Aktemur, Tankut Baris
2020-10-29 17:30     ` Pedro Alves
2020-11-10 19:33       ` Aktemur, Tankut Baris [this message]
2020-12-05 17:30         ` Pedro Alves
2020-12-10 20:30           ` Tom Tromey
2020-12-15 11:20             ` Aktemur, Tankut Baris
2020-11-10 19:51       ` Aktemur, Tankut Baris
2020-10-28 16:57   ` [PATCH v4 0/2] Breakpoint conditions at locations with differing contexts Gary Benson
2020-10-29  7:43     ` Aktemur, Tankut Baris
2021-04-05 17:45 ` [PATCH " Jonah Graham
2021-04-06 14:11   ` Aktemur, Tankut Baris
2021-04-06 14:37     ` Jonah Graham
2021-04-07  7:09       ` Aktemur, Tankut Baris
2021-04-07 11:26         ` Jonah Graham
2021-04-07 14:55   ` [PATCH 0/4] Multi-context invalid breakpoint conditions and MI Tankut Baris Aktemur
2021-04-07 14:55     ` [PATCH 1/4] gdb/doc: update the 'enabled' field's description for BP locations in MI Tankut Baris Aktemur
2021-04-07 15:15       ` Eli Zaretskii
2021-04-07 21:42       ` Simon Marchi
2021-04-07 14:55     ` [PATCH 2/4] testsuite, gdb.mi: fix duplicate test names in mi-break.exp Tankut Baris Aktemur
2021-04-07 21:49       ` Simon Marchi
2021-04-07 14:55     ` [PATCH 3/4] gdb/breakpoint: add a 'force_condition' parameter to 'create_breakpoint' Tankut Baris Aktemur
2021-04-07 22:08       ` Simon Marchi
2021-04-08  7:44         ` Aktemur, Tankut Baris
2021-04-08 13:59           ` Simon Marchi
2021-04-08 14:19             ` Aktemur, Tankut Baris
2021-04-07 14:55     ` [PATCH 4/4] gdb/mi: add a '-b' flag to the '-break-insert' cmd to force the condition Tankut Baris Aktemur
2021-04-07 15:18       ` Eli Zaretskii
2021-04-07 15:27         ` Aktemur, Tankut Baris
2021-04-07 15:53           ` Eli Zaretskii
2021-04-07 16:05             ` Aktemur, Tankut Baris
2021-04-07 16:50               ` Eli Zaretskii
2021-04-07 22:26       ` Simon Marchi
2021-04-08 14:22     ` [PATCH v2 0/4] Multi-context invalid breakpoint conditions and MI Tankut Baris Aktemur
2021-04-08 14:22       ` [PATCH v2 1/4] gdb/breakpoint: display "N" on MI for disabled-by-condition locations Tankut Baris Aktemur
2021-04-08 15:04         ` Eli Zaretskii
2021-04-08 14:22       ` [PATCH v2 2/4] testsuite, gdb.mi: fix duplicate test names in mi-break.exp Tankut Baris Aktemur
2021-04-08 14:22       ` [PATCH v2 3/4] gdb/breakpoint: add a 'force_condition' parameter to 'create_breakpoint' Tankut Baris Aktemur
2021-04-08 14:22       ` [PATCH v2 4/4] gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd Tankut Baris Aktemur
2021-04-08 15:06         ` Eli Zaretskii
2021-04-08 15:12           ` Aktemur, Tankut Baris
2021-04-11  1:06         ` Jonah Graham
2021-04-11  1:12           ` Simon Marchi
2021-04-21 12:06             ` Aktemur, Tankut Baris
2021-04-21 12:36               ` Simon Marchi
2021-04-11  1:13       ` [PATCH v2 0/4] Multi-context invalid breakpoint conditions and MI Jonah Graham
2021-04-21 12:17       ` [PATCH v3 " Tankut Baris Aktemur
2021-04-21 12:17         ` [PATCH v3 1/4] gdb/breakpoint: display "N" on MI for disabled-by-condition locations Tankut Baris Aktemur
2021-04-21 12:48           ` Eli Zaretskii
2021-04-21 12:17         ` [PATCH v3 2/4] testsuite, gdb.mi: fix duplicate test names in mi-break.exp Tankut Baris Aktemur
2021-04-21 12:17         ` [PATCH v3 3/4] gdb/breakpoint: add a 'force_condition' parameter to 'create_breakpoint' Tankut Baris Aktemur
2021-04-21 13:18           ` Simon Marchi
2021-04-21 13:29             ` Aktemur, Tankut Baris
2021-04-21 14:28               ` Simon Marchi
2021-04-21 12:17         ` [PATCH v3 4/4] gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd Tankut Baris Aktemur
2021-04-21 12:50           ` Eli Zaretskii
2021-04-21 13:37           ` Simon Marchi
2021-04-21 13:49             ` Aktemur, Tankut Baris
2021-04-21 14:26               ` Simon Marchi
2021-04-22 14:35         ` [PATCH v4 0/2] Multi-context invalid breakpoint conditions and MI Tankut Baris Aktemur
2021-04-22 14:35           ` [PATCH v4 1/2] gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd Tankut Baris Aktemur
2021-05-06  2:40             ` Simon Marchi
2021-04-22 14:35           ` [PATCH v4 2/2] gdb/mi: add a '--force' flag to the '-break-condition' command Tankut Baris Aktemur
2021-04-22 14:47             ` Aktemur, Tankut Baris
2021-05-06  2:46             ` Simon Marchi
2021-05-06  8:50               ` Aktemur, Tankut Baris
2021-07-11 18:51               ` Jonah Graham
2021-07-12  0:25                 ` Jonah Graham
2021-07-12  8:33                 ` Aktemur, Tankut Baris
2021-05-05 15:57           ` [PATCH v4 0/2] Multi-context invalid breakpoint conditions and MI Aktemur, Tankut Baris
2021-04-07 21:24   ` [PATCH 0/2] Breakpoint conditions at locations with differing contexts Simon Marchi
2021-04-07 21:36     ` Jonah Graham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SN6PR11MB2893E685964964948497A5D7C4E90@SN6PR11MB2893.namprd11.prod.outlook.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).