gdb: add interp::on_breakpoint_modified method

Same idea as previous patches, but for breakpoint_modified.

Change-Id: I4f0a9edea912de431e32451d74224b2022a7c328
This commit is contained in:
Simon Marchi 2023-04-21 09:45:30 -04:00
parent e4239559f4
commit 19081eb5f1
8 changed files with 58 additions and 43 deletions

View File

@ -995,6 +995,15 @@ set_breakpoint_location_condition (const char *cond_string, bp_location *loc,
error (_("Garbage '%s' follows condition"), cond_string);
}
/* See breakpoint.h. */
void
notify_breakpoint_modified (breakpoint *b)
{
interps_notify_breakpoint_modified (b);
gdb::observers::breakpoint_modified.notify (b);
}
void
set_breakpoint_condition (struct breakpoint *b, const char *exp,
int from_tty, bool force)
@ -1087,7 +1096,7 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp,
}
mark_breakpoint_modified (b);
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
/* See breakpoint.h. */
@ -1431,7 +1440,7 @@ breakpoint_set_commands (struct breakpoint *b,
validate_commands_for_breakpoint (b, commands.get ());
b->commands = std::move (commands);
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
/* Set the internal `silent' flag on the breakpoint. Note that this
@ -1445,7 +1454,7 @@ breakpoint_set_silent (struct breakpoint *b, int silent)
b->silent = silent;
if (old_silent != silent)
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
/* See breakpoint.h. */
@ -1462,7 +1471,7 @@ breakpoint_set_thread (struct breakpoint *b, int thread)
b->thread = thread;
if (old_thread != thread)
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
/* See breakpoint.h. */
@ -1479,7 +1488,7 @@ breakpoint_set_task (struct breakpoint *b, int task)
b->task = task;
if (old_task != task)
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
static void
@ -1548,7 +1557,7 @@ commands_command_1 (const char *arg, int from_tty,
{
validate_commands_for_breakpoint (b, cmd.get ());
b->commands = cmd;
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
});
}
@ -2886,7 +2895,7 @@ insert_bp_location (struct bp_location *bl,
{
/* See also: disable_breakpoints_in_shlibs. */
bl->shlib_disabled = 1;
gdb::observers::breakpoint_modified.notify (bl->owner);
notify_breakpoint_modified (bl->owner);
if (!*disabled_breaks)
{
gdb_printf (tmp_error_stream,
@ -5575,7 +5584,7 @@ bpstat_check_breakpoint_conditions (bpstat *bs, thread_info *thread)
bs->stop = false;
/* Increase the hit count even though we don't stop. */
++(b->hit_count);
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
return;
}
@ -5738,7 +5747,7 @@ bpstat_stop_status (const address_space *aspace,
b->enable_state = bp_disabled;
removed_any = 1;
}
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
if (b->silent)
bs->print = false;
bs->commands = b->commands;
@ -7868,7 +7877,7 @@ disable_breakpoints_in_unloaded_shlib (struct so_list *solib)
loc->inserted = 0;
/* This may cause duplicate notifications for the same breakpoint. */
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
if (!disabled_shlib_breaks)
{
@ -7948,7 +7957,7 @@ disable_breakpoints_in_freed_objfile (struct objfile *objfile)
}
if (bp_modified)
gdb::observers::breakpoint_modified.notify (&b);
notify_breakpoint_modified (&b);
}
}
@ -11057,7 +11066,7 @@ download_tracepoint_locations (void)
tracepoint &t = gdb::checked_static_cast<tracepoint &> (b);
t.number_on_target = b.number;
if (bp_location_downloaded)
gdb::observers::breakpoint_modified.notify (&b);
notify_breakpoint_modified (&b);
}
}
@ -12826,7 +12835,7 @@ update_breakpoint_locations (code_breakpoint *b,
}
if (!locations_are_equal (existing_locations, b->locations ()))
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
}
/* Find the SaL locations corresponding to the given LOCSPEC.
@ -13075,7 +13084,7 @@ set_ignore_count (int bptnum, int count, int from_tty)
"crossings of breakpoint %d."),
count, bptnum);
}
gdb::observers::breakpoint_modified.notify (&b);
notify_breakpoint_modified (&b);
return;
}
@ -13329,7 +13338,7 @@ enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable)
}
update_global_location_list (UGLL_DONT_INSERT);
gdb::observers::breakpoint_modified.notify (loc->owner);
notify_breakpoint_modified (loc->owner);
}
/* Calculates LOC_NUM for LOC by traversing the bp_location chain of LOC's
@ -13386,7 +13395,7 @@ enable_disable_bp_location (bp_location *loc, bool enable)
target_disable_tracepoint (loc);
update_global_location_list (UGLL_DONT_INSERT);
gdb::observers::breakpoint_modified.notify (loc->owner);
notify_breakpoint_modified (loc->owner);
}
/* Enable or disable a range of breakpoint locations. BP_NUM is the
@ -13431,7 +13440,7 @@ disable_breakpoint (struct breakpoint *bpt)
update_global_location_list (UGLL_DONT_INSERT);
gdb::observers::breakpoint_modified.notify (bpt);
notify_breakpoint_modified (bpt);
}
/* Enable or disable the breakpoint(s) or breakpoint location(s)
@ -13556,7 +13565,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
bpt->enable_count = count;
update_global_location_list (UGLL_MAY_INSERT);
gdb::observers::breakpoint_modified.notify (bpt);
notify_breakpoint_modified (bpt);
}
@ -14027,7 +14036,7 @@ static void
trace_pass_set_count (struct tracepoint *tp, int count, int from_tty)
{
tp->pass_count = count;
gdb::observers::breakpoint_modified.notify (tp);
notify_breakpoint_modified (tp);
if (from_tty)
gdb_printf (_("Setting tracepoint %d's passcount to %d\n"),
tp->number, count);

View File

@ -2007,4 +2007,9 @@ extern void describe_other_breakpoints (struct gdbarch *,
extern void enable_disable_bp_location (bp_location *loc, bool enable);
/* Notify interpreters and observers that breakpoint B was modified. */
extern void notify_breakpoint_modified (breakpoint *b);
#endif /* !defined (BREAKPOINT_H) */

