From patchwork Sat Nov 26 02:04:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 55324 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 489BF382FADE for ; Sat, 26 Nov 2022 02:05:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 489BF382FADE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669428339; bh=asuARsdZk+GuvMsXjnerUIlOgiBHgS/h2HookcywWLM=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=BK5yiTs7FwUJNzYa28O3eZgVmdL24BoboRfYTYceBcwJRIQxZLv/tKWkg9moNzjt5 hKMEMtL9Ug81hB/tPyVAWWoRIbCNxXn74VdoYTSEV2nRjAIJlHPYofbpmIenmsmXyV 5YmCcNms3ewXZul7qAvpnoR/myhEZmv1x82uAE+E= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by sourceware.org (Postfix) with ESMTPS id 6318938451AC for ; Sat, 26 Nov 2022 02:05:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6318938451AC Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1322d768ba7so7022050fac.5 for ; Fri, 25 Nov 2022 18:05:13 -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:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=asuARsdZk+GuvMsXjnerUIlOgiBHgS/h2HookcywWLM=; b=J7mw2TVIMq/9PdMETGEX81PkSPgisMuxZq88MQXO5Lf9I7AequZ6LOfjESTI0j8H2p fEfWidqEJ/jF2Gm7/vUB0sgRvi/HCxU/vEuKXtKu+zp07pYYDVvozYKOda+nPw3j74WH Jf400Oboe5nKQ3emnCcKhyamP/ioP4cgU5+WgH6LLZQnMGFhbEbHGd7jLpEPYyl3sONJ aAOJXAdHiHuNNWQ+oIw9RpGvWYu7nndSfNZoqYzWGvPhQ7IAWrWIDeCR9IT7oNSLe7sO 4qoGWfBld1+79BqrXXBkniEl0M1ia+Z84DzAhCERcK6gguvZ2b4I91C9CXMpYg6FtkrZ NmKQ== X-Gm-Message-State: ANoB5pkxAwVVXbCIG+/vBpHlzDoJJup7FuzeSA5xwsLD1iTOcYy+ElQd y9dh8m2K4IRubXoF6xcZUVcUOy5ZrNJ/UQ== X-Google-Smtp-Source: AA0mqf547OBG4TuO2ZIzCo1WATO9BOZrUI0OOdeyJM8ECkp9jlOk32n6y/Q4SJsGYjn+fA7wNhpAlA== X-Received: by 2002:a05:6870:962a:b0:13b:fead:f3d7 with SMTP id d42-20020a056870962a00b0013bfeadf3d7mr12676451oaq.18.1669428312697; Fri, 25 Nov 2022 18:05:12 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:41ee:c7fc:c991:eee6]) by smtp.gmail.com with ESMTPSA id u35-20020a056870d5a300b00130d060ce80sm2898515oao.31.2022.11.25.18.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 18:05:12 -0800 (PST) To: gdb-patches@sourceware.org Cc: Luis Machado , Thiago Jung Bauermann Subject: [PATCH v2 0/6] gdbserver improvements for AArch64 SVE support Date: Sat, 26 Nov 2022 02:04:46 +0000 Message-Id: <20221126020452.1686509-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 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: , X-Patchwork-Original-From: Thiago Jung Bauermann via Gdb-patches From: Thiago Jung Bauermann Reply-To: Thiago Jung Bauermann Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Hello, This is version 2 of the patch series adding support to gdbserver for inferiors that change the SVE vector length at runtime. This is already supported by GDB, but not by gdbserver. Version 1 was posted here: https://inbox.sourceware.org/gdb-patches/20220908064151.3959930-1-thiago.bauermann@linaro.org/ The main difference in this version is that it implements Luis' suggestion of keeping the per-process target description and using per-thread ones only when necessary (i.e., when the inferior supports SVE). This simplified the patches significantly (thank you for the suggestion, Luis!), and they now cause minimal change on non-SVE targets. To recap, GDB supports different vector lengths by calling target_ops::thread_architecture, and aarch64_linux_nat_target provides an implementation of that method. This patch series' idea is to provide a remote_target::thread_architecture method so that the same mechanism can be used in the case of remote debugging. It returns a gdbarch based on the expedited registers seen in the most recent stop reply. To arrive at that solution some preparation is necessary. Most patches are small cleanups or code reorganisation to make review easier. The biggest change is in patch 4, which adds a per-thread target description to gdbserver. As mentioned earlier though, only SVE-supporting aarch64-linux targets will actually use different per-thread tdescs. All other targets continue using the per-process target description. Also, contrary to what I mentioned to some people at the GNU Tools Cauldron, XML target descriptions are not transmitted over the wire. What happens is: 1. When the inferior thread stops, gdbserver fetches its vector length. If it's different from the last time it stopped, gdbserver sets a thread-specific tdesc (in aarch64_target::arch_update_tdesc). 2. gdbserver sends the new vector length as “VG” an expedited pseudo-register (it was already doing that, this patch series doesn't change this part). 3. When GDB receives a stop reply, it gets the vector length from the expedited registers and uses it to get a new target description and gdbarch, then stores the latter in remote_thread_info->expedited_arch (in remote_target::process_stop_reply). 4. When GDB needs to know the thread's gdbarch, it calls the process stratum's thread_architecture method. With these patches remote_target now provides said method, which returns the gdbarch obtained from the last stop reply. So GDB and gdbserver independently update their own target descriptions when they notice that the vector length changed. With this series applied, gdb.arch/aarch64-sve.exp passes all tests on extended-remote aarch64-linux. Without them, it fails tests after the testcase changes the vector length. Tested on native and extended-remote aarch64-linux, x86_64-linux and armv7l-linux-gnueabihf (the last one on QEMU TCG). Changes since v1: - Patch 1: gdbserver: Add asserts in register_size and register_data functions - No change. - Patch 2: gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap - Changed to add an “int pid” parameter rather than a “struct thread_info” one. Suggested by Luis. - Patch 3: gdb,gdbserver/aarch64-linux: Allow aarch64_sve_get_vq to return error - Dropped, since as Luis mentioned “we will always be able to validate supported features when we start/attach to a process”, and also the situation it helped with doesn't happen anymore in the new version of the code. - Patch 4: gdbserver/linux-aarch64: Factor out function to get aarch64_features - Changed aarch64_get_arch_features to return “struct aarch64_features” rather than “gdb::optional” since we can assume that aarch64_sve_get_vq always works. - Patch 5: gdbserver: Move target description from being per-process to being per-thread - Squashed into the next patch, since it became much simpler after implementing Luis' suggestion of keeping per-process target descriptions. - Patch 6: gdbserver/linux-aarch64: When thread stops, update its target description - Added “has_sve” bool to linux-aarch64-low's “struct arch_process_info”. - Changed aarch64_target::arch_update_tdesc to return early if the given thread's has_sve property is false. - Changed get_thread_regcache to look for a target description in the thread before looking for one in the process. - Changed current_target_desc to look for a target description in the current_thread before looking for one in the current_process. - Patch 7: gdb/aarch64: Factor out most of the thread_architecture method - Fixed memory leak where aarch64_update_gdbarch was calling aarch64_create_target_description instead of aarch64_read_description. - Patch 8: gdb/aarch64: Detect vector length changes when debugging remotely - Changed the title and description to try making them a bit clearer. Thiago Jung Bauermann (6): gdbserver: Add asserts in register_size and register_data functions gdbserver: Add PID parameter to linux_get_auxv and linux_get_hwcap gdbserver/linux-aarch64: Factor out function to get aarch64_features gdbserver/linux-aarch64: When thread stops, update its target description gdb/aarch64: Factor out most of the thread_architecture method gdb/aarch64: Detect vector length changes when debugging remotely gdb/aarch64-linux-nat.c | 28 +------------- gdb/aarch64-tdep.c | 59 +++++++++++++++++++++++++++++ gdb/aarch64-tdep.h | 2 + gdb/arch-utils.c | 9 +++++ gdb/arch-utils.h | 5 +++ gdb/gdbarch-components.py | 16 ++++++++ gdb/gdbarch-gen.h | 11 ++++++ gdb/gdbarch.c | 22 +++++++++++ gdb/remote.c | 42 +++++++++++++++++++++ gdbserver/gdbthread.h | 2 + gdbserver/linux-aarch64-low.cc | 69 ++++++++++++++++++++++++++++------ gdbserver/linux-arm-low.cc | 2 +- gdbserver/linux-low.cc | 36 +++++++++++++----- gdbserver/linux-low.h | 14 ++++--- gdbserver/linux-ppc-low.cc | 6 +-- gdbserver/linux-s390-low.cc | 2 +- gdbserver/netbsd-low.cc | 4 +- gdbserver/netbsd-low.h | 2 +- gdbserver/regcache.cc | 15 ++++++-- gdbserver/server.cc | 2 +- gdbserver/target.cc | 4 +- gdbserver/target.h | 2 +- gdbserver/tdesc.cc | 3 ++ 23 files changed, 289 insertions(+), 68 deletions(-) base-commit: 31c1130f35e0ef800ea4d92224a72872ffe4a5db