From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
To: gdb-patches@sourceware.org
Cc: Luis Machado <luis.machado@arm.com>,
Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Subject: [PATCH v2 4/6] gdbserver/linux-aarch64: When thread stops, update its target description
Date: Sat, 26 Nov 2022 02:04:50 +0000 [thread overview]
Message-ID: <20221126020452.1686509-5-thiago.bauermann@linaro.org> (raw)
In-Reply-To: <20221126020452.1686509-1-thiago.bauermann@linaro.org>
This change allows aarch64-linux to support debugging programs where
different threads have different SVE vector lengths. It requires
gdbserver to support different inferior threads having different target
descriptions.
The arch_update_tdesc method is added to the linux_process_target class to
allow aarch64-linux to probe the inferior's vq register and provide an
updated thread target description reflecting the new vector length.
After this change, all targets except SVE-supporting aarch64-linux will
still use per-process target descriptions.
---
gdbserver/gdbthread.h | 2 ++
gdbserver/linux-aarch64-low.cc | 37 +++++++++++++++++++++++++++++++++-
gdbserver/linux-low.cc | 18 +++++++++++++++++
gdbserver/linux-low.h | 5 +++++
gdbserver/regcache.cc | 11 +++++++---
gdbserver/tdesc.cc | 3 +++
6 files changed, 72 insertions(+), 4 deletions(-)
diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h
index 8b897e73d33b..47b44d03b8e0 100644
--- a/gdbserver/gdbthread.h
+++ b/gdbserver/gdbthread.h
@@ -80,6 +80,8 @@ struct thread_info
/* Branch trace target information for this thread. */
struct btrace_target_info *btrace = nullptr;
+
+ const struct target_desc *tdesc = nullptr;
};
extern std::list<thread_info *> all_threads;
diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index cab4fc0a4674..786ce4071279 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -99,6 +99,9 @@ protected:
void low_arch_setup () override;
+ gdb::optional<const struct target_desc *>
+ arch_update_tdesc (const thread_info *thread) override;
+
bool low_cannot_fetch_register (int regno) override;
bool low_cannot_store_register (int regno) override;
@@ -184,6 +187,8 @@ struct arch_process_info
same for each thread, it is reasonable for the data to live here.
*/
struct aarch64_debug_reg_state debug_reg_state;
+
+ bool has_sve;
};
/* Return true if the size of register 0 is 8 byte. */
@@ -840,8 +845,16 @@ aarch64_target::low_arch_setup ()
{
struct aarch64_features features
= aarch64_get_arch_features (current_thread);
+ const target_desc *tdesc = aarch64_linux_read_description (features);
- current_process ()->tdesc = aarch64_linux_read_description (features);
+ /* Only SVE-enabled inferiors need per-thread target descriptions. */
+ if (features.vq > 0)
+ {
+ current_thread->tdesc = tdesc;
+ current_process ()->priv->arch_private->has_sve = true;
+ }
+
+ current_process ()->tdesc = tdesc;
/* Adjust the register sets we should use for this particular set of
features. */
@@ -853,6 +866,28 @@ aarch64_target::low_arch_setup ()
aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread));
}
+/* Implementation of linux target ops method "arch_update_tdesc". */
+
+gdb::optional<const struct target_desc *>
+aarch64_target::arch_update_tdesc (const thread_info *thread)
+{
+ /* Only processes using SVE need to update the thread's target description. */
+ if (!get_thread_process (thread)->priv->arch_private->has_sve)
+ return {};
+
+ const struct aarch64_features features = aarch64_get_arch_features (thread);
+ const struct target_desc *tdesc = aarch64_linux_read_description (features);
+
+ if (tdesc == thread->tdesc)
+ return {};
+
+ /* Adjust the register sets we should use for this particular set of
+ features. */
+ aarch64_adjust_register_sets(features);
+
+ return tdesc;
+}
+
/* Implementation of linux target ops method "get_regs_info". */
const regs_info *
diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc
index fc496275d6a3..7c510e26f0f5 100644
--- a/gdbserver/linux-low.cc
+++ b/gdbserver/linux-low.cc
@@ -483,6 +483,12 @@ linux_process_target::arch_setup_thread (thread_info *thread)
low_arch_setup ();
}
+gdb::optional<const struct target_desc *>
+linux_process_target::arch_update_tdesc (const thread_info *thread)
+{
+ return {};
+}
+
int
linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp,
int wstat)
@@ -2348,6 +2354,18 @@ linux_process_target::filter_event (int lwpid, int wstat)
return;
}
}
+ else
+ {
+ /* Give the arch code an opportunity to update the thread's target
+ description. */
+ gdb::optional<const struct target_desc *> new_tdesc
+ = arch_update_tdesc (thread);
+ if (new_tdesc.has_value ())
+ {
+ regcache_release ();
+ thread->tdesc = *new_tdesc;
+ }
+ }
}
if (WIFSTOPPED (wstat) && child->must_set_ptrace_flags)
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 182a540f3bb3..ff14423e9e07 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -604,6 +604,11 @@ class linux_process_target : public process_stratum_target
/* Architecture-specific setup for the current thread. */
virtual void low_arch_setup () = 0;
+ /* Allows arch-specific code to update the thread's target description when
+ the inferior stops. */
+ virtual gdb::optional<const struct target_desc *>
+ arch_update_tdesc (const thread_info *thread);
+
/* Return false if we can fetch/store the register, true if we cannot
fetch/store the register. */
virtual bool low_cannot_fetch_register (int regno) = 0;
diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 14236069f712..03ee88b3cfd1 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -39,11 +39,16 @@ get_thread_regcache (struct thread_info *thread, int fetch)
have. */
if (regcache == NULL)
{
- struct process_info *proc = get_thread_process (thread);
+ /* First see if there's a thread-specific target description. */
+ const target_desc *tdesc = thread->tdesc;
- gdb_assert (proc->tdesc != NULL);
+ /* If not, get it from the process instead. */
+ if (tdesc == nullptr)
+ tdesc = get_thread_process (thread)->tdesc;
- regcache = new_register_cache (proc->tdesc);
+ gdb_assert (tdesc != nullptr);
+
+ regcache = new_register_cache (tdesc);
set_thread_regcache_data (thread, regcache);
}
diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc
index 5693cc6626fb..3665ab0540d5 100644
--- a/gdbserver/tdesc.cc
+++ b/gdbserver/tdesc.cc
@@ -129,6 +129,9 @@ current_target_desc (void)
if (current_thread == NULL)
return &default_description;
+ if (current_thread->tdesc != nullptr)
+ return current_thread->tdesc;
+
return current_process ()->tdesc;
}
next prev parent reply other threads:[~2022-11-26 2:05 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-26 2:04 [PATCH v2 0/6] gdbserver improvements for AArch64 SVE support Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 1/6] gdbserver: Add asserts in register_size and register_data functions Thiago Jung Bauermann
2022-11-28 11:51 ` Luis Machado
2022-11-29 2:53 ` Thiago Jung Bauermann
2022-11-28 14:48 ` Simon Marchi
2022-11-28 14:53 ` Simon Marchi
2022-11-29 2:52 ` Thiago Jung Bauermann
2022-11-29 2:43 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 2/6] gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap Thiago Jung Bauermann
2022-11-28 11:50 ` Luis Machado
2022-11-28 15:01 ` Simon Marchi
2022-11-29 3:10 ` Thiago Jung Bauermann
2022-11-28 15:07 ` Simon Marchi
2022-11-28 15:20 ` Luis Machado
2022-11-29 3:17 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 3/6] gdbserver/linux-aarch64: Factor out function to get aarch64_features Thiago Jung Bauermann
2022-11-28 11:54 ` Luis Machado
2022-11-29 3:19 ` Thiago Jung Bauermann
2022-11-28 15:12 ` Simon Marchi
2022-11-29 3:26 ` Thiago Jung Bauermann
2022-11-26 2:04 ` Thiago Jung Bauermann [this message]
2022-11-28 12:06 ` [PATCH v2 4/6] gdbserver/linux-aarch64: When thread stops, update its target description Luis Machado
2022-11-29 3:59 ` Thiago Jung Bauermann
2022-11-28 15:47 ` Simon Marchi
2022-11-28 16:01 ` Luis Machado
2022-11-28 16:07 ` Simon Marchi
2022-11-29 4:30 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 5/6] gdb/aarch64: Factor out most of the thread_architecture method Thiago Jung Bauermann
2022-11-28 12:09 ` Luis Machado
2022-11-29 4:32 ` Thiago Jung Bauermann
2022-11-28 16:09 ` Simon Marchi
2022-11-29 4:33 ` Thiago Jung Bauermann
2022-11-26 2:04 ` [PATCH v2 6/6] gdb/aarch64: Detect vector length changes when debugging remotely Thiago Jung Bauermann
2022-11-28 13:27 ` Luis Machado
2022-12-01 1:15 ` Thiago Jung Bauermann
2022-11-28 16:36 ` Simon Marchi
2022-12-01 3:16 ` Thiago Jung Bauermann
2022-12-01 8:32 ` Luis Machado
2022-12-01 16:16 ` Simon Marchi
2022-11-30 8:43 ` Luis Machado
2022-12-05 22:37 ` Thiago Jung Bauermann
2022-12-07 17:05 ` Luis Machado
2022-12-07 19:25 ` Simon Marchi
2022-12-07 23:01 ` Luis Machado
2022-12-09 2:20 ` Thiago Jung Bauermann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221126020452.1686509-5-thiago.bauermann@linaro.org \
--to=thiago.bauermann@linaro.org \
--cc=gdb-patches@sourceware.org \
--cc=luis.machado@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).