From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x22f.google.com (mail-oi1-x22f.google.com [IPv6:2607:f8b0:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 6C8713858D1E for ; Tue, 29 Nov 2022 03:59:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6C8713858D1E 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-x22f.google.com with SMTP id c129so13940426oia.0 for ; Mon, 28 Nov 2022 19:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=+RARso3jhpO550bOg3XWhaO7ePB0C9BQtaTS2FKlQbo=; b=w1fz4IfptXPRL6fJBlUItMMBYWfUbi2qmZbBiyOb9quvGKU95aOadscx46M7kzSUiN P93hBXPzO3lFM8qNUEPk7qUfaMGwG6UXcIRF/CQliczN2aDtgNTBmBD3h0ITQqRDRyes 8FZYOKccjhOwoHlhfMKguLiIWbva4CI1WvVgICWUCdOm6WVGdDVp/L7RoxITaNaC2sr5 hwX0TMvswod85Gt8FjLK22p9dNqZgxxRVK6+aPXczR56rPNvrQnZu1oswZdMQZ9QXMYa giIufXuOGw+0BHQ8hotO0hnpHcKRmJclUde4nL08BBbttiOeczE7GiZnsXnJRsNQMKXW DfWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:in-reply-to :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=+RARso3jhpO550bOg3XWhaO7ePB0C9BQtaTS2FKlQbo=; b=Ez4H3u78GiB57MDoA/Sn/eO+SyiYupT7Z8H2MNZRpFSK0WRIzwtv8meDBAbGQbw1hQ h8Bt53P9jmJ8hRgLtJ1sA5xzNSWC6jDlyipOP30WHdp8op5gEcdMqlaUcQU5GZbNBQxs WJJrd6H2SmXueVdBbdU7QuNHTpfbLlBcHFoi0NVGxwLrvOb4WeIIhSLzPElR23iXBPdb ytAjR/XsZnvOWh5h8qSwirVoj5LvV6Rh7lL2DLYMksIyiurx5GRFD0Qb8ASsh8DPbEqF PpNrRojlt7Y6cHRHG713Lgz/S0ZWcGAWS1HFcAYp+Ter9hKNQQjpRm+tUc5Aubf+i4un iWJQ== X-Gm-Message-State: ANoB5pnNSP8g5p2XSqppv2/gmVwu9Tx7zLK8183kYROCD6nU8FXW0MYZ KlLFL2yJC2pTIBKK4/Vu6Ba/zQ== X-Google-Smtp-Source: AA0mqf7rXWThYg3HbIqRMYWaZQif1B+7cODtjZFG3UNB2fpw65jPMHnITVcKfTPmWWjo/U+x/X6kUg== X-Received: by 2002:a05:6808:1984:b0:35a:ccc:2a5e with SMTP id bj4-20020a056808198400b0035a0ccc2a5emr20477627oib.131.1669694396775; Mon, 28 Nov 2022 19:59:56 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:201c:ea26:41ce:5eb]) by smtp.gmail.com with ESMTPSA id h8-20020a4aa9c8000000b0049427725e62sm5038231oon.19.2022.11.28.19.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 19:59:56 -0800 (PST) References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> <20221126020452.1686509-5-thiago.bauermann@linaro.org> User-agent: mu4e 1.8.11; emacs 28.2 From: Thiago Jung Bauermann To: Luis Machado Cc: gdb-patches@sourceware.org Subject: Re: [PATCH v2 4/6] gdbserver/linux-aarch64: When thread stops, update its target description In-reply-to: Date: Tue, 29 Nov 2022 03:59:53 +0000 Message-ID: <87iliyh0li.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.3 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: Luis Machado writes: > Thanks for the patch. > > On 11/26/22 02:04, Thiago Jung Bauermann wrote: >> 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 =3D nullptr; >> + >> + const struct target_desc *tdesc =3D nullptr; > > Should we add a bit of information on how this new field is used, through= a comment? Good idea. For v3 I added: /* Target description for this thread. Only present if it's different from the one in process_info. */ const struct target_desc *tdesc =3D nullptr; >> }; >> extern std::list all_threads; >> diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-lo= w.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; >> }; > > Though obvious, adding a comment like "has_sve" in gdb/aarch64-tdep.h wil= l clarify the use > of this field. Indeed. For v3 I added: /* Whether this process has the Scalable Vector Extension available. */ bool has_sve; >> 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 () =3D 0; >> + /* Allows arch-specific code to update the thread's target descript= ion when >> + the inferior stops. */ > > I'd also mention sometimes we don't need to update the target description= if nothing's > changed. So an empty return is expected. Good point. Including Simon's suggestions this is what I have for v3: /* Allows arch-specific code to set the thread's target description when = the inferior stops. Returns nullptr if no thread-specific target descript= ion is necessary. */ virtual const struct target_desc * get_thread_tdesc (const thread_info *thread); >> + 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) =3D 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 =3D=3D NULL) >> { >> - struct process_info *proc =3D get_thread_process (thread); >> + /* First see if there's a thread-specific target description. */ >> + const target_desc *tdesc =3D thread->tdesc; >> - gdb_assert (proc->tdesc !=3D NULL); >> + /* If not, get it from the process instead. */ >> + if (tdesc =3D=3D nullptr) >> + tdesc =3D get_thread_process (thread)->tdesc; > > Just a suggestion. Your call. > > We could abstract away trying to fetch a tdesc from a thread and then fro= m a process by > having a function "get_tdesc ()" and calling it here. > > Possibly with a better name. I like the idea. I implemented it and named the function =E2=80=9Cget_thread_target_desc=E2=80=9D. > >> - regcache =3D new_register_cache (proc->tdesc); >> + gdb_assert (tdesc !=3D nullptr); >> + >> + regcache =3D 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 =3D=3D NULL) >> return &default_description; >> + if (current_thread->tdesc !=3D nullptr) >> + return current_thread->tdesc; >> + >> return current_process ()->tdesc; > > We'd use the above function in here as well. I did that for v3. There's a small difference in the code with the new version: instead of using current_process (), it ends up doing =E2=80=9Cget_thread_process (current_thread)=E2=80=9D. I expect it to be eq= uivalent though, and I'm not seeing any regression in the testsuite. >> } >>=20=20=20 > > Otherwise LGTM. > > Reviewed-by: Luis Machado Thanks! Added the Reviewed-by tag to the patch description for v3. --=20 Thiago