From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30615 invoked by alias); 6 Oct 2002 09:16:36 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 30605 invoked from network); 6 Oct 2002 09:16:35 -0000 Received: from unknown (HELO mail-out2.apple.com) (17.254.0.51) by sources.redhat.com with SMTP; 6 Oct 2002 09:16:35 -0000 Received: from mailgate2.apple.com (A17-129-100-225.apple.com [17.129.100.225]) by mail-out2.apple.com (8.11.3/8.11.3) with ESMTP id g969GYs24617 for ; Sun, 6 Oct 2002 02:16:34 -0700 (PDT) Received: from scv2.apple.com (scv2.apple.com) by mailgate2.apple.com (Content Technologies SMTPRS 4.2.1) with ESMTP id for ; Sun, 6 Oct 2002 02:16:34 -0700 Received: from molly.local. (vpn-scv-x1-10.apple.com [17.219.193.10]) by scv2.apple.com (8.11.3/8.11.3) with ESMTP id g969GXV17685 for ; Sun, 6 Oct 2002 02:16:34 -0700 (PDT) Date: Sun, 06 Oct 2002 02:16:00 -0000 Mime-Version: 1.0 (Apple Message framework v543) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: [PATCH] Compare contents when evaluating an array watchpoint From: Klee Dienes To: gdb-patches@sources.redhat.com Content-Transfer-Encoding: 7bit Message-Id: <51EACEDC-D90C-11D6-9330-00039396EEB8@apple.com> X-SW-Source: 2002-10/txt/msg00157.txt.bz2 The following patch allows one to set watchpoints on arrays, and have the watchpoint triggered if any element in the array changes. Without the patch, the C value_equal semantics causes the address of the array to be checked for change, not the contents --- resulting in a watchpoint that can never be hit. This is particularly useful if one wants to do commands like watch {char[80]} 0xfff0000, or similar, in order to watch an arbitrary region of memory. 2002-08-06 Klee Dienes * breakpoint.c (watchpoint_equal): New function. Like value_equal, but arrays only count as "equal" if they have the same contents. (watchpoint_check): Update to use watchpoint_equal. diff -u -r1.1.1.21 -r1.47 --- breakpoint.c 2002/09/26 20:56:41 1.1.1.21 +++ breakpoint.c 2002/10/06 09:07:23 1.47 @@ -2359,6 +2448,34 @@ return bs; } +/* Like value_equal, but two arrays are only considered equal if their + contents are equal. */ + +static int +watchpoint_equal (struct value *arg1, struct value *arg2) +{ + register int len; + register char *p1, *p2; + + if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY) + && (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_ARRAY)) + { + int len = TYPE_LENGTH (VALUE_TYPE (arg1)); + if (TYPE_LENGTH (VALUE_TYPE (arg1)) != TYPE_LENGTH (VALUE_TYPE (arg2))) + return 0; + p1 = VALUE_CONTENTS (arg1); + p2 = VALUE_CONTENTS (arg2); + while (--len >= 0) + { + if (*p1++ != *p2++) + break; + } + return len < 0; + } + + return value_equal (arg1, arg2); +} + /* Possible return values for watchpoint_check (this can't be an enum because of check_errors). */ /* The watchpoint has been deleted. */ @@ -2417,7 +2535,7 @@ struct value *mark = value_mark (); struct value *new_val = evaluate_expression (bs->breakpoint_at->exp); - if (!value_equal (b->val, new_val)) + if (!watchpoint_equal (b->val, new_val)) { release_value (new_val);