diff options
author | Tom de Vries <tdevries@suse.de> | 2023-08-24 13:40:38 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2023-08-24 13:40:38 +0200 |
commit | 1f08d324601ef7fd4cce3cff8f8db4a774791828 (patch) | |
tree | f5dc02b94c0fe17232557d8bf24b9f705a7ba337 /gdb | |
parent | f1917fc63166d73a9d0930d96468e486a49c666d (diff) | |
download | gdb-1f08d324601ef7fd4cce3cff8f8db4a774791828.zip gdb-1f08d324601ef7fd4cce3cff8f8db4a774791828.tar.gz gdb-1f08d324601ef7fd4cce3cff8f8db4a774791828.tar.bz2 |
[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>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/linux-thread-db.c | 13 | ||||
-rw-r--r-- | gdb/python/py-infthread.c | 4 | ||||
-rw-r--r-- | gdb/remote.c | 6 | ||||
-rw-r--r-- | gdb/target-debug.h | 8 | ||||
-rw-r--r-- | gdb/target-delegates.c | 16 | ||||
-rw-r--r-- | gdb/target.c | 2 | ||||
-rw-r--r-- | gdb/target.h | 10 |
7 files changed, 35 insertions, 24 deletions
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<const gdb_byte> 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<gdb::byte_vector> 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<const gdb_byte> 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 diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c index 1bd25d0..00d7171 100644 --- a/gdb/python/py-infthread.c +++ b/gdb/python/py-infthread.c @@ -291,8 +291,8 @@ thpy_thread_handle (PyObject *self, PyObject *args) thread_object *thread_obj = (thread_object *) self; THPY_REQUIRE_VALID (thread_obj); - gdb::byte_vector hv; - + gdb::array_view<const gdb_byte> hv; + try { hv = target_thread_info_to_thread_handle (thread_obj->thread); diff --git a/gdb/remote.c b/gdb/remote.c index 7abe084..5af40bd 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -784,8 +784,8 @@ public: int handle_len, inferior *inf) override; - gdb::byte_vector thread_info_to_thread_handle (struct thread_info *tp) - override; + gdb::array_view<const gdb_byte> thread_info_to_thread_handle (struct thread_info *tp) + override; void stop (ptid_t) override; @@ -14550,7 +14550,7 @@ remote_target::thread_handle_to_thread_info (const gdb_byte *thread_handle, return NULL; } -gdb::byte_vector +gdb::array_view<const gdb_byte> remote_target::thread_info_to_thread_handle (struct thread_info *tp) { remote_thread_info *priv = get_remote_thread_info (tp); diff --git a/gdb/target-debug.h b/gdb/target-debug.h index acb01d4..082550d 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -219,7 +219,7 @@ target_debug_print_size_t (size_t size) } 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); @@ -232,6 +232,12 @@ target_debug_print_const_gdb_byte_vector_r (const gdb::byte_vector &vector) } 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 target_debug_print_gdb_byte_vector_r (gdb::byte_vector &vector) { target_debug_print_const_gdb_byte_vector_r (vector); diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 06f22d5..715e50b 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -89,7 +89,7 @@ struct dummy_target : public target_ops const char *extra_thread_info (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; - 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 interrupt () 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 *thread_name (thread_info *arg0) 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 interrupt () 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; } -gdb::byte_vector +gdb::array_view<const_gdb_byte> target_ops::thread_info_to_thread_handle (struct thread_info *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) { - 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) { 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); gdb_printf (gdb_stdlog, "<- %s->thread_info_to_thread_handle (", this->beneath ()->shortname ()); target_debug_print_struct_thread_info_p (arg0); 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); return result; } diff --git a/gdb/target.c b/gdb/target.c index 16f43d0..8b1d48d 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -2640,7 +2640,7 @@ target_thread_handle_to_thread_info (const gdb_byte *thread_handle, /* See target.h. */ -gdb::byte_vector +gdb::array_view<const gdb_byte> target_thread_info_to_thread_handle (struct thread_info *tip) { target_ops *target = current_inferior ()->top_target (); diff --git a/gdb/target.h b/gdb/target.h index 6ae400e..0cea955 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -39,6 +39,10 @@ struct expression; struct dcache_struct; 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 "breakpoint.h" /* For enum bptype. */ #include "gdbsupport/scoped_restore.h" @@ -679,8 +683,8 @@ struct target_ops inferior *inf) TARGET_DEFAULT_RETURN (NULL); /* See target_thread_info_to_thread_handle. */ - virtual gdb::byte_vector thread_info_to_thread_handle (struct thread_info *) - TARGET_DEFAULT_RETURN (gdb::byte_vector ()); + virtual gdb::array_view<const_gdb_byte> thread_info_to_thread_handle (struct thread_info *) + TARGET_DEFAULT_RETURN (gdb::array_view<const gdb_byte> ()); virtual void stop (ptid_t) TARGET_DEFAULT_IGNORE (); 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 bytes which serves as a thread identifier within the program being 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 *); /* Attempts to find the pathname of the executable file |