From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iCVcBZ5+YWYlUygAWB0awg (envelope-from ) for ; Thu, 06 Jun 2024 05:17:18 -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=RgLCIafg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 113C51E0C0; Thu, 6 Jun 2024 05:17:18 -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 EA2AB1E092 for ; Thu, 6 Jun 2024 05:17:15 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABFE738F981D for ; Thu, 6 Jun 2024 09:17:15 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 2057738F9832 for ; Thu, 6 Jun 2024 09:16:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2057738F9832 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 2057738F9832 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717665388; cv=none; b=TOhmggI+pnZyO5dNzpJRAdIBat1jpUCgehw3/V8MgTOaMWk4+dQm5D93Fr5/SaqNTmdlCCEigm+Qi3H4WGGm7fjg3Z9VlazvqbSV/pgtNmbsygTm+vjPwXuNGkqy1dNQhvo6qF5xjz3CPGLCVn+qQcTA4wPDYRmV9BTYekyPtR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717665388; c=relaxed/simple; bh=SUCEyUdYT5yH+ojiR6lwWTpk9gNG+oc9q9TMgHwh8IY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=eMabqrzOX/w71Xx6sm4MS7zNOqWLtSyAuA/YRniiOnCspbPUXM3DcpU9xziSOZbOVBkRFpPfKWxhkRC4PkNmgzzR7S/CTH0vWQjXNnq0WyoOkV3TaDyy4pEtU3zgAQhvufO9YvDjW/UGhYXxOGb6T3eCyVdEKd7uG9+HCPyQZW8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717665380; 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=Yy2oyYXYEQqPTlXAVDFfmIrAHi1fp3AQDev8ET/iBp0=; b=RgLCIafgwfunJrWhzzk2ctD7Gcm/ZWo74YO2OqnwcKxPMuy7J7v08oSoBaOUiJx/JGjhWR ZuNBL3O+PkS5j6E7nGCVZqBGvO/4H3qKEdyttUAoFz+kikrPkVwqRgJbC0aoH1S3DN7FJC MCcsd1Y1j2vUDrFwDATEKrd6PqRmGOk= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-USVFbT5ePoKPudKxHwREGQ-1; Thu, 06 Jun 2024 05:16:19 -0400 X-MC-Unique: USVFbT5ePoKPudKxHwREGQ-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-421292df2adso6137575e9.3 for ; Thu, 06 Jun 2024 02:16:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717665377; x=1718270177; 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=oMAWK17Qoh1P0KtArSdEhd3GM8fNtie+ZiJsQFb2GLo=; b=BXvYw3TalX5NP0KUb1FcQNs6G2/LL8fyuxg6E6rzMjryHbrPUyRWVdCRH25vZJYmqE YEH+0H7v9WpM+Jqr1XbVItTa10xH67FCjSoupAry2iJeNkBSvl23yK5hFbX08RyKluOY n1hqgqKYNijFHMLTX70FpXxmAg6Lz8276ntly3fTHuVtLsd5oa80dGTnHSkAKyQZCi8X GIPerzjoo2G1nACiLEEUiKGcrA2eVcEv3oU7f7L3vbZZ77UVM0mxfZ45wHabOKqQ03Cm kzVrCZZDRf2QL0kAgQ6jsYPAtwGCDCOugD0tWWPHMUE9CFyE9w450NtHkhS3f+Z1b50q HNoA== X-Gm-Message-State: AOJu0YwO2+6I5CC4U6OPhJQPVXiJ4plSFDg5h4PsIXk6H1OgZZnDSBtx pzZojA1yPHpxXh2Udd7PorMwI0RI75wT58U/dX8VhXw6q0f+L/rJ+Pylh2YZiM9MwtFswqQMRuA WM3dBEYvxQReYE6FNQIx5wxWVKSw6dmzN+EFcfUJh6zL65LyFrqiUpkBTtAzLWNEZKykzvWXsNb lJsfJuhEhal88XMLmEOxlpZ7UHERYhyyDbckMpkx7ZULI= X-Received: by 2002:a05:600c:444b:b0:420:18e9:86d5 with SMTP id 5b1f17b1804b1-421562cf39dmr41776265e9.10.1717665377112; Thu, 06 Jun 2024 02:16:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPFnkK09QijL8xr0no/v0cELvMLkazErWfGR/7yrBRDSv24oKJ+g9Ps9UQ3uO7uDk+gVStCQ== X-Received: by 2002:a05:600c:444b:b0:420:18e9:86d5 with SMTP id 5b1f17b1804b1-421562cf39dmr41776085e9.10.1717665376563; Thu, 06 Jun 2024 02:16:16 -0700 (PDT) Received: from localhost ([31.111.84.186]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4215c2cd803sm14598725e9.45.2024.06.06.02.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 02:16:16 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , felix.willgerodt@intel.com Subject: [PATCHv8 3/9] gdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory Date: Thu, 6 Jun 2024 10:15:59 +0100 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 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, 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+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 3752bdff79b..277f878371c 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