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
This commit is contained in:
Simon Marchi
2021-09-01 12:19:30 -04:00
parent 7ebaa5f782
commit 25558938d0
6 changed files with 57 additions and 30 deletions

View File

@@ -4565,13 +4565,12 @@ maybe_print_thread_hit_breakpoint (struct ui_out *uiout)
if (show_thread_that_caused_stop ())
{
const char *name;
struct thread_info *thr = inferior_thread ();
uiout->text ("Thread ");
uiout->field_string ("thread-id", print_thread_id (thr));
name = thr->name != NULL ? thr->name : target_thread_name (thr);
const char *name = thread_name (thr);
if (name != NULL)
{
uiout->text (" \"");