diff options
author | Lancelot SIX <lancelot.six@amd.com> | 2022-01-11 10:10:11 -0500 |
---|---|---|
committer | Lancelot SIX <lancelot.six@amd.com> | 2022-02-07 06:12:06 -0500 |
commit | 573269a87c89ae866db556428fe9ea63d6c4db5f (patch) | |
tree | eb6f3111a711e0609ee6db4ff25e17d3ae889194 /gdb/gdbthread.h | |
parent | d08cbc5d3203118da5583296e49273cf82378042 (diff) | |
download | binutils-573269a87c89ae866db556428fe9ea63d6c4db5f.zip binutils-573269a87c89ae866db556428fe9ea63d6c4db5f.tar.gz binutils-573269a87c89ae866db556428fe9ea63d6c4db5f.tar.bz2 |
gdb: make thread_info::m_thread_fsm a std::unique_ptr
While working on function calls, I realized that the thread_fsm member
of struct thread_info is a raw pointer to a resource it owns. This
commit changes the type of the thread_fsm member to a std::unique_ptr in
order to signify this ownership relationship and slightly ease resource
management (no need to manually call delete).
To ensure consistent use, the field is made a private member
(m_thread_fsm). The setter method (set_thread_fsm) can then check
that it is incorrect to associate a FSM to a thread_info object if
another one is already in place. This is ensured by an assertion.
The function run_inferior_call takes an argument as a pointer to a
call_thread_fsm and installs it in it in a thread_info instance. Also
change this function's signature to accept a unique_ptr in order to
signify that the ownership of the call_thread_fsm is transferred during
the call.
No user visible change expected after this commit.
Tested on x86_64-linux with no regression observed.
Change-Id: Ia1224f72a4afa247801ce6650ce82f90224a9ae8
Diffstat (limited to 'gdb/gdbthread.h')
-rw-r--r-- | gdb/gdbthread.h | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 9921dae..1a33eb6 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -34,6 +34,7 @@ struct symtab; #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; @@ -443,6 +444,32 @@ public: 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; @@ -480,11 +507,6 @@ public: 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. */ @@ -550,6 +572,11 @@ private: 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 |