From 25558938d07b61ad628952a7bdc0a793d27f1b71 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 1 Sep 2021 12:19:30 -0400 Subject: 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 --- gdb/python/py-infthread.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'gdb/python') diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 74bbe99..a815f3f 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -66,14 +66,10 @@ static PyObject * thpy_get_name (PyObject *self, void *ignore) { thread_object *thread_obj = (thread_object *) self; - const char *name; THPY_REQUIRE_VALID (thread_obj); - name = thread_obj->thread->name; - if (name == NULL) - name = target_thread_name (thread_obj->thread); - + const char *name = thread_name (thread_obj->thread); if (name == NULL) Py_RETURN_NONE; @@ -115,8 +111,7 @@ thpy_set_name (PyObject *self, PyObject *newvalue, void *ignore) return -1; } - xfree (thread_obj->thread->name); - thread_obj->thread->name = name.release (); + thread_obj->thread->set_name (std::move (name)); return 0; } -- cgit v1.1