View File

@ -575,6 +575,14 @@ interps_notify_breakpoint_deleted (breakpoint *b)
interps_notify (&interp::on_breakpoint_deleted, b);
}
/* See interps.h. */
void
interps_notify_breakpoint_modified (breakpoint *b)
{
interps_notify (&interp::on_breakpoint_modified, b);
}
/* This just adds the "interpreter-exec" command. */
void _initialize_interpreter ();
void

View File

@ -172,6 +172,9 @@ public:
/* Notify the interpreter that breakpoint B was deleted. */
virtual void on_breakpoint_deleted (breakpoint *b) {}
/* Notify the interpreter that breakpoint B was modified. */
virtual void on_breakpoint_modified (breakpoint *b) {}
private:
/* The memory for this is static, it comes from literal strings (e.g. "cli"). */
const char *m_name;
@ -347,6 +350,9 @@ extern void interps_notify_breakpoint_created (breakpoint *b);
/* Notify all interpreters that breakpoint B was deleted. */
extern void interps_notify_breakpoint_deleted (breakpoint *b);
/* Notify all interpreters that breakpoint B was modified. */
extern void interps_notify_breakpoint_modified (breakpoint *b);
/* well-known interpreters */
#define INTERP_CONSOLE "console"
#define INTERP_MI2 "mi2"

View File

@ -470,7 +470,7 @@ mi_cmd_break_passcount (const char *command, const char *const *argv,
if (t)
{
t->pass_count = p;
gdb::observers::breakpoint_modified.notify (t);
notify_breakpoint_modified (t);
}
else
{

View File

@ -60,7 +60,6 @@ static int mi_interp_query_hook (const char *ctlstr, va_list ap)
static void mi_insert_notify_hooks (void);
static void mi_remove_notify_hooks (void);
static void mi_breakpoint_modified (struct breakpoint *b);
static void mi_command_param_changed (const char *param, const char *value);
static void mi_memory_changed (struct inferior *inf, CORE_ADDR memaddr,
ssize_t len, const bfd_byte *myaddr);
@ -621,10 +620,8 @@ mi_interp::on_breakpoint_deleted (breakpoint *b)
gdb_flush (this->event_channel);
}
/* Emit notification about modified breakpoint. */
static void
mi_breakpoint_modified (struct breakpoint *b)
void
mi_interp::on_breakpoint_modified (breakpoint *b)
{
if (mi_suppress_notification.breakpoint)
return;
@ -632,21 +629,12 @@ mi_breakpoint_modified (struct breakpoint *b)
if (b->number <= 0)
return;
SWITCH_THRU_ALL_UIS ()
{
struct mi_interp *mi = as_mi_interp (top_level_interpreter ());
target_terminal::scoped_restore_terminal_state term_state;
target_terminal::ours_for_output ();
gdb_printf (this->event_channel, "breakpoint-modified");
mi_print_breakpoint_for_event (this, b);
if (mi == NULL)
continue;
target_terminal::scoped_restore_terminal_state term_state;
target_terminal::ours_for_output ();
gdb_printf (mi->event_channel,
"breakpoint-modified");
mi_print_breakpoint_for_event (mi, b);
gdb_flush (mi->event_channel);
}
gdb_flush (this->event_channel);
}
static void
@ -985,8 +973,6 @@ _initialize_mi_interp ()
interp_factory_register (INTERP_MI4, mi_interp_factory);
interp_factory_register (INTERP_MI, mi_interp_factory);
gdb::observers::breakpoint_modified.attach (mi_breakpoint_modified,
"mi-interp");
gdb::observers::command_param_changed.attach (mi_command_param_changed,
"mi-interp");
gdb::observers::memory_changed.attach (mi_memory_changed, "mi-interp");

View File

@ -68,6 +68,7 @@ public:
void on_tsv_modified (const trace_state_variable *tsv) override;
void on_breakpoint_created (breakpoint *b) override;
void on_breakpoint_deleted (breakpoint *b) override;
void on_breakpoint_modified (breakpoint *b) override;
/* MI's output channels */
mi_console_file *out;

View File

@ -1640,7 +1640,7 @@ start_tracing (const char *notes)
loc.probe.prob->set_semaphore (loc.probe.objfile, loc.gdbarch);
if (bp_location_downloaded)
gdb::observers::breakpoint_modified.notify (&b);
notify_breakpoint_modified (&b);
}
/* Send down all the trace state variables too. */
@ -3134,7 +3134,7 @@ merge_uploaded_tracepoints (struct uploaded_tp **uploaded_tps)
/* Notify 'breakpoint-modified' observer that at least one of B's
locations was changed. */
for (breakpoint *b : modified_tp)
gdb::observers::breakpoint_modified.notify (b);
notify_breakpoint_modified (b);
free_uploaded_tps (uploaded_tps);
}