From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yDJHCU3l4WL2rBsAWB0awg (envelope-from ) for ; Wed, 27 Jul 2022 21:24:29 -0400 Received: by simark.ca (Postfix, from userid 112) id 22D321E9ED; Wed, 27 Jul 2022 21:24:29 -0400 (EDT) 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=wVVbcxK1; 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=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.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 17E631E87E for ; Wed, 27 Jul 2022 21:24:26 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D55D3857B98 for ; Thu, 28 Jul 2022 01:24:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D55D3857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1658971465; bh=dlsKPUafk+XtsLIxyxgWPFNO2lMeBWqrhWr7K7SSlUA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=wVVbcxK1F7ZK+G9CES4qw72Lu4NK9nYZIEW/feNWpJaM6cUiQ8d5IJZIi6HmN5yke srW9MS84tyB/YNo/LWCYi3gesCtj1Xdlsp0sUmA9WBzw3yQlpBD7u0M7QrRWtYLnox r+nvq8Q7D9M2RQaSYoRfQT7iB+h7DnvCvRUFrQRA= Received: from mail-oo1-xc2e.google.com (mail-oo1-xc2e.google.com [IPv6:2607:f8b0:4864:20::c2e]) by sourceware.org (Postfix) with ESMTPS id 15D07385829F for ; Thu, 28 Jul 2022 01:23:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15D07385829F Received: by mail-oo1-xc2e.google.com with SMTP id d12-20020a4aeb8c000000b004214e709b72so51764ooj.6 for ; Wed, 27 Jul 2022 18:23:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dlsKPUafk+XtsLIxyxgWPFNO2lMeBWqrhWr7K7SSlUA=; b=APFOKORHqoODtDSU4G9gwAxJSfSGLUXx7q7fTjqOCap57GF9bHe9oAN+may6SGS1bP 8+stCBmjH/ff0gRWUzM4kmdIdsouRLBtNes0M3wZ64mQgIxsZTXWd0xB/anPYzvJLFRY 6sY2WkIgWA7GowZOSRjhsTETdzFMIPi1UghQQmmmaxFNWbvV28IFZC7rDeOfcUwnS/iq ExvAcVEwIa+gT8J3zFO5aEaEwiBjcBVT/Ixjvg2/Fiawp2oIkjHYrDR8NdQP1OKAb3fI X+EahkyuKohMAX07/orzpgYSQg6CELHTaF2diA3iEzQENSRC9Js3ZHm5u6KHUwG4FfBR 2UfQ== X-Gm-Message-State: AJIora91Cv0n0ZyhBytemRI2yl7JL5pVDSg+b/TzmQlKWRBlkU7V9Gy+ jg2HYLAkXuZK4tBMC/diaboBMJVXmqSHxg== X-Google-Smtp-Source: AGRyM1sT+cd/PaivSQbPue1JUxxhV8FKOxnDjwg9qN0rmzGy4lZ3zAZrMaJuCI8v7N6UvdxlHZ/kFw== X-Received: by 2002:a4a:49d2:0:b0:435:9edb:9e8 with SMTP id z201-20020a4a49d2000000b004359edb09e8mr8462905ooa.62.1658971419362; Wed, 27 Jul 2022 18:23:39 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:40de:7e97:7485:cc8e]) by smtp.gmail.com with ESMTPSA id 1-20020aca0701000000b00334c2e81dfbsm7878439oih.0.2022.07.27.18.23.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Jul 2022 18:23:39 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH 1/2] gdb/aarch64: Fix thread's gdbarch when SVE vector length changes Date: Thu, 28 Jul 2022 01:23:05 +0000 Message-Id: <20220728012306.157639-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220728012306.157639-1-thiago.bauermann@linaro.org> References: <20220728012306.157639-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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" When the inferior program changes the SVE length, GDB can stop tracking some registers as it obtains the new gdbarch that corresponds to the updated length: Breakpoint 1, do_sve_ioctl_test () at sve-ioctls.c:44 44 res = prctl(PR_SVE_SET_VL, i, 0, 0, 0, 0); (gdb) print i $2 = 32 (gdb) info registers ⋮ [ snip registers x0 to x30 ] ⋮ sp 0xffffffffeff0 0xffffffffeff0 pc 0xaaaaaaaaa8ac 0xaaaaaaaaa8ac cpsr 0x60000000 [ EL=0 BTYPE=0 C Z ] fpsr 0x0 0 fpcr 0x0 0 vg 0x8 8 tpidr 0xfffff7fcb320 0xfffff7fcb320 (gdb) next 45 if (res < 0) { (gdb) info registers ⋮ [ snip registers x0 to x30 ] ⋮ sp 0xffffffffeff0 0xffffffffeff0 pc 0xaaaaaaaaa8cc 0xaaaaaaaaa8cc cpsr 0x200000 [ EL=0 BTYPE=0 SS ] fpsr 0x0 0 fpcr 0x0 0 vg 0x4 4 (gdb) Notice that register tpidr disappeared when vg (which holds the vector length) changed from 8 to 4. The tpidr register is provided by the org.gnu.gdb.aarch64.tls feature. This happens because the code that searches for a new gdbarch to match the new vector length in aarch64_linux_nat_target::thread_architecture doesn't take into account the features present in the target description associated with the previous gdbarch. This patch makes it do that. --- gdb/aarch64-linux-nat.c | 11 ++++++++--- gdb/aarch64-tdep.c | 25 +++++++++++++++++++++++++ gdb/aarch64-tdep.h | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index a457fcd48ad8..5963e246b43f 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -900,11 +900,16 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid) /* We reach here if the vector length for the thread is different from its value at process start. Lookup gdbarch via info (potentially creating a - new one), stashing the vector length inside id. Use -1 for when SVE - unavailable, to distinguish from an unset value of 0. */ + new one) by using a target description that corresponds to the new vq value + and the current architecture features. */ + + const struct target_desc *tdesc = gdbarch_target_desc (inf->gdbarch); + aarch64_features features = aarch64_features_from_target_desc (tdesc); + features.vq = vq; + struct gdbarch_info info; info.bfd_arch_info = bfd_lookup_arch (bfd_arch_aarch64, bfd_mach_aarch64); - info.id = (int *) (vq == 0 ? -1 : vq); + info.target_desc = aarch64_create_target_description (features); return gdbarch_find_by_info (info); } diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 8670197a8889..8b89b877f8f0 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3352,6 +3352,31 @@ aarch64_read_description (const aarch64_features &features) return tdesc; } +/* Get the AArch64 features present in the given target description. */ + +aarch64_features +aarch64_features_from_target_desc (const struct target_desc *tdesc) +{ + aarch64_features features; + const struct tdesc_feature *feature; + + if (tdesc == nullptr) + return features; + + feature = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.sve"); + if (feature != nullptr) + features.vq = tdesc_register_bitsize (feature, "z0") / 128; + + features.pauth + = (tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.pauth") != nullptr); + features.mte + = (tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.mte") != nullptr); + features.tls + = (tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.tls") != nullptr); + + return features; +} + /* Return the VQ used when creating the target description TDESC. */ static uint64_t diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h index 5bdd733dce32..d8513023c376 100644 --- a/gdb/aarch64-tdep.h +++ b/gdb/aarch64-tdep.h @@ -121,6 +121,8 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base }; const target_desc *aarch64_read_description (const aarch64_features &features); +aarch64_features +aarch64_features_from_target_desc (const struct target_desc *tdesc); extern int aarch64_process_record (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr);