aboutsummaryrefslogtreecommitdiff
path: root/gdb/objfiles.c
diff options
context:
space:
mode:
authorChristian Biesinger <cbiesinger@google.com>2019-10-03 00:36:35 -0500
committerChristian Biesinger <cbiesinger@google.com>2019-10-19 15:45:33 -0500
commit39ef2f6256737db92f5d60fa201fe0b301bb8100 (patch)
tree13ff1a57f5ecac08df8f0ecdc2f3544cb4d97564 /gdb/objfiles.c
parent18338fcee6c75bf0b41f803b84ae15221676f8cd (diff)
downloadgdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.zip
gdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.tar.gz
gdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.tar.bz2
Replace some more qsort calls with std::sort
This has better typesafety, avoids a function pointer indirection, and can benefit from inlining. gdb/ChangeLog: 2019-10-19 Christian Biesinger <cbiesinger@google.com> * bcache.c (bcache::print_statistics): Use std::sort instead of qsort. * breakpoint.c (bp_locations_compare): Rename to... (bp_location_is_less_than): ...this, and change to std::sort semantics. (update_global_location_list): Use std::sort instead of qsort. * buildsym.c (compare_line_numbers): Rename to... (lte_is_less_than): ...this, and change to std::sort semantics. (buildsym_compunit::end_symtab_with_blockvector): Use std::sort instead of qsort. * disasm.c (compare_lines): Rename to... (line_is_less_than): ...this, and change to std::sort semantics. (do_mixed_source_and_assembly_deprecated): Call std::sort instead of qsort. * dwarf2-frame.c (qsort_fde_cmp): Rename to... (fde_is_less_than): ...this, and change to std::sort semantics. (dwarf2_build_frame_info): Call std::sort instead of qsort. * mdebugread.c (compare_blocks): (block_is_less_than): ...this, and change to std::sort semantics. (sort_blocks): Call std::sort instead of qsort. * objfiles.c (qsort_cmp): Rename to... (sort_cmp): ...this, and change to std::sort semantics. (update_section_map): Call std::sort instead of qsort. * remote.c (compare_pnums): Remove. (map_regcache_remote_table): Call std::sort instead of qsort. * utils.c (compare_positive_ints): Remove. * utils.h (compare_positive_ints): Remove. * xcoffread.c (compare_lte): Remove. (arrange_linetable): Call std::sort instead of qsort. Change-Id: Ibcddce12a3d07448701e731b7150fa23611d86de
Diffstat (limited to 'gdb/objfiles.c')
-rw-r--r--gdb/objfiles.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index bae556a..f1e708d 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1019,18 +1019,16 @@ have_minimal_symbols (void)
/* Qsort comparison function. */
-static int
-qsort_cmp (const void *a, const void *b)
+static bool
+sort_cmp (const struct obj_section *sect1, const obj_section *sect2)
{
- const struct obj_section *sect1 = *(const struct obj_section **) a;
- const struct obj_section *sect2 = *(const struct obj_section **) b;
const CORE_ADDR sect1_addr = obj_section_addr (sect1);
const CORE_ADDR sect2_addr = obj_section_addr (sect2);
if (sect1_addr < sect2_addr)
- return -1;
+ return true;
else if (sect1_addr > sect2_addr)
- return 1;
+ return false;
else
{
/* Sections are at the same address. This could happen if
@@ -1047,12 +1045,12 @@ qsort_cmp (const void *a, const void *b)
/* Case A. The ordering doesn't matter: separate debuginfo files
will be filtered out later. */
- return 0;
+ return false;
}
/* Case B. Maintain stable sort order, so bugs in GDB are easier to
triage. This section could be slow (since we iterate over all
- objfiles in each call to qsort_cmp), but this shouldn't happen
+ objfiles in each call to sort_cmp), but this shouldn't happen
very often (GDB is already in a confused state; one hopes this
doesn't happen at all). If you discover that significant time is
spent in the loops below, do 'set complaints 100' and examine the
@@ -1067,9 +1065,9 @@ qsort_cmp (const void *a, const void *b)
ALL_OBJFILE_OSECTIONS (objfile1, osect)
if (osect == sect1)
- return -1;
+ return true;
else if (osect == sect2)
- return 1;
+ return false;
/* We should have found one of the sections before getting here. */
gdb_assert_not_reached ("section not found");
@@ -1080,9 +1078,9 @@ qsort_cmp (const void *a, const void *b)
for (objfile *objfile : current_program_space->objfiles ())
if (objfile == objfile1)
- return -1;
+ return true;
else if (objfile == objfile2)
- return 1;
+ return false;
/* We should have found one of the objfiles before getting here. */
gdb_assert_not_reached ("objfile not found");
@@ -1091,7 +1089,7 @@ qsort_cmp (const void *a, const void *b)
/* Unreachable. */
gdb_assert_not_reached ("unexpected code path");
- return 0;
+ return false;
}
/* Select "better" obj_section to keep. We prefer the one that came from
@@ -1283,7 +1281,7 @@ update_section_map (struct program_space *pspace,
if (insert_section_p (objfile->obfd, s->the_bfd_section))
map[i++] = s;
- qsort (map, alloc_size, sizeof (*map), qsort_cmp);
+ std::sort (map, map + alloc_size, sort_cmp);
map_size = filter_debuginfo_sections(map, alloc_size);
map_size = filter_overlapping_sections(map, map_size);