From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IFBXKQxEP2ZODg4AWB0awg (envelope-from ) for ; Sat, 11 May 2024 06:10:20 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gJ3vtiQh; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9EE461E0C1; Sat, 11 May 2024 06:10:20 -0400 (EDT) Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 83CD91E0C0 for ; Sat, 11 May 2024 06:10:18 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA7C3387089C for ; Sat, 11 May 2024 10:10:17 +0000 (GMT) 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 D34F63870882 for ; Sat, 11 May 2024 10:08:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D34F63870882 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 D34F63870882 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=1715422144; cv=none; b=oBWLXFjWhpiNoeyR9GesUJNcAT+dkbCSvaggzTDRgPE/c6Zo8sL+VRSVrsHKkyDZEkmQIgNoApewkzuhHCbEYMbD9Uo0J4BzEAIw2TvXeSAJ4yVIqgyNAC4+fwj9oty083sVK+RdHtHJCPQg4JDyuI6xc28AMOfhQjoxQNdK7tc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715422144; c=relaxed/simple; bh=6EO2w7nUJEp10tVwP1HUlGZPDsg9gTYlChYOB7mTdc8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=nKRx7C8IS4wt+8b3tc0V/mP6HpxTsGReiV9YhYCkJEtuSKw+DI/mqPo2BdcP3fN+41deeOeT7IbQLbgE+DjIzuS33VK1erqU+uYXUaoUCOjK/fRu22yhvqeQBXBg3ZtXWACcHBhose3IWwGYu3NLL8F1eEE02Dm2OpAp2mPIPnE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715422137; 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=FA9MflsIZqClh4yOGr/Ei8Yse3gJoGW6ZGDDlNpdjqM=; b=gJ3vtiQhKeGmXH2ycHiPxePP9jqtj9P8hHt8O/SdZZjiIDWQKpCsCZ1wXhPRJRAXjxsKZp CGuebm612llzLa4UKE+FnmhHSN6he86ZPAdY83Ma7pZqtAEali7xoETYFHXd4JU9mFg/BW xXlJaJJhO7b9zv0n/jGvy6/L7rkXGN4= Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-2-V6xdNqlVOXWJsBHhQ1V7zA-1; Sat, 11 May 2024 06:08:56 -0400 X-MC-Unique: V6xdNqlVOXWJsBHhQ1V7zA-1 Received: by mail-lj1-f197.google.com with SMTP id 38308e7fff4ca-2e233a3d4b0so30127761fa.3 for ; Sat, 11 May 2024 03:08:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715422134; x=1716026934; 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=JlxV3JzwvF1U7dbmzbLEskz7Bbt/9pfgP3JN37+sgas=; b=tt12joaQhk8mZPdhuusjWqVaGrZ9Z5BLto4sjx2w+6cQ3FG1ETUKaUb3DjwZEIIRsX 4qqbOj5Koi/a6LtiDapMkvnDZBBnuFHnIGdyH33v1qTMqVZLFbx+t7LMebvkP+Hnlcfo H9BjaHQyqG7qHKCLYhjX5VYAQQxHqQYP+EfPxeHwmdnoY922eqOcR4xBpuUDhFdsDKuA 8rYfxA472dArei0YQCvNf0j73BBWtighRVaqIuzM13+ayJmb008kbQt/42P1vEd6TgN5 wj3sO+MLW40PqBYPzEV8UUYUzAcmdMu2niZDAnS7dyQnGEsn3qBdZjjiIcUOXymuqmJT oK/Q== X-Gm-Message-State: AOJu0Yy06Dkngh7tcctzQaKsLaBPK8ZGVlcfacckTWgu8vLCBE197xpI Uhk9BieOfXoEyEmCS1Mu6fMmXxuUC0A45QkwFOaszUIAR6OndMkZhfy0DFsSfEVlKhQNA0y45js 4k0laWBfI9MOLljmWYBU/pKeapzL2Kqz1bS3+yEhlmYRzfpqk1cheNR2qP1NLlxcHIncSGZZ5f7 4b4Sfethy6oq8hJHZ+zq17XHtmV9/W6h3cxXdaDJyHmgc= X-Received: by 2002:a2e:7015:0:b0:2e2:f6e6:ada2 with SMTP id 38308e7fff4ca-2e51fd2dd20mr33625201fa.8.1715422134020; Sat, 11 May 2024 03:08:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmKwJnXzhqKAXjczyemLjDCrp8rMjQxrPh6THiBFG9iP/VOpXSCFtwZq0y/ZGSz/IiwS26pg== X-Received: by 2002:a2e:7015:0:b0:2e2:f6e6:ada2 with SMTP id 38308e7fff4ca-2e51fd2dd20mr33625021fa.8.1715422133328; Sat, 11 May 2024 03:08:53 -0700 (PDT) Received: from localhost (92.40.185.101.threembb.co.uk. [92.40.185.101]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccbe8f74sm94687465e9.8.2024.05.11.03.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 03:08:52 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , felix.willgerodt@intel.com, jhb@FreeBSD.org Subject: [PATCHv7 3/9] gdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory Date: Sat, 11 May 2024 11:08:33 +0100 Message-Id: <95646b59108329cb1e168e7815d242c0292ab3c2.1715421687.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=-6.8 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, 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+public-inbox=simark.ca@sourceware.org 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), I think 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 | 2 +- gdb/configure.nat | 2 +- gdb/i386-linux-nat.c | 26 +++------------ gdb/{i386-linux-nat.h => nat/i386-linux.c} | 15 +++++---- gdb/nat/i386-linux.h | 37 ++++++++++++++++++++++ gdb/x86-linux-nat.c | 6 ++-- gdbserver/configure.srv | 1 + gdbserver/linux-x86-low.cc | 19 +++-------- 8 files changed, 62 insertions(+), 46 deletions(-) rename gdb/{i386-linux-nat.h => nat/i386-linux.c} (77%) create mode 100644 gdb/nat/i386-linux.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 234d0051f49..bdb8a3683b5 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 \ @@ -1594,6 +1593,7 @@ HFILES_NO_SRCDIR = \ nat/gdb_ptrace.h \ nat/gdb_thread_db.h \ nat/fork-inferior.h \ + nat/i386-linux.h \ nat/linux-btrace.h \ nat/linux-namespaces.h \ nat/linux-nat.h \ diff --git a/gdb/configure.nat b/gdb/configure.nat index 8b98511cef7..25268bb268b 100644 --- a/gdb/configure.nat +++ b/gdb/configure.nat @@ -256,7 +256,7 @@ case ${gdb_host} in NATDEPFILES="${NATDEPFILES} x86-nat.o nat/x86-dregs.o \ nat/x86-xstate.o \ i386-linux-nat.o x86-linux-nat.o nat/linux-btrace.o \ - nat/x86-linux.o nat/x86-linux-dregs.o" + nat/x86-linux.o nat/x86-linux-dregs.o nat/i386-linux.o" ;; ia64) # Host: Intel IA-64 running GNU/Linux diff --git a/gdb/i386-linux-nat.c b/gdb/i386-linux-nat.c index 7278dd91ff0..bfe3fb84d0a 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/i386-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/nat/i386-linux.c similarity index 77% rename from gdb/i386-linux-nat.h rename to gdb/nat/i386-linux.c index c3d32aff1be..64605be4fc5 100644 --- a/gdb/i386-linux-nat.h +++ b/gdb/nat/i386-linux.c @@ -1,6 +1,6 @@ /* Native-dependent code for GNU/Linux i386. - Copyright (C) 1999-2024 Free Software Foundation, Inc. + Copyright (C) 2024 Free Software Foundation, Inc. This file is part of GDB. @@ -17,10 +17,13 @@ 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; +#include "nat/i386-linux.h" +/* See nat/i386-linux.h. */ +tribool have_ptrace_getfpxregs = +#ifdef HAVE_PTRACE_GETFPXREGS + TRIBOOL_UNKNOWN +#else + TRIBOOL_FALSE #endif +; diff --git a/gdb/nat/i386-linux.h b/gdb/nat/i386-linux.h new file mode 100644 index 00000000000..c93626b6439 --- /dev/null +++ b/gdb/nat/i386-linux.h @@ -0,0 +1,37 @@ +/* Native-dependent code for GNU/Linux i386. + + Copyright (C) 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 NAT_I386_LINUX_H +#define NAT_I386_LINUX_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; + +#endif /* NAT_I386_LINUX_H */ diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index a3d8ffb60f1..762151ff378 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -27,7 +27,7 @@ #include "x86-nat.h" #ifndef __x86_64__ -#include "i386-linux-nat.h" +#include "nat/i386-linux.h" #endif #include "x86-linux-nat.h" #include "i386-linux-tdep.h" @@ -147,13 +147,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/configure.srv b/gdbserver/configure.srv index 9e861a75088..8e882d2159b 100644 --- a/gdbserver/configure.srv +++ b/gdbserver/configure.srv @@ -109,6 +109,7 @@ case "${gdbserver_host}" in srv_tgtobj="${srv_tgtobj} nat/linux-btrace.o" srv_tgtobj="${srv_tgtobj} nat/x86-linux.o" srv_tgtobj="${srv_tgtobj} nat/x86-linux-dregs.o" + srv_tgtobj="${srv_tgtobj} nat/i386-linux.o" srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc index e8ef3667eb4..2d99a82f566 100644 --- a/gdbserver/linux-x86-low.cc +++ b/gdbserver/linux-x86-low.cc @@ -29,6 +29,8 @@ #ifdef __x86_64__ #include "nat/amd64-linux-siginfo.h" +#else +#include "nat/i386-linux.h" #endif #include "gdb_proc_service.h" @@ -831,17 +833,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 +877,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