From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id uJCqG6xL12Pd8iQAWB0awg (envelope-from ) for ; Sun, 29 Jan 2023 23:46:36 -0500 Received: by simark.ca (Postfix, from userid 112) id 6DF211E128; Sun, 29 Jan 2023 23:46:36 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=kYp8x7CJ; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A9AF31E110 for ; Sun, 29 Jan 2023 23:46:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3F55C3857835 for ; Mon, 30 Jan 2023 04:46:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F55C3857835 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675053995; bh=y9V/RcC6gO/K/p4J18q4SdPtNqfxcreCPFqK4dwS/zc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kYp8x7CJ1m96NkSnYXJ30ntSGF3T2LfViQqcrvy2D3392RpQPHO/ksbvgn3LZlp3K UQo0Z2iZWalUtdeWxjWtBJyi8i0nXbe4EwaN/+U+qO+lm4v7W/KwmHlYW9OabjNbnx pzMbSTLjVS6NGsWcKnE05O/2MYIKT0ZYrbHfdy5A= Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by sourceware.org (Postfix) with ESMTPS id DCC4E385841C for ; Mon, 30 Jan 2023 04:45:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCC4E385841C Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1442977d77dso13639182fac.6 for ; Sun, 29 Jan 2023 20:45:48 -0800 (PST) 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=y9V/RcC6gO/K/p4J18q4SdPtNqfxcreCPFqK4dwS/zc=; b=2GKRAy0e9/733gzJn1Pz+WJOdRtC8inoN/wMnwJhwqQgCpOPsLZWr+NQJyrI0hW4ZE SVOTzkJurfTyz6qrCPD8PZklxv9Xoz/8pObjgwpTcg5EzgJ506MtilF5N1sTWVc7Rifo 6vkIWtjLNJE+LhOiDT7FF+rqY14Slxpow02RgEBnNbW49o7KMiZCoALpTIk4w87I0L+8 hsz7COiazlICckJeYaXuQyWakqX1fVOYfwWn+qHanrXVY4Whzd/BClZIuBRkWL+0kcjs SxeSNHWtG7G4SH7P3MxPQaxdyvPsVIwUTeiMqbVCtVEJAAZe6aUwbuFlY2eHu7A7y04j 6C8g== X-Gm-Message-State: AO0yUKWKk1/pUucORieHp1qT9EXoWyz7bhqphrM+YGh1wTQqMs99DGFV U36DKoCTVMcXOeQhf+EiTDG6Vl4lRzflqISH X-Google-Smtp-Source: AK7set/YIPL0LeGIjquQVYiJ81pez5tL5V0qx/us6esPc48EZAoiiJxfpl757LrUTvmhu28ygO7UEA== X-Received: by 2002:a05:6870:a994:b0:163:3231:3f93 with SMTP id ep20-20020a056870a99400b0016332313f93mr10512036oab.39.1675053948240; Sun, 29 Jan 2023 20:45:48 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:df99:10bd:7dca:b2e9]) by smtp.gmail.com with ESMTPSA id et10-20020a0568705cca00b00163263f84dasm4701940oab.12.2023.01.29.20.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 20:45:47 -0800 (PST) To: gdb-patches@sourceware.org Cc: Thiago Jung Bauermann , Luis Machado Subject: [PATCH v3 4/8] gdbserver/linux-aarch64: When thread stops, update its target description Date: Mon, 30 Jan 2023 04:45:14 +0000 Message-Id: <20230130044518.3322695-5-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130044518.3322695-1-thiago.bauermann@linaro.org> References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Thiago Jung Bauermann via Gdb-patches Reply-To: Thiago Jung Bauermann Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" This change prepares gdbserver to support remotely debugging programs in aarch64-linux where different threads have different SVE vector lengths. It allows gdbserver to support different inferior threads having different target descriptions. To that end, a tdesc field is added to struct thread_info. If it's nullptr (the default) it means that the thread uses the target description stored in struct process_info and thus gdbserver behaviour is unchanged. The get_thread_tdesc method is added to the linux_process_target class to allow aarch64-linux code to probe the inferior's vq register and provide a thread-specific target description reflecting the new vector length. After this change, all targets except SVE-supporting aarch64-linux will still use per-process target descriptions. Reviewed-by: Luis Machado --- gdbserver/gdbthread.h | 4 ++++ gdbserver/linux-aarch64-low.cc | 31 +++++++++++++++++++++++++++++++ gdbserver/linux-low.cc | 17 +++++++++++++++++ gdbserver/linux-low.h | 6 ++++++ gdbserver/regcache.cc | 10 ++++++---- gdbserver/regcache.h | 4 ++++ gdbserver/tdesc.cc | 13 ++++++++++++- gdbserver/tdesc.h | 5 +++++ 8 files changed, 85 insertions(+), 5 deletions(-) diff --git a/gdbserver/gdbthread.h b/gdbserver/gdbthread.h index 493e1dbf6cb6..5b5ba6f8e521 100644 --- a/gdbserver/gdbthread.h +++ b/gdbserver/gdbthread.h @@ -80,6 +80,10 @@ struct thread_info /* Branch trace target information for this thread. */ struct btrace_target_info *btrace = nullptr; + + /* Target description for this thread. Only present if it's different + from the one in process_info. */ + 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 92c621e5548c..69765ee90db3 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -99,6 +99,9 @@ protected: void low_arch_setup () override; + const struct target_desc * + get_thread_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,9 @@ 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; + + /* Whether this process has the Scalable Vector Extension available. */ + bool has_sve; }; /* Return true if the size of register 0 is 8 byte. */ @@ -869,6 +875,9 @@ aarch64_target::low_arch_setup () current_process ()->tdesc = aarch64_linux_read_description (features); + if (features.vq > 0) + current_process ()->priv->arch_private->has_sve = true; + /* Adjust the register sets we should use for this particular set of features. */ aarch64_adjust_register_sets (features); @@ -879,6 +888,28 @@ aarch64_target::low_arch_setup () aarch64_linux_get_debug_reg_capacity (lwpid_of (current_thread)); } +/* Implementation of linux target ops method "get_thread_tdesc". */ + +const struct target_desc * +aarch64_target::get_thread_tdesc (const thread_info *thread) +{ + const struct process_info *process = get_thread_process (thread); + + /* Only inferiors with SVE need a thread-specific target description. */ + if (!process->priv->arch_private->has_sve) + return nullptr; + + const struct aarch64_features features = aarch64_get_arch_features (thread); + const struct target_desc *tdesc = aarch64_linux_read_description (features); + + /* If the target description we just found is the same as the process-wide + one, there's no need to set a thread-specific one. */ + if (tdesc == process->tdesc) + return nullptr; + + 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 5cd22824e470..47916009ebaf 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 (); } +const struct target_desc * +linux_process_target::get_thread_tdesc (const thread_info *thread) +{ + return nullptr; +} + int linux_process_target::handle_extended_wait (lwp_info **orig_event_lwp, int wstat) @@ -2348,6 +2354,17 @@ linux_process_target::filter_event (int lwpid, int wstat) return; } } + else + { + /* Give the arch code an opportunity to set the thread's target + description. */ + const struct target_desc *new_tdesc = get_thread_tdesc (thread); + if (new_tdesc != thread->tdesc) + { + free_register_cache_thread (thread); + 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 221de85aa2ee..b52eb23cc444 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -604,6 +604,12 @@ 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 set the thread's target description when the + inferior stops. Returns nullptr if no thread-specific target description + is necessary. */ + virtual const struct target_desc * + get_thread_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 7b896a19767d..fb60e2c9c399 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -39,11 +39,11 @@ get_thread_regcache (struct thread_info *thread, int fetch) have. */ if (regcache == NULL) { - struct process_info *proc = get_thread_process (thread); + const target_desc *tdesc = get_thread_target_desc (thread); - gdb_assert (proc->tdesc != NULL); + gdb_assert (tdesc != nullptr); - regcache = new_register_cache (proc->tdesc); + regcache = new_register_cache (tdesc); set_thread_regcache_data (thread, regcache); } @@ -270,7 +270,9 @@ find_regno (const struct target_desc *tdesc, const char *name) internal_error ("Unknown register %s requested", name); } -static void +/* See regcache.h. */ + +void free_register_cache_thread (struct thread_info *thread) { struct regcache *regcache = thread_regcache_data (thread); diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index 7248bcf5808a..4beea0139cd6 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -79,6 +79,10 @@ void free_register_cache (struct regcache *regcache); void regcache_invalidate_thread (struct thread_info *); +/* Invalidate and release the register cache of the given THREAD. */ + +void free_register_cache_thread (struct thread_info *thread); + /* Invalidate cached registers for all threads of the given process. */ void regcache_invalidate_pid (int pid); diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc index 2c7257c458f4..e3339dde4d6c 100644 --- a/gdbserver/tdesc.cc +++ b/gdbserver/tdesc.cc @@ -123,13 +123,24 @@ copy_target_description (struct target_desc *dest, dest->xmltarget = src->xmltarget; } +/* See tdesc.h. */ + +const struct target_desc * +get_thread_target_desc (const struct thread_info *thread) +{ + if (thread->tdesc != nullptr) + return thread->tdesc; + + return get_thread_process (thread)->tdesc; +} + const struct target_desc * current_target_desc (void) { if (current_thread == NULL) return &default_description; - return current_process ()->tdesc; + return get_thread_target_desc (current_thread); } /* An empty structure. */ diff --git a/gdbserver/tdesc.h b/gdbserver/tdesc.h index 7fe7d0d8eb30..71cc5b51c84e 100644 --- a/gdbserver/tdesc.h +++ b/gdbserver/tdesc.h @@ -88,6 +88,11 @@ void copy_target_description (struct target_desc *dest, void init_target_desc (struct target_desc *tdesc, const char **expedite_regs); +/* Return the target description corresponding to the given THREAD. */ + +const struct target_desc * + get_thread_target_desc (const struct thread_info *thread); + /* Return the current inferior's target description. Never returns NULL. */