From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>
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 [thread overview]
Message-ID: <201102141939.10946.pedro@codesourcery.com> (raw)
In-Reply-To: <20110214115939.GC2454@host1.dyn.jankratochvil.net>
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,
next prev parent reply other threads:[~2011-02-14 19:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-07 14:29 Pedro Alves
2011-02-14 11:59 ` Jan Kratochvil
2011-02-14 19:54 ` Pedro Alves [this message]
2011-02-14 21:44 ` Jan Kratochvil
2011-02-15 18:42 ` Tom Tromey
2011-02-15 19:14 ` Pedro Alves
2011-02-15 21:02 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201102141939.10946.pedro@codesourcery.com \
--to=pedro@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox