From 1f08d324601ef7fd4cce3cff8f8db4a774791828 Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 24 Aug 2023 13:40:38 +0200 Subject: [gdb/build] Return gdb::array_view in thread_info_to_thread_handle In remote_target::thread_info_to_thread_handle we return a copy: ... gdb::byte_vector remote_target::thread_info_to_thread_handle (struct thread_info *tp) { remote_thread_info *priv = get_remote_thread_info (tp); return priv->thread_handle; } ... Fix this by returning a gdb::array_view instead: ... gdb::array_view remote_target::thread_info_to_thread_handle (struct thread_info *tp) ... Tested on x86_64-linux. This fixes the build when building with -std=c++20. Approved-By: Pedro Alves --- gdb/linux-thread-db.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'gdb/linux-thread-db.c') diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 7d9fd57..16c250c 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -107,7 +107,7 @@ public: thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle, int handle_len, inferior *inf) override; - gdb::byte_vector thread_info_to_thread_handle (struct thread_info *) override; + gdb::array_view thread_info_to_thread_handle (struct thread_info *) override; }; static std::string libthread_db_search_path = LIBTHREAD_DB_SEARCH_PATH; @@ -312,6 +312,7 @@ struct thread_db_thread_info : public private_thread_info /* Cached thread state. */ td_thrhandle_t th {}; thread_t tid {}; + gdb::optional thread_handle; }; static thread_db_thread_info * @@ -1724,20 +1725,20 @@ thread_db_target::thread_handle_to_thread_info (const gdb_byte *thread_handle, /* Return the thread handle associated the thread_info pointer TP. */ -gdb::byte_vector +gdb::array_view thread_db_target::thread_info_to_thread_handle (struct thread_info *tp) { thread_db_thread_info *priv = get_thread_db_thread_info (tp); if (priv == NULL) - return gdb::byte_vector (); + return {}; int handle_size = sizeof (priv->tid); - gdb::byte_vector rv (handle_size); + priv->thread_handle.emplace (handle_size); - memcpy (rv.data (), &priv->tid, handle_size); + memcpy (priv->thread_handle->data (), &priv->tid, handle_size); - return rv; + return *priv->thread_handle; } /* Get the address of the thread local variable in load module LM which -- cgit v1.1