From 46e3ed7ff94dc2d65f3d937d483c459b4cee6a0a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 2 Jan 2019 14:35:57 -0700 Subject: C++-ify struct thread_fsm This C++-ifies struct thread_fsm, replacing the "ops" structure with virtual methods, and changing all the implementations to derive from thread_fsm. gdb/ChangeLog 2019-02-07 Tom Tromey * thread.c (thread_cancel_execution_command): Update. * thread-fsm.h (struct thread_fsm): Add constructor, destructor, methods. (struct thread_fsm_ops): Remove. (thread_fsm_ctor, thread_fsm_delete, thread_fsm_clean_up) (thread_fsm_should_stop, thread_fsm_return_value) (thread_fsm_set_finished, thread_fsm_finished_p) (thread_fsm_async_reply_reason, thread_fsm_should_notify_stop): Don't declare. * mi/mi-interp.c (mi_on_normal_stop_1): Update. * infrun.c (clear_proceed_status_thread) (clean_up_just_stopped_threads_fsms, fetch_inferior_event) (print_stop_event): Update. * infcmd.c (struct step_command_fsm): Inherit from thread_fsm. Add constructor. (step_command_fsm_ops): Remove. (new_step_command_fsm): Remove. (step_1): Update. (step_command_fsm::should_stop): Rename from step_command_fsm_should_stop. (step_command_fsm::clean_up): Rename from step_command_fsm_clean_up. (step_command_fsm::do_async_reply_reason): Rename from step_command_fsm_async_reply_reason. (struct until_next_fsm): Inherit from thread_fsm. Add constructor. (until_next_fsm_ops): Remove. (new_until_next_fsm): Remove. (until_next_fsm::should_stop): Rename from until_next_fsm_should_stop. (until_next_fsm::clean_up): Rename from until_next_fsm_clean_up. (until_next_fsm::do_async_reply_reason): Rename from until_next_fsm_async_reply_reason. (struct finish_command_fsm): Inherit from thread_fsm. Add constructor. Change type of breakpoint. (finish_command_fsm_ops): Remove. (new_finish_command_fsm): Remove. (finish_command_fsm::should_stop): Rename from finish_command_fsm_should_stop. (finish_command_fsm::clean_up): Rename from finish_command_fsm_clean_up. (finish_command_fsm::return_value): Rename from finish_command_fsm_return_value. (finish_command_fsm::do_async_reply_reason): Rename from finish_command_fsm_async_reply_reason. (finish_command): Update. * infcall.c (struct call_thread_fsm): Inherit from thread_fsm. Add constructor. (call_thread_fsm_ops): Remove. (call_thread_fsm::call_thread_fsm): Rename from new_call_thread_fsm. (call_thread_fsm::should_stop): Rename from call_thread_fsm_should_stop. (call_thread_fsm::should_notify_stop): Rename from call_thread_fsm_should_notify_stop. (run_inferior_call, call_function_by_hand_dummy): Update. * cli/cli-interp.c (should_print_stop_to_console): Update. * breakpoint.c (struct until_break_fsm): Inherit from thread_fsm. Add constructor. Change type of location_breakpoint, caller_breakpoint. (until_break_fsm_ops): Remove. (new_until_break_fsm): Remove. (until_break_fsm::should_stop): Rename from until_break_fsm_should_stop. (until_break_fsm::clean_up): Rename from until_break_fsm_clean_up. (until_break_fsm::do_async_reply_reason): Rename from until_break_fsm_async_reply_reason. (until_break_command): Update. * thread-fsm.c: Remove. * Makefile.in (COMMON_SFILES): Remove thread-fsm.c. --- gdb/breakpoint.c | 108 +++++++++++++++++-------------------------------------- 1 file changed, 33 insertions(+), 75 deletions(-) (limited to 'gdb/breakpoint.c') diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index b2096c58b74..bd05707d48f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -10950,106 +10950,66 @@ awatch_command (const char *arg, int from_tty) in infcmd.c. Here because it uses the mechanisms of breakpoints. */ -struct until_break_fsm +struct until_break_fsm : public thread_fsm { - /* The base class. */ - struct thread_fsm thread_fsm; - - /* The thread that as current when the command was executed. */ + /* The thread that was current when the command was executed. */ int thread; /* The breakpoint set at the destination location. */ - struct breakpoint *location_breakpoint; + breakpoint_up location_breakpoint; /* Breakpoint set at the return address in the caller frame. May be NULL. */ - struct breakpoint *caller_breakpoint; -}; - -static void until_break_fsm_clean_up (struct thread_fsm *self, - struct thread_info *thread); -static int until_break_fsm_should_stop (struct thread_fsm *self, - struct thread_info *thread); -static enum async_reply_reason - until_break_fsm_async_reply_reason (struct thread_fsm *self); + breakpoint_up caller_breakpoint; -/* until_break_fsm's vtable. */ + until_break_fsm (struct interp *cmd_interp, int thread, + breakpoint_up &&location_breakpoint, + breakpoint_up &&caller_breakpoint) + : thread_fsm (cmd_interp), + thread (thread), + location_breakpoint (std::move (location_breakpoint)), + caller_breakpoint (std::move (caller_breakpoint)) + { + } -static struct thread_fsm_ops until_break_fsm_ops = -{ - NULL, /* dtor */ - until_break_fsm_clean_up, - until_break_fsm_should_stop, - NULL, /* return_value */ - until_break_fsm_async_reply_reason, + void clean_up (struct thread_info *thread) override; + bool should_stop (struct thread_info *thread) override; + enum async_reply_reason do_async_reply_reason () override; }; -/* Allocate a new until_break_command_fsm. */ - -static struct until_break_fsm * -new_until_break_fsm (struct interp *cmd_interp, int thread, - breakpoint_up &&location_breakpoint, - breakpoint_up &&caller_breakpoint) -{ - struct until_break_fsm *sm; - - sm = XCNEW (struct until_break_fsm); - thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp); - - sm->thread = thread; - sm->location_breakpoint = location_breakpoint.release (); - sm->caller_breakpoint = caller_breakpoint.release (); - - return sm; -} - /* Implementation of the 'should_stop' FSM method for the until(location)/advance commands. */ -static int -until_break_fsm_should_stop (struct thread_fsm *self, - struct thread_info *tp) +bool +until_break_fsm::should_stop (struct thread_info *tp) { - struct until_break_fsm *sm = (struct until_break_fsm *) self; - if (bpstat_find_breakpoint (tp->control.stop_bpstat, - sm->location_breakpoint) != NULL - || (sm->caller_breakpoint != NULL + location_breakpoint.get ()) != NULL + || (caller_breakpoint != NULL && bpstat_find_breakpoint (tp->control.stop_bpstat, - sm->caller_breakpoint) != NULL)) - thread_fsm_set_finished (self); + caller_breakpoint.get ()) != NULL)) + set_finished (); - return 1; + return true; } /* Implementation of the 'clean_up' FSM method for the until(location)/advance commands. */ -static void -until_break_fsm_clean_up (struct thread_fsm *self, - struct thread_info *thread) +void +until_break_fsm::clean_up (struct thread_info *) { - struct until_break_fsm *sm = (struct until_break_fsm *) self; - /* Clean up our temporary breakpoints. */ - if (sm->location_breakpoint != NULL) - { - delete_breakpoint (sm->location_breakpoint); - sm->location_breakpoint = NULL; - } - if (sm->caller_breakpoint != NULL) - { - delete_breakpoint (sm->caller_breakpoint); - sm->caller_breakpoint = NULL; - } - delete_longjmp_breakpoint (sm->thread); + location_breakpoint.reset (); + caller_breakpoint.reset (); + delete_longjmp_breakpoint (thread); } /* Implementation of the 'async_reply_reason' FSM method for the until(location)/advance commands. */ -static enum async_reply_reason -until_break_fsm_async_reply_reason (struct thread_fsm *self) +enum async_reply_reason +until_break_fsm::do_async_reply_reason () { return EXEC_ASYNC_LOCATION_REACHED; } @@ -11063,7 +11023,6 @@ until_break_command (const char *arg, int from_tty, int anywhere) struct frame_id caller_frame_id; int thread; struct thread_info *tp; - struct until_break_fsm *sm; clear_proceed_status (0); @@ -11142,10 +11101,9 @@ until_break_command (const char *arg, int from_tty, int anywhere) location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, stack_frame_id, bp_until); - sm = new_until_break_fsm (command_interp (), tp->global_num, - std::move (location_breakpoint), - std::move (caller_breakpoint)); - tp->thread_fsm = &sm->thread_fsm; + tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, + std::move (location_breakpoint), + std::move (caller_breakpoint)); if (lj_deleter) lj_deleter->release (); -- cgit v1.2.1