From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id AFA8E3858417; Mon, 25 Mar 2024 17:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFA8E3858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1711387125; bh=+VPBbk4Ew1Px0RTezRi94/PpfDD1zKzfT4wRHTTjrrw=; h=From:To:Subject:Date:From; b=wbEz2YJldGj3qyTLA+k9MaWU/5rmxfKJEALBnqPzqnQNh36Id//tssOY+2tF0jL8o mt7dZrsBODOZYE7b4K5qDvpZmyP2c1hx+rRCWzPZq9+eFfnlgTk1xLx+3FU9X3r+9U GdGBq504n0jGgTMpADD3ZVEgVbnlMjp9FO6bB6Mk= 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] gdbserver/x86: move no-xml code earlier in x86_linux_read_description X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 01ed1674d4435aa4e194fd9373b7705e425ef354 X-Git-Newrev: 0a7bb97ad2f2fe2d18a442dad265051e34eab13e Message-Id: <20240325171845.AFA8E3858417@sourceware.org> Date: Mon, 25 Mar 2024 17:18:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0a7bb97ad2f2= fe2d18a442dad265051e34eab13e commit 0a7bb97ad2f2fe2d18a442dad265051e34eab13e Author: Andrew Burgess Date: Sat Jan 27 09:33:14 2024 +0000 gdbserver/x86: move no-xml code earlier in x86_linux_read_description =20 This commit is part of a series that aims to share more of the x86 target description reading/generation code between GDB and gdbserver. =20 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. =20 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. =20 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. =20 Anyway.... this commit doesn't do that. =20 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? =20 So in this commit I propose to move the '!use_xml' block earlier in the x86_linux_read_description function. =20 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. =20 Approved-By: John Baldwin Diff: --- 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 } =20 + /* 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 =3D=3D 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 =3D=3D EM_386 && have_ptrace_getfpxregs =3D=3D -1) { @@ -907,17 +923,6 @@ x86_linux_read_description (void) } #endif =20 - if (!use_xml) - { - /* Don't use XML. */ -#ifdef __x86_64__ - if (machine =3D=3D EM_X86_64) - return tdesc_amd64_linux_no_xml.get (); - else -#endif - return tdesc_i386_linux_no_xml.get (); - } - if (have_ptrace_getregset =3D=3D TRIBOOL_UNKNOWN) { uint64_t xstateregs[(X86_XSTATE_SSE_SIZE / sizeof (uint64_t))];