]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
12 months agogdbserver: update target description creation for x86/linux
Andrew Burgess [Wed, 31 Jan 2024 11:18:34 +0000 (11:18 +0000)] 
gdbserver: update target description creation for x86/linux

This commit is part of a series which aims to share more of the target
description creation between GDB and gdbserver for x86/Linux.

After some refactoring earlier in this series the shared
x86_linux_tdesc_for_tid function was added into nat/x86-linux-tdesc.c.
However, this function still relies on amd64_linux_read_description
and i386_linux_read_description which are implemented separately for
both gdbserver and GDB.  Given that at their core, all these functions
do is:

  1. take an xcr0 value as input,
  2. mask out some feature bits,
  3. look for a cached pre-generated target description and return it
     if found,
  4. if no cached target description is found then call either
     amd64_create_target_description or
     i386_create_target_description to create a new target
     description, which is then added to the cache.  Return the newly
     created target description.

The inner functions amd64_create_target_description and
i386_create_target_description are already shared between GDB and
gdbserver (in the gdb/arch/ directory), so the only thing that
the *_read_description functions really do is add the caching layer,
and it feels like this really could be shared.

However, we have a small problem.

Despite using the same {amd64,i386}_create_target_description
functions in both GDB and gdbserver to create the target descriptions,
on the gdbserver side we cache target descriptions based on a reduced
set of xcr0 feature bits.

What this means is that, in theory, different xcr0 values can map to
the same cache entry, which could result in the wrong target
description being used.

However, I'm not sure if this can actually happen in reality.  Within
gdbserver we already split the target description cache based on i386,
amd64, and x32.  I suspect within a given gdbserver session we'll only
see at most one target description for each of these.

The cache conflicting problem is caused by xcr0_to_tdesc_idx, which
maps an xcr0 value to a enum x86_linux_tdesc value, and there are only
7 usable values in enum x86_linux_tdesc.

In contrast, on the GDB side there are 64, 32, and 16 cache slots for
i386, amd64, and x32 respectively.

On the GDB side it is much more important to cache things correctly as
a single GDB session might connect to multiple different remote
targets, each of which might have slightly different x86
architectures.

And so, if we want to merge the target description caching between GDB
and gdbserver, then we need to first update gdbserver so that it
caches in the same way as GDB, that is, it needs to adopt a mechanism
that allows for the same number of cache slots of each of i386, amd64,
and x32.  In this way, when the caching is shared, GDB's behaviour
will not change.

Unfortunately it's a little more complex than that due to the in
process agent (IPA).

When the IPA is in use, gdbserver sends a target description index to
the IPA, and the IPA uses this to find the correct target description
to use, the IPA having first generated every possible target
description.

Interestingly, there is certainly a bug here which results from only
having 7 values in enum x86_linux_tdesc.  As multiple possible target
descriptions in gdbserver map to the same enum x86_linux_tdesc value,
then, when the enum x86_linux_tdesc value is sent to the IPA there is
no way for gdbserver to know that the IPA will select the correct
target description.  This bug will get fixed by this commit.

** START OF AN ASIDE **

Back in the day I suspect this approach of sending a target
description index made perfect sense.  However since this commit:

  commit a8806230241d201f808d856eaae4d44088117b0c
  Date:   Thu Dec 7 17:07:01 2017 +0000

      Initialize target description early in IPA

I think that passing an index was probably a bad idea.

We used to pass the index, and then use that index to lookup which
target description to instantiate and use, the target description was
not generated until the index arrived.

However, the above commit fixed an issue where we can't call malloc()
within (certain parts of) the IPA (apparently), so instead we now
pre-compute _every_ possible target description within the IPA.  The
index is only used to lookup which of the (many) pre-computed target
descriptions to use.

It would (I think) have been easier all around if the IPA just
self-inspected, figured out its own xcr0 value, and used that to
create the one target description that is required.  So long as the
xcr0 to target description code is shared (at compile time) with
gdbserver, then we can be sure that the IPA will derive the same
target description as gdbserver, and we would avoid all this index
passing business, which has made this commit so very, very painful.

I did look at how a process might derive its own xcr0 value, but I
don't believe this is actually that simple, so for now I've just
doubled down on the index passing approach.

While reviewing earlier iterations of this patch there has been
discussion about the possibility of removing the IPA from GDB.  That
would certainly make all of the code touched in this patch much
simpler, but I don't really want to do that as part of this series.

** END OF AN ASIDE **

Currently then for x86/linux, gdbserver sends a number between 0 and 7
to the IPA, and the IPA uses this to create a target description.

However, I am proposing that gdbserver should now create one of (up
to) 64 different target descriptions for i386, so this 0 to 7 index
isn't going to be good enough any more (amd64 and x32 have slightly
fewer possible target descriptions, but still more than 8, so the
problem is the same).

For a while I wondered if I was going to have to try and find some
backward compatible solution for this mess.  But after seeing how
lightly the IPA is actually documented, I wonder if it is not the case
that there is a tight coupling between a version of gdbserver and a
version of the IPA?  At least I'm hoping so, and that's what I've
assumed in this commit.

In this commit I have thrown out the old IPA target description index
numbering scheme, and switched to a completely new numbering scheme.
Instead of the index that is passed being arbitrary, the index is
instead calculated from the set of xcr0 features that are present on
the target.  Within the IPA we can then reverse this logic to recreate
the xcr0 value based on the index, and from the xcr0 value we can
choose the correct target description.

With the gdbserver to IPA numbering scheme issue resolved I have then
update the gdbserver versions of amd64_linux_read_description and
i386_linux_read_description so that they cache target descriptions
using the same set of xcr0 features as GDB itself.

After this gdbserver should now always come up with the same target
description as GDB does on any x86/Linux target.

This commit does not introduce any new code sharing between GDB and
gdbserver as previous commits in this series have done.  Instead this
commit is all about bringing GDB and gdbserver into alignment
functionally so that the next commit(s) can merge the GDB and
gdbserver versions of these functions.

Notes On The Implementation
---------------------------

Previously, within gdbserver, target descriptions were cached within
arrays.  These arrays were sized based on enum x86_linux_tdesc and
xcr0_to_tdesc_idx returned the array (cache) index.

Now we need different array lengths for each of i386, amd64, and x32.
And the index to use within each array is calculated based on which
xcr0 bits are set and valid for a particular target type.

I really wanted to avoid having fixed array sizes, or having the set
of relevant xcr0 bits encoded in multiple places.

The solution I came up with was to create a single data structure
which would contain a list of xcr0 bits along with flags to indicate
which of the i386, amd64, and x32 targets the bit is relevant for.  By
making the table constexpr, and adding some constexpr helper
functions, it is possible to calculate the sizes for the cache arrays
at compile time, as well as the bit masks needed to each target type.

During review it was pointed out[1] that possibly the failure to check
the SSE and X87 bits for amd64/x32 targets might be an error, however,
if this is the case then this is an issue that existed long before
this patch.  I'd really like to keep this patch focused on reworking
the existing code and try to avoid changing how target descriptions
are actually created, mostly out of fear that I'll break something.

[1] https://inbox.sourceware.org/gdb-patches/MN2PR11MB4566070607318EE7E669A5E28E1B2@MN2PR11MB4566.namprd11.prod.outlook.com

Approved-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
12 months agogdb/gdbserver: share some code relating to target description creation
Andrew Burgess [Thu, 25 Jan 2024 14:25:57 +0000 (14:25 +0000)] 
gdb/gdbserver: share some code relating to target description creation

This commit is part of a series to share more of the x86 target
description creation code between GDB and gdbserver.

Unlike previous commits which were mostly refactoring, this commit is
the first that makes a real change, though that change should mostly
be for gdbserver; I've largely adopted the "GDB" way of doing things
for gdbserver, and this fixes a real gdbserver bug.

On a x86-64 Linux target, running the test:

  gdb.server/connect-with-no-symbol-file.exp

results in two core files being created.  Both of these core files are
from the inferior process, created after gdbserver has detached.

In this test a gdbserver process is started and then, after gdbserver
has started, but before GDB attaches, we either delete the inferior
executable, or change its permissions so it can't be read.  Only after
doing this do we attempt to connect with GDB.

As GDB connects to gdbserver, gdbserver attempts to figure out the
target description so that it can send the description to GDB, this
involves a call to x86_linux_read_description.

In x86_linux_read_description one of the first things we do is try to
figure out if the process is 32-bit or 64-bit.  To do this we look up
the executable via the thread-id, and then attempt to read the
architecture size from the executable.  This isn't going to work if
the executable has been deleted, or is no longer readable.

And so, as we can't read the executable, we default to an i386 target
and use an i386 target description.

