#include <ctype.h>
#include "cp-abi.h"
#include "cp-support.h"
-#include "observer.h"
+#include "observable.h"
#include "solist.h"
#include "macrotab.h"
#include "macroscope.h"
find the one whose first PC is closer than that of the next line in this
symtab. */
-/* If it's worth the effort, we could be using a binary search. */
-
struct symtab_and_line
find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent)
{
if (item->pc > pc && (!alt || item->pc < alt->pc))
alt = item;
- for (i = 0; i < len; i++, item++)
- {
- /* Leave prev pointing to the linetable entry for the last line
- that started at or before PC. */
- if (item->pc > pc)
- break;
+ auto pc_compare = [](const CORE_ADDR & pc,
+ const struct linetable_entry & lhs)->bool
+ {
+ return pc < lhs.pc;
+ };
- prev = item;
- }
+ struct linetable_entry *first = item;
+ struct linetable_entry *last = item + len;
+ item = std::upper_bound (first, last, pc, pc_compare);
+ if (item != first)
+ prev = item - 1; /* Found a matching item. */
/* At this point, prev points at the line whose start addr is <= pc, and
item points at the next line. If we ran off the end of the linetable
/* If another line (denoted by ITEM) is in the linetable and its
PC is after BEST's PC, but before the current BEST_END, then
use ITEM's PC as the new best_end. */
- if (best && i < len && item->pc > best->pc
+ if (best && item < last && item->pc > best->pc
&& (best_end == 0 || best_end > item->pc))
best_end = item->pc;
}
_("Flush the symbol cache for each program space."),
&maintenancelist);
- observer_attach_executable_changed (symtab_observer_executable_changed);
- observer_attach_new_objfile (symtab_new_objfile_observer);
- observer_attach_free_objfile (symtab_free_objfile_observer);
+ gdb::observers::executable_changed.attach (symtab_observer_executable_changed);
+ gdb::observers::new_objfile.attach (symtab_new_objfile_observer);
+ gdb::observers::free_objfile.attach (symtab_free_objfile_observer);
}