From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7189 invoked by alias); 15 Feb 2011 18:28:49 -0000 Received: (qmail 7181 invoked by uid 22791); 15 Feb 2011 18:28:48 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 15 Feb 2011 18:28:43 +0000 Received: (qmail 7553 invoked from network); 15 Feb 2011 18:28:41 -0000 Received: from unknown (HELO scottsdale.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Feb 2011 18:28:41 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [unavailable values part 1, 06/17] array element repeats, confused with 0. Date: Tue, 15 Feb 2011 18:34:00 -0000 User-Agent: KMail/1.13.5 (Linux/2.6.35-25-generic; KDE/4.6.0; x86_64; ; ) Cc: Jan Kratochvil References: <201102071430.49735.pedro@codesourcery.com> <20110214120015.GF2454@host1.dyn.jankratochvil.net> In-Reply-To: <20110214120015.GF2454@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201102151828.36004.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-02/txt/msg00330.txt.bz2 On Monday 14 February 2011 12:00:16, Jan Kratochvil wrote: > > --- src.orig/gdb/value.h 2011-02-07 11:15:02.926705996 +0000 > > +++ src/gdb/value.h 2011-02-07 11:15:23.176706001 +0000 > > @@ -374,6 +374,31 @@ extern int value_bytes_available (const > > extern void mark_value_bytes_unavailable (struct value *value, > > int offset, int length); > > > > +/* Compare LENGTH bytes of VAL1's contents starting at OFFSET1 with > > + LENGTH bytes of VAL2's contents starting at OFFSET2. Returns true > > /* OFFSET1 and OFFSET2 should include possible EMBEDDED_OFFSET. */ Ah, I can see how someone not looking at the implementation might not realize which "contents" are we talking about. I've extended the describing comment. > > +int > > +value_available_contents_eq (const struct value *val1, int offset1, > > + const struct value *val2, int offset2, > > + int length) > > +{ > > + int org_len = length; > > + int org_offset1 = offset1; > > + int org_offset2 = offset2; > > All the org_* fields can be dropped by reusing other variables making the code > more readable. You're right! I like that change. > > + > > + /* Compare the _available_ contents. */ > > + if (memcmp (val1->contents + org_offset1 + prev_avail, > > + val2->contents + org_offset2 + prev_avail, > > + l2 - prev_avail) != 0) > > `l2 - prev_avail' is not right. `l2' is already this available chunk size, > `prev_avail' can be much larger covering all the preceding ranges, > `prev_avail' is already subtracted from `l2' by `offset1'/`offset2' above. Indeed. Could you double-check the patch below? Thanks! Pedro Alves 2011-02-15 Pedro Alves Jan Kratochvil gdb/ * value.c (value_available_contents_eq): Remove redundant local variables. Fix available contents comparision. * value.h (value_available_contents_eq): Extend describing comment. --- gdb/value.c | 19 ++++--------------- gdb/value.h | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 21 deletions(-) Index: src/gdb/value.c =================================================================== --- src.orig/gdb/value.c 2011-02-15 16:19:15.000000000 +0000 +++ src/gdb/value.c 2011-02-15 17:51:58.018123001 +0000 @@ -533,21 +533,13 @@ value_available_contents_eq (const struc const struct value *val2, int offset2, int length) { - int org_len = length; - int org_offset1 = offset1; - int org_offset2 = offset2; int idx1 = 0, idx2 = 0; - int prev_avail; /* This routine is used by printing routines, where we should already have read the value. Note that we only know whether a value chunk is available if we've tried to read it. */ gdb_assert (!val1->lazy && !val2->lazy); - /* The offset from either ORG_OFFSET1 or ORG_OFFSET2 where the - available contents we haven't compared yet start. */ - prev_avail = 0; - while (length > 0) { range_s *r1, *r2; @@ -561,9 +553,9 @@ value_available_contents_eq (const struc /* The usual case is for both values to be completely available. */ if (idx1 == -1 && idx2 == -1) - return (memcmp (val1->contents + org_offset1 + prev_avail, - val2->contents + org_offset2 + prev_avail, - org_len - prev_avail) == 0); + return (memcmp (val1->contents + offset1, + val2->contents + offset2, + length) == 0); /* The contents only match equal if the available set matches as well. */ else if (idx1 == -1 || idx2 == -1) @@ -596,12 +588,9 @@ value_available_contents_eq (const struc return 0; /* Compare the _available_ contents. */ - if (memcmp (val1->contents + org_offset1 + prev_avail, - val2->contents + org_offset2 + prev_avail, - l2 - prev_avail) != 0) + if (memcmp (val1->contents + offset1, val2->contents + offset2, l1) != 0) return 0; - prev_avail += h1; length -= h1; offset1 += h1; offset2 += h1; Index: src/gdb/value.h =================================================================== --- src.orig/gdb/value.h 2011-02-14 21:51:17.000000000 +0000 +++ src/gdb/value.h 2011-02-15 18:11:23.938123001 +0000 @@ -379,12 +379,21 @@ extern void mark_value_bytes_unavailable int offset, int length); /* Compare LENGTH bytes of VAL1's contents starting at OFFSET1 with - LENGTH bytes of VAL2's contents starting at OFFSET2. Returns true - iff the set of available contents match. Unavailable contents - compare equal with unavailable contents, and different with any - available byte. For example, if 'x's represent an unavailable - byte, and 'V' and 'Z' represent different available bytes, in a - value with length 16: + LENGTH bytes of VAL2's contents starting at OFFSET2. + + Note that "contents" refers to the whole value's contents + (value_contents_all), without any embedded offset adjustment. For + example, to compare a complete object value with itself, including + its enclosing type chunk, you'd do: + + int len = TYPE_LENGTH (check_typedef (value_enclosing_type (val))); + value_available_contents (val, 0, val, 0, len); + + Returns true iff the set of available contents match. Unavailable + contents compare equal with unavailable contents, and different + with any available byte. For example, if 'x's represent an + unavailable byte, and 'V' and 'Z' represent different available + bytes, in a value with length 16: offset: 0 4 8 12 16 contents: xxxxVVVVxxxxVVZZ