aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbthread.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-09-01 12:19:30 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-09-24 17:25:55 -0400
commit25558938d07b61ad628952a7bdc0a793d27f1b71 (patch)
tree1cce292b3623c2f8cecc2426bb2011dfe1716fba /gdb/gdbthread.h
parent7ebaa5f7821682c40e79ee1fdfe43528b7d87376 (diff)
downloadgdb-25558938d07b61ad628952a7bdc0a793d27f1b71.zip
gdb-25558938d07b61ad628952a7bdc0a793d27f1b71.tar.gz
gdb-25558938d07b61ad628952a7bdc0a793d27f1b71.tar.bz2
gdb: change thread_info::name to unique_xmalloc_ptr, add helper function
This started out as changing thread_info::name to a unique_xmalloc_ptr. That showed that almost all users of that field had the same logic to get a thread's name: use thread_info::name if non-nullptr, else ask the target. Factor out this logic in a new thread_name free function. Make the field private (rename to m_name) and add some accessors. Change-Id: Iebdd95f4cd21fbefc505249bd1d05befc466a2fc
Diffstat (limited to 'gdb/gdbthread.h')
-rw-r--r--gdb/gdbthread.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 4b27194..7beccba 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -235,7 +235,6 @@ class thread_info : public refcounted_object,
{
public:
explicit thread_info (inferior *inf, ptid_t ptid);
- ~thread_info ();
bool deletable () const;
@@ -286,9 +285,21 @@ public:
/* The inferior this thread belongs to. */
struct inferior *inf;
- /* The name of the thread, as specified by the user. This is NULL
- if the thread does not have a user-given name. */
- char *name = NULL;
+ /* The user-given name of the thread.
+
+ Returns nullptr if the thread does not have a user-given name. */
+ const char *name () const
+ {
+ return m_name.get ();
+ }
+
+ /* Set the user-given name of the thread.
+
+ Pass nullptr to clear the name. */
+ void set_name (gdb::unique_xmalloc_ptr<char> name)
+ {
+ m_name = std::move (name);
+ }
bool executing () const
{ return m_executing; }
@@ -523,6 +534,11 @@ private:
/* State of inferior thread to restore after GDB is done with an inferior
call. See `struct thread_suspend_state'. */
thread_suspend_state m_suspend;
+
+ /* The user-given name of the thread.
+
+ Nullptr if the thread does not have a user-given name. */
+ gdb::unique_xmalloc_ptr<char> m_name;
};
using thread_info_resumed_with_pending_wait_status_node
@@ -953,4 +969,10 @@ extern void print_selected_thread_frame (struct ui_out *uiout,
alive anymore. */
extern void thread_select (const char *tidstr, class thread_info *thr);
+/* Return THREAD's name.
+
+ If THREAD has a user-given name, return it. Otherwise, query the thread's
+ target to get the name. May return nullptr. */
+extern const char *thread_name (thread_info *thread);
+
#endif /* GDBTHREAD_H */