Skip to content

Commit 46e3ed7

Browse files
committed
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 <[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.
1 parent 1a5c259 commit 46e3ed7

File tree

11 files changed

+289
-486
lines changed

11 files changed

+289
-486
lines changed

gdb/ChangeLog

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
1+
2019-02-07 Tom Tromey <[email protected]>
2+
3+
* thread.c (thread_cancel_execution_command): Update.
4+
* thread-fsm.h (struct thread_fsm): Add constructor, destructor,
5+
methods.
6+
(struct thread_fsm_ops): Remove.
7+
(thread_fsm_ctor, thread_fsm_delete, thread_fsm_clean_up)
8+
(thread_fsm_should_stop, thread_fsm_return_value)
9+
(thread_fsm_set_finished, thread_fsm_finished_p)
10+
(thread_fsm_async_reply_reason, thread_fsm_should_notify_stop):
11+
Don't declare.
12+
* mi/mi-interp.c (mi_on_normal_stop_1): Update.
13+
* infrun.c (clear_proceed_status_thread)
14+
(clean_up_just_stopped_threads_fsms, fetch_inferior_event)
15+
(print_stop_event): Update.
16+
* infcmd.c (struct step_command_fsm): Inherit from thread_fsm.
17+
Add constructor.
18+
(step_command_fsm_ops): Remove.
19+
(new_step_command_fsm): Remove.
20+
(step_1): Update.
21+
(step_command_fsm::should_stop): Rename from
22+
step_command_fsm_should_stop.
23+
(step_command_fsm::clean_up): Rename from
24+
step_command_fsm_clean_up.
25+
(step_command_fsm::do_async_reply_reason): Rename from
26+
step_command_fsm_async_reply_reason.
27+
(struct until_next_fsm): Inherit from thread_fsm. Add
28+
constructor.
29+
(until_next_fsm_ops): Remove.
30+
(new_until_next_fsm): Remove.
31+
(until_next_fsm::should_stop): Rename from
32+
until_next_fsm_should_stop.
33+
(until_next_fsm::clean_up): Rename from until_next_fsm_clean_up.
34+
(until_next_fsm::do_async_reply_reason): Rename from
35+
until_next_fsm_async_reply_reason.
36+
(struct finish_command_fsm): Inherit from thread_fsm. Add
37+
constructor. Change type of breakpoint.
38+
(finish_command_fsm_ops): Remove.
39+
(new_finish_command_fsm): Remove.
40+
(finish_command_fsm::should_stop): Rename from
41+
finish_command_fsm_should_stop.
42+
(finish_command_fsm::clean_up): Rename from
43+
finish_command_fsm_clean_up.
44+
(finish_command_fsm::return_value): Rename from
45+
finish_command_fsm_return_value.
46+
(finish_command_fsm::do_async_reply_reason): Rename from
47+
finish_command_fsm_async_reply_reason.
48+
(finish_command): Update.
49+
* infcall.c (struct call_thread_fsm): Inherit from thread_fsm.
50+
Add constructor.
51+
(call_thread_fsm_ops): Remove.
52+
(call_thread_fsm::call_thread_fsm): Rename from
53+
new_call_thread_fsm.
54+
(call_thread_fsm::should_stop): Rename from
55+
call_thread_fsm_should_stop.
56+
(call_thread_fsm::should_notify_stop): Rename from
57+
call_thread_fsm_should_notify_stop.
58+
(run_inferior_call, call_function_by_hand_dummy): Update.
59+
* cli/cli-interp.c (should_print_stop_to_console): Update.
60+
* breakpoint.c (struct until_break_fsm): Inherit from thread_fsm.
61+
Add constructor. Change type of location_breakpoint,
62+
caller_breakpoint.
63+
(until_break_fsm_ops): Remove.
64+
(new_until_break_fsm): Remove.
65+
(until_break_fsm::should_stop): Rename from
66+
until_break_fsm_should_stop.
67+
(until_break_fsm::clean_up): Rename from
68+
until_break_fsm_clean_up.
69+
(until_break_fsm::do_async_reply_reason): Rename from
70+
until_break_fsm_async_reply_reason.
71+
(until_break_command): Update.
72+
* thread-fsm.c: Remove.
73+
* Makefile.in (COMMON_SFILES): Remove thread-fsm.c.
74+
175
2019-02-07 Tom Tromey <[email protected]>
276

377
* yy-remap.h: Add include guard.

gdb/Makefile.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,6 @@ COMMON_SFILES = \
11221122
test-target.c \
11231123
thread.c \
11241124
thread-iter.c \
1125-
thread-fsm.c \
11261125
tid-parse.c \
11271126
top.c \
11281127
tracefile.c \

gdb/breakpoint.c

Lines changed: 33 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -10950,106 +10950,66 @@ awatch_command (const char *arg, int from_tty)
1095010950
in infcmd.c. Here because it uses the mechanisms of
1095110951
breakpoints. */
1095210952

10953-
struct until_break_fsm
10953+
struct until_break_fsm : public thread_fsm
1095410954
{
10955-
/* The base class. */
10956-
struct thread_fsm thread_fsm;
10957-
10958-
/* The thread that as current when the command was executed. */
10955+
/* The thread that was current when the command was executed. */
1095910956
int thread;
1096010957

1096110958
/* The breakpoint set at the destination location. */
10962-
struct breakpoint *location_breakpoint;
10959+
breakpoint_up location_breakpoint;
1096310960

1096410961
/* Breakpoint set at the return address in the caller frame. May be
1096510962
NULL. */
10966-
struct breakpoint *caller_breakpoint;
10967-
};
10968-
10969-
static void until_break_fsm_clean_up (struct thread_fsm *self,
10970-
struct thread_info *thread);
10971-
static int until_break_fsm_should_stop (struct thread_fsm *self,
10972-
struct thread_info *thread);
10973-
static enum async_reply_reason
10974-
until_break_fsm_async_reply_reason (struct thread_fsm *self);
10963+
breakpoint_up caller_breakpoint;
1097510964

10976-
/* until_break_fsm's vtable. */
10965+
until_break_fsm (struct interp *cmd_interp, int thread,
10966+
breakpoint_up &&location_breakpoint,
10967+
breakpoint_up &&caller_breakpoint)
10968+
: thread_fsm (cmd_interp),
10969+
thread (thread),
10970+
location_breakpoint (std::move (location_breakpoint)),
10971+
caller_breakpoint (std::move (caller_breakpoint))
10972+
{
10973+
}
1097710974

10978-
static struct thread_fsm_ops until_break_fsm_ops =
10979-
{
10980-
NULL, /* dtor */
10981-
until_break_fsm_clean_up,
10982-
until_break_fsm_should_stop,
10983-
NULL, /* return_value */
10984-
until_break_fsm_async_reply_reason,
10975+
void clean_up (struct thread_info *thread) override;
10976+
bool should_stop (struct thread_info *thread) override;
10977+
enum async_reply_reason do_async_reply_reason () override;
1098510978
};
1098610979

10987-
/* Allocate a new until_break_command_fsm. */
10988-
10989-
static struct until_break_fsm *
10990-
new_until_break_fsm (struct interp *cmd_interp, int thread,
10991-
breakpoint_up &&location_breakpoint,
10992-
breakpoint_up &&caller_breakpoint)
10993-
{
10994-
struct until_break_fsm *sm;
10995-
10996-
sm = XCNEW (struct until_break_fsm);
10997-
thread_fsm_ctor (&sm->thread_fsm, &until_break_fsm_ops, cmd_interp);
10998-
10999-
sm->thread = thread;
11000-
sm->location_breakpoint = location_breakpoint.release ();
11001-
sm->caller_breakpoint = caller_breakpoint.release ();
11002-
11003-
return sm;
11004-
}
11005-
1100610980
/* Implementation of the 'should_stop' FSM method for the
1100710981
until(location)/advance commands. */
1100810982

11009-
static int
11010-
until_break_fsm_should_stop (struct thread_fsm *self,
11011-
struct thread_info *tp)
10983+
bool
10984+
until_break_fsm::should_stop (struct thread_info *tp)
1101210985
{
11013-
struct until_break_fsm *sm = (struct until_break_fsm *) self;
11014-
1101510986
if (bpstat_find_breakpoint (tp->control.stop_bpstat,
11016-
sm->location_breakpoint) != NULL
11017-
|| (sm->caller_breakpoint != NULL
10987+
location_breakpoint.get ()) != NULL
10988+
|| (caller_breakpoint != NULL
1101810989
&& bpstat_find_breakpoint (tp->control.stop_bpstat,
11019-
sm->caller_breakpoint) != NULL))
11020-
thread_fsm_set_finished (self);
10990+
caller_breakpoint.get ()) != NULL))
10991+
set_finished ();
1102110992

