PR breakpoints/15697: Remove =breakpoint-modified when hitting dprintf

Message ID 1398716623-16991-1-git-send-email-marc.khouzam@ericsson.com
State Changes Requested, archived
Headers

Commit Message

Marc Khouzam April 28, 2014, 8:23 p.m. UTC
  GDB currently sends a =breakpoint-modified for every dprintf hit.
This can cause performance degradation at the frontend.  The below
patch prevents GDB from sending this event for dprintf when the
event is triggered by the dprintf being hit.  This means the event
is not sent when the hit-count is incremented or the ignore-count
is decremented due to a hit.

https://sourceware.org/bugzilla/show_bug.cgi?id=15697

This was discussed last year:
http://sourceware.org/ml/gdb-patches/2013-03/msg00260.html

No regressions.

Ok?

Thanks

Marc

---

DPrintfs can be hit very often since they don't interrupt
the execution.  Having a =breakpoint-modified event at
every hit can cause performance degradation at the
frontend.  The only value in this event is to indicate that
the hit-count has changed.  For the hit-count value however,
it is sufficient for a frontend to get the latest value upon
request and not through an asynchronous event.

We also remove =breakpoint-modified when hitting a dprintf
and decrementing the ignore count.  If the ignore count is
set to a high number, the =breakpoint-modified could also
cause performance degradation as it will be sent at every
dprintf hit which decrements the ignore count.

2014-04-28  Marc Khouzam  <marc.khouzam@ericsson.com>

	PR breakpoints/15697
	* breakpoint.c (bpstat_check_breakpoint_conditions):
	Don't call observer_notify_breakpoint_modified for dprintf.
	* breakpoint.c (bpstat_stop_status): Ditto.
---
 gdb/breakpoint.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Doug Evans April 28, 2014, 10:06 p.m. UTC | #1
On Mon, Apr 28, 2014 at 1:23 PM, Marc Khouzam <marc.khouzam@ericsson.com> wrote:
> GDB currently sends a =breakpoint-modified for every dprintf hit.
> This can cause performance degradation at the frontend.  The below
> patch prevents GDB from sending this event for dprintf when the
> event is triggered by the dprintf being hit.  This means the event
> is not sent when the hit-count is incremented or the ignore-count
> is decremented due to a hit.
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=15697
>
> This was discussed last year:
> http://sourceware.org/ml/gdb-patches/2013-03/msg00260.html
>
> No regressions.
>
> Ok?
>
> Thanks
>
> Marc
>
> ---
>
> DPrintfs can be hit very often since they don't interrupt
> the execution.  Having a =breakpoint-modified event at
> every hit can cause performance degradation at the
> frontend.  The only value in this event is to indicate that
> the hit-count has changed.  For the hit-count value however,
> it is sufficient for a frontend to get the latest value upon
> request and not through an asynchronous event.
>
> We also remove =breakpoint-modified when hitting a dprintf
> and decrementing the ignore count.  If the ignore count is
> set to a high number, the =breakpoint-modified could also
> cause performance degradation as it will be sent at every
> dprintf hit which decrements the ignore count.
>
> 2014-04-28  Marc Khouzam  <marc.khouzam@ericsson.com>
>
>         PR breakpoints/15697
>         * breakpoint.c (bpstat_check_breakpoint_conditions):
>         Don't call observer_notify_breakpoint_modified for dprintf.
>         * breakpoint.c (bpstat_stop_status): Ditto.

Nit. No need to write "* breakpoint.c" twice.

