public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: Simon Marchi <simark@simark.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2] Fix PR 28308 - dprintf breakpoints not working when run from script
Date: Tue, 9 Nov 2021 20:34:26 -0700	[thread overview]
Message-ID: <20211109203426.0656c9ea@f35-m3> (raw)
In-Reply-To: <fbea6009-2ba2-11fe-3eb8-3eeb32a438bb@simark.ca>

On Fri, 5 Nov 2021 12:05:02 -0400
Simon Marchi <simark@simark.ca> wrote:

>...
> > Yet another thing to be aware of regarding this problem is the
> > difference in the way that commands associated dprintf breakpoints  
> 
> associated *to* dprintf breakpoints

Fixed.

[...]

> Not really related to your patch, but reading your patch made me wonder
> if it's really necessary to implement dprintfs using pre-generated
> command lines.  It just looks like a lot of unnecessary layers (one of
> which you removed, calling bpstat_do_actions_1) that are hard to follow.
> Couldn't we just do the necessary actions in
> dprintf_after_condition_true based on the current settings?  Not by
> building strings of GDB commands and evaluating them, but just with
> regular C++ code?

Another way of implementing it would have been to associate three
commands with a dprintf breakpoint:

  quiet
  printf ...  / call (void) printf (...) / agent-print ...
  continue

This is basically what you'd use as a breakpoint command list if GDB
didn't have the dprintf facility.  The virtue of this approach is that
it could use the existing breakpoint w/ associated command logic
without having to introduce some of the stuff that's only used by the
dprintf mechanism.  This current bug either wouldn't have happened or,
if it did, would have affected the rest of the breakpoint/command
functionality as well.

I think it's probable that this approach (that I'm suggesting) was
considered but was found lacking in some way.  If so, I'd guess that
either there's some major "gotcha" which I have considered or else
it's too slow.

> > ---
> >  gdb/breakpoint.c | 13 ++++---------
> >  1 file changed, 4 insertions(+), 9 deletions(-)
> >
> > diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> > index 10b28c97be7..0ca3995894e 100644
> > --- a/gdb/breakpoint.c
> > +++ b/gdb/breakpoint.c
> > @@ -13029,9 +13029,6 @@ dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp)
> >  static void
> >  dprintf_after_condition_true (struct bpstats *bs)
> >  {
> > -  struct bpstats tmp_bs;
> > -  struct bpstats *tmp_bs_p = &tmp_bs;
> > -
> >    /* dprintf's never cause a stop.  This wasn't set in the
> >       check_status hook instead because that would make the dprintf's
> >       condition not be evaluated.  */
> > @@ -13042,14 +13039,12 @@ dprintf_after_condition_true (struct bpstats *bs)
> >       bpstat_do_actions, if a breakpoint that causes a stop happens to
> >       be set at same address as this dprintf, or even if running the
> >       commands here throws.  */
> > -  tmp_bs.commands = bs->commands;
> > +  struct command_line *cmds = (bs->commands == NULL)
> > +                            ? NULL
> > +			    : bs->commands.get ();
> >    bs->commands = NULL;
> >
> > -  bpstat_do_actions_1 (&tmp_bs_p);
> > -
> > -  /* 'tmp_bs.commands' will usually be NULL by now, but
> > -     bpstat_do_actions_1 may return early without processing the whole
> > -     list.  */
> > +  execute_control_commands (cmds, 0);  
> 
> Given that bs->commands (the counted_command_line type, actually) is a
> shared pointer, this would be more straightforward, and make it clear
> that we steal the ownership of the commands, as the comment explains:
> 
>   counted_command_line cmds = std::move (bs->commands);
>   gdb_assert (cmds != nullptr);
>   execute_control_commands (cmds.get (), 0);
> 
> 
> I put a gdb_assert in there, because from my understanding there will
> always be at least one command in a dprintf.  But if that's not true,
> then it should be a condition.

I've made this change too.

I've pushed this commit along with the commit for the new tests.

Thanks for the review!

Kevin


  reply	other threads:[~2021-11-10  3:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-02  1:00 [PATCH 0/2] " Kevin Buettner
2021-10-02  1:00 ` [PATCH 1/2] " Kevin Buettner
2021-11-05 16:05   ` Simon Marchi
2021-11-10  3:34     ` Kevin Buettner [this message]
2021-11-16 20:18       ` Tom Tromey
2021-11-18 18:34         ` Kevin Buettner
2021-10-02  1:00 ` [PATCH 2/2] Test case for Bug 28308 Kevin Buettner
2021-11-05 16:21   ` Simon Marchi
2021-11-10  1:44     ` Kevin Buettner
2021-11-18 22:46       ` Kevin Buettner
2021-10-19  9:30 ` [PATCH 0/2] Fix PR 28308 - dprintf breakpoints not working when run from script Kevin Buettner
2021-11-02 19:09 ` Kevin Buettner

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=20211109203426.0656c9ea@f35-m3 \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --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).