summaryrefslogtreecommitdiff
path: root/gdb/disasm.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/disasm.c
parent18338fcee6c75bf0b41f803b84ae15221676f8cd (diff)
downloadbinutils-gdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.tar.gz
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/disasm.c')
-rw-r--r--gdb/disasm.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/gdb/disasm.c b/gdb/disasm.c
index b9a88395805..164939b5882 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -163,28 +163,27 @@ gdb_disassembler::dis_asm_print_address (bfd_vma addr,
print_address (self->arch (), addr, self->stream ());
}
-static int
-compare_lines (const void *mle1p, const void *mle2p)
+static bool
+line_is_less_than (const deprecated_dis_line_entry &mle1,
+ const deprecated_dis_line_entry &mle2)
{
- struct deprecated_dis_line_entry *mle1, *mle2;
- int val;
-
- mle1 = (struct deprecated_dis_line_entry *) mle1p;
- mle2 = (struct deprecated_dis_line_entry *) mle2p;
+ bool val;
/* End of sequence markers have a line number of 0 but don't want to
be sorted to the head of the list, instead sort by PC. */
- if (mle1->line == 0 || mle2->line == 0)
+ if (mle1.line == 0 || mle2.line == 0)
{
- val = mle1->start_pc - mle2->start_pc;
- if (val == 0)
- val = mle1->line - mle2->line;
+ if (mle1.start_pc != mle2.start_pc)
+ val = mle1.start_pc < mle2.start_pc;
+ else
+ val = mle1.line < mle2.line;
}
else
{
- val = mle1->line - mle2->line;
- if (val == 0)
- val = mle1->start_pc - mle2->start_pc;
+ if (mle1.line != mle2.line)
+ val = mle1.line < mle2.line;
+ else
+ val = mle1.start_pc < mle2.start_pc;
}
return val;
}
@@ -404,8 +403,7 @@ do_mixed_source_and_assembly_deprecated
/* Now, sort mle by line #s (and, then by addresses within lines). */
if (out_of_order)
- qsort (mle, newlines, sizeof (struct deprecated_dis_line_entry),
- compare_lines);
+ std::sort (mle, mle + newlines, line_is_less_than);
/* Now, for each line entry, emit the specified lines (unless
they have been emitted before), followed by the assembly code