From: Andrew Burgess <andrew.burgess@embecosm.com>
To: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC][PATCH 2/2] gdb/breakpoint: add a '-force' flag to the 'condition' command
Date: Mon, 3 Aug 2020 11:28:27 +0100 [thread overview]
Message-ID: <20200803102827.GU853475@embecosm.com> (raw)
In-Reply-To: <94a5e4dc4f144cc0f9c170bdabeec7c0cb4fda4d.1596209606.git.tankut.baris.aktemur@intel.com>
* Tankut Baris Aktemur via Gdb-patches <gdb-patches@sourceware.org> [2020-07-31 17:42:29 +0200]:
> The previous patch made it possible to define a condition if it's
> valid at some locations. If the condition is invalid at all of the
> locations, it's rejected. However, there may be cases where the user
> knows the condition will be valid at a location in the *future*,
> e.g. due to a shared library load.
>
> To make it possible that such condition is defined, this patch
> adds an optional '-force' flag to the 'condition' command. When this
> command is passed, the condition is not rejected even when it is
> invalid for all the current locations (note that all the locations
> would be internally disabled in this case).
>
> For instance:
>
> (gdb) break test.c:5
> Breakpoint 1 at 0x1155: file test.c, line 5.
> (gdb) cond 1 foo == 42
> No symbol "foo" in current context.
>
> Defining the condition was not possible because 'foo' is not
> available. The user can override this behavior with the '-force'
> flag:
>
> (gdb) cond -force 1 foo == 42
> warning: disabling breakpoint 1.1: No symbol "foo" in current context.
> (gdb) info breakpoints
> Num Type Disp Enb Address What
> 1 breakpoint keep y <MULTIPLE>
> stop only if foo == 42
> 1.1 n 0x0000000000001155 in main at test.c:5
>
> Now the condition is accepted, but the location is automatically
> disabled. If a future location has a context in which 'foo' is
> available, that location would be enabled.
>
> This is an RFC. If the idea of having this '-force' flag makes sense,
> I could also work on the same feature for the 'break' command, write
> test cases, and submit as a full patch.
I'd be happy to see the `-force` flag added, I think adding flags like
this makes perfect sense. There's already many flags like this for
the break command so I don't see why adding one more should be a
problem.
I'd be tempted to name the flag for `break` as `-force-condition` to
make it clear what's being forced. The flags already accept unique
sub-strings, so `-force` would still work, plus there's always
tab-completion.
>
> Another potentially interesting approach is to query the user.
> Something along the following idea:
>
> (gdb) cond 1 foo == 42
> Condition expression is invalid at all locations of breakpoint 1.
> Do you want force GDB to nevertheless define the condition, but
> disable the current locations? [y/N] y
> warning: disabling breakpoint 1.1: No symbol "foo" in current context.
>
> This query approach may break some scripts because it is changing the
> existing behavior.
Unless the script is parsing the exact output of GDB this should be a
problem. When GDB is run in an non-interactive manor the default
answer is assumed to prompts like this, so in the above case the user
would still get the `N` behaviour.
But I wouldn't rush to add more interactive prompts to GDB personally.
These are just my thoughts. Others might feel differently.
Thanks,
Andrew
>
> gdb/ChangeLog:
> 2020-07-31 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
>
> * breakpoint.h (set_breakpoint_condition): Add a new bool parameter.
> * breakpoint.c (set_breakpoint_condition): Take a new bool parameter
> to control whether condition definition should be forced even when
> the condition expression is invalid in all of the current locations.
> (condition_command): Update the call to 'set_breakpoint_condition'.
> * ada-lang.c (create_ada_exception_catchpoint): Ditto.
> * guile/scm-breakpoint.c (gdbscm_set_breakpoint_condition_x): Ditto.
> * python/py-breakpoint.c (bppy_set_condition): Ditto.
>
> gdb/doc/ChangeLog:
> 2020-07-31 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
>
> * gdb.texinfo: Document the '-force' flag of the 'condition' command.
> ---
> gdb/ada-lang.c | 2 +-
> gdb/breakpoint.c | 28 ++++++++++++++++++++++------
> gdb/breakpoint.h | 6 ++++--
> gdb/doc/gdb.texinfo | 6 ++++++
> gdb/guile/scm-breakpoint.c | 2 +-
> gdb/python/py-breakpoint.c | 2 +-
> 6 files changed, 35 insertions(+), 11 deletions(-)
>
> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> index 29951528e5e..69b3c3c63cd 100644
> --- a/gdb/ada-lang.c
> +++ b/gdb/ada-lang.c
> @@ -12702,7 +12702,7 @@ create_ada_exception_catchpoint (struct gdbarch *gdbarch,
> c->excep_string = excep_string;
> create_excep_cond_exprs (c.get (), ex_kind);
> if (!cond_string.empty ())
> - set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty);
> + set_breakpoint_condition (c.get (), cond_string.c_str (), from_tty, false);
> install_breakpoint (0, std::move (c), 1);
> }
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index 7abfd510abc..5fe9358b381 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -874,7 +874,7 @@ set_breakpoint_location_condition (const char *cond_string, bp_location *loc,
>
> void
> set_breakpoint_condition (struct breakpoint *b, const char *exp,
> - int from_tty)
> + int from_tty, bool force)
> {
> if (*exp == 0)
> {
> @@ -941,9 +941,11 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
> catch (const gdb_exception_error &e)
> {
> /* Condition string is invalid. If this happens to
> - be the last loc, abandon. */
> + be the last loc, abandon (if not forced) or continue
> + (if forced). */
> if (loc->next == nullptr)
> - throw;
> + if (!force)
> + throw;
> }
> }
>
> @@ -1023,6 +1025,18 @@ condition_command (const char *arg, int from_tty)
> error_no_arg (_("breakpoint number"));
>
> p = arg;
> +
> + /* Check if the "-force" flag was passed. */
> + bool force = false;
> + const char *tok = skip_spaces (p);
> + const char *end_tok = skip_to_space (tok);
> + int toklen = end_tok - tok;
> + if (toklen >= 1 && strncmp (tok, "-force", toklen) == 0)
> + {
> + force = true;
> + p = end_tok + 1;
> + }
> +
> bnum = get_number (&p);
> if (bnum == 0)
> error (_("Bad breakpoint argument: '%s'"), arg);
> @@ -1042,7 +1056,7 @@ condition_command (const char *arg, int from_tty)
> " a %s stop condition defined for this breakpoint."),
> ext_lang_capitalized_name (extlang));
> }
> - set_breakpoint_condition (b, p, from_tty);
> + set_breakpoint_condition (b, p, from_tty, force);
>
> if (is_breakpoint (b))
> update_global_location_list (UGLL_MAY_INSERT);
> @@ -15576,8 +15590,10 @@ then no output is printed when it is hit, except what the commands print."));
>
> c = add_com ("condition", class_breakpoint, condition_command, _("\
> Specify breakpoint number N to break only if COND is true.\n\
> -Usage is `condition N COND', where N is an integer and COND is an\n\
> -expression to be evaluated whenever breakpoint N is reached."));
> +Usage is `condition [-force] N COND', where N is an integer and COND\n\
> +is an expression to be evaluated whenever breakpoint N is reached.\n\
> +With the `-force` flag, the condition is defined even when it is\n\
> +invalid for all current locations."));
> set_cmd_completer (c, condition_completer);
>
> c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\
> diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
> index 145bc8a397a..6acec428a9a 100644
> --- a/gdb/breakpoint.h
> +++ b/gdb/breakpoint.h
> @@ -1617,9 +1617,11 @@ extern int breakpoints_should_be_inserted_now (void);
> in our opinion won't ever trigger. */
> extern void breakpoint_retire_moribund (void);
>
> -/* Set break condition of breakpoint B to EXP. */
> +/* Set break condition of breakpoint B to EXP.
> + If FORCE, define the condition even if it is invalid in
> + all of the breakpoint locations. */
> extern void set_breakpoint_condition (struct breakpoint *b, const char *exp,
> - int from_tty);
> + int from_tty, bool force);
>
> /* Checks if we are catching syscalls or not.
> Returns 0 if not, greater than 0 if we are. */
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 1b9f76573b9..a81689dab21 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -5453,6 +5453,12 @@ prints an error message:
> No symbol "foo" in current context.
> @end smallexample
>
> +@item condition -force @var{bnum} @var{expression}
> +When the @code{-force} flag is used, define the condition even if
> +@var{expression} is invalid in all the current locations of breakpoint
> +@var{bpnum}. This is useful if it is known that @var{expression} will
> +be valid for a future shared library location.
> +
> @noindent
> @value{GDBN} does
> not actually evaluate @var{expression} at the time the @code{condition}
> diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
> index 96b6ca91f8d..7c9707235ec 100644
> --- a/gdb/guile/scm-breakpoint.c
> +++ b/gdb/guile/scm-breakpoint.c
> @@ -905,7 +905,7 @@ gdbscm_set_breakpoint_condition_x (SCM self, SCM newvalue)
> ? nullptr
> : gdbscm_scm_to_c_string (newvalue));
>
> - set_breakpoint_condition (bp_smob->bp, exp ? exp.get () : "", 0);
> + set_breakpoint_condition (bp_smob->bp, exp ? exp.get () : "", 0, false);
>
> return SCM_UNSPECIFIED;
> });
> diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
> index 11345ad3052..56640421994 100644
> --- a/gdb/python/py-breakpoint.c
> +++ b/gdb/python/py-breakpoint.c
> @@ -461,7 +461,7 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
>
> try
> {
> - set_breakpoint_condition (self_bp->bp, exp, 0);
> + set_breakpoint_condition (self_bp->bp, exp, 0, false);
> }
> catch (gdb_exception &ex)
> {
> --
> 2.17.1
>
next prev parent reply other threads:[~2020-08-03 10:28 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 [this message]
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 via Gdb-patches
2020-09-25 16:10 ` Simon Marchi
2020-09-25 18:15 ` Aktemur, Tankut Baris via Gdb-patches
2020-10-13 12:24 ` Aktemur, Tankut Baris via Gdb-patches
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 via Gdb-patches
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 via Gdb-patches
2020-09-25 15:51 ` [PATCH v3 2/2] gdb/breakpoint: add flags to 'condition' and 'break' commands to force condition Tankut Baris Aktemur via Gdb-patches
2020-10-13 12:25 ` [PATCH v4 0/2] Breakpoint conditions at locations with differing contexts Tankut Baris Aktemur via Gdb-patches
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 via Gdb-patches
2020-10-13 15:06 ` Eli Zaretskii via Gdb-patches
2020-10-13 15:17 ` Aktemur, Tankut Baris via Gdb-patches
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 via Gdb-patches
2020-10-13 15:08 ` Eli Zaretskii via Gdb-patches
2020-10-13 15:46 ` Aktemur, Tankut Baris via Gdb-patches
2020-10-13 16:12 ` Eli Zaretskii via Gdb-patches
2020-10-16 22:45 ` Simon Marchi
2020-10-19 13:58 ` Aktemur, Tankut Baris via Gdb-patches
2020-10-19 14:07 ` Simon Marchi
2020-10-27 10:13 ` Aktemur, Tankut Baris via Gdb-patches
2020-10-29 10:10 ` Tom de Vries
2020-10-29 10:30 ` Aktemur, Tankut Baris via Gdb-patches
2020-10-29 17:30 ` Pedro Alves
2020-11-10 19:33 ` Aktemur, Tankut Baris via Gdb-patches
2020-12-05 17:30 ` Pedro Alves
2020-12-10 20:30 ` Tom Tromey
2020-12-15 11:20 ` Aktemur, Tankut Baris via Gdb-patches
2020-11-10 19:51 ` Aktemur, Tankut Baris via Gdb-patches
2020-10-28 16:57 ` [PATCH v4 0/2] Breakpoint conditions at locations with differing contexts Gary Benson via Gdb-patches
2020-10-29 7:43 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-05 17:45 ` [PATCH " Jonah Graham
2021-04-06 14:11 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-06 14:37 ` Jonah Graham
2021-04-07 7:09 ` Aktemur, Tankut Baris via Gdb-patches
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 via Gdb-patches
2021-04-07 14:55 ` [PATCH 1/4] gdb/doc: update the 'enabled' field's description for BP locations in MI Tankut Baris Aktemur via Gdb-patches
2021-04-07 15:15 ` Eli Zaretskii via Gdb-patches
2021-04-07 21:42 ` Simon Marchi via Gdb-patches
2021-04-07 14:55 ` [PATCH 2/4] testsuite, gdb.mi: fix duplicate test names in mi-break.exp Tankut Baris Aktemur via Gdb-patches
2021-04-07 21:49 ` Simon Marchi via Gdb-patches
2021-04-07 14:55 ` [PATCH 3/4] gdb/breakpoint: add a 'force_condition' parameter to 'create_breakpoint' Tankut Baris Aktemur via Gdb-patches
2021-04-07 22:08 ` Simon Marchi via Gdb-patches
2021-04-08 7:44 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-08 13:59 ` Simon Marchi via Gdb-patches
2021-04-08 14:19 ` Aktemur, Tankut Baris via Gdb-patches
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 via Gdb-patches
2021-04-07 15:18 ` Eli Zaretskii via Gdb-patches
2021-04-07 15:27 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-07 15:53 ` Eli Zaretskii via Gdb-patches
2021-04-07 16:05 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-07 16:50 ` Eli Zaretskii via Gdb-patches
2021-04-07 22:26 ` Simon Marchi via Gdb-patches
2021-04-08 14:22 ` [PATCH v2 0/4] Multi-context invalid breakpoint conditions and MI Tankut Baris Aktemur via Gdb-patches
2021-04-08 14:22 ` [PATCH v2 1/4] gdb/breakpoint: display "N" on MI for disabled-by-condition locations Tankut Baris Aktemur via Gdb-patches
2021-04-08 15:04 ` Eli Zaretskii via Gdb-patches
2021-04-08 14:22 ` [PATCH v2 2/4] testsuite, gdb.mi: fix duplicate test names in mi-break.exp Tankut Baris Aktemur via Gdb-patches
2021-04-08 14:22 ` [PATCH v2 3/4] gdb/breakpoint: add a 'force_condition' parameter to 'create_breakpoint' Tankut Baris Aktemur via Gdb-patches
2021-04-08 14:22 ` [PATCH v2 4/4] gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd Tankut Baris Aktemur via Gdb-patches
2021-04-08 15:06 ` Eli Zaretskii via Gdb-patches
2021-04-08 15:12 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-11 1:06 ` Jonah Graham
2021-04-11 1:12 ` Simon Marchi via Gdb-patches
2021-04-21 12:06 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-21 12:36 ` Simon Marchi via Gdb-patches
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 via Gdb-patches
2021-04-21 12:17 ` [PATCH v3 1/4] gdb/breakpoint: display "N" on MI for disabled-by-condition locations Tankut Baris Aktemur via Gdb-patches
2021-04-21 12:48 ` Eli Zaretskii via Gdb-patches
2021-04-21 12:17 ` [PATCH v3 2/4] testsuite, gdb.mi: fix duplicate test names in mi-break.exp Tankut Baris Aktemur via Gdb-patches
2021-04-21 12:17 ` [PATCH v3 3/4] gdb/breakpoint: add a 'force_condition' parameter to 'create_breakpoint' Tankut Baris Aktemur via Gdb-patches
2021-04-21 13:18 ` Simon Marchi via Gdb-patches
2021-04-21 13:29 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-21 14:28 ` Simon Marchi via Gdb-patches
2021-04-21 12:17 ` [PATCH v3 4/4] gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd Tankut Baris Aktemur via Gdb-patches
2021-04-21 12:50 ` Eli Zaretskii via Gdb-patches
2021-04-21 13:37 ` Simon Marchi via Gdb-patches
2021-04-21 13:49 ` Aktemur, Tankut Baris via Gdb-patches
2021-04-21 14:26 ` Simon Marchi via Gdb-patches
2021-04-22 14:35 ` [PATCH v4 0/2] Multi-context invalid breakpoint conditions and MI Tankut Baris Aktemur via Gdb-patches
2021-04-22 14:35 ` [PATCH v4 1/2] gdb/mi: add a '--force-condition' flag to the '-break-insert' cmd Tankut Baris Aktemur via Gdb-patches
2021-05-06 2:40 ` Simon Marchi via Gdb-patches
2021-04-22 14:35 ` [PATCH v4 2/2] gdb/mi: add a '--force' flag to the '-break-condition' command Tankut Baris Aktemur via Gdb-patches
2021-04-22 14:47 ` Aktemur, Tankut Baris via Gdb-patches
2021-05-06 2:46 ` Simon Marchi via Gdb-patches
2021-05-06 8:50 ` Aktemur, Tankut Baris via Gdb-patches
2021-07-11 18:51 ` Jonah Graham
2021-07-12 0:25 ` Jonah Graham
2021-07-12 8:33 ` Aktemur, Tankut Baris via Gdb-patches
2021-05-05 15:57 ` [PATCH v4 0/2] Multi-context invalid breakpoint conditions and MI Aktemur, Tankut Baris via Gdb-patches
2021-04-07 21:24 ` [PATCH 0/2] Breakpoint conditions at locations with differing contexts Simon Marchi via Gdb-patches
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=20200803102827.GU853475@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
--cc=tankut.baris.aktemur@intel.com \
/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