From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id C7A843858414; Tue, 26 Mar 2024 18:59:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7A843858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711479569; bh=PtH+Evj6ewxu1gq1xu5POc03lkqgwlqcDtN96Pd/bU4=; h=From:To:Subject:Date:From; b=TxH1bu1qh5a6rIjpYr+e63IhGqnyrF2u68RfkBW/I2uAE2U0Wv4jM6oH3KPxRYD5G CAZphVuFSlK2InlTM54fMlJPBL+t8aQxEteUumn4Z9S7UvOPC/QIbWy2sIHFo2GIQc 2S+hH6PG74qjRdyMLFsYMgXTZ60mXwlxNHCc6N4o= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Revert "gdb/x86: move reading of cs and ds state into gdb/nat directory" X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 59b198a6163a23de5fdba04eb107686e1b871be0 X-Git-Newrev: 9480801c1f446952d6b499f5fb45e3474ac87a90 Message-Id: <20240326185929.C7A843858414@sourceware.org> Date: Tue, 26 Mar 2024 18:59:29 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9480801c1f44= 6952d6b499f5fb45e3474ac87a90 commit 9480801c1f446952d6b499f5fb45e3474ac87a90 Author: Andrew Burgess Date: Tue Mar 26 18:53:17 2024 +0000 Revert "gdb/x86: move reading of cs and ds state into gdb/nat directory" =20 This reverts commit 01ed1674d4435aa4e194fd9373b7705e425ef354. Diff: --- gdb/nat/x86-linux.c | 47 ----------------------------------------------- gdb/nat/x86-linux.h | 28 ---------------------------- gdb/x86-linux-nat.c | 42 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 80 deletions(-) diff --git a/gdb/nat/x86-linux.c b/gdb/nat/x86-linux.c index 4242a1baafb..e61f4d749ba 100644 --- a/gdb/nat/x86-linux.c +++ b/gdb/nat/x86-linux.c @@ -20,8 +20,6 @@ #include "gdbsupport/common-defs.h" #include "x86-linux.h" #include "x86-linux-dregs.h" -#include "nat/gdb_ptrace.h" -#include =20 /* Per-thread arch-specific data we want to keep. */ =20 @@ -82,48 +80,3 @@ x86_linux_prepare_to_resume (struct lwp_info *lwp) { x86_linux_update_debug_registers (lwp); } - -#ifdef __x86_64__ -/* Value of CS segment register: - 64bit process: 0x33 - 32bit process: 0x23 */ -#define AMD64_LINUX_USER64_CS 0x33 - -/* Value of DS segment register: - LP64 process: 0x0 - X32 process: 0x2b */ -#define AMD64_LINUX_X32_DS 0x2b -#endif - -/* See nat/x86-linux.h. */ - -x86_linux_arch_size -x86_linux_ptrace_get_arch_size (int tid) -{ -#ifdef __x86_64__ - unsigned long cs; - unsigned long ds; - - /* Get CS register. */ - errno =3D 0; - cs =3D ptrace (PTRACE_PEEKUSER, tid, - offsetof (struct user_regs_struct, cs), 0); - if (errno !=3D 0) - perror_with_name (_("Couldn't get CS register")); - - bool is_64bit =3D cs =3D=3D AMD64_LINUX_USER64_CS; - - /* Get DS register. */ - errno =3D 0; - ds =3D ptrace (PTRACE_PEEKUSER, tid, - offsetof (struct user_regs_struct, ds), 0); - if (errno !=3D 0) - perror_with_name (_("Couldn't get DS register")); - - bool is_x32 =3D ds =3D=3D AMD64_LINUX_X32_DS; - - return x86_linux_arch_size (is_64bit, is_x32); -#else - return x86_linux_arch_size (false, false); -#endif -} diff --git a/gdb/nat/x86-linux.h b/gdb/nat/x86-linux.h index 15153ea277e..822882173f9 100644 --- a/gdb/nat/x86-linux.h +++ b/gdb/nat/x86-linux.h @@ -47,32 +47,4 @@ extern void x86_linux_delete_thread (struct arch_lwp_inf= o *arch_lwp); =20 extern void x86_linux_prepare_to_resume (struct lwp_info *lwp); =20 -/* Return value from x86_linux_ptrace_get_arch_size function. Indicates if - a thread is 32-bit, 64-bit, or x32. */ - -struct x86_linux_arch_size -{ - explicit x86_linux_arch_size (bool is_64bit, bool is_x32) - : m_is_64bit (is_64bit), - m_is_x32 (is_x32) - { - /* Nothing. */ - } - - bool is_64bit () const - { return m_is_64bit; } - - bool is_x32 () const - { return m_is_x32; } - -private: - bool m_is_64bit =3D false; - bool m_is_x32 =3D false; -}; - -/* Use ptrace calls to figure out if thread TID is 32-bit, 64-bit, or - 64-bit running in x32 mode. */ - -extern x86_linux_arch_size x86_linux_ptrace_get_arch_size (int tid); - #endif /* NAT_X86_LINUX_H */ diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index b39d05c401f..b93ffca38db 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -91,6 +91,18 @@ x86_linux_nat_target::post_startup_inferior (ptid_t ptid) linux_nat_target::post_startup_inferior (ptid); } =20 +#ifdef __x86_64__ +/* Value of CS segment register: + 64bit process: 0x33 + 32bit process: 0x23 */ +#define AMD64_LINUX_USER64_CS 0x33 + +/* Value of DS segment register: + LP64 process: 0x0 + X32 process: 0x2b */ +#define AMD64_LINUX_X32_DS 0x2b +#endif + /* Get Linux/x86 target description from running target. */ =20 const struct target_desc * @@ -110,11 +122,31 @@ x86_linux_nat_target::read_description () tid =3D inferior_ptid.pid (); =20 #ifdef __x86_64__ - - x86_linux_arch_size arch_size =3D x86_linux_ptrace_get_arch_size (tid); - is_64bit =3D arch_size.is_64bit (); - is_x32 =3D arch_size.is_x32 (); - + { + unsigned long cs; + unsigned long ds; + + /* Get CS register. */ + errno =3D 0; + cs =3D ptrace (PTRACE_PEEKUSER, tid, + offsetof (struct user_regs_struct, cs), 0); + if (errno !=3D 0) + perror_with_name (_("Couldn't get CS register")); + + is_64bit =3D cs =3D=3D AMD64_LINUX_USER64_CS; + + /* Get DS register. */ + errno =3D 0; + ds =3D ptrace (PTRACE_PEEKUSER, tid, + offsetof (struct user_regs_struct, ds), 0); + if (errno !=3D 0) + perror_with_name (_("Couldn't get DS register")); + + is_x32 =3D ds =3D=3D AMD64_LINUX_X32_DS; + + if (sizeof (void *) =3D=3D 4 && is_64bit && !is_x32) + error (_("Can't debug 64-bit process with 32-bit GDB")); + } #elif HAVE_PTRACE_GETFPXREGS if (have_ptrace_getfpxregs =3D=3D -1) {