From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18004 invoked by alias); 14 Feb 2011 19:39:22 -0000 Received: (qmail 17995 invoked by uid 22791); 14 Feb 2011 19:39:21 -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; Mon, 14 Feb 2011 19:39:15 +0000 Received: (qmail 30592 invoked from network); 14 Feb 2011 19:39:13 -0000 Received: from unknown (HELO scottsdale.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 14 Feb 2011 19:39:13 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [unavailable values part 1, 03/17] expose list of available ranges to common code Date: Mon, 14 Feb 2011 19:54:00 -0000 User-Agent: KMail/1.13.5 (Linux/2.6.35-25-generic; KDE/4.6.0; x86_64; ; ) Cc: Jan Kratochvil References: <201102071429.19096.pedro@codesourcery.com> <20110214115939.GC2454@host1.dyn.jankratochvil.net> In-Reply-To: <20110214115939.GC2454@host1.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201102141939.10946.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/msg00292.txt.bz2 On Monday 14 February 2011 11:59:39, Jan Kratochvil wrote: > > +/* qsort comparison function, that compares mem_ranges. */ > > "and sorts them in ascending order according to their START." Added something like that. > > +void > > +normalize_mem_ranges (VEC(mem_range_s) *ranges) > > /* This function must not use any VEC operation on RANGES which may reallocate > the memory block as the callers keep the original memory location. */ Added something like this too. > > > +{ > > + if (!VEC_empty (mem_range_s, ranges)) > > + { > > + struct mem_range *ra, *rb; > > + int a, b; > > + > > + qsort (VEC_address (mem_range_s, ranges), > > + VEC_length (mem_range_s, ranges), > > + sizeof (mem_range_s), > > + compare_mem_ranges); > > + > > + a = 0; > > + ra = VEC_index (mem_range_s, ranges, a); > > + for (b = 1; VEC_iterate (mem_range_s, ranges, b, rb); b++) > > + { > > + /* If mem_range B overlaps or is adjacent to mem_range A, > > + merge them. */ > > + if (rb->start <= ra->start + ra->length) > > + { > > + ra->length = (rb->start + rb->length) - ra->start; > > + continue; /* next b, same a */ > > + } > > Here if `ra->start == rb->start && ra->length > rb->length' this normalization > will lose the `ra->length - rb->length' part. Indeed. Fixed. > Not sure if gdbserver can generate such data but at least this function looks > general enough so it should behave general enough. Indeed I think it can. > > > > +struct mem_range > > +{ > > + /* Lowest address in the range. */ > > + CORE_ADDR start; > > + > > + /* Length of the range. */ > > + int length; > > +}; > > Why couldn't GDB become 64bit clean - that is CORE_ADDR length. Probably a leftover from the value ranges stuff (value lengths are ints, and so I made the value range lengths be ints too). But I disagree with making it a CORE_ADDR. I think lengths should be LONGEST or ULONGEST. I'll have come back to this type and length stuff later. > > + *result = NULL; > > I would make this line unconditional. Or the function comment should be > different. Tweaked the comment. Here's what I applied. Thanks for the review! Pedro Alves 2011-02-14 Pedro Alves Jan Kratochvil gdb/ * memrange.c (compare_mem_ranges): Mention sort order in describing comment. (normalize_mem_ranges): Add comment. Fix ra->length calculation. * tracepoint.c (traceframe_available_memory): Extend comment to mention what happens to RESULT when the target does not support the query. --- gdb/memrange.c | 10 ++++++++-- gdb/tracepoint.c | 9 +++++---- 2 files changed, 13 insertions(+), 6 deletions(-) Index: src/gdb/memrange.c =================================================================== --- src.orig/gdb/memrange.c 2011-02-14 11:19:33.000000000 +0000 +++ src/gdb/memrange.c 2011-02-14 19:04:47.803994993 +0000 @@ -31,7 +31,8 @@ mem_ranges_overlap (CORE_ADDR start1, in return (l < h); } -/* qsort comparison function, that compares mem_ranges. */ +/* qsort comparison function, that compares mem_ranges. Ranges are + sorted in ascending START order. */ static int compare_mem_ranges (const void *ap, const void *bp) @@ -50,6 +51,10 @@ compare_mem_ranges (const void *ap, cons void normalize_mem_ranges (VEC(mem_range_s) *ranges) { + /* This function must not use any VEC operation on RANGES that + reallocates the memory block as that invalidates the RANGES + pointer, which callers expect to remain valid. */ + if (!VEC_empty (mem_range_s, ranges)) { struct mem_range *ra, *rb; @@ -68,7 +73,8 @@ normalize_mem_ranges (VEC(mem_range_s) * merge them. */ if (rb->start <= ra->start + ra->length) { - ra->length = (rb->start + rb->length) - ra->start; + ra->length = max (ra->length, + (rb->start - ra->start) + rb->length); continue; /* next b, same a */ } a++; /* next a */ Index: src/gdb/tracepoint.c =================================================================== --- src.orig/gdb/tracepoint.c 2011-02-14 12:39:56.000000000 +0000 +++ src/gdb/tracepoint.c 2011-02-14 18:52:32.063995011 +0000 @@ -4635,10 +4635,11 @@ get_traceframe_info (void) return traceframe_info; } -/* Return in RESULT, the set of collected memory in the current - traceframe, found within the LEN bytes range starting at MEMADDR. - Returns true if the target supports the query, otherwise returns - false. */ +/* If the target supports the query, return in RESULT the set of + collected memory in the current traceframe, found within the LEN + bytes range starting at MEMADDR. Returns true if the target + supports the query, otherwise returns false, and RESULT is left + undefined. */ int traceframe_available_memory (VEC(mem_range_s) **result,