A consequence of using an i386 target description is that addresses
are assumed to be 32-bits.  Here's an example session that shows the
problems this causes.  This is run on an x86-64 machine, and the test
binary (xx.x) is a standard 64-bit x86-64 binary:

  shell_1$ gdbserver --once localhost :54321 /tmp/xx.x

  shell_2$ gdb -q
  (gdb) set sysroot
  (gdb) shell chmod 000 /tmp/xx.x
  (gdb) target remote :54321
  Remote debugging using :54321
  warning: /tmp/xx.x: Permission denied.
  0xf7fd3110 in ?? ()
  (gdb) show architecture
  The target architecture is set to "auto" (currently "i386").
  (gdb) p/x $pc
  $1 = 0xf7fd3110
  (gdb) info proc mappings
  process 2412639
  Mapped address spaces:

   Start Addr   End Addr       Size     Offset  Perms   objfile
     0x400000   0x401000     0x1000        0x0  r--p   /tmp/xx.x
     0x401000   0x402000     0x1000     0x1000  r-xp   /tmp/xx.x
     0x402000   0x403000     0x1000     0x2000  r--p   /tmp/xx.x
     0x403000   0x405000     0x2000     0x2000  rw-p   /tmp/xx.x
   0xf7fcb000 0xf7fcf000     0x4000        0x0  r--p   [vvar]
   0xf7fcf000 0xf7fd1000     0x2000        0x0  r-xp   [vdso]
   0xf7fd1000 0xf7fd3000     0x2000        0x0  r--p   /usr/lib64/ld-2.30.so
   0xf7fd3000 0xf7ff3000    0x20000     0x2000  r-xp   /usr/lib64/ld-2.30.so
   0xf7ff3000 0xf7ffb000     0x8000    0x22000  r--p   /usr/lib64/ld-2.30.so
   0xf7ffc000 0xf7ffe000     0x2000    0x2a000  rw-p   /usr/lib64/ld-2.30.so
   0xf7ffe000 0xf7fff000     0x1000        0x0  rw-p
   0xfffda000 0xfffff000    0x25000        0x0  rw-p   [stack]
   0xff600000 0xff601000     0x1000        0x0  r-xp   [vsyscall]
  (gdb) info inferiors
    Num  Description       Connection           Executable
  * 1    process 2412639   1 (remote :54321)
  (gdb) shell cat /proc/2412639/maps
  00400000-00401000 r--p 00000000 fd:03 45907133           /tmp/xx.x
  00401000-00402000 r-xp 00001000 fd:03 45907133           /tmp/xx.x
  00402000-00403000 r--p 00002000 fd:03 45907133           /tmp/xx.x
  00403000-00405000 rw-p 00002000 fd:03 45907133           /tmp/xx.x
  7ffff7fcb000-7ffff7fcf000 r--p 00000000 00:00 0          [vvar]
  7ffff7fcf000-7ffff7fd1000 r-xp 00000000 00:00 0          [vdso]
  7ffff7fd1000-7ffff7fd3000 r--p 00000000 fd:00 143904     /usr/lib64/ld-2.30.so
  7ffff7fd3000-7ffff7ff3000 r-xp 00002000 fd:00 143904     /usr/lib64/ld-2.30.so
  7ffff7ff3000-7ffff7ffb000 r--p 00022000 fd:00 143904     /usr/lib64/ld-2.30.so
  7ffff7ffc000-7ffff7ffe000 rw-p 0002a000 fd:00 143904     /usr/lib64/ld-2.30.so
  7ffff7ffe000-7ffff7fff000 rw-p 00000000 00:00 0
  7ffffffda000-7ffffffff000 rw-p 00000000 00:00 0          [stack]
  ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0  [vsyscall]
  (gdb)

Notice the difference between the mappings reported via GDB and those
reported directly from the kernel via /proc/PID/maps, the addresses of
every mapping is clamped to 32-bits for GDB, while the kernel reports
real 64-bit addresses.

Notice also that the $pc value is a 32-bit value.  It appears to be
within one of the mappings reported by GDB, but is outside any of the
mappings reported from the kernel.

And this is where the problem arises.  When gdbserver detaches from
the inferior we pass the inferior the address from which it should
resume.  Due to the 32/64 bit confusion we tell the inferior to resume
from the 32-bit $pc value, which is not within any valid mapping, and
so, as soon as the inferior resumes, it segfaults.

If we look at how GDB (not gdbserver) figures out its target
description then we see an interesting difference.  GDB doesn't try to
read the executable.  Instead GDB uses ptrace to query the thread's
state, and uses this to figure out the if the thread is 32 or 64 bit.

If we update gdbserver to do it the "GDB" way then the above problem
is resolved, gdbserver now sees the process as 64-bit, and when we
detach from the inferior we give it the correct 64-bit address, and
the inferior no longer segfaults.

Now, I could just update the gdbserver code, but better, I think, to
share one copy of the code between GDB and gdbserver in gdb/nat/.
That is what this commit does.

The cores of x86_linux_read_description from gdbserver and
x86_linux_nat_target::read_description from GDB are moved into a new
file gdb/nat/x86-linux-tdesc.c and combined into a single function
x86_linux_tdesc_for_tid which is called from each location.

This new function does things mostly the GDB way, some changes are
needed to allow for the sharing; we now take some pointers for where
the shared code can cache the xcr0 and xsave layout values.

Another thing to note about this commit is how the functions
i386_linux_read_description and amd64_linux_read_description are
handled.  For now I've left these function as implemented separately
in GDB and gdbserver.  I've moved the declarations of these functions
into gdb/arch/{i386,amd64}-linux-tdesc.h, but the implementations are
left where they are.

A later commit in this series will make these functions shared too,
but doing this is not trivial, so I've left that for a separate
commit.  Merging the declarations as I've done here ensures that
everyone implements the function to the same API, and once these
functions are shared (in a later commit) we'll want a shared
declaration anyway.

Reviewed-By: Felix Willgerodt <felix.willgerodt@intel.com>
Acked-By: John Baldwin <jhb@FreeBSD.org>
12 months agogdb: move xcr0 == 0 check into i386_linux_core_read_description
Andrew Burgess [Wed, 27 Mar 2024 14:30:48 +0000 (14:30 +0000)] 
gdb: move xcr0 == 0 check into i386_linux_core_read_description

Currently, in i386_linux_core_read_description, if GDB fails to
extract an xcr0 value from the core file, then we will have a default
zero value for the xcr0 variable, we still call the
i386_linux_read_description function, which checks for this zero value
and returns nullptr.

Back in i386_linux_core_read_description we spot the nullptr return
value from i386_linux_read_description and call
i386_linux_read_description again, but this time passing a default
value for xcr0.

In the next commit I plan to rework i386_linux_read_description, and
in so doing I will remove the check for xcr0 == 0, this is inline with
how the amd64 code is written.

However, this means that the 'xcr0 == 0' check needs to move up the
stack to i386_linux_core_read_description, again, this brings the i386
code into line with the amd64 code.

This is just a refactor in preparation for the next commit, there
should be no user visible changes after this commit.

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
Approved-By: John Baldwin <jhb@FreeBSD.org>
12 months agogdb/x86: move reading of cs and ds state into gdb/nat directory
Andrew Burgess [Sat, 27 Jan 2024 09:15:35 +0000 (09:15 +0000)] 
gdb/x86: move reading of cs and ds state into gdb/nat directory

This patch is part of a series that has the aim sharing the x86 Linux
target description creation code between GDB and gdbserver.

Within GDB part of this process involves reading the cs and ds state
from the 'struct user_regs_struct' using a ptrace call.

This isn't done by gdbserver, which is part of the motivation for this
whole series; the approach gdbserver takes is inferior to the approach
GDB takes (gdbserver relies on reading the file being debugged, and
extracting similar information from the file headers).

This commit moves the reading of cs and ds, which is used to figure
out if a thread is 32-bit or 64-bit (or in x32 mode), into the gdb/nat
directory so that the code can be shared with gdbserver, but at this
point I'm not actually using the code in gdbserver, that will come
later.

As such there should be no user visible changes after this commit, GDB
continues to do things as it did before (reading cs/ds), while
gdbserver continues to use its own approach (which doesn't require
reading cs/ds).

Approved-By: John Baldwin <jhb@FreeBSD.org>
Reviewed-By: Felix Willgerodt <felix.willgerodt@intel.com>
12 months agogdb: move have_ptrace_getregset declaration into gdb/nat directory
Andrew Burgess [Wed, 8 May 2024 14:04:56 +0000 (15:04 +0100)] 
gdb: move have_ptrace_getregset declaration into gdb/nat directory

In a later commit I want to access have_ptrace_getregset from a .c
file in the nat/ directory.  To achieve this I need access to the
declaration of have_ptrace_getregset.

Currently have_ptrace_getregset is declared (and defined) twice, once
in GDB and once in gdbserver.

This commit moves the declaration into nat/linux-nat.h, but leaves the
two definitions where they are.  Now, in my later commit, I can pull
in the declaration from nat/linux-nat.h.

There should be no user visible changes after this commit.

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
12 months agogdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory
Andrew Burgess [Fri, 26 Apr 2024 13:24:40 +0000 (14:24 +0100)] 
gdb/x86: move have_ptrace_getfpxregs global into gdb/nat directory

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 <felix.willgerodt@intel.com>
12 months agogdbserver/x86: move no-xml code earlier in x86_linux_read_description
Andrew Burgess [Sat, 27 Jan 2024 09:33:14 +0000 (09:33 +0000)] 
gdbserver/x86: move no-xml code earlier in x86_linux_read_description

This commit is part of a series that aims to share more of the x86
target description reading/generation code between GDB and gdbserver.

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.

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.

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.

Anyway.... this commit doesn't do that.

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?

So in this commit I propose to move the '!use_xml' block earlier in
the x86_linux_read_description function.

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.

Approved-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
12 months agogdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition
Andrew Burgess [Sat, 27 Jan 2024 10:40:35 +0000 (10:40 +0000)] 
gdb/gdbserver: share I386_LINUX_XSAVE_XCR0_OFFSET definition

Share the definition of I386_LINUX_XSAVE_XCR0_OFFSET between GDB and
gdbserver.

This commit moves the definition into gdbsupport/x86-xstate.h, which
allows the #define to be shared.

There should be no user visible changes after this commit.