> ---
>  gdb/breakpoint.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index f422998..25615eb 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -5378,7 +5378,8 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
>        bs->stop = 0;
>        /* Increase the hit count even though we don't stop.  */
>        ++(b->hit_count);
> -      observer_notify_breakpoint_modified (b);
> +      if (b->type != bp_dprintf)
> +       observer_notify_breakpoint_modified (b);
>      }
>  }
>
> @@ -5515,7 +5516,8 @@ bpstat_stop_status (struct address_space *aspace,
>           if (bs->stop)
>             {
>               ++(b->hit_count);
> -             observer_notify_breakpoint_modified (b);
> +             if (b->type != bp_dprintf)
> +               observer_notify_breakpoint_modified (b);
>
>               /* We will stop here.  */
>               if (b->disposition == disp_disable)
> --
> 1.7.9.5
>

Hi.
I've read the mentioned thread and I agree with your analysis.
The patch is ok with me, but give it a few days for others to comment.

Adding a comment explaining why the test is present might be useful,
but I'm ok with skipping it.
E.g., something like
  /* Don't send notifications for dprintf, there can be a lot and aren't useful
     to frontends.  */
  
Pedro Alves April 29, 2014, 5 p.m. UTC | #2
On 04/28/2014 09:23 PM, Marc Khouzam wrote:
> GDB currently sends a =breakpoint-modified for every dprintf hit.
> This can cause performance degradation at the frontend.  The below
> patch prevents GDB from sending this event for dprintf when the
> event is triggered by the dprintf being hit.  This means the event
> is not sent when the hit-count is incremented or the ignore-count
> is decremented due to a hit.
> 
> https://sourceware.org/bugzilla/show_bug.cgi?id=15697
> 
> This was discussed last year:
> http://sourceware.org/ml/gdb-patches/2013-03/msg00260.html
> 
> No regressions.
> 
> Ok?
> 
> Thanks
> 
> Marc
> 
> ---
> 
> DPrintfs can be hit very often since they don't interrupt
> the execution.  Having a =breakpoint-modified event at
> every hit can cause performance degradation at the
> frontend.  The only value in this event is to indicate that
> the hit-count has changed.  For the hit-count value however,
> it is sufficient for a frontend to get the latest value upon
> request and not through an asynchronous event.
> 
> We also remove =breakpoint-modified when hitting a dprintf
> and decrementing the ignore count.  If the ignore count is
> set to a high number, the =breakpoint-modified could also
> cause performance degradation as it will be sent at every
> dprintf hit which decrements the ignore count.
> 
> 2014-04-28  Marc Khouzam  <marc.khouzam@ericsson.com>
> 
> 	PR breakpoints/15697
> 	* breakpoint.c (bpstat_check_breakpoint_conditions):
> 	Don't call observer_notify_breakpoint_modified for dprintf.
> 	* breakpoint.c (bpstat_stop_status): Ditto.
> ---
>  gdb/breakpoint.c |    6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index f422998..25615eb 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -5378,7 +5378,8 @@ bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
>        bs->stop = 0;
>        /* Increase the hit count even though we don't stop.  */
>        ++(b->hit_count);
> -      observer_notify_breakpoint_modified (b);
> +      if (b->type != bp_dprintf)
> +	observer_notify_breakpoint_modified (b);

Sorry to be a naysayer, but I don't think treating dprintf
any different from other breakpoints here is a good idea.

You get the exact same flood with setting an ignore count
an any breakpoint whose condition evaluates false.  The
simplest being "break foo if 0".

So we get to apply some kind of treatment to all kinds of
breakpoints, or to none.

> @@ -5515,7 +5516,8 @@ bpstat_stop_status (struct address_space *aspace,
>  	  if (bs->stop)
>  	    {
>  	      ++(b->hit_count);
> -	      observer_notify_breakpoint_modified (b);
> +	      if (b->type != bp_dprintf)
> +		observer_notify_breakpoint_modified (b);

This one is tricker -- at first blush, this looks odd -- bs->stop
is set, so this path would seem to mean we're stopping.
If one emulates dprintfs with "b foo if return_false ()", we notice
that that breakpoints doesn't get its hit count incremented,
even though internally GDB sees the breakpoints hits trigger.
But in the dprintfs case, we get here with bs->stop set, we
increment the hit_count, and then a bit below, we call
after_condition_true:

	  if (bs->stop)
	    {
	      ++(b->hit_count);
	      observer_notify_breakpoint_modified (b);

	      /* We will stop here.  */
...
	      b->ops->after_condition_true (bs);


and dprintf's implementation has:

static void
dprintf_after_condition_true (struct bpstats *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.  */
  bs->stop = 0;


This has the effect that "b foo if return_false()" doesn't
result in the hit incrementing, while it does get incremented
for dprintfs:

(gdb) info breakpoints
Num     Type           Disp Enb Address            What
4       dprintf        keep y   0x00000000004007b7 in thread_function0 at threads.c:63
        breakpoint already hit 1329 times
        printf "asdf"
5       breakpoint     keep y   0x00000000004007b7 in thread_function0 at threads.c:63
        stop only if return_false ()


I suppose that the hit count incrementing for dprintfs does
make sense.  So this change here would need at least a comment
explaining why dprintfs are special here.

But even ignoring the comments above, this change here isn't
right because just below we have:

	  if (bs->stop)
	    {
	      ++(b->hit_count);
	      observer_notify_breakpoint_modified (b);

	      /* We will stop here.  */
	      if (b->disposition == disp_disable)
		{
		  --(b->enable_count);
		  if (b->enable_count <= 0
		      && b->enable_state != bp_permanent)
		    b->enable_state = bp_disabled;
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		  removed_any = 1;
		}


so if the user sets an enable count on a dprintf-style gdb dprintf,
we lose the MI notification when the dprintf ends up disabled.
Is that OK?  And if OK for dprintfs, why not for other kinds of
breakpoints?

I'm not sure I agree that "it is sufficient for a frontend
to get the latest value upon request and not through an
asynchronous event.".  Completely disabling this notification
means that the frontend gets no notification when the
enable or ignore counts are reached.  Not sure that's disirable.

Also when you have another breakpoint set at the same address, that
does cause a stop, the frontend has no clue that the dprintf hit
counts changed -- basically you're saying that for dprintfs,
frontends _always_ need to refresh the info from gdb after a stop.
This at least needs a documentation update.  To avoid that, GDB could
store the last hit count value it reported to the frontend, and delay
sending the breakpoint changed notification to when it tells the
frontend about a stop.

I mildly wonder also whether a different frontend might have
different preferences here.

Related, I'm not sure we should filter the
observer_notify_breakpoint_modified call -- it would seem
better if observers are notified, and the its MI that filters
out those modifications that it isn't interested in.
E.g., could TUI be interested in still receiving the nofications?
Maybe we should split the notification in two (modified /
counters-modified).

I don't have answers to the above, but I think these issues
all need to be considered, and whatever resolutions we end up
with need to be cast as comments in the code and manual.

Thanks,
  
Marc Khouzam April 29, 2014, 5:47 p.m. UTC | #3
> -----Original Message-----
> From: Pedro Alves [mailto:palves@redhat.com]
> Sent: Tuesday, April 29, 2014 1:01 PM
> To: Marc Khouzam
> Cc: gdb-patches@sourceware.org
> Subject: Re: [PATCH] PR breakpoints/15697: Remove =breakpoint-modified
> when hitting dprintf

[Bunch of very valid concerns]

> Related, I'm not sure we should filter the
> observer_notify_breakpoint_modified call -- it would seem better if
> observers are notified, and the its MI that filters out those modifications that
> it isn't interested in.
> E.g., could TUI be interested in still receiving the nofications?

Something to think about.  Simon made the same comment off-line.

> I don't have answers to the above, but I think these issues all need to be
> considered, and whatever resolutions we end up with need to be cast as
> comments in the code and manual.

Thanks Pedro, you are bringing up valid (and tricky :-)) points.  I'll look into them
and see if I can come up with equally valid solutions.

Marc
  
Marc Khouzam May 20, 2014, 7:45 p.m. UTC | #4
> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Marc Khouzam
> Sent: Tuesday, April 29, 2014 1:48 PM
> To: 'Pedro Alves'
> Cc: 'gdb-patches@sourceware.org'
> Subject: RE: [PATCH] PR breakpoints/15697: Remove =breakpoint-modified
> when hitting dprintf
> 
> > -----Original Message-----
> > From: Pedro Alves [mailto:palves@redhat.com]
> > Sent: Tuesday, April 29, 2014 1:01 PM
> > To: Marc Khouzam
> > Cc: gdb-patches@sourceware.org
> > Subject: Re: [PATCH] PR breakpoints/15697: Remove =breakpoint-modified
> > when hitting dprintf
> 
> [Bunch of very valid concerns]
> 
> > Related, I'm not sure we should filter the
> > observer_notify_breakpoint_modified call -- it would seem better if
> > observers are notified, and the its MI that filters out those
> > modifications that it isn't interested in.
> > E.g., could TUI be interested in still receiving the nofications?
> 
> Something to think about.  Simon made the same comment off-line.
> 
> > I don't have answers to the above, but I think these issues all need
> > to be considered, and whatever resolutions we end up with need to be
> > cast as comments in the code and manual.
> 
> Thanks Pedro, you are bringing up valid (and tricky :-)) points.  I'll look into
> them and see if I can come up with equally valid solutions.

To follow up on this.  After discussing with Pedro offline, he helped point-out
that the many =breakpoint-modified notifications were not actually causing
any problems to Eclipse.  The issue was actually in the corresponding extra
*running event.

Pedro has already followed-up on a fix for the *running event here (thanks!):
https://sourceware.org/ml/gdb-patches/2014-05/msg00273.html

And I'm dropping this patch, as it is not helpful.

Thanks

Marc
  

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f422998..25615eb 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5378,7 +5378,8 @@  bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid)
       bs->stop = 0;
       /* Increase the hit count even though we don't stop.  */
       ++(b->hit_count);
-      observer_notify_breakpoint_modified (b);
+      if (b->type != bp_dprintf)
+	observer_notify_breakpoint_modified (b);
     }	
 }
 
@@ -5515,7 +5516,8 @@  bpstat_stop_status (struct address_space *aspace,
 	  if (bs->stop)
 	    {
 	      ++(b->hit_count);
-	      observer_notify_breakpoint_modified (b);
+	      if (b->type != bp_dprintf)
+		observer_notify_breakpoint_modified (b);
 
 	      /* We will stop here.  */
 	      if (b->disposition == disp_disable)