11022-
return 1;
10993+
return true;
1102310994
}
1102410995

1102510996
/* Implementation of the 'clean_up' FSM method for the
1102610997
until(location)/advance commands. */
1102710998

11028-
static void
11029-
until_break_fsm_clean_up (struct thread_fsm *self,
11030-
struct thread_info *thread)
10999+
void
11000+
until_break_fsm::clean_up (struct thread_info *)
1103111001
{
11032-
struct until_break_fsm *sm = (struct until_break_fsm *) self;
11033-
1103411002
/* Clean up our temporary breakpoints. */
11035-
if (sm->location_breakpoint != NULL)
11036-
{
11037-
delete_breakpoint (sm->location_breakpoint);
11038-
sm->location_breakpoint = NULL;
11039-
}
11040-
if (sm->caller_breakpoint != NULL)
11041-
{
11042-
delete_breakpoint (sm->caller_breakpoint);
11043-
sm->caller_breakpoint = NULL;
11044-
}
11045-
delete_longjmp_breakpoint (sm->thread);
11003+
location_breakpoint.reset ();
11004+
caller_breakpoint.reset ();
11005+
delete_longjmp_breakpoint (thread);
1104611006
}
1104711007

1104811008
/* Implementation of the 'async_reply_reason' FSM method for the
1104911009
until(location)/advance commands. */
1105011010

