From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 1E9BE382EF1E for ; Sat, 26 Nov 2022 02:05:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1E9BE382EF1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x231.google.com with SMTP id l127so6114966oia.8 for ; Fri, 25 Nov 2022 18:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KvxV0OAzT3TQ+DSNSsgv7chYhKWMoVjFPAy8JBuPUII=; b=uPiN2flJYJbmbTuxc6DdIDHi/OexPli/hJVWV8TGP1TYkmayHRfY5pXtfye+AbQu5m hYXiQvsWfPIX7PC4e/YP30kRRICT2dz/bFQP83WyfpIzQPM4+nOdXdrWhsZfXToF2ylw lGHb2MjX4I2U5w9zA6c1GsWKGYYVI4brnDjrzWBPOI+bzo3gNmtN1GZXqDL+8yMve1Ry 2YvwEkL6JuMOgWGo/Efnvb0te7g7lwoAXX9EnmTJbUDX8CeclP//njtHFNtI8atqX47G 22KIdD3T38yreKxQ5C6hy7VgiN76oJRJNl3wTxhAvAOp7+wKaxkcp3NDSPJJjGmBa2ob VQxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KvxV0OAzT3TQ+DSNSsgv7chYhKWMoVjFPAy8JBuPUII=; b=3Xot+P0YyG7/GWj/pn99sNDQXBuh9chcb9vJm6s+QEyAfkKC2X3rPf34MHg8/Rz9Rv iwlzJynT+B3IeMi4BF6lvB9Y0UahtHajQsqRUemUlD0Y7XGRn+c6r5P85bzP0wbcbA/p u9IP0dJXTUhqRwBFH8XO6X3OAQY3eJpV89PBNMJsMwoFXJWcS7u9v+La2RUCg4ObLE57 nfN1tUvgQY7rNdR1T7Dh31m43RdypM92IA/IfpKAB6aAzvsqJVukjcwF0gyGI1XBzy8P QPwj6YfTqdL9/elLmQ0oNnIh1xLbCGOINA4QVk9rVS/3LyNcxShzoPp4KxrgKlHfze7p uZ3w== X-Gm-Message-State: ANoB5pkhra209TfS5u/sBZTA+KWPkc7c69ChuWPVtOIUVd3j1tsYM3hb lHsCqG8BUQFtEkbaLNkpWW9o788FG+LpMg== X-Google-Smtp-Source: AA0mqf5WmB7DOA3h5L+EuscSf/ACDZ/+l0p6Bio9By99v2eC9WO3Mmt75agQ9mYFeCA+2zbE0zqgKQ== X-Received: by 2002:a54:4813:0:b0:34f:796c:f1d5 with SMTP id j19-20020a544813000000b0034f796cf1d5mr11655154oij.100.1669428324392; Fri, 25 Nov 2022 18:05:24 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:41ee:c7fc:c991:eee6]) by smtp.gmail.com with ESMTPSA id l27-20020a056830335b00b0066da36d2c45sm2340260ott.22.2022.11.25.18.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 18:05:24 -0800 (PST) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Luis Machado , Thiago Jung Bauermann Subject: [PATCH v2 4/6] gdbserver/linux-aarch64: When thread stops, update its target description Date: Sat, 26 Nov 2022 02:04:50 +0000 Message-Id: <20221126020452.1686509-5-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221126020452.1686509-1-thiago.bauermann@linaro.org> References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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 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 + 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 +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 +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 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 + 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; }