[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<const gdb_byte>
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 <pedro@palves.net>
This commit is contained in:
Tom de Vries 2023-08-24 13:40:38 +02:00
parent f1917fc631
commit 1f08d32460
7 changed files with 35 additions and 24 deletions

View File

@ -107,7 +107,7 @@ public:
thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle, thread_info *thread_handle_to_thread_info (const gdb_byte *thread_handle,
int handle_len, int handle_len,
inferior *inf) override; inferior *inf) override;
gdb::byte_vector thread_info_to_thread_handle (struct thread_info *) override; gdb::array_view<const gdb_byte> thread_info_to_thread_handle (struct thread_info *) override;
}; };
static std::string libthread_db_search_path = LIBTHREAD_DB_SEARCH_PATH; 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. */ /* Cached thread state. */
td_thrhandle_t th {}; td_thrhandle_t th {};
thread_t tid {}; thread_t tid {};
gdb::optional<gdb::byte_vector> thread_handle;
}; };
static thread_db_thread_info * 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. */ /* Return the thread handle associated the thread_info pointer TP. */
gdb::byte_vector gdb::array_view<const gdb_byte>
thread_db_target::thread_info_to_thread_handle (struct thread_info *tp) thread_db_target::thread_info_to_thread_handle (struct thread_info *tp)
{ {
thread_db_thread_info *priv = get_thread_db_thread_info (tp); thread_db_thread_info *priv = get_thread_db_thread_info (tp);
if (priv == NULL) if (priv == NULL)
return gdb::byte_vector (); return {};
int handle_size = sizeof (priv->tid); 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 /* Get the address of the thread local variable in load module LM which

View File

@ -291,8 +291,8 @@ thpy_thread_handle (PyObject *self, PyObject *args)
thread_object *thread_obj = (thread_object *) self; thread_object *thread_obj = (thread_object *) self;
THPY_REQUIRE_VALID (thread_obj); THPY_REQUIRE_VALID (thread_obj);
gdb::byte_vector hv; gdb::array_view<const gdb_byte> hv;
try try
{ {
hv = target_thread_info_to_thread_handle (thread_obj->thread); hv = target_thread_info_to_thread_handle (thread_obj->thread);

View File

@ -784,8 +784,8 @@ public:
int handle_len, int handle_len,
inferior *inf) override; inferior *inf) override;
gdb::byte_vector thread_info_to_thread_handle (struct thread_info *tp) gdb::array_view<const gdb_byte> thread_info_to_thread_handle (struct thread_info *tp)
override; override;
void stop (ptid_t) override; void stop (ptid_t) override;
@ -14550,7 +14550,7 @@ remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle,
return NULL; return NULL;
} }
gdb::byte_vector gdb::array_view<const gdb_byte>
remote_target::thread_info_to_thread_handle (struct thread_info *tp) remote_target::thread_info_to_thread_handle (struct thread_info *tp)
{ {
remote_thread_info *priv = get_remote_thread_info (tp); remote_thread_info *priv = get_remote_thread_info (tp);

View File

@ -219,7 +219,7 @@ target_debug_print_size_t (size_t size)
} }
static void static void
target_debug_print_const_gdb_byte_vector_r (const gdb::byte_vector &vector) target_debug_print_gdb_array_view_const_gdb_byte (gdb::array_view<const gdb_byte> vector)
{ {
gdb_puts ("{", gdb_stdlog); gdb_puts ("{", gdb_stdlog);
@ -231,6 +231,12 @@ target_debug_print_const_gdb_byte_vector_r (const gdb::byte_vector &vector)
gdb_puts (" }", gdb_stdlog); gdb_puts (" }", gdb_stdlog);
} }
static void
target_debug_print_const_gdb_byte_vector_r (const gdb::byte_vector &vector)
{
target_debug_print_gdb_array_view_const_gdb_byte (vector);
}
static void static void
target_debug_print_gdb_byte_vector_r (gdb::byte_vector &vector) target_debug_print_gdb_byte_vector_r (gdb::byte_vector &vector)
{ {

View File

@ -89,7 +89,7 @@ struct dummy_target : public target_ops
const char *extra_thread_info (thread_info *arg0) override; const char *extra_thread_info (thread_info *arg0) override;
const char *thread_name (thread_info *arg0) override; const char *thread_name (thread_info *arg0) override;
thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override; thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override;
gdb::byte_vector thread_info_to_thread_handle (struct thread_info *arg0) override; gdb::array_view<const_gdb_byte> thread_info_to_thread_handle (struct thread_info *arg0) override;
void stop (ptid_t arg0) override; void stop (ptid_t arg0) override;
void interrupt () override; void interrupt () override;
void pass_ctrlc () override; void pass_ctrlc () override;
@ -263,7 +263,7 @@ struct debug_target : public target_ops
const char *extra_thread_info (thread_info *arg0) override; const char *extra_thread_info (thread_info *arg0) override;
const char *thread_name (thread_info *arg0) override; const char *thread_name (thread_info *arg0) override;
thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override; thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override;
gdb::byte_vector thread_info_to_thread_handle (struct thread_info *arg0) override; gdb::array_view<const_gdb_byte> thread_info_to_thread_handle (struct thread_info *arg0) override;
void stop (ptid_t arg0) override; void stop (ptid_t arg0) override;
void interrupt () override; void interrupt () override;
void pass_ctrlc () override; void pass_ctrlc () override;
@ -1871,28 +1871,28 @@ debug_target::thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, infe
return result; return result;
} }
gdb::byte_vector gdb::array_view<const_gdb_byte>
target_ops::thread_info_to_thread_handle (struct thread_info *arg0) target_ops::thread_info_to_thread_handle (struct thread_info *arg0)
{ {
return this->beneath ()->thread_info_to_thread_handle (arg0); return this->beneath ()->thread_info_to_thread_handle (arg0);
} }
gdb::byte_vector gdb::array_view<const_gdb_byte>
dummy_target::thread_info_to_thread_handle (struct thread_info *arg0) dummy_target::thread_info_to_thread_handle (struct thread_info *arg0)
{ {
return gdb::byte_vector (); return gdb::array_view<const gdb_byte> ();
} }
gdb::byte_vector gdb::array_view<const_gdb_byte>
debug_target::thread_info_to_thread_handle (struct thread_info *arg0) debug_target::thread_info_to_thread_handle (struct thread_info *arg0)
{ {
gdb_printf (gdb_stdlog, "-> %s->thread_info_to_thread_handle (...)\n", this->beneath ()->shortname ()); gdb_printf (gdb_stdlog, "-> %s->thread_info_to_thread_handle (...)\n", this->beneath ()->shortname ());
gdb::byte_vector result gdb::array_view<const_gdb_byte> result
= this->beneath ()->thread_info_to_thread_handle (arg0); = this->beneath ()->thread_info_to_thread_handle (arg0);
gdb_printf (gdb_stdlog, "<- %s->thread_info_to_thread_handle (", this->beneath ()->shortname ()); gdb_printf (gdb_stdlog, "<- %s->thread_info_to_thread_handle (", this->beneath ()->shortname ());
target_debug_print_struct_thread_info_p (arg0); target_debug_print_struct_thread_info_p (arg0);
gdb_puts (") = ", gdb_stdlog); gdb_puts (") = ", gdb_stdlog);
target_debug_print_gdb_byte_vector (result); target_debug_print_gdb_array_view_const_gdb_byte (result);
gdb_puts ("\n", gdb_stdlog); gdb_puts ("\n", gdb_stdlog);
return result; return result;
} }

View File

@ -2640,7 +2640,7 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle,
/* See target.h. */ /* See target.h. */
gdb::byte_vector gdb::array_view<const gdb_byte>
target_thread_info_to_thread_handle (struct thread_info *tip) target_thread_info_to_thread_handle (struct thread_info *tip)
{ {
target_ops *target = current_inferior ()->top_target (); target_ops *target = current_inferior ()->top_target ();

View File

@ -39,6 +39,10 @@ struct expression;
struct dcache_struct; struct dcache_struct;
struct inferior; struct inferior;
/* Define const gdb_byte using one identifier, to make it easy for
make-target-delegates.py to parse. */
typedef const gdb_byte const_gdb_byte;
#include "infrun.h" /* For enum exec_direction_kind. */ #include "infrun.h" /* For enum exec_direction_kind. */
#include "breakpoint.h" /* For enum bptype. */ #include "breakpoint.h" /* For enum bptype. */
#include "gdbsupport/scoped_restore.h" #include "gdbsupport/scoped_restore.h"
@ -679,8 +683,8 @@ struct target_ops
inferior *inf) inferior *inf)
TARGET_DEFAULT_RETURN (NULL); TARGET_DEFAULT_RETURN (NULL);
/* See target_thread_info_to_thread_handle. */ /* See target_thread_info_to_thread_handle. */
virtual gdb::byte_vector thread_info_to_thread_handle (struct thread_info *) virtual gdb::array_view<const_gdb_byte> thread_info_to_thread_handle (struct thread_info *)
TARGET_DEFAULT_RETURN (gdb::byte_vector ()); TARGET_DEFAULT_RETURN (gdb::array_view<const gdb_byte> ());
virtual void stop (ptid_t) virtual void stop (ptid_t)
TARGET_DEFAULT_IGNORE (); TARGET_DEFAULT_IGNORE ();
virtual void interrupt () virtual void interrupt ()
@ -1924,7 +1928,7 @@ extern struct thread_info *target_thread_handle_to_thread_info
/* Given a thread, return the thread handle, a target-specific sequence of /* Given a thread, return the thread handle, a target-specific sequence of
bytes which serves as a thread identifier within the program being bytes which serves as a thread identifier within the program being
debugged. */ debugged. */
extern gdb::byte_vector target_thread_info_to_thread_handle extern gdb::array_view<const gdb_byte> target_thread_info_to_thread_handle
(struct thread_info *); (struct thread_info *);
/* Attempts to find the pathname of the executable file /* Attempts to find the pathname of the executable file