11051-
static enum async_reply_reason
11052-
until_break_fsm_async_reply_reason (struct thread_fsm *self)
11011+
enum async_reply_reason
11012+
until_break_fsm::do_async_reply_reason ()
1105311013
{
1105411014
return EXEC_ASYNC_LOCATION_REACHED;
1105511015
}
@@ -11063,7 +11023,6 @@ until_break_command (const char *arg, int from_tty, int anywhere)
1106311023
struct frame_id caller_frame_id;
1106411024
int thread;
1106511025
struct thread_info *tp;
11066-
struct until_break_fsm *sm;
1106711026

1106811027
clear_proceed_status (0);
1106911028

@@ -11142,10 +11101,9 @@ until_break_command (const char *arg, int from_tty, int anywhere)
1114211101
location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal,
1114311102
stack_frame_id, bp_until);
1114411103

11145-
sm = new_until_break_fsm (command_interp (), tp->global_num,
11146-
std::move (location_breakpoint),
11147-
std::move (caller_breakpoint));
11148-
tp->thread_fsm = &sm->thread_fsm;
11104+
tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num,
11105+
std::move (location_breakpoint),
11106+
std::move (caller_breakpoint));
1114911107

1115011108
if (lj_deleter)
1115111109
lj_deleter->release ();

gdb/cli/cli-interp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ should_print_stop_to_console (struct interp *console_interp,
113113
== BPSTAT_WHAT_STOP_NOISY)
114114
|| tp->thread_fsm == NULL
115115
|| tp->thread_fsm->command_interp == console_interp
116-
|| !thread_fsm_finished_p (tp->thread_fsm))
116+
|| !tp->thread_fsm->finished_p ())
117117
return 1;
118118
return 0;
119119
}

0 commit comments

Comments
 (0)