This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [unavailable values part 1, 03/17] expose list of available ranges to common code


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  <pedro@codesourcery.com>
	    Jan Kratochvil  <jan.kratochvil@redhat.com>

	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,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]