Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Antony KING <antony.king@st.com>
To: gdb@sourceware.org
Subject: [GDB 6.8] Problem using watchpoints with compound objects
Date: Tue, 03 Mar 2009 17:39:00 -0000	[thread overview]
Message-ID: <49AD6B30.2010102@st.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1898 bytes --]

I am investigating a problem with H/W watchpoints on compound objects in
GDB 6.8 whereby they are not being set in the target nor are they being
detected as being changed (once the first problem is fixed). Take for
example the following simple application:

int a[4];
int main (void)
{
  a[0] = 1;
  return 0;
}

Problem 1 - watchpoint is not set
---------------------------------

If I issue "watch a" to GDB then GDB reports that it has set a H/W
watchpoint but when I continue the watchpoint is not being set. This I
believe is due to a problem in update_watchpoints() in the following test:

	      if (v == b->val
		  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
		      && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))

The if is unnecessary failing since the test "v == b->val" is not taking
into account that b->val may *not* have been set to v earlier on in the
same function. Looking the CVS head this code has been modified so that
this problem is no longer present. Making a similar change to GDB 6.8
seems to fix the problem (see patch1.txt). Is this solution correct ?

Problem 2 - watchpoint is not detected
--------------------------------------

After applying the patch for problem 1 I then encountered a second
problem where a watchpoint is being erroneously dismissed as being
unchanged. I believe this problem is due to the following test in
watchpoint_check():

      if (!value_equal (b->val, new_val))

This test is only comparing the address of the object and not its
contents. I think the test should be revised to the following:

      if (!value_equal (b->val, new_val)
          || !value_contents_equal (b->val, new_val))

assuming that the value_equal() test is still required (otherwise the
value_equal test could be dropped). Looking at the code in the CVS head
the same issue still seems present. Do you think the above is sufficient
to fix the problem ?

Cheers,

Antony.


[-- Attachment #2: gdb.patch --]
[-- Type: text/plain, Size: 1833 bytes --]

--- breakpoint.c@@/INSIGHT-6.8-ST-2.0	2008-09-11 12:00:00.000000000 +0100
+++ breakpoint.c	2009-03-03 14:20:50.232257000 +0000
@@ -898,7 +898,7 @@ update_watchpoint (struct breakpoint *b,
      is different from out-of-scope watchpoint.  */
   if (within_current_scope && b->exp)
     {
-      struct value *v, *next;
+      struct value *v, *result, *next;
 
       /* Evaluate the expression and make sure it's not lazy, so that
 	 after target stops again, we have a non-lazy previous value
@@ -910,18 +910,18 @@ update_watchpoint (struct breakpoint *b,
 	 In addition, we look at all values which were created
 	 during evaluation, and set watchoints at addresses as needed.
 	 Those values are explicitly deleted here.  */
-      v = evaluate_expression (b->exp);
+      result = evaluate_expression (b->exp);
       /* Avoid setting b->val if it's already set.  The meaning of
 	 b->val is 'the last value' user saw, and we should update
 	 it only if we reported that last value to user.  As it
 	 happens, the code that reports it updates b->val directly.  */
       if (b->val == NULL)
-	b->val = v;
-      value_contents (v);
+	b->val = result;
+      value_contents (result);
       value_release_to_mark (mark);
 
       /* Look at each value on the value chain.  */
-      for (; v; v = next)
+      for (v = result; v; v = next)
 	{
 	  /* If it's a memory location, and GDB actually needed
 	     its contents to evaluate the expression, then we
@@ -934,7 +934,7 @@ update_watchpoint (struct breakpoint *b,
 	      /* We only watch structs and arrays if user asked
 		 for it explicitly, never if they just happen to
 		 appear in the middle of some value chain.  */
-	      if (v == b->val
+	      if (v == result
 		  || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
 		      && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
 		{

             reply	other threads:[~2009-03-03 17:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-03 17:39 Antony KING [this message]
2009-03-03 20:33 ` Daniel Jacobowitz
2009-03-03 21:18   ` Antony KING
2009-03-03 21:46     ` Daniel Jacobowitz
2009-03-04 19:20       ` Antony KING
2009-03-04 19:28         ` Daniel Jacobowitz

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=49AD6B30.2010102@st.com \
    --to=antony.king@st.com \
    --cc=gdb@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