aboutsummaryrefslogtreecommitdiff
path: root/gdb/memrange.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2017-10-16 10:14:53 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2017-10-16 11:07:18 -0400
commita79b1bc6f690f3d146a3caddabd9f13a886c856a (patch)
treea80d8994788044e3c175bb974b2893352b065db5 /gdb/memrange.c
parent63f0e930d4667eb7dbc95c78f770cd58acd328ef (diff)
downloadgdb-a79b1bc6f690f3d146a3caddabd9f13a886c856a.zip
gdb-a79b1bc6f690f3d146a3caddabd9f13a886c856a.tar.gz
gdb-a79b1bc6f690f3d146a3caddabd9f13a886c856a.tar.bz2
Get rid of VEC(mem_range_s)
This patch replaces the last usages of VEC(mem_range_s) with std::vector<mem_range>. This allows getting rid of a few cleanups and of the DEF_VEC_O(mem_range_s). I added a test for normalize_mem_ranges to make sure I didn't break anything there. Regtested on the buildbot. gdb/ChangeLog: * memrange.h (struct mem_range): Define operator< and operator==. (mem_range_s): Remove. (DEF_VEC_O (mem_range_s)): Remove. (normalize_mem_ranges): Change parameter type to std::vector. * memrange.c (compare_mem_ranges): Remove. (normalize_mem_ranges): Change parameter type to std::vector, adjust to vector change. * exec.c (section_table_available_memory): Return vector, remove parameter. (section_table_read_available_memory): Adjust to std::vector change. * remote.c (remote_read_bytes): Adjust to std::vector change. * tracepoint.h (traceframe_available_memory): Change parameter type to std::vector. * tracepoint.c (traceframe_available_memory): Change parameter type to std::vector, adjust. * gdb/mi/mi-main.c (mi_cmd_trace_frame_collected): Adjust to std::vector change. * gdb/Makefile.in (SUBDIR_UNITTESTS_SRCS): Add unittests/memrange-selftests.c. (SUBDIR_UNITTESTS_OBS): Add memrange-selftests.o. * gdb/unittests/memrange-selftests.c: New file.
Diffstat (limited to 'gdb/memrange.c')
-rw-r--r--gdb/memrange.c46
1 files changed, 12 insertions, 34 deletions
diff --git a/gdb/memrange.c b/gdb/memrange.c
index 74da19d..34feac5 100644
--- a/gdb/memrange.c
+++ b/gdb/memrange.c
@@ -41,58 +41,36 @@ address_in_mem_range (CORE_ADDR address, const struct mem_range *r)
&& (address - r->start) < r->length);
}
-/* 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)
-{
- const struct mem_range *r1 = (const struct mem_range *) ap;
- const struct mem_range *r2 = (const struct mem_range *) bp;
-
- if (r1->start > r2->start)
- return 1;
- else if (r1->start < r2->start)
- return -1;
- else
- return 0;
-}
-
void
-normalize_mem_ranges (VEC(mem_range_s) *ranges)
+normalize_mem_ranges (std::vector<mem_range> *memory)
{
/* 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))
+ if (!memory->empty ())
{
- struct mem_range *ra, *rb;
- int a, b;
+ std::vector<mem_range> &m = *memory;
- qsort (VEC_address (mem_range_s, ranges),
- VEC_length (mem_range_s, ranges),
- sizeof (mem_range_s),
- compare_mem_ranges);
+ std::sort (m.begin (), m.end ());
- a = 0;
- ra = VEC_index (mem_range_s, ranges, a);
- for (b = 1; VEC_iterate (mem_range_s, ranges, b, rb); b++)
+ int a = 0;
+ for (int b = 1; b < m.size (); b++)
{
/* If mem_range B overlaps or is adjacent to mem_range A,
merge them. */
- if (rb->start <= ra->start + ra->length)
+ if (m[b].start <= m[a].start + m[a].length)
{
- ra->length = std::max ((CORE_ADDR) ra->length,
- (rb->start - ra->start) + rb->length);
+ m[a].length = std::max ((CORE_ADDR) m[a].length,
+ (m[b].start - m[a].start) + m[b].length);
continue; /* next b, same a */
}
a++; /* next a */
- ra = VEC_index (mem_range_s, ranges, a);
if (a != b)
- *ra = *rb;
+ m[a] = m[b];
}
- VEC_truncate (mem_range_s, ranges, a + 1);
+
+ m.resize (a + 1);
}
}