From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8585 invoked by alias); 14 Feb 2011 12:00:34 -0000 Received: (qmail 8577 invoked by uid 22791); 14 Feb 2011 12:00:33 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Feb 2011 12:00:29 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p1EC0JhI006126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Feb 2011 07:00:19 -0500 Received: from host1.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p1EC0GAU017523 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 14 Feb 2011 07:00:18 -0500 Received: from host1.dyn.jankratochvil.net (localhost [127.0.0.1]) by host1.dyn.jankratochvil.net (8.14.4/8.14.4) with ESMTP id p1EC0GoK029970; Mon, 14 Feb 2011 13:00:16 +0100 Received: (from jkratoch@localhost) by host1.dyn.jankratochvil.net (8.14.4/8.14.4/Submit) id p1EC0G5H029921; Mon, 14 Feb 2011 13:00:16 +0100 Date: Mon, 14 Feb 2011 12:00:00 -0000 From: Jan Kratochvil To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [unavailable values part 1, 06/17] array element repeats, confused with 0. Message-ID: <20110214120015.GF2454@host1.dyn.jankratochvil.net> References: <201102071430.49735.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201102071430.49735.pedro@codesourcery.com> User-Agent: Mutt/1.5.21 (2010-09-15) 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/msg00267.txt.bz2 > --- 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. */ > + 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 > + > + then: > + > + value_available_contents_eq(val, 0, val, 8, 6) => 1 > + value_available_contents_eq(val, 0, val, 4, 4) => 1 > + value_available_contents_eq(val, 0, val, 8, 8) => 0 > + value_available_contents_eq(val, 4, val, 12, 2) => 1 > + value_available_contents_eq(val, 4, val, 12, 4) => 0 > + value_available_contents_eq(val, 3, val, 4, 4) => 0 > +*/ > + > +extern int value_available_contents_eq (const struct value *val1, int offset1, > + const struct value *val2, int offset2, > + int length); > +/* Find the first range in RANGES that overlaps the range defined by > + OFFSET and LENGTH, starting at element POS in the RANGES vector, > + Returns the index into RANGES where such overlapping range was > + found, or -1 if none was found. */ > + > +static int > +find_first_range_overlap (VEC(range_s) *ranges, int pos, > + int offset, int length) > +{ > + range_s *r; > + int i; > + > + for (i = pos; VEC_iterate (range_s, ranges, i, r); i++) > + if (ranges_overlap (r->offset, r->length, offset, length)) > + return i; > + > + return -1; > +} > + > +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. > + 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; > + ULONGEST l1, h1; > + ULONGEST l2, h2; > + > + idx1 = find_first_range_overlap (val1->unavailable, idx1, > + offset1, length); > + idx2 = find_first_range_overlap (val2->unavailable, idx2, > + offset2, length); > + > + /* The usual case is for both values to be completely available. */ > + if (idx1 == -1 && idx2 == -1) > + return (memcmp (val1->contents + org_offset1 + prev_avail, `org_offset1 + prev_avail' -> `offset1'. > + val2->contents + org_offset2 + prev_avail, > + org_len - prev_avail) == 0); `org_len - prev_avail' -> `length' to drop `org_len'. > + /* The contents only match equal if the available set matches as > + well. */ > + else if (idx1 == -1 || idx2 == -1) > + return 0; > + > + gdb_assert (idx1 != -1 && idx2 != -1); > + > + r1 = VEC_index (range_s, val1->unavailable, idx1); > + r2 = VEC_index (range_s, val2->unavailable, idx2); > + > + /* Get the unavailable windows intersected by the incoming > + ranges. The first and last ranges that overlap the argument > + range may be wider than said incoming arguments ranges. */ > + l1 = max (offset1, r1->offset); > + h1 = min (offset1 + length, r1->offset + r1->length); > + > + l2 = max (offset2, r2->offset); > + h2 = min (offset2 + length, r2->offset + r2->length); > + > + /* Make them relative to the respective start offsets, so we can > + compare them for equality. */ > + l1 -= offset1; > + h1 -= offset1; > + > + l2 -= offset2; > + h2 -= offset2; > + > + /* Different availability, no match. */ > + if (l1 != l2 || h1 != h2) > + return 0; > + > + /* 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. > + return 0; > + > + prev_avail += h1; > + length -= h1; > + offset1 += h1; > + offset2 += h1; > + } > + > + return 1; > +} Thanks, Jan