From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YFzaLKho7GJs8CAAWB0awg (envelope-from ) for ; Thu, 04 Aug 2022 20:47:36 -0400 Received: by simark.ca (Postfix, from userid 112) id B50CD1EA06; Thu, 4 Aug 2022 20:47:36 -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=BuSWaAMe; 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 5E4141EA03 for ; Thu, 4 Aug 2022 20:47:33 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C2805385AC0A for ; Fri, 5 Aug 2022 00:47:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C2805385AC0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1659660452; bh=YQCf1Fl+0AyT61uPzltAMH0g7OxYeip1BmJn2Zo8E8o=; 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=BuSWaAMe/KBmDT4tvMJx9FMz+Z1hP+g3E5MsBq0PFlWV0duc65rKM0Xdq6E6NtNUy RJjexQIm/BxIg+1tgF63MoVm9PfUOJ7c695VFh6A4h+iGy/smi/23ZGIxRlpiB/C2J kDQ+OS0mUczuYmx41E/jK20yY5M5w1qAq2yc/7kI= Received: from mail-vs1-xe33.google.com (mail-vs1-xe33.google.com [IPv6:2607:f8b0:4864:20::e33]) by sourceware.org (Postfix) with ESMTPS id 496ED3857407 for ; Fri, 5 Aug 2022 00:47:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 496ED3857407 Received: by mail-vs1-xe33.google.com with SMTP id b124so1094112vsc.9 for ; Thu, 04 Aug 2022 17:47:09 -0700 (PDT) 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; bh=YQCf1Fl+0AyT61uPzltAMH0g7OxYeip1BmJn2Zo8E8o=; b=bnd2cGMAyG+M+UNc0hw9abcFIwf39ht9a5ICZLeqGGqziPyez4QOAFoUzy/ledHMp7 6AhCGB0VaGCgMrVSV5zZ4jkF52j0jQe518Zfze/vdG+rtR8a1JJbHVFZ7/dzzVRjUFBT bTrz31OjPY0FtQ6+24sFLJ2zenUuNhnhkkDA6rYJmtnp1gSJiR9Tm3JtXunvOV3wxcAJ KC+29S5p84Dsy4oyAiajUqMkj9mNWuT9+ppUUVF5vAy6Ky6BfBP+PZ4uoBV/6/03OAhX BgKEZW7JdreigjcM9xUhLB4NPspKKStWRwZzm4Xvn4lXjV7ckkJkcgepjvGtBJmBKAYj Vmhg== X-Gm-Message-State: ACgBeo1YQu7vimFJ+hYTHX9NGNZDe5dGhvvU0xswbwYLEs0q4qkg8iek FxMSs9rPSgIIwDAbMl5VlChqJJfUtVY7Uw== X-Google-Smtp-Source: AA6agR7UL4p2PCYj5UP63rexRTfkEhjB0cgxVfEa+D2qQT9wwyx3ZBMtOV9WRVrWszoey6+ZQNrxpw== X-Received: by 2002:a67:c201:0:b0:386:b3ad:6c2c with SMTP id i1-20020a67c201000000b00386b3ad6c2cmr2098028vsj.53.1659660428609; Thu, 04 Aug 2022 17:47:08 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:bfe4:e3f1:491d:133e]) by smtp.gmail.com with ESMTPSA id 90-20020a9f26e3000000b003843ad3b42fsm2408920uay.5.2022.08.04.17.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 17:47:08 -0700 (PDT) To: gdb-patches@sourceware.org Subject: [PATCH v2 1/2] gdb/aarch64: Fix thread's gdbarch when SVE vector length changes Date: Fri, 5 Aug 2022 00:46:47 +0000 Message-Id: <20220805004648.111358-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220805004648.111358-1-thiago.bauermann@linaro.org> References: <20220805004648.111358-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. Since the id member of struct gdbarch_info is now unused, it's removed. --- gdb/aarch64-linux-nat.c | 11 ++++++++--- gdb/aarch64-tdep.c | 41 ++++++++++++++++++++++++----------------- gdb/aarch64-tdep.h | 2 ++ gdb/gdbarch.h | 13 ++----------- 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index a457fcd48ad8..eda79ec6d35c 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_read_description (features); return gdbarch_find_by_info (info); } diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 8670197a8889..c9ce4f95447c 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -3372,6 +3372,27 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc) return sve_vq_from_vl (vl); } +/* 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; + + if (tdesc == nullptr) + return features; + + features.vq = aarch64_get_tdesc_vq (tdesc); + 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; +} + /* Implement the "cannot_store_register" gdbarch method. */ static int @@ -3422,17 +3443,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) int i, num_regs = 0, num_pseudo_regs = 0; int first_pauth_regnum = -1, ra_sign_state_offset = -1; int first_mte_regnum = -1, tls_regnum = -1; - - /* Use the vector length passed via the target info. Here -1 is used for no - SVE, and 0 is unset. If unset then use the vector length from the existing - tdesc. */ - uint64_t vq = 0; - if (info.id == (int *) -1) - vq = 0; - else if (info.id != 0) - vq = (uint64_t) info.id; - else - vq = aarch64_get_tdesc_vq (info.target_desc); + uint64_t vq = aarch64_get_tdesc_vq (info.target_desc); if (vq > AARCH64_MAX_SVE_VQ) internal_error (__FILE__, __LINE__, _("VQ out of bounds: %s (max %d)"), @@ -3452,12 +3463,8 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) /* Ensure we always have a target descriptor, and that it is for the given VQ value. */ const struct target_desc *tdesc = info.target_desc; - if (!tdesc_has_registers (tdesc) || vq != aarch64_get_tdesc_vq (tdesc)) - { - aarch64_features features; - features.vq = vq; - tdesc = aarch64_read_description (features); - } + if (!tdesc_has_registers (tdesc)) + tdesc = aarch64_read_description ({}); gdb_assert (tdesc); feature_core = tdesc_find_feature (tdesc,"org.gnu.gdb.aarch64.core"); 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); diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 324958469a7e..1287f0214885 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -250,17 +250,8 @@ struct gdbarch_info bfd *abfd = nullptr; - union - { - /* Architecture-specific target description data. Numerous targets - need only this, so give them an easy way to hold it. */ - struct tdesc_arch_data *tdesc_data; - - /* SPU file system ID. This is a single integer, so using the - generic form would only complicate code. Other targets may - reuse this member if suitable. */ - int *id; - }; + /* Architecture-specific target description data. */ + struct tdesc_arch_data *tdesc_data; enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;