From patchwork Sat Mar 23 16:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 87568 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 CE9663858434 for ; Sat, 23 Mar 2024 16:36:23 +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 1952B385841D for ; Sat, 23 Mar 2024 16:35:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1952B385841D 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 1952B385841D 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=1711211743; cv=none; b=w6OYSrFr8Sj2HLfoXziHK1m0MCTkKjwJmNDtq/97hG7v1orq475bFRmF90O+p+DihCVOJVsZrNrlZ9yOROXi2ISuLJWmkx/SOLOJF+j+JLtCZ5bHGNX36YyUPF+c4W9gTjWdRB0CPHGHcRZSSrxGusz0Gcq32vexPAiBSAI5890= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711211743; c=relaxed/simple; bh=7t4LmZg+ucPi0FDIQOGKk4lXbxWxFF/sf+7DKEfWFT0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=NBV7cholx0RnQORjoGj7+n+Vgp4stTrDybYdVfl9+ROSIwWM4wyUk/UW+2XJ4yD19PIzr2CHWjiujT5V0ftearUVFJSwKR7NhKMc5HMLBaE3taKYYq91q5hkA5Ib7ZiAYacvT8Xn9mVl/AeRillPQgRb0Jyeo96LxP2YHkQAZ+w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711211740; 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=qhce6W3Po2gQnGr5GFOqJIP7oKiLB2b/gCArYC+U3l4=; b=LvnLSOCFnN9KdRpdepGMGCo0ccsoNPqTjYQbv4m4cmIlDF/fCiDa0G5zE+aqUnqrCnBrJy FE7MoJGTIGyADYYF9gZMnEQRDjDS4NsJde6S44VZ0cNAik2xVRVC9RqW+Zh7zA/o/+7N7X OWoOYNiqdBJ0e3Oex2OAmQbB14+iu1I= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-190-AzTNILw3MI66ZVdz1dwDkg-1; Sat, 23 Mar 2024 12:35:39 -0400 X-MC-Unique: AzTNILw3MI66ZVdz1dwDkg-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-513e7ff16a8so2371629e87.1 for ; Sat, 23 Mar 2024 09:35:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711211737; x=1711816537; 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=qhce6W3Po2gQnGr5GFOqJIP7oKiLB2b/gCArYC+U3l4=; b=FBN7Wd82wp7Y/d4leNkNh9almlyYLzZ3noIH97iOKytkFx3iWBZQoo5GzeS7VsaK9O sF28bsiDJovBVa847bH2PnrlFHxZ+fuiAIJQKrKeoH24ZD1K2pDruqmgLdzWLwIsU7Zf 8ERo1UGLXk39ySpPffo/XCdh1e9TRgNRpBQdeHF7Wjdjfa21FMp5OCQRWdP8woZTRpuw hhIHY6DRrxxuYT6BYxbJkzXb/8AbG1ngZOBeZbGXwSMdRPs3SWckDQrZcUIMf+xoWnlw T2Sw957KeHwOyYXap8+vAuEhNAeC6bJv6rfBm9mBtpRDJaIx/VsU2pxqHON79FuMStRt S1nA== X-Gm-Message-State: AOJu0Yysav7H1oXSHYScdcKA6C87SnF0ykkhKo5R2lmHLgz6OYgL8lLh efaPn3qz3IZp2q4CHztFP5A76WTDsh+VzprB2ahwICVF2xUgbypyGja7qELCIBvaopTHKSEDAq6 esX3MbO7MxaD47wVOgFOX3fP8/vH+DfdHvVdmXGisvlnzN8CHSQSyZuW7qmMscjcwRuq2iOd/f9 IR0AdtVkaKiBZp2e6qJatoxdXegkwlVnWLsHbloA6XSsY= X-Received: by 2002:a19:7615:0:b0:513:5a9e:78af with SMTP id c21-20020a197615000000b005135a9e78afmr1692840lff.58.1711211737193; Sat, 23 Mar 2024 09:35:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzZIuuvqkkrfChUsHktsjFH6tmeN+FHd82NIFD1BrIpP1GNBhQ5GanZtxkyjQ7bi49wV22+Q== X-Received: by 2002:a19:7615:0:b0:513:5a9e:78af with SMTP id c21-20020a197615000000b005135a9e78afmr1692826lff.58.1711211736740; Sat, 23 Mar 2024 09:35:36 -0700 (PDT) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id q3-20020a5085c3000000b005645961ad39sm1019729edh.47.2024.03.23.09.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 09:35:35 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , hjl.tools@gmail.com, John Baldwin Subject: [PATCHv3 3/8] gdbserver/x86: move no-xml code earlier in x86_linux_read_description Date: Sat, 23 Mar 2024 16:35:21 +0000 Message-Id: <7934bb6ffde7ea8608245d9a7f6f380bee50a99f.1711211528.git.aburgess@redhat.com> 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.1 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 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. Approved-By: John Baldwin --- 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 04202e355bb..872c3fc69c7 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))];