Approved-By: Felix Willgerodt <felix.willgerodt@intel.com>
12 months agoAutomatic date update in version.in
GDB Administrator [Fri, 14 Jun 2024 00:00:26 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agoAdd gdbpy_call_method overloads for gdbpy_ref<>
Tom Tromey [Tue, 11 Jun 2024 20:12:09 +0000 (14:12 -0600)] 
Add gdbpy_call_method overloads for gdbpy_ref<>

This adds an overload of gdbpy_call_method that accepts a gdbpy_ref<>.
This is just a small convenience.

Reviewed-By: Tom de Vries <tdevries@suse.de>
12 months agoReturn gdbpy_ref<> from gdbpy_call_method
Tom Tromey [Tue, 11 Jun 2024 20:10:08 +0000 (14:10 -0600)] 
Return gdbpy_ref<> from gdbpy_call_method

This changes gdbpy_call_method to return a gdbpy_ref<>.  This is
slightly safer because it makes it simpler to correctly handle
reference counts.

Reviewed-By: Tom de Vries <tdevries@suse.de>
12 months agoAdjust linker tests that are sensitive to --rosegment
Nick Clifton [Thu, 13 Jun 2024 16:00:29 +0000 (17:00 +0100)] 
Adjust linker tests that are sensitive to --rosegment

12 months ago[gdb/testsuite] Add gdb.base/fission-macro.exp
Tom de Vries [Thu, 13 Jun 2024 15:39:40 +0000 (17:39 +0200)] 
[gdb/testsuite] Add gdb.base/fission-macro.exp

Starting with gcc commit 80048aa13a6 ("debug/111409 - don't generate COMDAT
macro sections for split DWARF"), available from release gcc 14.1 onwards, gcc
produces a usable dwarf-5 32-bit .debug_macro.dwo section.

Add a test-case excercising this.

Tested on x86_64-linux.

Tested test-case using a current gcc trunk build, and gcc 14.

12 months ago[gdb/testsuite] Fix kfail number in gdb.base/watchpoint-running.exp
Tom de Vries [Thu, 13 Jun 2024 15:29:37 +0000 (17:29 +0200)] 
[gdb/testsuite] Fix kfail number in gdb.base/watchpoint-running.exp

Test-case gdb.base/watchpoint-running.exp reports the following kfail:
...
KFAIL: $exp: all-stop: software: watchpoint hit (timeout) (PRMS: gdb/111111)
...
but the referenced gdb PR doesn't exist.

Fix this by using an actual PR.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31833

12 months agoAdd --rosegment option to BFD linker to stop the '-z separate-code' from generating...
Nick Clifton [Thu, 13 Jun 2024 14:10:15 +0000 (15:10 +0100)] 
Add --rosegment option to BFD linker to stop the '-z separate-code' from generating two read-only segments.

  PR 30907

12 months agoMIPS/opcodes: Rework INSN_* flags into a consistent block
Maciej W. Rozycki [Thu, 13 Jun 2024 13:01:54 +0000 (14:01 +0100)] 
MIPS/opcodes: Rework INSN_* flags into a consistent block

For historic reasons we have ended up with a random set of discontiguous
bit assignments for INSN_* flags within `membership' and `exclusions'
members of `mips_opcode'.  Some of the bits were previously used for ASE
assignments and have been reused in a disorganised fashion since `ase'
has been split off as a member on its own.  It makes them hard to track
and maintain, and to see how many we still have available for future
assignments.

Therefore reorder the flags using consecutive bits and matching the
order used with the switch statement in `cpu_is_member'.

12 months agoMIPS/opcodes: Update INSN_CHIP_MASK for INSN_ALLEGREX
Maciej W. Rozycki [Thu, 13 Jun 2024 13:01:54 +0000 (14:01 +0100)] 
MIPS/opcodes: Update INSN_CHIP_MASK for INSN_ALLEGREX

An update has been missed with commit df18f71b565c ("Add MIPS Allegrex
CPU as a MIPS2-based CPU") for INSN_CHIP_MASK to include INSN_ALLEGREX.
Fix it.

12 months agoAutomatic date update in version.in
GDB Administrator [Thu, 13 Jun 2024 00:00:22 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agoRemove LS_TOKEN_STOKEN macro
Tom Tromey [Thu, 6 Jun 2024 14:04:26 +0000 (08:04 -0600)] 
Remove LS_TOKEN_STOKEN macro

This removes the LS_TOKEN_STOKEN macro from linespec.c.

Reviewed-by: Keith Seitz <keiths@redhat.com>
12 months agoRemove LS_TOKEN_KEYWORD macro
Tom Tromey [Thu, 6 Jun 2024 14:02:18 +0000 (08:02 -0600)] 
Remove LS_TOKEN_KEYWORD macro

This removes the LS_TOKEN_KEYWORD macro from linespec.c.

Reviewed-by: Keith Seitz <keiths@redhat.com>
12 months agoRemove PARSER_STREAM macro
Tom Tromey [Thu, 6 Jun 2024 13:50:09 +0000 (07:50 -0600)] 
Remove PARSER_STREAM macro

This removes the PARSER_STREAM macro from linespec.c.

Reviewed-by: Keith Seitz <keiths@redhat.com>
12 months agoRemove PARSER_EXPLICIT macro
Tom Tromey [Thu, 6 Jun 2024 13:48:29 +0000 (07:48 -0600)] 
Remove PARSER_EXPLICIT macro

This removes the PARSER_EXPLICIT macro from linespec.c.

Reviewed-by: Keith Seitz <keiths@redhat.com>
12 months agoRemove PARSER_RESULT macro
Tom Tromey [Thu, 6 Jun 2024 13:36:26 +0000 (07:36 -0600)] 
Remove PARSER_RESULT macro

This removes the PARSER_RESULT macro from linespec.c.

Reviewed-by: Keith Seitz <keiths@redhat.com>
12 months agoRemove PARSER_STATE macro
Tom Tromey [Thu, 6 Jun 2024 12:54:24 +0000 (06:54 -0600)] 
Remove PARSER_STATE macro

This removes the PARSER_STATE macro from linespec.c.

Reviewed-by: Keith Seitz <keiths@redhat.com>
12 months ago[gdb/testsuite] Fix error in gdb.server/server-kill-python.exp
Tom de Vries [Wed, 12 Jun 2024 17:15:45 +0000 (19:15 +0200)] 
[gdb/testsuite] Fix error in gdb.server/server-kill-python.exp

With test-case gdb.server/server-kill-python.exp, I sometimes run into:
...
builtin_spawn gdb -nw -nx -q -iex set height 0 -iex set width 0 \
  -data-directory data-directory^M
kill^M
(gdb) kill^M
file server-kill-python^M
The program is not being run.^M
(gdb) ERROR: Couldn't load server-kill-python into GDB.
...

The problem is that the spawn produces a prompt, but it's not explicitly
consumed.

This is a regression since commit 0f077fcae0f ("[gdb/testsuite] Simplify
gdb.server/server-kill-python.exp").

Fix this by consuming the initial prompt.

PR testsuite/31819
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31819
Fixes: 0f077fcae0f ("[gdb/testsuite] Simplify gdb.server/server-kill-python.exp"
12 months ago[gdb/python] Add typesafe wrapper around PyObject_CallMethod
Tom Tromey [Wed, 12 Jun 2024 16:58:49 +0000 (18:58 +0200)] 
[gdb/python] Add typesafe wrapper around PyObject_CallMethod

In gdb/python/py-tui.c we have code like this:
...
      gdbpy_ref<> result (PyObject_CallMethod (m_window.get(), "hscroll",
                                              "i", num_to_scroll, nullptr));
...

The nullptr is superfluous, the format string already indicates that there's
only one method argument.

OTOH, passing no method args does use a nullptr:
...
      gdbpy_ref<> result (PyObject_CallMethod (m_window.get (), "render",
                                               nullptr));
...

Furthermore, choosing the right format string chars can be tricky.

Add a typesafe wrapper around PyObject_CallMethod that hides these
details, such that we can use the more intuitive:
...
      gdbpy_ref<> result (gdbpy_call_method (m_window.get(), "hscroll",
                                             num_to_scroll));
...
and:
...
      gdbpy_ref<> result (gdbpy_call_method (m_window.get (), "render"));
...

Tested on x86_64-linux.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
Approved-By: Tom Tromey <tom@tromey.com>
12 months agoaarch64: add Branch Record Buffer extension instructions
Claudio Bantaloukas [Fri, 7 Jun 2024 13:59:02 +0000 (13:59 +0000)] 
aarch64: add Branch Record Buffer extension instructions

The FEAT_BRBE extension provides two aliases of sys:
- brb iall (Invalidates all Branch records in the Branch Record Buffer)
- brb inj (Injects the Branch Record held in BRBINFINJ_EL1,
  BRBSRCINJ_EL1, and BRBTGTINJ_EL1 into the Branch Record Buffer)

This patch adds:
- the feature option "brbe" that must be added for the aliases to be available
- a new operand flag AARCH64_OPND_Rt_IN_SYS_ALIASES that warns in a comment
  when Rt is set to the non default value 0b11111 (it is constrained
  unpredictable whether the instruction is undefined or behaves as if the Rt
  field is set to 0b11111).
- a new operand flag AARCH64_OPND_BRBOP that encodes and decodes Op2 values
  from bit 5
- support for the two brb aliases above

See:
- https://developer.arm.com/documentation/ddi0602/2024-03/Base-Instructions/BRB--Branch-Record-Buffer--an-alias-of-SYS-?lang=en
- https://developer.arm.com/documentation/ddi0601/2024-03/AArch64-Instructions/BRB-INJ--Branch-Record-Injection-into-the-Branch-Record-Buffer?lang=en
- https://developer.arm.com/documentation/ddi0601/2024-03/AArch64-Instructions/BRB-IALL--Invalidate-the-Branch-Record-Buffer?lang=en

12 months agoAllow calling of user-defined function call operators
Hannes Domani [Wed, 12 Jun 2024 13:24:02 +0000 (15:24 +0200)] 
Allow calling of user-defined function call operators

Currently it's not possible to call user-defined function call
operators, at least not without specifying operator() directly:
```
(gdb) l 1
1       struct S {
2         int operator() (int x) { return x + 5; }
3       };
4
5       int main () {
6         S s;
7
8         return s(23);
9       }
(gdb) p s(10)
Invalid data type for function to be called.
(gdb) p s.operator()(10)
$1 = 15
```

This now looks if an user-defined call operator is available when
trying to 'call' a struct value, and calls it instead, making this
possible:
```
(gdb) p s(10)
$1 = 15
```

The change in operation::evaluate_funcall is to make sure the type
fields are only used for function types, only they use them as the
argument types.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12213
Approved-By: Tom Tromey <tom@tromey.com>
12 months agoAdd "error_message+" feature to qSupported
Alexandra Hájková [Tue, 19 Mar 2024 11:34:34 +0000 (12:34 +0100)] 
Add "error_message+" feature to qSupported

Add a new 'error_message' feature to the qSupported packet. When GDB
supports this feature then gdbserver is able to send
errors in the E.errtext format for the qRcmd and m packets.

Update qRcmd packet and m packets documentation as qRcmd newly
accepts errors in a E.errtext format.
Previously these two packets didn't support E.errtext style errors.

Approved-By: Tom Tromey <tom@tromey.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
12 months agoPR 31882 libctf: test suite incorrect format specifiers
A. Wilcox [Tue, 11 Jun 2024 21:40:00 +0000 (21:40 +0000)] 
PR 31882 libctf: test suite incorrect format specifiers

12 months agoRISC-V: Support S[sm]csrind extension csrs.
Jiawei [Tue, 11 Jun 2024 13:59:00 +0000 (21:59 +0800)] 
RISC-V: Support S[sm]csrind extension csrs.

This patch supports RISC-V Smcsrind/Sscsrind privilege extension csrs.
Reuse csr 'smselect/siselect', 'mireg/sireg' and 'vsiselect,vsireg' csrs
in Smaia/Ssaia extension.

bfd/ChangeLog:

* elfxx-riscv.c: New extensions.

gas/ChangeLog:

* NEWS: Updated.
* config/tc-riscv.c (enum riscv_csr_class): New extensions.
(riscv_csr_address): Ditto.
* testsuite/gas/riscv/csr-version-1p10.d: New csrs.
* testsuite/gas/riscv/csr-version-1p10.l: Ditto.
* testsuite/gas/riscv/csr-version-1p11.d: Ditto.
* testsuite/gas/riscv/csr-version-1p11.l: Ditto.
* testsuite/gas/riscv/csr-version-1p12.d: Ditto.
* testsuite/gas/riscv/csr-version-1p12.l: Ditto.
* testsuite/gas/riscv/csr.s: Ditto.
* testsuite/gas/riscv/march-help.l: New extensions.

include/ChangeLog:

* opcode/riscv-opc.h (CSR_MIREG2): New csr.
(CSR_MIREG3): Ditto.
(CSR_MIREG4): Ditto.
(CSR_MIREG5): Ditto.
(CSR_MIREG6): Ditto.
(CSR_SIREG2): Ditto.
(CSR_SIREG3): Ditto.
(CSR_SIREG4): Ditto.
(CSR_SIREG5): Ditto.
(CSR_SIREG6): Ditto.
(CSR_VSIREG2): Ditto.
(CSR_VSIREG3): Ditto.
(CSR_VSIREG4): Ditto.
(CSR_VSIREG5): Ditto.
(CSR_VSIREG6): Ditto.
(DECLARE_CSR): Ditto.

12 months agoAutomatic date update in version.in
GDB Administrator [Wed, 12 Jun 2024 00:00:37 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agogdb: convert separate-debug-file to new(ish) debug scheme
Andrew Burgess [Tue, 21 May 2024 16:42:55 +0000 (17:42 +0100)] 
gdb: convert separate-debug-file to new(ish) debug scheme

Convert 'set/show debug separate-debug-file' to the new debug scheme.
Though I'm not sure if we can really call it "new" any more!

Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: warn of slow remote file reading only after a successful open
Andrew Burgess [Tue, 21 May 2024 14:38:23 +0000 (15:38 +0100)] 
gdb: warn of slow remote file reading only after a successful open

While working on a later patch in this series, I noticed that GDB
would print the message:

  Reading /path/to/file from remote target...

Even when /path/to/file doesn't exist on the remote target.

GDB does indeed try to open /path/to/file, but I'm not sure we really
need to tell the user unless we actually manage to open the file, and
plan to read content from it.

If we consider how GDB probes for separate debug files, we can attempt
to open multiple possible files, most of them will not exist.  When we
are native debugging we don't bother telling the user about each file
we're checking for, we just announce any file we finally use.

I think it makes sense to do a similar thing for remote files.

So, in remote_target::remote_hostio_open(), I'd like to move the block
of code that prints the above message to after the open call has been
made, and we should only print the message if the open succeeds.

Now GDB only tells the user about files that we actually open and read
from the remote.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: avoid duplicate search in build_id_to_bfd_suffix
Andrew Burgess [Thu, 23 May 2024 17:11:55 +0000 (18:11 +0100)] 
gdb: avoid duplicate search in build_id_to_bfd_suffix

In build_id_to_bfd_suffix we look in each debug-file-directory for a
file matching the required build-id.

If we don't find one then we add the sysroot and perform the search
again.

However, the default sysroot is 'target:', and for a native target
this just means to search on the local machine.  So by default, if the
debug information is not present, then we end up searching each
location twice.

I think we only need to perform the "with sysroot" check if either:

 1. The sysroot is something other than 'target:'.  If the user has
 set it to '/some/directory' then we should check this sysroot.  Or if
 the user has set it to 'target:/some/other_directory', this is also
 worth checking.

 2. If the sysroot is 'target:', but the target's filesystem is not
 local (i.e. the user is connected to a remote target), then we should
 check using the sysroot as this will be looking on the remote
 machine.

There's no tests for this as the whole point here is that I'm removing
duplicate work.  No test regressions were seen though.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb/fileio: fix errno for packets where an attachment is expected
Andrew Burgess [Tue, 21 May 2024 10:22:26 +0000 (11:22 +0100)] 
gdb/fileio: fix errno for packets where an attachment is expected

In remote.c lives remote_target::remote_hostio_send_command(), which
is used to handle sending a fileio packet to the remote, and for
parsing the reply packet.

Some commands, e.g. open, pwrite, close, send some arguments to the
remote, and then get back a single integer return value.

Other commands though, e.g. pread, readlink, fstat, send some
arguments and get back an integer return value and some additional
data.  This additional data is called the attachment.

Except, we only get the attachment if the command completes
successfully.  For example, calling readlink with a non existent path
will result in a return packet: 'F-1,2' with no attachment.  This is
as expected.

Within remote_hostio_send_command we call remote_hostio_parse_result,
this parses the status code (-1 in our example above) and
then parses the errno value (2 in our example above).

Back in remote_hostio_parse_result we then hit this block:

  /* Make sure we saw an attachment if and only if we expected one.  */
  if ((attachment_tmp == NULL && attachment != NULL)
      || (attachment_tmp != NULL && attachment == NULL))
    {
      *remote_errno = FILEIO_EINVAL;
      return -1;
    }

Which ensures that commands that expect an attachment, got an
attachment.

The problem is, we'll only get an attachment if the command
succeeded.  If it didn't, then there is no attachment, and that is as
expected.

As remote_hostio_parse_result always sets the returned error number to
FILEIO_SUCCESS unless the packet contained an actual error
number (e.g. 2 in our example above), I suggest we should return early
if remote_hostio_parse_result indicates an error packet.

I ran into this issue while working on another patch.  In that patch I
was checking the error code returned by a remote readlink call and
spotted that when I passed an invalid path I got EINVAL instead of
ENOENT.  This patch fixes this issue.

Unfortunately the patch I was working on evolved, and my need to check
the error code went away, and so, right now, I have no way to reveal
this bug.  But I think this is an obviously correct fix, and worth
merging even without a test.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agoFix cast types for opencl
Hannes Domani [Tue, 11 Jun 2024 19:30:45 +0000 (21:30 +0200)] 
Fix cast types for opencl

The bitshift tests for opencl have these failures:

print /x (signed char) 0x0f << 8
No type named signed char.
(gdb) FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, promoted: print /x (signed char) 0x0f << 8
print (signed char) 0x0f << 8
No type named signed char.
(gdb) FAIL: gdb.base/bitshift.exp: lang=opencl: 8-bit, promoted: print (signed char) 0x0f << 8

Apparently opencl doesn't have the 'signed' modifier for types, only
the 'unsigned' modifier.
Even 'char' is guaranteed to be signed if no modifier is used, so
this changes the casts to match this logic.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agoFix 64-bit shifts where long only has 32-bit size
Hannes Domani [Tue, 11 Jun 2024 18:36:51 +0000 (20:36 +0200)] 
Fix 64-bit shifts where long only has 32-bit size

On systems where long has 32-bit size you get these failures:

print 1 << (unsigned long long) 0xffffffffffffffff
Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295)
(gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print 1 << (unsigned long long) 0xffffffffffffffff
print 1 >> (unsigned long long) 0xffffffffffffffff
Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295)
(gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print 1 >> (unsigned long long) 0xffffffffffffffff
print -1 << (unsigned long long) 0xffffffffffffffff
Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295)
(gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print -1 << (unsigned long long) 0xffffffffffffffff
print -1 >> (unsigned long long) 0xffffffffffffffff
Cannot export value 18446744073709551615 as 32-bits unsigned integer (must be between 0 and 4294967295)
(gdb) FAIL: gdb.base/bitshift.exp: lang=c: max-uint64: print -1 >> (unsigned long long) 0xffffffffffffffff

Fixed by changing the number-of-bits variable to ULONGEST.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agoFix too-large or negative right shift of negative numbers
Hannes Domani [Tue, 11 Jun 2024 18:32:59 +0000 (20:32 +0200)] 
Fix too-large or negative right shift of negative numbers

As seen in these test failures:

print -1 >> -1
warning: right shift count is negative
$N = 0
(gdb) FAIL: gdb.base/bitshift.exp: lang=c: neg lhs/rhs: print -1 >> -1
print -4 >> -2
warning: right shift count is negative
$N = 0
(gdb) FAIL: gdb.base/bitshift.exp: lang=c: neg lhs/rhs: print -4 >> -2

Fixed by restoring the logic from before the switch to gmp.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agoFix right shift of negative numbers
Hannes Domani [Tue, 11 Jun 2024 18:32:27 +0000 (20:32 +0200)] 
Fix right shift of negative numbers

PR31590 shows that right shift of negative numbers doesn't work
correctly since GDB 14:

(gdb) p (-3) >> 1
$1 = -1

GDB 13 and earlier returned the correct value -2.
And there actually is one test that shows the failure:

print -1 >> 1
$84 = 0
(gdb) FAIL: gdb.base/bitshift.exp: lang=asm: rsh neg lhs: print -1 >> 1

The problem was introduced with the change to gmp functions in
commit 303a881f87.
It's wrong because gdb_mpz::operator>> uses mpz_tdif_q_2exp, which
always rounds toward zero, and the gmp docu says this:

For positive n both mpz_fdiv_q_2exp and mpz_tdiv_q_2exp are simple
bitwise right shifts.
For negative n, mpz_fdiv_q_2exp is effectively an arithmetic right shift
treating n as two's complement the same as the bitwise logical functions
do, whereas mpz_tdiv_q_2exp effectively treats n as sign and magnitude.

So this changes mpz_tdiv_q_2exp to mpz_fdiv_q_2exp, since it
does right shifts for both positive and negative numbers.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31590
Approved-By: Tom Tromey <tom@tromey.com>
12 months agoRestore bitshift.exp tests
Hannes Domani [Tue, 11 Jun 2024 18:31:54 +0000 (20:31 +0200)] 
Restore bitshift.exp tests

Commit cdd4206647 unintentionally disabled all tests of bitshift.exp,
so it actually just does this:

Running /c/src/repos/binutils-gdb.git/gdb/testsuite/gdb.base/bitshift.exp ...
PASS: gdb.base/bitshift.exp: complete set language

=== gdb Summary ===

 # of expected passes 1

It changed the 'continue' of unsupported languages to 'return', and
since ada is the first language and is unsupported, no tests were run.

This changes it back to 'continue', and the following patches fix
the regressions that were introduced since then unnoticed.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agofix division by zero in target_read_string()
Kilian Kilger [Sun, 26 May 2024 08:41:12 +0000 (10:41 +0200)] 
fix division by zero in target_read_string()

Under certain circumstances, a floating point exception in
target_read_string() can happen when the type has been obtained
by a call to stpy_lazy_string_elt_type(). In the latter function,
a call to check_typedef() has been forgotten. This makes
type->length = 0 in this case.

12 months agoRemove useless call to wnoutrefresh
Tom Tromey [Sun, 17 Dec 2023 20:22:10 +0000 (13:22 -0700)] 
Remove useless call to wnoutrefresh

This call to wnoutrefresh is not useful.  It's based on the
misunderstanding that wnoutrefresh somehow prevents display, whereas
actually what it does is copy from one curses buffer to another.

I'm working on a larger patch to clean up this area, but this
particular call can be removed immediately without consequence.

Approved-By: Andrew Burgess <aburgess@redhat.com>
12 months agoRemove extract_long_unsigned_integer
Tom Tromey [Wed, 8 May 2024 00:07:43 +0000 (18:07 -0600)] 
Remove extract_long_unsigned_integer

The function extract_long_unsigned_integer is unused, so remove it.
Tested by rebuilding.

Approved-By: Andrew Burgess <aburgess@redhat.com>
12 months agosupport_dt_relr aarch64
Alan Modra [Tue, 11 Jun 2024 10:57:05 +0000 (20:27 +0930)] 
support_dt_relr aarch64

Tweak commit db335d7e0a so that support_dt_relr returns false for
aarch64*-*-*ilp32.

12 months agoFix printing strings on macOS Sonoma
Ciaran Woodward [Mon, 10 Jun 2024 15:52:37 +0000 (16:52 +0100)] 
Fix printing strings on macOS Sonoma

On macOS sonoma, printing a string would only print the first
character. For instance, if there was a 'const char *s = "foobar"',
then the 'print s' command would print '$1 = "f"' rather than the
expected '$1 = "foobar"'.

It seems that this is due to Apple silently replacing the version
of libiconv they ship with the OS to one which silently fails to
handle the 'outbytesleft' parameter correctly when using 'wchar_t'
as a target encoding.

This specifically causes issues when using iterating through a
string as wchar_iterator does.

This bug is visible even if you build for an old version of macOS,
but then run on Sonoma. Therefore this fix in the code applies
generally to macOS, and not specific to building on Sonoma. Building
for an older version and expecting forwards compatibility is a
common situation on macOS.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31853

12 months agoMIPS/opcodes: Add MIPS Allegrex DBREAK instruction
David Guillen Fandos [Tue, 11 Jun 2024 08:36:11 +0000 (09:36 +0100)] 
MIPS/opcodes: Add MIPS Allegrex DBREAK instruction

This complements the debug instruction set and uses the same encoding as
the VR5400/VR5500 devices.

12 months agoMIPS/opcodes: Exclude trap instructions for MIPS Allegrex
David Guillen Fandos [Tue, 11 Jun 2024 08:36:11 +0000 (09:36 +0100)] 
MIPS/opcodes: Exclude trap instructions for MIPS Allegrex

These instructions are not supported by the target even though they are
part of the MIPS II specification.

12 months agoPR31872, Segfault in objdump (elf_slurp_reloc_table_from_section)
Alan Modra [Mon, 10 Jun 2024 23:52:49 +0000 (09:22 +0930)] 
PR31872, Segfault in objdump (elf_slurp_reloc_table_from_section)

This one was triggered by trying to dump an AMDGPU object.
elf64-amdgcn.c lacks support for objdump relocation handling.

PR 31872
* elfcode.h (elf_slurp_reloc_table_from_section): Don't segfault
on NULL elf_info_to_howto_rel.

12 months agoAutomatic date update in version.in
GDB Administrator [Tue, 11 Jun 2024 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agoIBM zSystems: Rewrite l(g)rl @GOTENT to larl for --no-pie
Ilya Leoshkevich [Mon, 10 Jun 2024 13:33:48 +0000 (15:33 +0200)] 
IBM zSystems: Rewrite l(g)rl @GOTENT to larl for --no-pie

Regtested on s390x-redhat-linux.

Rewriting l(g)rl @GOTENT to larl is unnecessarily guarded by
bfd_link_pic().  There were no use cases for this in the past, but
since recently the Linux Kernel on s390x is compiled with -fPIE
and linked with --no-pie.  Remove the unnecessary bfd_link_pic()
check.

bfd/ChangeLog:

        * elf32-s390.c (elf_s390_relocate_section): Don't check for
bfd_link_pic() when rewriting lrl@GOTENT to larl.
(elf_s390_finish_dynamic_symbol): Emit a relative reloc for
the above case.
        * elf64-s390.c (elf_s390_relocate_section): Don't check for
bfd_link_pic() when rewriting lgrl@GOTENT to larl.
(elf_s390_finish_dynamic_symbol): Emit a relative reloc for
the above case.

ld/ChangeLog:

* testsuite/ld-s390/s390.exp: Hook up the new tests.
        * testsuite/ld-s390/gotreloc_31-no-pie-1.dd: New test.
        * testsuite/ld-s390/gotreloc_64-no-pie-1.dd: New test.

12 months agoMake global_symbol_searcher::filenames private
Tom Tromey [Fri, 24 May 2024 18:31:45 +0000 (12:31 -0600)] 
Make global_symbol_searcher::filenames private

This patch renames global_symbol_searcher::filenames and makes it
private, adding a new method to append a filename to the vector.  This
also cleans up memory management here, removing an alloca from rbreak,
and removing a somewhat ugly SCOPE_EXIT from the Python code, in favor
of having global_symbol_searcher manage the memory itself.

Regression tested on x86-64 Fedora 38.

12 months ago[gdb/python] Fix GDB_PY_{LL,LLU}_ARG on platform without long long
Tom de Vries [Mon, 10 Jun 2024 15:53:30 +0000 (17:53 +0200)] 
[gdb/python] Fix GDB_PY_{LL,LLU}_ARG on platform without long long

If in gdb/python/python-internal.h, we pretend to have a platform that doesn't
support long long:
...
-#ifdef HAVE_LONG_LONG
+#if 0
...
I get on arm-linux:
...
(gdb) placement_candidate()
disassemble test^M
Dump of assembler code for function test:^M
   0x004004d8 <+0>:     push    {r11}           @ (str r11, [sp, #-4]!)^M
   0x004004dc <+4>:     Python Exception <class 'ValueError'>: \
     Buffer returned from read_memory is sized 0 instead of the expected 4^M
^M
unknown disassembler error (error = -1)^M
(gdb) FAIL: $exp: memory source api: second disassembler pass
...

The problem is that gdb_py_longest is typedef-ed to long, but the
corresponding format character GDB_PY_LL_ARG is defined to "L", meaning
"long long" [1].

Fix this by using "l", meaning long instead.  Likewise for GDB_PY_LLU_ARG.

Tested on arm-linux.

Approved-By: Tom Tromey <tom@tromey.com>
PR python/31845
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31845

[1] https://docs.python.org/3/c-api/arg.html

12 months ago[gdb/python] Fix gdb.python/py-disasm.exp on arm-linux
Tom de Vries [Mon, 10 Jun 2024 15:53:30 +0000 (17:53 +0200)] 
[gdb/python] Fix gdb.python/py-disasm.exp on arm-linux

After fixing test-case gdb.python/py-disasm.exp to recognize the arm nop:
...
nop {0}
...
we run into:
...
disassemble test^M
Dump of assembler code for function test:^M
   0x004004d8 <+0>:     push    {r11}           @ (str r11, [sp, #-4]!)^M
   0x004004dc <+4>:     add     r11, sp, #0^M
   0x004004e0 <+8>:     nop     {0}^M
=> 0x004004e4 <+12>:    Python Exception <class 'ValueError'>: Buffer \
  returned from read_memory is sized 0 instead of the expected 4^M
^M
unknown disassembler error (error = -1)^M
(gdb) FAIL: $exp: global_disassembler=ShowInfoRepr: disassemble test
...

This is caused by this code in gdbpy_disassembler::read_memory_func:
...
  gdbpy_ref<> result_obj (PyObject_CallMethod ((PyObject *) obj,
                                              "read_memory",
                                              "KL", len, offset));
...
where len has type "unsigned int", while "K" means "unsigned long long" [1].

Fix this by using "I" instead, meaning "unsigned int".

Also, offset has type LONGEST, which is typedef'ed to int64_t, while "L" means
"long long".

Fix this by using type gdb_py_longest for offset, in combination with format
character "GDB_PY_LL_ARG".  Likewise in disasmpy_info_read_memory.

Tested on arm-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
PR python/31845
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31845

[1] https://docs.python.org/3/c-api/arg.html

12 months agoaarch64: warn on unpredictable results for new rcpc3 instructions
Matthieu Longo [Tue, 21 May 2024 16:37:07 +0000 (17:37 +0100)] 
aarch64: warn on unpredictable results for new rcpc3 instructions

The previous patch for the feature rcpc3 introduced 4 new operations
(ldiapp, stilp, ldapr, stlr).
The specification mentions some cases of inputs causing unpredictable
results. gas currently fails to diagnose them, and does not emit
warnings. Even if the instruction encoding is valid, the developer
probably wants to know for those cases that the instruction won't have
the expected effect.
- ldiapp & stilp:
  * unpredictable load pair transfer with register overlap
  * unpredictable transfer with writeback
- ldapr & stlr:
  * unpredictable transfer with writeback

This patch also completes the existing relevant tests.

12 months agoRevert "MIPS/Allegrex: Exclude trap instructions"
Maciej W. Rozycki [Mon, 10 Jun 2024 15:00:33 +0000 (16:00 +0100)] 
Revert "MIPS/Allegrex: Exclude trap instructions"

This reverts commit a2e71b281a9365872451a157767e03a2e89ddaad.

12 months agoRevert "MIPS/Allegrex: Enable dbreak instruction"
Maciej W. Rozycki [Mon, 10 Jun 2024 15:00:08 +0000 (16:00 +0100)] 
Revert "MIPS/Allegrex: Enable dbreak instruction"

This reverts commit c41020942b94ea7c5a58de4fed644826e8f0b509.

12 months ago[gdb/python] Note that python 3.6 assumes long long support
Tom de Vries [Mon, 10 Jun 2024 14:52:06 +0000 (16:52 +0200)] 
[gdb/python] Note that python 3.6 assumes long long support

Starting with python 3.6, support for platforms without long long support
has been removed [1].

HAVE_LONG_LONG and PY_LONG_LONG are still defined, but only for compatibility,
so stop relying on them.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://github.com/python/cpython/issues/72148

12 months agoPR31873, buffer overflow in evax_bfd_print_dst
Alan Modra [Mon, 10 Jun 2024 13:20:26 +0000 (22:50 +0930)] 
PR31873, buffer overflow in evax_bfd_print_dst

PR 31873
* vms-alpha.c (evax_bfd_print_dst): Sanity check len against
dst_size.

12 months agosrc-release.sh: don't take untracked files into account in the uncommitted changes...
Rostislav Krasny [Mon, 10 Jun 2024 11:40:06 +0000 (12:40 +0100)] 
src-release.sh: don't take untracked files into account in  the uncommitted changes check

12 months agoMIPS/Allegrex: Enable dbreak instruction
David Guillen Fandos [Thu, 22 Jun 2023 23:25:10 +0000 (01:25 +0200)] 
MIPS/Allegrex: Enable dbreak instruction

12 months agoMIPS/Allegrex: Exclude trap instructions
David Guillen Fandos [Thu, 22 Jun 2023 23:25:09 +0000 (01:25 +0200)] 
MIPS/Allegrex: Exclude trap instructions

These instructions are not supported by the target even though they are
part of the MIPS II specification.

12 months agox86/APX: convert ZU to operand constraint
Jan Beulich [Mon, 10 Jun 2024 08:46:21 +0000 (10:46 +0200)] 
x86/APX: convert ZU to operand constraint

Extremely rarely used attributes are inefficient when represented by a
separate attribute. Convert it to an operand constraint, as already
suggested during review. The collision with RegKludge is pretty simple
to resolve.

12 months agox86: disassembler macro for condition code
Jan Beulich [Mon, 10 Jun 2024 08:45:56 +0000 (10:45 +0200)] 
x86: disassembler macro for condition code

Both CMPccXADD and APX'es {,CF}CMOVcc have almost identical entries
replicated 16 times each. Fold those to just one each by introducing a
%CC macro. (Note that the recording of ->condition_code in print_insn()
is merely for completeness for now; it's not used as long as only
VEX/EVEX encodings would consume it.)

This then also renders condition codes printed consistent across all
respective insns; CMPxxXADD had a number of outliers so far.

12 months agox86/APX: support extended SETcc form
Jan Beulich [Mon, 10 Jun 2024 08:45:16 +0000 (10:45 +0200)] 
x86/APX: support extended SETcc form

As indicated during review, spelling/readability-wise

setz %eax

is easier than

setzuz %al

_and_ properly specifies the full register that's being modified. Permit
that form to be used, even if the spec writers are unwilling to formally
mention it.

While there also correct the non-ZU EVEX form: That ought to also permit
memory operands.

12 months agogdb: re-add necessary includes in tui/tui-win.c
Simon Marchi [Mon, 10 Jun 2024 08:43:10 +0000 (10:43 +0200)] 
gdb: re-add necessary includes in tui/tui-win.c

Commit 9102a6c15c75 ("gdb/tui: cleanup includes") broke
gdb.python/tui-window.exp on Linux:

    Running /data/vries/gdb/src/gdb/testsuite/gdb.python/tui-window.exp ...
    WARNING: timeout in accept_gdb_output
    WARNING: timeout in accept_gdb_output
    FAIL: gdb.python/tui-window.exp: Window was updated

and caused a build failure on AIX:

    CXX    tui/tui-win.o
    tui/tui-win.c: In function 'void tui_sigwinch_handler(int)':
    tui/tui-win.c:532:3: error: 'mark_async_signal_handler' was not declared in this scope; did you mean 'async_signal_handler'?
      532 |   mark_async_signal_handler (tui_sigwinch_token);
          |   ^~~~~~~~~~~~~~~~~~~~~~~~~
          |   async_signal_handler
    tui/tui-win.c: At global scope:
    tui/tui-win.c:538:1: error: variable or field 'tui_async_resize_screen' declared void
      538 | tui_async_resize_screen (gdb_client_data arg)
          | ^~~~~~~~~~~~~~~~~~~~~~~
    tui/tui-win.c:538:26: error: 'gdb_client_data' was not declared in this scope
      538 | tui_async_resize_screen (gdb_client_data arg)
          |                          ^~~~~~~~~~~~~~~
    tui/tui-win.c: In function 'void tui_initialize_win()':
    tui/tui-win.c:579:36: error: 'tui_async_resize_screen' was not declared in this scope
      579 |     = create_async_signal_handler (tui_async_resize_screen, NULL,
          |                                    ^~~~~~~~~~~~~~~~~~~~~~~
    tui/tui-win.c:579:7: error: 'create_async_signal_handler' was not declared in this scope; did you mean 'async_signal_handler'?
      579 |     = create_async_signal_handler (tui_async_resize_screen, NULL,
          |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
          |       async_signal_handler
    gmake: *** [Makefile:1947: tui/tui-win.o] Error 1

On Linux, the removal of the signal.h include causes the `#ifdef
SIGWINCH` sections to become inactive.  The code builds, but then the
TUI fails to react to terminal size changes.  When we add back the
inclusion of signal.h, then we see the same build error as on AIX.

On AIX, I suppose that the SIGWINCH define is still seen by some other
transitive include.

When I go back to before 9102a6c15c75, I don't see async-event.h and
signal.h being marked as unneeded by clangd, so I'm not sure why I
removed them in the first place... I'll be more careful in the future
(files with #ifdef/#ifndef can be tricky w.r.t. determining necessary
includes).

So, re-add the inclusion of signal.h and async-event.h

Change-Id: I3ed385c2dc1726ade2118a5186ea7cccffd12635
Reported-By: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
Reported-By: Tom de Vries <tdevries@suse.de>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31865

12 months ago[gdb/testsuite] Don't use set auto-solib-add off
Tom de Vries [Mon, 10 Jun 2024 08:43:10 +0000 (10:43 +0200)] 
[gdb/testsuite] Don't use set auto-solib-add off

In test-case gdb.mi/mi-var-child-f.exp, we have:
...
mi_gdb_test "-gdb-set auto-solib-add off" "\\^done"
mi_runto prog_array
mi_gdb_test "nosharedlibrary" ".*\\^done"
...

This was added to avoid a name clash between the array variable as defined in
gdb.mi/array.f90 and debug info in shared libraries, and used in other places
in the testsuite.

The same workaround is also used to ignore symbols from shared libraries when
excercising for instance a command that prints all symbols.

However, this approach can cause problems for targets like arm that require
symbol info for some libraries like ld.so and libc to fully function.

While absense of debug info for shared libraries should be handled gracefully
(which does need fixing, see PR31817), failure to do so should not result
in failures in unrelated test-cases.

Fix this by removing "set auto-solib-add off".

This ensures that we don't run into PR31817, while the presence of
nosharedlibrary still ensures that in the rest of the test-case we're not
bothered by shared library symbols.

Likewise in other test-cases.

Approved-by: Kevin Buettner <kevinb@redhat.com>
Tested on arm-linux.

12 months agogas: extend \+ support to .rept
Jan Beulich [Mon, 10 Jun 2024 07:06:37 +0000 (09:06 +0200)] 
gas: extend \+ support to .rept

PR gas/31752

While not quite as macro-like as .irp / .irpc, this perhaps benefits from
supporting \+ even more than those: It allows, where desired, to get away
without maintaining an explicit count variable in source code.

Keep .rep (and custom per-arch uses of s_rept() / do_repeat()) behavior
unaltered.

12 months agox86/APX: add missing CPU requirement to imm+rm forms of <alu2> insns
Jan Beulich [Mon, 10 Jun 2024 07:05:23 +0000 (09:05 +0200)] 
x86/APX: add missing CPU requirement to imm+rm forms of <alu2> insns

This was overlooked when the form was added by dd74a603376e ("Support
APX NF").

12 months agold-aarch64: check support before launching dt_relr tests
Clément Chigot [Fri, 7 Jun 2024 13:42:52 +0000 (15:42 +0200)] 
ld-aarch64: check support before launching dt_relr tests

Not all aarch64 targets supports dt_relr as this requires some
mechanisms on the OS side.

Adjust support_dt_relr helper and use it in aarch64-elf.exp.

12 months agoAutomatic date update in version.in
GDB Administrator [Mon, 10 Jun 2024 00:00:23 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agoregen sim/frv files for copyright update
Alan Modra [Fri, 7 Jun 2024 00:55:01 +0000 (10:25 +0930)] 
regen sim/frv files for copyright update

12 months agoautoupdate: regen after replacing obsolete macros
Matthieu Longo [Tue, 28 May 2024 09:49:49 +0000 (10:49 +0100)] 
autoupdate: regen after replacing obsolete macros

12 months agoautoconf: delete obsolete unused m4 file
Matthieu Longo [Tue, 28 May 2024 09:49:48 +0000 (10:49 +0100)] 
autoconf: delete obsolete unused m4 file

config/uintmax_t.m4 contains only one function: jm_AC_TYPE_UINTMAX_T.
After a grep, I could not find any usage of it.

jm_AC_TYPE_UINTMAX_T seems to be an old implementation of the officially
suppported AC_TYPE_UINTMAX_T.
Doc: https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/
     autoconf-2.72/autoconf.html#index-AC_005fTYPE_005fUINTMAX_005fT-1

config/stdint.m4 seems to have taken over. The usage of
AC_REQUIRE([AC_TYPE_UINTMAX_T]) is not garded or inside a function, so it
will also automatically be run for the configure.ac files using
AC_CONFIG_MACRO_DIRS([../config]) instead of m4_include([../config/stdint.m4]).

It seems that people replaced jm_AC_TYPE_UINTMAX_T occurences by
AC_TYPE_UINTMAX_T, and forgot to delete uintmax_t.m4.
Deleting the file and regenerating the build scripts results in no diff,
so it looks safe to delete it from the repository.

12 months agoautoupdate: add square brackets around arguments of AC_INIT
Matthieu Longo [Tue, 28 May 2024 09:49:47 +0000 (10:49 +0100)] 
autoupdate: add square brackets around arguments of AC_INIT

https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fINIT-2

12 months agoautoupdate: add square brackets around argument of AC_PREREQ
Matthieu Longo [Tue, 28 May 2024 09:49:46 +0000 (10:49 +0100)] 
autoupdate: add square brackets around argument of AC_PREREQ

https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fPREREQ-1

12 months agoautoupdate: replace old version of AC_INIT by the new one
Matthieu Longo [Tue, 28 May 2024 09:49:45 +0000 (10:49 +0100)] 
autoupdate: replace old version of AC_INIT by the new one

- old AC_INIT by AC_INIT + AC_CONFIG_SRC_DIR
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fINIT-3

12 months agoautoupdate: replace obsolete macros AC_CONFIG_HEADER
Matthieu Longo [Tue, 28 May 2024 09:49:44 +0000 (10:49 +0100)] 
autoupdate: replace obsolete macros AC_CONFIG_HEADER

- AC_CONFIG_HEADER by AC_CONFIG_HEADERS
  https://www.gnu.org/software/automake/manual/1.12.2/html_node/Obsolete-Macros.html#index-AM_005fCONFIG_005fHEADER

12 months agoautoupdate: replace obsolete macros AC_CANONICAL_SYSTEM
Matthieu Longo [Tue, 28 May 2024 09:49:43 +0000 (10:49 +0100)] 
autoupdate: replace obsolete macros AC_CANONICAL_SYSTEM

- AC_CANONICAL_SYSTEM by:
    * AC_CANONICAL_HOST where host, and host_alias are needed
    * AC_CANONICAL_TARGET where target_alias is needed
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCANONICAL_005fTARGET-1

12 months agoautoupdate: replace obsolete macros AC_PROG_LIBTOOL
Matthieu Longo [Tue, 28 May 2024 09:49:42 +0000 (10:49 +0100)] 
autoupdate: replace obsolete macros AC_PROG_LIBTOOL

- AC_PROG_LIBTOOL by LT_INIT
  https://www.gnu.org/software/libtool/manual/html_node/LT_005fINIT.html#index-LT_005fINIT

12 months agoautoupdate: replace obsolete macros AC_AIX, AC_MINIX, and AC_GNU_SOURCE
Matthieu Longo [Tue, 28 May 2024 09:49:41 +0000 (10:49 +0100)] 
autoupdate: replace obsolete macros AC_AIX, AC_MINIX, and AC_GNU_SOURCE

- AC_AIX, AC_MINIX, and AC_GNU_SOURCE by AC_USE_SYSTEM_EXTENSIONS
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fAIX
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fMINIX-1
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fGNU_005fSOURCE-1

12 months agoautoupdate: replace obsolete macros AC_HELP_STRING
Matthieu Longo [Tue, 28 May 2024 09:49:40 +0000 (10:49 +0100)] 
autoupdate: replace obsolete macros AC_HELP_STRING

- AC_HELP_STRING by AS_HELP_STRING
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fHELP_005fSTRING-1
Except for the ifdef in lib-prefix.m4, make the defun of AC_LIB_ARG_WITH
unconditional.

12 months agogold: Properly remove the versioned symbol
H.J. Lu [Sat, 1 Jun 2024 04:30:34 +0000 (21:30 -0700)] 
gold: Properly remove the versioned symbol

When the versioned symbol foo is removed from the shared library,  the
".symver foo,foo@VER" directive provides binary compatibility for foo@VER.
In this case, the unversioned symbol foo should be hidden and shouldn't
generate a multiple definition error.

PR gold/31830
* resolve.cc (Symbol_table::resolve): Move symbol version handling
to ...
* symtab.cc (Symbol_table::add_from_object): Here. If the hidden
version from .symver is the same as the default version from the
unversioned symbol, don't make the unversioned symbol the default
versioned
symbol.
* testsuite/Makefile.am (check_SCRIPTS): Add ver_test_pr31830.sh.
(check_DATA): ver_test_pr31830_a.syms and ver_test_pr31830_b.syms.
(ver_test_pr31830_a.syms): New.
(ver_test_pr31830_b.syms): Likewise.
(ver_test_pr31830_a.so): Likewise.
(ver_test_pr31830_b.so): Likewise.
* testsuite/Makefile.in: Regenerated.
* testsuite/ver_test_pr31830.script: New file.
* testsuite/ver_test_pr31830.sh: Likewise.
* testsuite/ver_test_pr31830_a.c: Likewise.
* testsuite/ver_test_pr31830_b.c: Likewise.
* testsuite/ver_test_pr31830_lto.c: Likewise.
* testsuite/ver_test_pr31830_lto.sh: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
12 months agoAutomatic date update in version.in
GDB Administrator [Sun, 9 Jun 2024 00:00:35 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agoFix typo in warning in gdb/configure
Tom Tromey [Sat, 8 Jun 2024 14:30:03 +0000 (08:30 -0600)] 
Fix typo in warning in gdb/configure

Eli pointed out that "babeltrace" is misspelled in a warning in
gdb/configure.  This patch fixes the typo.

12 months agogdb: Avoid compilation warning in gcore.c.
Eli Zaretskii [Sat, 8 Jun 2024 07:22:03 +0000 (10:22 +0300)] 
gdb: Avoid compilation warning in gcore.c.

See https://sourceware.org/pipermail/gdb-patches/2024-June/209726.html
for the details.

Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: remove get_exec_file
Simon Marchi [Thu, 30 May 2024 18:53:56 +0000 (14:53 -0400)] 
gdb: remove get_exec_file

I believe that the get_exec_file function is unnecessary, and the code
can be simplified if we remove it.

Consider for instance when you "run" a program on Linux with native
debugging.

 1. run_command_1 obtains the executable file from
    `current_program_space->exec_filename ()`
 2. it passes it to `run_target->create_inferior()`, which is
    `inf_ptrace_target::create_inferior()` in this case, which then
    passes it to `fork_inferior()`
 3. `fork_inferior()` then has a fallback, where if the passed exec file
    is nullptr, it gets its from `get_exec_file()`.
 4. `get_exec_file()` returns `current_program_space->exec_filename ()`
    - just like the things we started with - or errors out if the
    current program space doesn't have a specified executable.

If there's no exec filename passed in step 1, there's not going to be
any in step 4, so it seems pointless to call `get_exec_file()`, we could
just error out when `exec_file` is nullptr.  But we can't error out
directly in `fork_inferior()`, since the error is GDB-specific, and that
function is shared with GDBserver.

Speaking of GDBserver, all code paths that lead to `fork_inferior()`
provide a non-nullptr exec file.

Therefore, to simplify things:

 - Make `fork_inferior()` assume that the passed exec file is not
   nullptr, don't call `get_exec_file()`
 - Change some targets (darwin-nat, go32-nat, gnu-nat, inf-ptrace,
   nto-procfs, procfs) to error out when the exec file passed to their
   create_inferior method is nullptr.  Some targets are fine with a
   nullptr exec file, so we can't check that in `run_command_1()`.
 - Add the `no_executable_specified_error()` function, which re-uses the
   error message that `get_exec_file()` had.
 - Change some targets (go32-nat, nto-procfs) to not call
   `get_exec_file()`, since it's pointless for the same reason as in the
   example above, if it returns, it's going the be the same value as the
   `exec_file` parameter.  Just rely on `exec_file`.
 - Remove the final use of `get_exec_file()`, in `load_command()`.
 - Remove the `get_exec_file()` implementations in GDB and GDBserver and
   remove the shared declaration.

Change-Id: I601c16498e455f7baa1f111a179da2f6c913baa3
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: remove dead code in nto-procfs.c
Simon Marchi [Thu, 30 May 2024 18:53:55 +0000 (14:53 -0400)] 
gdb: remove dead code in nto-procfs.c

`get_exec_file()` never returns nullptr, so remove some dead code that
check for a nullptr return.

Change-Id: I9eff2a013d602588aaf4477a22cf45f2bc417c6a
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: replace `get_exec_file (0)` calls with `current_program_space->exec_filename ()`
Simon Marchi [Thu, 30 May 2024 18:53:54 +0000 (14:53 -0400)] 
gdb: replace `get_exec_file (0)` calls with `current_program_space->exec_filename ()`

Calls of `get_exec_file (0)` are equivalent to just getting the exec
filename from the current program space.  I'm looking to remove
`get_exec_file`, so replace these uses with
`current_program_space->exec_filename ()`.

Remove the `err` parameter of `get_exec_wrapper` since all the calls
that remain pass 1, meaning to error out if no executable is specified.

Change-Id: I7729ea4c7f03dbb046211cc5aa3858ab3a551965
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: make progspace::exec_filename private, add getter / setter
Simon Marchi [Thu, 30 May 2024 18:53:53 +0000 (14:53 -0400)] 
gdb: make progspace::exec_filename private, add getter / setter

Just like the title says... I think this makes things a bit clearer, for
instance where the exec filename is set.  It also makes the read call
sites a bit nicer, avoiding the `.get ()`.

Change-Id: If8b58ae8f6270c8a34b868f6ca06128c6671ea3c
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb/tui: cleanup includes
Simon Marchi [Fri, 31 May 2024 02:54:07 +0000 (22:54 -0400)] 
gdb/tui: cleanup includes

Remove includes reported as unused by clangd.  Then, add any includes
necessary to get rid of errors (includes possibly relying on previous
includes)..

I didn't remove the includes of gdb-safe-ctypes.h, because it appears to
do some some preprocessor magic, redefining standard macros.  I'm afraid
that removing these includes could change the behavior unintentionally.

Change-Id: I4c5b652355c3bbce022fe0d447a72dc4e1d17d34
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb: add IWYU export pragams to gdb_curses.h
Simon Marchi [Fri, 31 May 2024 02:54:06 +0000 (22:54 -0400)] 
gdb: add IWYU export pragams to gdb_curses.h

It seems like gdb_curses.h is included whenever we want to access
ncurses functionality, instead of including directly ncurses.h.  As a
result, clangd often erroneously shows that gdb_curses.h inclusions are
unused.

By adding those pragmas, clangd (and the include-what-you-use tool)
understands that gdb_curses.h is a valid provider for whatever these
ncurses.h files provide.

Change-Id: Ia8acd761dae1577f7151d5fb558f35514b4e4ea2
Approved-By: Tom Tromey <tom@tromey.com>
12 months agogdb/tui: change some macros to functions
Simon Marchi [Fri, 31 May 2024 02:54:05 +0000 (22:54 -0400)] 
gdb/tui: change some macros to functions

Change the `TUI_*` macros to access known windows to functions.  Define
them in their respective files, because trying to define them in
tui-data.h would end up causing include cycles.

This makes static analysis (detection of unused include files in this
case) more accurate, and I think in general we should avoid hiding
code behind macros if not necessary.

Change-Id: I1e38cee843984c48ab34030b19dac0d726f851af
Approved-By: Tom Tromey <tom@tromey.com>
12 months agoAutomatic date update in version.in
GDB Administrator [Sat, 8 Jun 2024 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

12 months agogdb/testsuite: Add gdb.arch/aarch64-mops-watchpoint.exp
Thiago Jung Bauermann [Thu, 4 Apr 2024 17:05:47 +0000 (14:05 -0300)] 
gdb/testsuite: Add gdb.arch/aarch64-mops-watchpoint.exp

Test behaviour of watchpoints triggered by MOPS instructions.  This test
is similar to gdb.base/memops-watchpoint.exp, but specifically for MOPS
instructions rather than whatever instructions are used in the libc's
implementation of memset/memcpy/memmove.

There's a separate watched variable for each set of instructions so that
the testcase can test whether GDB correctly identified the watchpoint
that triggered in each case.

Approved-By: Luis Machado <luis.machado@arm.com>
Tested-By: Luis Machado <luis.machado@arm.com>
12 months agogdb/aarch64: Add record support for MOPS instructions.
Thiago Jung Bauermann [Sun, 21 Apr 2024 02:18:26 +0000 (23:18 -0300)] 
gdb/aarch64: Add record support for MOPS instructions.

There are two kinds of MOPS instructions: set instructions and copy
instructions.  Within each group there are variants with minor
differences in how they read or write to memory — e.g., non-temporal
read and/or write, unprivileged read and/or write and permutations of
those — but they work in the same way in terms of the registers and
regions of memory that they modify.

The new gdb.reverse/aarch64-mops.exp testcase verifies that MOPS
instructions are recorded and correctly reversed.  Not all variants of the
copy and set instructions are tested, since there are many and the record
and replay target processes them in the same way.

PR tdep/31666
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31666
Approved-By: Luis Machado <luis.machado@arm.com>
Tested-By: Luis Machado <luis.machado@arm.com>
12 months agogdb/aarch64: Disable displaced single-step for MOPS instructions
Thiago Jung Bauermann [Sat, 27 Apr 2024 21:38:22 +0000 (18:38 -0300)] 
gdb/aarch64: Disable displaced single-step for MOPS instructions

The AArch64 MOPS (Memory Operation) instructions provide a standardised
instruction sequence to perform a memset, memcpy or memmove.  A sequence is
always composed of three instructions: a prologue instruction, a main
instruction and an epilogue instruction.  As an illustration, here are the
implementations of these memory operations in glibc 2.39:

  (gdb) disassemble/r
  Dump of assembler code for function __memset_mops:
  => 0x0000fffff7e8d780 <+0>:     d503201f        nop
     0x0000fffff7e8d784 <+4>:     aa0003e3        mov     x3, x0
     0x0000fffff7e8d788 <+8>:     19c10443        setp    [x3]!, x2!, x1
     0x0000fffff7e8d78c <+12>:    19c14443        setm    [x3]!, x2!, x1
     0x0000fffff7e8d790 <+16>:    19c18443        sete    [x3]!, x2!, x1
     0x0000fffff7e8d794 <+20>:    d65f03c0        ret
  End of assembler dump.

  (gdb) disassemble/r
  Dump of assembler code for function __memcpy_mops:
  => 0x0000fffff7e8c580 <+0>:     d503201f        nop
     0x0000fffff7e8c584 <+4>:     aa0003e3        mov     x3, x0
     0x0000fffff7e8c588 <+8>:     19010443        cpyfp   [x3]!, [x1]!, x2!
     0x0000fffff7e8c58c <+12>:    19410443        cpyfm   [x3]!, [x1]!, x2!
     0x0000fffff7e8c590 <+16>:    19810443        cpyfe   [x3]!, [x1]!, x2!
     0x0000fffff7e8c594 <+20>:    d65f03c0        ret
  End of assembler dump.

  (gdb) disassemble/r
  Dump of assembler code for function __memmove_mops:
  => 0x0000fffff7e8d180 <+0>:     d503201f        nop
     0x0000fffff7e8d184 <+4>:     aa0003e3        mov     x3, x0
     0x0000fffff7e8d188 <+8>:     1d010443        cpyp    [x3]!, [x1]!, x2!
     0x0000fffff7e8d18c <+12>:    1d410443        cpym    [x3]!, [x1]!, x2!
     0x0000fffff7e8d190 <+16>:    1d810443        cpye    [x3]!, [x1]!, x2!
     0x0000fffff7e8d194 <+20>:    d65f03c0        ret
  End of assembler dump.

The Arm Architecture Reference Manual says that "the prologue, main, and
epilogue instructions are expected to be run in succession and to appear
consecutively in memory".  Therefore this patch disables displaced stepping
on them.

The testcase verifies that MOPS sequences are correctly single-stepped.

PR tdep/31666
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31666
Approved-By: Luis Machado <luis.machado@arm.com>
Tested-By: Luis Machado <luis.machado@arm.com>
12 months ago[gdb/tdep] Fix ARM_LINUX_JB_PC_EABI
Tom de Vries [Fri, 7 Jun 2024 11:59:46 +0000 (13:59 +0200)] 
[gdb/tdep] Fix ARM_LINUX_JB_PC_EABI

In arm-linux-tdep.c, ARM_LINUX_JB_PC_EABI is defined as 9, but it's been 1
since glibc 2.20.

See glibc commit 80a56cc3ee ("ARM: Add SystemTap probes to longjmp and
setjmp.").

Update it, allowing us to run into the gdb/26967 kfail.

Tested on arm-linux.

Approved-By: Luis Machado <luis.machado@arm.com>
PR arm/tdep
Bug: https://www.sourceware.org/bugzilla/show_bug.cgi?id=31089

12 months agoRe: Yet another ecoff fuzzed object fix
Alan Modra [Thu, 6 Jun 2024 22:57:31 +0000 (08:27 +0930)] 
Re: Yet another ecoff fuzzed object fix

In commit 6fc018e9e593 I replaced the fdr_ptr csym check against the
header isymMax count with a check against bfd symcount.  In fact, both
checks are needed.  The isymMax check sanity checks accesses against
the external sym array, the symcount one against the internal array.

* ecoff.c (_bfd_ecoff_slurp_symbol_table): Reinstate fdr_ptr
csym check against isymMax.

12 months agoaarch64: Test DT_RELR with discarded sections
Szabolcs Nagy [Tue, 4 Jun 2024 08:23:41 +0000 (09:23 +0100)] 
aarch64: Test DT_RELR with discarded sections