From patchwork Tue Mar 5 17:00:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 86826 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 1BEB23857C4A for ; Tue, 5 Mar 2024 17:02:01 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E06B0385840A for ; Tue, 5 Mar 2024 17:00:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E06B0385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E06B0385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709658039; cv=none; b=GqXooy1b+8wehRouxquVYnTGgC5h8iQpVSxeQwvFxCuwV5o4hqt5mRe4stsFlmAMfoubejFzmn4KZCY5KlaagbptHQN0y+tPlbzgyjZFeGU8ff8v/xGnW9sdy3xgm7kyBXrPp5ID/GB3oPD3n4sTYPOygaPDQNt06DqAlsVH8yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709658039; c=relaxed/simple; bh=9/HqTaCvTazW1RjeOAOizbbNirCf+b+Oq8ruTP8S+qw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=UQZ4S4kskbiVXI2xNxi+kQQx4tUlxKoPYRdU/sImt+Lb5pP+TxnKlcJue3aV4xTpLDd3MA1Oux25MzFpIf5+CaNbC6fI67A3aHWUN2LdMve6th3Deb1ULMFgzP8cw1aVsOo8qzSJXYarAcdCeVGNwdXkQ2O2a/ctIgXAmeEAi5w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709658036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gIxf/Z9eGBVC+AA09DfGemGgR17B1hKcwD9+MJo0YZ0=; b=g+CW8FI46Hq+kuR31VaDPjK0TwxPmiKbNj1aJo65W8rD06oXSsITGdZPzRluTRYtSb/GJP ZCOJ0a7X36KBtYzPRmuIlIJIVXETrmIMEzP2a+EeIvkI0xXJRpQz91IPwojTsOKzQLOl4k jPwl4wKbaZRPIxF+/vy4qFawaefFlkw= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-116-ugFJWvOpP_GX2upnpAXy0A-1; Tue, 05 Mar 2024 12:00:35 -0500 X-MC-Unique: ugFJWvOpP_GX2upnpAXy0A-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-567d4f5b3d1so80104a12.2 for ; Tue, 05 Mar 2024 09:00:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709658031; x=1710262831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gIxf/Z9eGBVC+AA09DfGemGgR17B1hKcwD9+MJo0YZ0=; b=uQT3inHrQcfpreEmaxMTyQelaLqiuVpJqqCjUJQqQYUxqN0JeTS9+MRN6jcDVBPlM2 h0mIwcZ4vMZn7SVatredAYtgZqdFOqWuYcHlz2XMoif3vs7E1c/gUyfYb1h6UcdHdKoQ g3oD1Sb3jO1VEVX8N22ahWCOnizs2mikEk6Tt+8crIuEMlzxbvpUzAhhqbJYb7geS/P1 2yvlzOl8U975NLiF1F1RXEn7krg9tOxY7g3KJB6HPTLelBXeJK+kt70xKzncdKNOBtDN Bnm3l3c/3Vp9XsrkNxOldcbWQE0BdU9Njw4NcLQKLtIPpaeuIXgKRO+wGXx8/hfDhFqt Y4FQ== X-Gm-Message-State: AOJu0Yz9i3ykK0pw8TCReeg20C5ffNM+n6xp4AgegpHD+GjD+SyVq6ul gRTdkDjkWRHCSpkFdYrYZBdoQyOxyoQXbGHCcjQlg31/C+Jbu9mU+rN09/9b7KzV5zuVZknkXwi u227Q92uxNX55oJdViQXN1YTVmGfmb2t8KLipon/InahCvtcrSc0DuTSC0oHSu2nbxDwfO/mx3e IJCKqREXbKMru/2NYQVRQIyd/HmIPPmioM0AgbR1//zr0= X-Received: by 2002:a05:6402:b18:b0:565:bb25:bb7a with SMTP id bm24-20020a0564020b1800b00565bb25bb7amr9067321edb.24.1709658031550; Tue, 05 Mar 2024 09:00:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPC9EFCuFle00iTMlO/bSfwa3pkVRwe7Q2/38QV3aP+tLhK2u4DDtztHkMv51o09vkdLHx2w== X-Received: by 2002:a05:6402:b18:b0:565:bb25:bb7a with SMTP id bm24-20020a0564020b1800b00565bb25bb7amr9067296edb.24.1709658030949; Tue, 05 Mar 2024 09:00:30 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id cs4-20020a0564020c4400b00566a4dec01fsm5870501edb.11.2024.03.05.09.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 09:00:30 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 3/7] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Date: Tue, 5 Mar 2024 17:00:18 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit is part of a series that aims to share more of the x86 target description reading/generation code between GDB and gdbserver. There are a huge number of similarities between the code in gdbserver's x86_linux_read_description function and GDB's x86_linux_nat_target::read_description function, and it is this similarity that I plan, in a later commit, to share between GDB and gdbserver. However, one thing that is different in x86_linux_read_description is the code inside the '!use_xml' block. This is the code that handles the case where gdbserver is not allowed to send an XML target description back to GDB. In this case gdbserver uses some predefined, fixed, target descriptions. First, it's worth noting that I suspect this code is not tested any more. I couldn't find anything in the testsuite that tries to disable XML target description support. And the idea of having a single "fixed" target description really doesn't work well when we think about all the various x86 extensions that exist. Part of me would like to rip out the no-xml support in gdbserver (at least for x86), and if a GDB connects that doesn't support XML target descriptions, gdbserver can just give an error and drop the connection. GDB has supported XML target descriptions for 16 years now, I think it would be reasonable for our shipped gdbserver to drop support for the old way of doing things. Anyway.... this commit doesn't do that. What I did notice was that, over time, the '!use_xml' block appears to have "drifted" within the x86_linux_read_description function; it's now not the first check we do. Instead we make some ptrace calls and return a target description generated based on the result of these ptrace calls. Surely it only makes sense to generate variable target descriptions if we can send these back to GDB? So in this commit I propose to move the '!use_xml' block earlier in the x86_linux_read_description function. The benefit of this is that this leaves the later half of x86_linux_read_description much more similar to the GDB function x86_linux_nat_target::read_description and sets us up for potentially sharing code between GDB and gdbserver in a later commit. --- gdbserver/linux-x86-low.cc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc index 0a3bd2c8670..ec80bfe905c 100644 --- a/gdbserver/linux-x86-low.cc +++ b/gdbserver/linux-x86-low.cc @@ -891,6 +891,22 @@ x86_linux_read_description (void) #endif } + /* If we are not allowed to send an XML target description then we need + to use the hard-wired target descriptions. This corresponds to GDB's + default machine for x86. + + This check needs to occur before any returns statements that might + generate some alternative target descriptions. */ + if (!use_xml) + { +#ifdef __x86_64__ + if (machine == EM_X86_64) + return tdesc_amd64_linux_no_xml.get (); + else +#endif + return tdesc_i386_linux_no_xml.get (); + } + #if !defined __x86_64__ && defined HAVE_PTRACE_GETFPXREGS if (machine == EM_386 && have_ptrace_getfpxregs == -1) { @@ -907,17 +923,6 @@ x86_linux_read_description (void) } #endif - if (!use_xml) - { - /* Don't use XML. */ -#ifdef __x86_64__ - if (machine == EM_X86_64) - return tdesc_amd64_linux_no_xml.get (); - else -#endif - return tdesc_i386_linux_no_xml.get (); - } - if (have_ptrace_getregset == TRIBOOL_UNKNOWN) { uint64_t xstateregs[(X86_XSTATE_SSE_SIZE / sizeof (uint64_t))];