Skip to content

Commit

Permalink
C++-ify struct thread_fsm
Browse files Browse the repository at this point in the history
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  <[email protected]>

	* 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.
  • Loading branch information
tromey committed Feb 7, 2019
1 parent 1a5c259 commit 46e3ed7
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 486 deletions.
74 changes: 74 additions & 0 deletions gdb/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,77 @@
2019-02-07 Tom Tromey <[email protected]>

* 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.

2019-02-07 Tom Tromey <[email protected]>

* yy-remap.h: Add include guard.
Expand Down
1 change: 0 additions & 1 deletion gdb/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ COMMON_SFILES = \
test-target.c \
thread.c \
thread-iter.c \
thread-fsm.c \
tid-parse.c \
top.c \
tracefile.c \
Expand Down
108 changes: 33 additions & 75 deletions gdb/breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion gdb/cli/cli-interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ should_print_stop_to_console (struct interp *console_interp,
== BPSTAT_WHAT_STOP_NOISY)
|| tp->thread_fsm == NULL
|| tp->thread_fsm->command_interp == console_interp
|| !thread_fsm_finished_p (tp->thread_fsm))
|| !tp->thread_fsm->finished_p ())
return 1;
return 0;
}
Expand Down
Loading

0 comments on commit 46e3ed7

Please sign in to comment.