breakpoints.emplace_back (std::move (location_breakpoint));
}
- tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num,
- std::move (breakpoints));
+ tp->set_thread_fsm
+ (std::unique_ptr<thread_fsm>
+ (new until_break_fsm (command_interp (), tp->global_num,
+ std::move (breakpoints))));
if (lj_deleter)
lj_deleter->release ();
{
if ((bpstat_what (tp->control.stop_bpstat).main_action
== BPSTAT_WHAT_STOP_NOISY)
- || tp->thread_fsm == NULL
- || tp->thread_fsm->command_interp == console_interp
- || !tp->thread_fsm->finished_p ())
+ || tp->thread_fsm () == nullptr
+ || tp->thread_fsm ()->command_interp == console_interp
+ || !tp->thread_fsm ()->finished_p ())
return 1;
return 0;
}
#include "gdbsupport/forward-scope-exit.h"
#include "displaced-stepping.h"
#include "gdbsupport/intrusive_list.h"
+#include "thread-fsm.h"
struct inferior;
struct process_stratum_target;
m_suspend.stop_reason = reason;
}
+ /* Get the FSM associated with the thread. */
+
+ struct thread_fsm *thread_fsm () const
+ {
+ return m_thread_fsm.get ();
+ }
+
+ /* Get the owning reference to the FSM associated with the thread.
+
+ After a call to this method, "thread_fsm () == nullptr". */
+
+ std::unique_ptr<struct thread_fsm> release_thread_fsm ()
+ {
+ return std::move (m_thread_fsm);
+ }
+
+ /* Set the FSM associated with the current thread.
+
+ It is invalid to set the FSM if another FSM is already installed. */
+
+ void set_thread_fsm (std::unique_ptr<struct thread_fsm> fsm)
+ {
+ gdb_assert (m_thread_fsm == nullptr);
+ m_thread_fsm = std::move (fsm);
+ }
+
int current_line = 0;
struct symtab *current_symtab = NULL;
when GDB gets back SIGTRAP from step_resume_breakpoint. */
int step_after_step_resume_breakpoint = 0;
- /* Pointer to the state machine manager object that handles what is
- left to do for the thread's execution command after the target
- stops. Several execution commands use it. */
- struct thread_fsm *thread_fsm = NULL;
-
/* This is used to remember when a fork or vfork event was caught by
a catchpoint, and thus the event is to be followed at the next
resume of the thread, and not immediately. */
Nullptr if the thread does not have a user-given name. */
gdb::unique_xmalloc_ptr<char> m_name;
+
+ /* Pointer to the state machine manager object that handles what is
+ left to do for the thread's execution command after the target
+ stops. Several execution commands use it. */
+ std::unique_ptr<struct thread_fsm> m_thread_fsm;
};
using thread_info_resumed_with_pending_wait_status_node
thrown errors. The caller should rethrow if there's an error. */
static struct gdb_exception
-run_inferior_call (struct call_thread_fsm *sm,
+run_inferior_call (std::unique_ptr<call_thread_fsm> sm,
struct thread_info *call_thread, CORE_ADDR real_pc)
{
struct gdb_exception caught_error;
clear_proceed_status (0);
/* Associate the FSM with the thread after clear_proceed_status
- (otherwise it'd clear this FSM), and before anything throws, so
- we don't leak it (and any resources it manages). */
- call_thread->thread_fsm = sm;
+ (otherwise it'd clear this FSM). */
+ call_thread->set_thread_fsm (std::move (sm));
disable_watchpoints_before_interactive_call_start ();
just below is the place to chop this function in two.. */
{
- struct thread_fsm *saved_sm;
- struct call_thread_fsm *sm;
-
/* Save the current FSM. We'll override it. */
- saved_sm = call_thread->thread_fsm;
- call_thread->thread_fsm = NULL;
+ std::unique_ptr<thread_fsm> saved_sm = call_thread->release_thread_fsm ();
+ struct call_thread_fsm *sm;
/* Save this thread's ptid, we need it later but the thread
may have exited. */
values_type,
return_method != return_method_normal,
struct_addr);
-
- e = run_inferior_call (sm, call_thread.get (), real_pc);
+ {
+ std::unique_ptr<call_thread_fsm> sm_up (sm);
+ e = run_inferior_call (std::move (sm_up), call_thread.get (), real_pc);
+ }
gdb::observers::inferior_call_post.notify (call_thread_ptid, funaddr);
if (call_thread->state != THREAD_EXITED)
{
/* The FSM should still be the same. */
- gdb_assert (call_thread->thread_fsm == sm);
+ gdb_assert (call_thread->thread_fsm () == sm);
- if (call_thread->thread_fsm->finished_p ())
+ if (call_thread->thread_fsm ()->finished_p ())
{
struct value *retval;
/* Get the return value. */
retval = sm->return_value;
- /* Clean up / destroy the call FSM, and restore the
- original one. */
- call_thread->thread_fsm->clean_up (call_thread.get ());
- delete call_thread->thread_fsm;
- call_thread->thread_fsm = saved_sm;
+ /* Restore the original FSM and clean up / destroh the call FSM.
+ Doing it in this order ensures that if the call to clean_up
+ throws, the original FSM is properly restored. */
+ {
+ std::unique_ptr<thread_fsm> finalizing
+ = call_thread->release_thread_fsm ();
+ call_thread->set_thread_fsm (std::move (saved_sm));
+
+ finalizing->clean_up (call_thread.get ());
+ }
maybe_remove_breakpoints ();
/* Didn't complete. Clean up / destroy the call FSM, and restore the
previous state machine, and handle the error. */
- call_thread->thread_fsm->clean_up (call_thread.get ());
- delete call_thread->thread_fsm;
- call_thread->thread_fsm = saved_sm;
+ {
+ std::unique_ptr<thread_fsm> finalizing
+ = call_thread->release_thread_fsm ();
+ call_thread->set_thread_fsm (std::move (saved_sm));
+
+ finalizing->clean_up (call_thread.get ());
+ }
}
}
steps. */
thr = inferior_thread ();
step_sm = new step_command_fsm (command_interp ());
- thr->thread_fsm = step_sm;
+ thr->set_thread_fsm (std::unique_ptr<thread_fsm> (step_sm));
step_command_fsm_prepare (step_sm, skip_subroutines,
single_inst, count, thr);
/* Stepped into an inline frame. Pretend that we've
stopped. */
- thr->thread_fsm->clean_up (thr);
+ thr->thread_fsm ()->clean_up (thr);
proceeded = normal_stop ();
if (!proceeded)
inferior_event_handler (INF_EXEC_COMPLETE);
delete_longjmp_breakpoint_cleanup lj_deleter (thread);
sm = new until_next_fsm (command_interp (), tp->global_num);
- tp->thread_fsm = sm;
+ tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm));
lj_deleter.release ();
proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
sm = new finish_command_fsm (command_interp ());
- tp->thread_fsm = sm;
+ tp->set_thread_fsm (std::unique_ptr<thread_fsm> (sm));
/* Finishing from an inline frame is completely different. We don't
try to show the "return value" - no way to locate it. */
int current_line = 0;
symtab *current_symtab = NULL;
struct frame_id step_frame_id = { 0 };
- struct thread_fsm *thread_fsm = NULL;
if (!non_stop)
{
case TARGET_WAITKIND_VFORKED:
{
ptid_t parent, child;
+ std::unique_ptr<struct thread_fsm> thread_fsm;
/* If the user did a next/step, etc, over a fork call,
preserve the stepping state in the fork child. */
step_frame_id = tp->control.step_frame_id;
exception_resume_breakpoint
= clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
- thread_fsm = tp->thread_fsm;
+ thread_fsm = tp->release_thread_fsm ();
/* For now, delete the parent's sr breakpoint, otherwise,
parent/child sr breakpoints are considered duplicates,
tp->control.step_range_end = 0;
tp->control.step_frame_id = null_frame_id;
delete_exception_resume_breakpoint (tp);
- tp->thread_fsm = NULL;
}
parent = inferior_ptid;
tp->control.step_frame_id = step_frame_id;
tp->control.exception_resume_breakpoint
= exception_resume_breakpoint;
- tp->thread_fsm = thread_fsm;
+ tp->set_thread_fsm (std::move (thread_fsm));
}
else
{
if (!signal_pass_state (tp->stop_signal ()))
tp->set_stop_signal (GDB_SIGNAL_0);
- delete tp->thread_fsm;
- tp->thread_fsm = NULL;
+ tp->release_thread_fsm ();
tp->control.trap_expected = 0;
tp->control.step_range_start = 0;
static void
clean_up_just_stopped_threads_fsms (struct execution_control_state *ecs)
{
- if (ecs->event_thread != NULL
- && ecs->event_thread->thread_fsm != NULL)
- ecs->event_thread->thread_fsm->clean_up (ecs->event_thread);
+ if (ecs->event_thread != nullptr
+ && ecs->event_thread->thread_fsm () != nullptr)
+ ecs->event_thread->thread_fsm ()->clean_up (ecs->event_thread);
if (!non_stop)
{
for (thread_info *thr : all_non_exited_threads ())
{
- if (thr->thread_fsm == NULL)
+ if (thr->thread_fsm () == nullptr)
continue;
if (thr == ecs->event_thread)
continue;
switch_to_thread (thr);
- thr->thread_fsm->clean_up (thr);
+ thr->thread_fsm ()->clean_up (thr);
}
- if (ecs->event_thread != NULL)
+ if (ecs->event_thread != nullptr)
switch_to_thread (ecs->event_thread);
}
}
delete_just_stopped_threads_infrun_breakpoints ();
- if (thr != NULL)
- {
- struct thread_fsm *thread_fsm = thr->thread_fsm;
-
- if (thread_fsm != NULL)
- should_stop = thread_fsm->should_stop (thr);
- }
+ if (thr != nullptr && thr->thread_fsm () != nullptr)
+ should_stop = thr->thread_fsm ()->should_stop (thr);
if (!should_stop)
{
clean_up_just_stopped_threads_fsms (ecs);
- if (thr != NULL && thr->thread_fsm != NULL)
- should_notify_stop = thr->thread_fsm->should_notify_stop ();
+ if (thr != nullptr && thr->thread_fsm () != nullptr)
+ should_notify_stop
+ = thr->thread_fsm ()->should_notify_stop ();
if (should_notify_stop)
{
}
tp = inferior_thread ();
- if (tp->thread_fsm != NULL
- && tp->thread_fsm->finished_p ())
+ if (tp->thread_fsm () != nullptr
+ && tp->thread_fsm ()->finished_p ())
{
struct return_value_info *rv;
- rv = tp->thread_fsm->return_value ();
- if (rv != NULL)
+ rv = tp->thread_fsm ()->return_value ();
+ if (rv != nullptr)
print_return_value (uiout, rv);
}
}
tp = inferior_thread ();
- if (tp->thread_fsm != NULL
- && tp->thread_fsm->finished_p ())
+ if (tp->thread_fsm () != nullptr
+ && tp->thread_fsm ()->finished_p ())
{
enum async_reply_reason reason;
- reason = tp->thread_fsm->async_reply_reason ();
+ reason = tp->thread_fsm ()->async_reply_reason ();
mi_uiout->field_string ("reason", async_reason_lookup (reason));
}
void
thread_cancel_execution_command (struct thread_info *thr)
{
- if (thr->thread_fsm != NULL)
+ if (thr->thread_fsm () != nullptr)
{
- thr->thread_fsm->clean_up (thr);
- delete thr->thread_fsm;
- thr->thread_fsm = NULL;
+ std::unique_ptr<thread_fsm> fsm = thr->release_thread_fsm ();
+ fsm->clean_up (thr);
}
}