Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: Chris Moller <cmoller@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: [patch]  pr11371 conditional watchpoints with a function in the condition.
Date: Fri, 04 Jun 2010 22:54:00 -0000	[thread overview]
Message-ID: <20100604225405.GA9012@host0.dyn.jankratochvil.net> (raw)
In-Reply-To: <4C0936B5.9080002@redhat.com>

On Fri, 04 Jun 2010 19:24:05 +0200, Chris Moller wrote:
> if the condition associated with a
> watchpoint contained a function call, it resulted in a segfault.

> --- breakpoint.c	13 May 2010 22:44:02 -0000	1.486
> +++ breakpoint.c	2 Jun 2010 19:39:12 -0000
> @@ -1355,7 +1355,10 @@
>    /* We don't free locations.  They are stored in bp_location array and
>       update_global_locations will eventually delete them and remove
>       breakpoints if needed.  */
> -  b->loc = NULL;
> +  
> +  if (b->type != bp_watchpoint && b->type != bp_hardware_watchpoint &&
> +      b->enable_state != bp_call_disabled)
> +    b->loc = NULL;

This change has a regression for:
int a[1000], *p = a;
int
main (void)
{
  int i;
  for (i = 0; i < 100; i++)
    p++;
  return 0;
}

./gdb -nx -ex 'watch *p' -ex r ./pr11371regression
	Watchpoint 1: *p
	Starting program: .../pr11371regression 
	Program exited normally.
->
	Watchpoint 1: *p
	Starting program: .../pr11371regression 
	Warning:
	Could not insert hardware watchpoint 1.
	Could not insert hardware breakpoints:
	You may have requested too many hardware breakpoints/watchpoints.
	(gdb) p i
	$1 = 2

The crash happened due to referencing unallocated memory of a freed
bp_location.  Your patch avoids freeing bp_locations in some cases.  But it is
not correct as these bp_locations become superfluous causing needless hardware
watchpoints.

I believe this `b->loc = NULL' should remain in place, there is more a problem
of bpstat not linked to thread should get cleared its stale bp_location
reference.

I was thinking more about something around the patch below but it does not
work anyway so just posting FYI.  Also maybe on should pre-apply:
	[patch 1/3] Clear stale specific locs, not whole bpts [rediff]
	http://sourceware.org/ml/gdb-patches/2010-05/msg00366.html


BTW the testcase gdb.base/pr11371.exp PASSes for me even on FSF GDB HEAD.


Thanks,
Jan


--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4108,6 +4111,9 @@ bpstat_stop_status (struct address_space *aspace,
 	  /* Print nothing for this entry if we dont stop or dont print.  */
 	  if (bs->stop == 0 || bs->print == 0)
 	    bs->print_it = print_it_noop;
+
+	  if (b->type == bp_hardware_watchpoint)
+	    break;
 	}
     }
 


      parent reply	other threads:[~2010-06-04 22:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-04 17:24 Chris Moller
2010-06-04 20:55 ` Jan Kratochvil
2010-06-04 20:34   ` Chris Moller
2010-06-04 22:54 ` Jan Kratochvil [this message]

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=20100604225405.GA9012@host0.dyn.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=cmoller@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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