gdb: Fix scrolling in TUI
[deliverable/binutils-gdb.git] / gdb / dwarf2-frame.c
index c41db791dc6005704754638c65025368822f5715..baa47c9438980c36c665fc899fc89fd44bf2b06e 100644 (file)
@@ -1,6 +1,6 @@
 /* Frame unwinder for frames with DWARF Call Frame Information.
 
-   Copyright (C) 2003-2019 Free Software Foundation, Inc.
+   Copyright (C) 2003-2020 Free Software Foundation, Inc.
 
    Contributed by Mark Kettenis.
 
@@ -39,6 +39,7 @@
 #include "ax.h"
 #include "dwarf2loc.h"
 #include "dwarf2-frame-tailcall.h"
+#include "gdbsupport/gdb_binary_search.h"
 #if GDB_SELF_TEST
 #include "gdbsupport/selftest.h"
 #include "selftest-arch.h"
@@ -383,8 +384,7 @@ execute_cfa_program (struct dwarf2_fde *fde, const gdb_byte *insn_ptr,
                                           fde->cie->ptr_size, insn_ptr,
                                           &bytes_read, fde->initial_location);
              /* Apply the objfile offset for relocatable objects.  */
-             fs->pc += ANOFFSET (fde->cie->unit->objfile->section_offsets,
-                                 SECT_OFF_TEXT (fde->cie->unit->objfile));
+             fs->pc += fde->cie->unit->objfile->section_offsets[SECT_OFF_TEXT (fde->cie->unit->objfile)];
              insn_ptr += bytes_read;
              break;
 
@@ -1652,15 +1652,12 @@ find_cie (const dwarf2_cie_table &cie_table, ULONGEST cie_pointer)
   return NULL;
 }
 
-static int
-bsearch_fde_cmp (const void *key, const void *element)
+static inline int
+bsearch_fde_cmp (const dwarf2_fde *fde, CORE_ADDR seek_pc)
 {
-  CORE_ADDR seek_pc = *(CORE_ADDR *) key;
-  struct dwarf2_fde *fde = *(struct dwarf2_fde **) element;
-
-  if (seek_pc < fde->initial_location)
+  if (fde->initial_location + fde->address_range <= seek_pc)
     return -1;
-  if (seek_pc < fde->initial_location + fde->address_range)
+  if (fde->initial_location <= seek_pc)
     return 0;
   return 1;
 }
@@ -1674,7 +1671,6 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
   for (objfile *objfile : current_program_space->objfiles ())
     {
       struct dwarf2_fde_table *fde_table;
-      struct dwarf2_fde **p_fde;
       CORE_ADDR offset;
       CORE_ADDR seek_pc;
 
@@ -1689,23 +1685,22 @@ dwarf2_frame_find_fde (CORE_ADDR *pc, CORE_ADDR *out_offset)
       if (fde_table->num_entries == 0)
        continue;
 
-      gdb_assert (objfile->section_offsets);
-      offset = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
+      gdb_assert (!objfile->section_offsets.empty ());
+      offset = objfile->section_offsets[SECT_OFF_TEXT (objfile)];
 
       gdb_assert (fde_table->num_entries > 0);
       if (*pc < offset + fde_table->entries[0]->initial_location)
         continue;
 
       seek_pc = *pc - offset;
-      p_fde = ((struct dwarf2_fde **)
-              bsearch (&seek_pc, fde_table->entries, fde_table->num_entries,
-                        sizeof (fde_table->entries[0]), bsearch_fde_cmp));
-      if (p_fde != NULL)
+      auto end = fde_table->entries + fde_table->num_entries;
+      auto it = gdb::binary_search (fde_table->entries, end, seek_pc, bsearch_fde_cmp);
+      if (it != end)
         {
-          *pc = (*p_fde)->initial_location + offset;
+          *pc = (*it)->initial_location + offset;
          if (out_offset)
            *out_offset = offset;
-          return *p_fde;
+          return *it;
         }
     }
   return NULL;
This page took 0.026187 seconds and 4 git commands to generate.