From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6VakDuBH2mOWEScAWB0awg (envelope-from ) for ; Wed, 01 Feb 2023 06:07:12 -0500 Received: by simark.ca (Postfix, from userid 112) id 2F6DE1E128; Wed, 1 Feb 2023 06:07:12 -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=dv6eEGug; 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=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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 7DB6C1E0D3 for ; Wed, 1 Feb 2023 06:07:11 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 377963858425 for ; Wed, 1 Feb 2023 11:07:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 377963858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675249630; bh=I5NNjQGNEKu5K/H9CMjk13pYviwjc1hU2ZwdZ7g5mm4=; h=To:Cc:Subject:In-Reply-To:References:Date:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dv6eEGugAiOyb2VX4vJCml6kcSdTNhQfR1GGDfhFeVuQOscfK1f86U4rh0QvNN9OW 6mwT7aEjKP6IRxNgQVy7m8pQGjjRQYvDEZQ3IaIZt5D335/WBykkkkYuJbTlmH9qJp 85vEuABvVeaiJodhZatvTSZOSnJbNNE0k+gdq4EQ= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 26C083858D37 for ; Wed, 1 Feb 2023 11:06:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 26C083858D37 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-223-H9Yhw5XqMcaa7xW80wJy1Q-1; Wed, 01 Feb 2023 06:06:46 -0500 X-MC-Unique: H9Yhw5XqMcaa7xW80wJy1Q-1 Received: by mail-qv1-f70.google.com with SMTP id b19-20020a0ccd13000000b005374d115edbso9903165qvm.19 for ; Wed, 01 Feb 2023 03:06:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I5NNjQGNEKu5K/H9CMjk13pYviwjc1hU2ZwdZ7g5mm4=; b=QP+KnPhmMJxlki8gp5nJeri/+Qsk9TohLM9U1Qo/hfhRVNiZMjjAHOV3V2GVyZgBdl kTiUm+lsn6j05TWeynOXeP2o2g3tkmQgdD1PHikvkwNaxV1Ywjh2MWFm/TtJkHYGx2bn 9NoCUGGRPyw0OwmR8PO+wHow6YxXa/L+jG7oD2g+Zzg/MuROfGq4ZGKilyCTS5HZhPa2 PpeH5HxlX95aLionogTLTxQVlAKkZYoqp7XUOxlQwgyUWUc6s4TuRbcgocgxdQD78Zvc VSRorYkiL2OqfrRE0Smd1oXdj4FAjWM3UypC8n8b9ejolhyGScC0Rr7Ip9rXy+DJXQ1D Sx3w== X-Gm-Message-State: AO0yUKXYyQbIJcSxYfdaY05OxS11ZDBo4oeccbzq0EL/fJHxOvXhL2VC SdCZHgxWuoe9yby1ECd84oSc0y3cGRFKQB8D0VKtZJTXQG98yhBDS77W9Kt3b4MYPJAk3EMs5H5 3Wm6LdLFTF5XLGSSHfkwjWRJW9CVOMF7/9CA5XaS/NbBr9+AI35XjVTxEVZek62wa572YaV+eKg == X-Received: by 2002:a0c:f3c3:0:b0:537:7619:58d9 with SMTP id f3-20020a0cf3c3000000b00537761958d9mr3106813qvm.9.1675249605930; Wed, 01 Feb 2023 03:06:45 -0800 (PST) X-Google-Smtp-Source: AK7set/kcqGZBgK+fh9PSuzEBxZrIhdAictx76FmRS7DBSYct622cU3gxWzcf1viLOe45Wk7Hqvhrg== X-Received: by 2002:a0c:f3c3:0:b0:537:7619:58d9 with SMTP id f3-20020a0cf3c3000000b00537761958d9mr3106764qvm.9.1675249605450; Wed, 01 Feb 2023 03:06:45 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id b2-20020a05620a0f8200b006f9f3c0c63csm2742557qkn.32.2023.02.01.03.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 03:06:45 -0800 (PST) To: Thiago Jung Bauermann via Gdb-patches , gdb-patches@sourceware.org Cc: Thiago Jung Bauermann , Luis Machado Subject: Re: [PATCH v3 4/8] gdbserver/linux-aarch64: When thread stops, update its target description In-Reply-To: <20230130044518.3322695-5-thiago.bauermann@linaro.org> References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> <20230130044518.3322695-5-thiago.bauermann@linaro.org> Date: Wed, 01 Feb 2023 11:06:43 +0000 Message-ID: <87pmattzjw.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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: Andrew Burgess via Gdb-patches Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Thiago Jung Bauermann via Gdb-patches writes: > 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); I think the comment for this function is not correct. The function does not SET the thread's target description, but just GETS a target description suitable for `thread`. It's the caller's job to do the setting. Thanks, Andrew > + > /* 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. */ >