From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1DC673849AC8 for ; Wed, 8 May 2024 16:46:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1DC673849AC8 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 1DC673849AC8 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=1715186821; cv=none; b=gIGoMPud5rmIojsXh0lLV0RBvOwSxT8QbY9Xrtde8EMFwSr8vH8xmx+5K/OF+wrYSUIJPRseVRvgYA/aP/dGSURH0vPLb8QkqvlvVRsEEYuYoX7zUbmpIpiENMfy9AKOQWxHaOkrw3min6PLfTbb/dhbWIe4CNO+Ee8ZxJRGbOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715186821; c=relaxed/simple; bh=a+qwqSX4FMxkjOzasN2GMuO1h/74ybrHSsGL/NEpaiw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=o6sCltGenzZTs+YL6wfOiEHSz1qhN3f440m9OG0XxkoxpIAMnA2t4yEeMQkPZmVC9ulev+borL2ieOWxbybIT+ttTncvxcLaMrBody+tNGvRJqPalpn4p48s6QBxi6RtAt1+BuyzpcTDxrNgN8AhWHfx8dTonWFSNFduxOfTIhU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715186814; 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=7AGyzN7u3UjZVQM4OmdGkgyIj3Yn7Gr0RFwDUu+Q/40=; b=dI5825J4aJGkVH+iBUA8D2ECYFJLmB9GdD6EoF5iDNeSfJhwCorpUFUfmV0GmhY6Ax/XGu Ughp+9Kft9eNS9FYyTo4dz+lEOvwLy9BNDRQeyf63PXN3WMRISiMljgUXYF3Y8maxOHnK8 rTyEN+Lvvcy+Plevh30JzFoRISHFqts= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-anqr64oQMYWpucX_-L0agw-1; Wed, 08 May 2024 12:46:53 -0400 X-MC-Unique: anqr64oQMYWpucX_-L0agw-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-34d9b4d3a4fso2651114f8f.1 for ; Wed, 08 May 2024 09:46:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715186812; x=1715791612; 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=hJzgxLGHtv31az+AlwvWJlHvMa4zPRAIlUCcOb5XP8Q=; b=lpSBe8tNwncPGQ3j+vAYGaJv+kOBw9A8FWmhbggfN6uWozUOd5MrRO4I3ouuKCWg+F LMWYS1iCHY9TRuh1oqpvzwxnoL1T3qsf1HUyu1iFAuGtEykXPwtrZHccrg5EC8lFoOcz 5VJy37qpmXTAngluDc8Ogm8WUJifv/LrGRLePiPkPSz1/pvqsIb/vAWY5RDBLo7BFWxA ugofessYK0ETCr/GQ1LOwE4MyiCnF3pYDHuHv2Oaz8L1dZIGHtyWr3CbErBEvmZ2MG/9 K7Vs6CqzDEwpWzfJZi2tSUosgATcN31450+bxSFShR7EGZXpbHsTjU313W/Rx44qpQ+h PyWw== X-Gm-Message-State: AOJu0Yxx6UX4zqE97tK4rRUVMhCXHLzEiXAmSoojF+uyRt5ngbSdnbBp oGhnjsdUAXvXaY6C9eCqGLJ03OVreIp/BTbyWwP3OwZWzFdaeSOBzQMwDrHZeIXW3LL2fCIGj0O k3kesoZpPe09wku+6rfhOhw9MYXAe9nTF3gmQc7IzZ9l2ZLnFEgItrqgCOvbREzeaw0x+1GGOTc R84z4bCUHq3akm5KqNSrBOklO9GXovfTjz/8Hq4kNPt2M= X-Received: by 2002:adf:e612:0:b0:34f:9b4:43d0 with SMTP id ffacd0b85a97d-34fcade2dffmr2536881f8f.26.1715186811416; Wed, 08 May 2024 09:46:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7aFOYOZGrAzZy306I11QECN77aK0V6RA99g8Bo+8Sb3U9HLK8JNX3Zq8rBxrywhXIH8oHzg== X-Received: by 2002:adf:e612:0:b0:34f:9b4:43d0 with SMTP id ffacd0b85a97d-34fcade2dffmr2536860f8f.26.1715186810829; Wed, 08 May 2024 09:46:50 -0700 (PDT) Received: from localhost ([31.111.84.240]) by smtp.gmail.com with ESMTPSA id c16-20020adffb10000000b0034f0633e322sm8652857wrr.38.2024.05.08.09.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 09:46:49 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , felix.willgerodt@intel.com, jhb@FreeBSD.org Subject: [PATCHv6 3/9] gdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory Date: Wed, 8 May 2024 17:46:39 +0100 Message-Id: <9efce46803ede508ac0fd0cf3f9d1497117e3aae.1715185683.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_INVALID,DKIM_SIGNED,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_SHORT,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 List-Id: The have_ptrace_getfpxregs global tracks whether GDB or gdbserver is running on a kernel that supports the GETFPXREGS ptrace request. Currently this global is declared twice (once in GDB and once in gdbserver), but it makes sense to move this global into the nat/ directory, and have a single declaration and definition. While moving this variable I have converted it to a tribool, as that was what it really was, if even used the same numbering as the tribool enum (-1, 0, 1). Where have_ptrace_getfpxregs was used I have updated in the obvious way. However, while making this change I noticed what I think is a bug in x86_linux_nat_target::read_description and x86_linux_read_description, both of these functions can be called multiple times, but in both cases we only end up calling i386_linux_read_description the first time through in the event that PTRACE_GETFPXREGS is not supported. This is because initially have_ptrace_getfpxregs will be TRIBOOL_UNKNOWN, but after the ptrace call fails we set have_ptrace_getfpxregs to TRIBOOL_FALSE. The next time we attempt to read the target description we'll skip the ptrace call, and so skip the call to i386_linux_read_description. I've not tried to address this preexisting bug in this commit, this is purely a refactor, there should be no user visible changes after this commit. In later commits I'll merge the gdbserver and GDB code together into the nat/ directory, and after that I'll try to address this bug. Reviewed-By: Felix Willgerodt --- gdb/Makefile.in | 1 - gdb/i386-linux-nat.c | 26 +++++--------------------- gdb/i386-linux-nat.h | 26 -------------------------- gdb/nat/x86-linux.c | 9 +++++++++ gdb/nat/x86-linux.h | 14 ++++++++++++++ gdb/x86-linux-nat.c | 7 ++----- gdbserver/linux-x86-low.cc | 17 +++-------------- 7 files changed, 33 insertions(+), 67 deletions(-) delete mode 100644 gdb/i386-linux-nat.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 234d0051f49..d1c9c2f2859 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1397,7 +1397,6 @@ HFILES_NO_SRCDIR = \ hppa-tdep.h \ i386-bsd-nat.h \ i386-darwin-tdep.h \ - i386-linux-nat.h \ i386-linux-tdep.h \ i386-tdep.h \ i387-tdep.h \ diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c index 7278dd91ff0..c54c9b8f9c1 100644 --- a/gdb/i386-linux-nat.c +++ b/gdb/i386-linux-nat.c @@ -26,7 +26,7 @@ #include "gregset.h" #include "gdb_proc_service.h" -#include "i386-linux-nat.h" +#include "nat/x86-linux.h" #include "i387-tdep.h" #include "i386-tdep.h" #include "i386-linux-tdep.h" @@ -80,22 +80,6 @@ int have_ptrace_getregs = 0 #endif ; - -/* Does the current host support the GETFPXREGS request? The header - file may or may not define it, and even if it is defined, the - kernel will return EIO if it's running on a pre-SSE processor. - - My instinct is to attach this to some architecture- or - target-specific data structure, but really, a particular GDB - process can only run on top of one kernel at a time. So it's okay - for this to be a simple variable. */ -int have_ptrace_getfpxregs = -#ifdef HAVE_PTRACE_GETFPXREGS - -1 -#else - 0 -#endif -; /* Accessing registers through the U area, one at a time. */ @@ -388,14 +372,14 @@ fetch_fpxregs (struct regcache *regcache, int tid) { elf_fpxregset_t fpxregs; - if (! have_ptrace_getfpxregs) + if (have_ptrace_getfpxregs == TRIBOOL_FALSE) return 0; if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0) { if (errno == EIO) { - have_ptrace_getfpxregs = 0; + have_ptrace_getfpxregs = TRIBOOL_FALSE; return 0; } @@ -415,14 +399,14 @@ store_fpxregs (const struct regcache *regcache, int tid, int regno) { elf_fpxregset_t fpxregs; - if (! have_ptrace_getfpxregs) + if (have_ptrace_getfpxregs == TRIBOOL_FALSE) return 0; if (ptrace (PTRACE_GETFPXREGS, tid, 0, &fpxregs) == -1) { if (errno == EIO) { - have_ptrace_getfpxregs = 0; + have_ptrace_getfpxregs = TRIBOOL_FALSE; return 0; } diff --git a/gdb/i386-linux-nat.h b/gdb/i386-linux-nat.h deleted file mode 100644 index c3d32aff1be..00000000000 --- a/gdb/i386-linux-nat.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Native-dependent code for GNU/Linux i386. - - Copyright (C) 1999-2024 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef I386_LINUX_NAT_H -#define I386_LINUX_NAT_H 1 - -/* Does the current host support the GETFPXREGS request? */ -extern int have_ptrace_getfpxregs; - -#endif diff --git a/gdb/nat/x86-linux.c b/gdb/nat/x86-linux.c index 7a21c8f2c26..f394dc5d5e1 100644 --- a/gdb/nat/x86-linux.c +++ b/gdb/nat/x86-linux.c @@ -20,6 +20,15 @@ #include "x86-linux.h" #include "x86-linux-dregs.h" +/* See nat/x86-linux.h. */ +tribool have_ptrace_getfpxregs = +#ifdef HAVE_PTRACE_GETFPXREGS + TRIBOOL_UNKNOWN +#else + TRIBOOL_FALSE +#endif +; + /* Per-thread arch-specific data we want to keep. */ struct arch_lwp_info diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h index 822882173f9..936e20154a0 100644 --- a/gdb/nat/x86-linux.h +++ b/gdb/nat/x86-linux.h @@ -22,6 +22,20 @@ #include "nat/linux-nat.h" +/* Does the current host support the GETFPXREGS request? The system header + file may or may not define it, but even if it is defined, the kernel + will return EIO if it's running on a pre-SSE processor. + + Initially this will be TRIBOOL_UNKNOWN and should be changed to + TRIBOOL_FALSE if the ptrace call is attempted and fails or changed to + TRIBOOL_TRUE if the ptrace call is attempted and succeeds. + + My instinct is to attach this to some architecture- or target-specific + data structure, but really, a particular GDB process can only run on top + of one kernel at a time. So it's okay - for this to be a global + variable. */ +extern tribool have_ptrace_getfpxregs; + /* Set whether our local mirror of LWP's debug registers has been changed since the values were last written to the thread. Nonzero indicates that a change has been made, zero indicates no change. */ diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index a3d8ffb60f1..b42884ad57f 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -26,9 +26,6 @@ #include #include "x86-nat.h" -#ifndef __x86_64__ -#include "i386-linux-nat.h" -#endif #include "x86-linux-nat.h" #include "i386-linux-tdep.h" #ifdef __x86_64__ @@ -147,13 +144,13 @@ x86_linux_nat_target::read_description () error (_("Can't debug 64-bit process with 32-bit GDB")); } #elif HAVE_PTRACE_GETFPXREGS - if (have_ptrace_getfpxregs == -1) + if (have_ptrace_getfpxregs == TRIBOOL_UNKNOWN) { elf_fpxregset_t fpxregs; if (ptrace (PTRACE_GETFPXREGS, tid, 0, (int) &fpxregs) < 0) { - have_ptrace_getfpxregs = 0; + have_ptrace_getfpxregs = TRIBOOL_FALSE; have_ptrace_getregset = TRIBOOL_FALSE; return i386_linux_read_description (X86_XSTATE_X87_MASK); } diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc index e8ef3667eb4..7937055c060 100644 --- a/gdbserver/linux-x86-low.cc +++ b/gdbserver/linux-x86-low.cc @@ -831,17 +831,6 @@ x86_target::low_siginfo_fixup (siginfo_t *ptrace, gdb_byte *inf, int direction) static int use_xml; -/* Does the current host support the GETFPXREGS request? The header - file may or may not define it, and even if it is defined, the - kernel will return EIO if it's running on a pre-SSE processor. */ -int have_ptrace_getfpxregs = -#ifdef HAVE_PTRACE_GETFPXREGS - -1 -#else - 0 -#endif -; - /* Get Linux/x86 target description from running target. */ static const struct target_desc * @@ -886,18 +875,18 @@ x86_linux_read_description (void) } #if !defined __x86_64__ && defined HAVE_PTRACE_GETFPXREGS - if (machine == EM_386 && have_ptrace_getfpxregs == -1) + if (machine == EM_386 && have_ptrace_getfpxregs == TRIBOOL_UNKNOWN) { elf_fpxregset_t fpxregs; if (ptrace (PTRACE_GETFPXREGS, tid, 0, (long) &fpxregs) < 0) { - have_ptrace_getfpxregs = 0; + have_ptrace_getfpxregs = TRIBOOL_FALSE; have_ptrace_getregset = TRIBOOL_FALSE; return i386_linux_read_description (X86_XSTATE_X87); } else - have_ptrace_getfpxregs = 1; + have_ptrace_getfpxregs = TRIBOOL_TRUE; } #endif -- 2.25.4