]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
7 months agoFix: ld testsuite: non-PIC shared tests fail on powerpc-linux-musl
A. Wilcox [Thu, 5 Oct 2023 12:52:56 +0000 (13:52 +0100)] 
Fix: ld testsuite: non-PIC shared tests fail on powerpc-linux-musl

  PR 30918
  * testsuite/ld-shared/shared.exp: Add XFAILs for tests that fail with the MUSL library.

7 months agoFix: ld testsuite: Thumb PLT and GOT tests should be skipped on musl armhf targets
A. Wilcox [Thu, 5 Oct 2023 11:51:53 +0000 (12:51 +0100)] 
Fix: ld testsuite: Thumb PLT and GOT tests should be skipped on musl armhf targets

  PR 30923
  * testsuite/ld-arm/thumb-plt-got.d: Skip test for configurations using the MUSL library.
  * testsuite/ld-arm/thumb-plt.d: Likewise.

7 months agoFix: ld testsuite: pr22001-1 test segfaults on musl/x86
A. Wilcox [Thu, 5 Oct 2023 11:38:40 +0000 (12:38 +0100)] 
Fix: ld testsuite: pr22001-1 test segfaults on musl/x86

  PR 30925
  PR 22001
  * testsuite/ld-i386/i386.exp: Skip the pr22001 test with TEXTREL relocations enabled on configurations using the MUSL library.

7 months agogdb: fix reread_symbols when an objfile has target: prefix
Andrew Burgess [Thu, 21 Sep 2023 15:35:30 +0000 (16:35 +0100)] 
gdb: fix reread_symbols when an objfile has target: prefix

When using a remote target, it is possible to tell GDB that the
executable to be debugged is located on the remote machine, like this:

  (gdb) target extended-remote :54321
  ... snip ...
  (gdb) file target:/tmp/hello.x
  Reading /tmp/hello.x from remote target...
  warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
  Reading /tmp/hello.x from remote target...
  Reading symbols from target:/tmp/hello.x...
  (gdb)

So far so good.  However, when we try to start the inferior we run
into a small problem:

  (gdb) set remote exec-file /tmp/hello.x
  (gdb) start
  `target:/tmp/hello.x' has disappeared; keeping its symbols.
  Temporary breakpoint 1 at 0x401198: file /tmp/hello.c, line 18.
  Starting program: target:/tmp/hello.x
  ... snip ...

  Temporary breakpoint 1, main () at /tmp/hello.c:18
  18   printf ("Hello World\n");
  (gdb)

Notice this line:

  `target:/tmp/hello.x' has disappeared; keeping its symbols.

That's wrong, the executable hasn't been removed, GDB just doesn't
know how to check if the remote file has changed, and so falls back to
assuming that the file has been removed.

In this commit I update reread_symbols to use bfd_stat instead of
a direct stat call, this adds support for target: files, and fixes the
problem.

This change was proposed before in this commit:

  https://inbox.sourceware.org/gdb-patches/20200114210956.25115-3-tromey@adacore.com/

However, that patch never got merged, and seemed to get stuck
discussing issues around gnulib stat vs system stat as used by BFD.

I didn't 100% understand the issues discussed in that thread, however,
I think the problem with the previous thread related to the changes in
gdb_bfd.c, rather than to the change in symfile.c.  As such, I think
this change might be acceptable, my reasoning is:

  - the objfile::mtime field is set by a call to bfd_get_mtime (see
    objfiles.c), which calls bfd_stat under the hood.  This will end
    up using the system stat,

  - In symfile.c we currently call stat directly, which will call the
    gnulib stat, which, if I understand the above thread correctly,
    might give a different result to the system stat in some cases,

  - By switching to using bfd_stat in symfile.c we should now be
    consistently calling the system stat.

There is another issue that came up during testing that this commit
fixes.  Consider this GDB session:

  $ gdb -q
  (gdb) target extended-remote | ./gdbserver/gdbserver --multi --once -
  Remote debugging using | ./gdbserver/gdbserver --multi --once -
  Remote debugging using stdio
  (gdb) file /tmp/hello.x
  Reading symbols from /tmp/hello.x...
  (gdb) set remote exec-file /tmp/hello.x
  (gdb) start
  ... snip ...
  (gdb) load
  `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols.
  Loading section .interp, size 0x1c lma 0x4002a8
  ... snip ...
  Start address 0x0000000000401050, load size 2004
  Transfer rate: 326 KB/sec, 87 bytes/write.

Notice this line:

  `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols.

We actually see the same output, for the same reasons, when using a
native target, like this:

  $ gdb -q
  (gdb) file /tmp/hello.x
  Reading symbols from /tmp/hello.x...
  (gdb) start
  ... snip ...
  (gdb) load
  `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols.
  You can't do that when your target is `native'
  (gdb)

In both cases this line appears because load_command (symfile.c) calls
reread_symbols, and reread_symbols loops over every currently loaded
objfile and tries to check if the file has changed on disk by calling
stat.

However, the `system-supplied DSO at 0x7ffff7fcf000' is an in-memory
BFD, the filename for this BFD is literally the string
'system-supplied DSO at 0x7ffff7fcf000'.

Before this commit GDB would try to use the system 'stat' call to stat
the file `system-supplied DSO at 0x7ffff7fcf000', which obviously
fails; there's no file with that name (usually).  As a consequence of
the stat failing GDB prints the ' .... has disappeared ...' line.

Initially, all this commit did was switch from using 'stat' to using
'bfd_stat'.  Calling bfd_stat on an in-memory BFD works just fine,
however, BFD just fills the 'struct stat' buffer with zeros (except
for the file size), see memory_bstat in bfd/bfdio.c.

However, there is a bit of a weirdness about in-memory BFDs.  When
they are initially created the libbfd caches an mtime within the bfd
object, this is done in bfd_from_remote_memory (elfcode.h), the cached
mtime is the time at which the in-memory BFD is created.

What this means is that when GDB creates the in-memory BFD, and we
call bfd_get_mtime(), the value returned, which GDB caches within
objfile::mtime is the creation time of the in-memory BFD.  But, when
this patch changes to use bfd_stat() we now get back 0, and so we
believe that the in-memory BFD has changed.  This is a change in
behaviour.

To avoid this change in behaviour, in this commit, I propose that we
always skip in-memory BFDs in reread_symbols.  This preserves the
behaviour from before this commit -- mostly.

As I'm not specifically checking for, and then skipping, in-memory
BFDs, we no longer see this line:

  `system-supplied DSO at 0x7ffff7fcf000' has disappeared; keeping its symbols.

Which I think is an improvement.

Co-Authored-By: Tom Tromey <tromey@adacore.com>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: remove print_sys_errmsg
Andrew Burgess [Sun, 24 Sep 2023 11:37:40 +0000 (12:37 +0100)] 
gdb: remove print_sys_errmsg

This started with me running into this comment in symfile.c:

  /* FIXME, should use print_sys_errmsg but it's not filtered.  */
  gdb_printf (_("`%ps' has disappeared; keeping its symbols.\n"),
              styled_string (file_name_style.style (), filename));

In this particular case I think I disagree with the comment; I think
the output should be a warning rather than just a message printed to
gdb_stdout, I think when the executable, or some other objfile that is
currently being debugged, disappears from disk, this is likely an
unexpected situation, and worth warning the user about.

So, in theory, I could just call print_sys_errmsg and remove the
comment, but that would mean loosing the filename styling in the
output... so in the end I remove the comment and updated the code to
call warning.

But that got me looking at print_sys_errmsg and how it's used.

Currently the function takes a string and an errno, and prints, to
stderr, the string followed by the result of calling strerror on the
errno.

In some places the string passed to print_sys_errmsg is just a
filename, and this is used when something goes wrong.  In these cases,
I think calling warning rather than gdb_printf to gdb_stderr, would be
better, and in fact, in a couple of places we manually print a
"warning" prefix, and then call print_sys_errmsg.  And so, for these
users I have added a new function warning_filename_and_errno, which
takes a filename, which is printed with styling, and an errno, which
is passed through strerror and the resulting string printed.  This new
function calls warning to print its output.  I then updated some of
the print_sys_errmsg users to use this new function.

Some other users of print_sys_errmsg are also emitting what is clearly
a warning, however, the string being passed in is more than just a
filename, so the new warning_filename_and_errno function can't be
used, it would style the whole string.  For these users I have
switched to calling warning directly, this allows me to style the
warning message correctly.

Finally, in inflow.c there is one last call to print_sys_errmsg, in
this case I just inlined the definition of print_sys_errmsg.  This is
a really weird case, as after printing this message GDB just does a
hard exit.  This is pretty old code, dating back to the initial GDB
import, I guess it should be updated to call error() maybe, but I'm
reluctant to make this change as part of this commit, just in case
there's some reason why we can't throw an error at this point.

With that done there are now no users of print_sys_errmsg, and so the
old function can be removed.

While I was doing all of the above I added some additional filename
styling in soure.c, this is in an else block where the if contained
the print_sys_errmsg call, so these felt related.

And finally, while I was updating the uses of print_sys_errmsg in
procfs.c, I noticed that we used a static errmsg buffer to format some
error strings.  As the above changes got rid of one of the users of
errmsg I also removed the other two users, and the static buffer.

There were a couple of tests that depended on the existing output
message format that needed updating.  In one case we gained an extra
'warning: ' prefix, and in the other 'Warning: ' becomes 'warning: ',
I think in both cases the new output is an improvement.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: remove use of a static buffer for building error strings
Andrew Burgess [Sun, 24 Sep 2023 12:37:06 +0000 (13:37 +0100)] 
gdb: remove use of a static buffer for building error strings

I noticed in procfs.c that we use a static buffer for building error
strings when we could easily use std::string and string_printf to
achieve the same result, this commit does that.

I ran into this while performing a further refactor/cleanup that will
be presented in a later patch in this series, and thought this was
worth splitting out into its own patch.

As far as I can tell, only Solaris uses procfs.c, so I did a test
build on a Solaris machine, and I don't believe that I've broken
anything.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: use archive name in warning when appropriate
Andrew Burgess [Sat, 23 Sep 2023 13:29:40 +0000 (14:29 +0100)] 
gdb: use archive name in warning when appropriate

While working on some other patch I noticed that in reread_symbols
there is a diagnostic message that can be printed, and in some cases
we might use the wrong filename in the message.

The code in question is checking to see if an objfile has changed on
disk, we do this by stat-ing the on disk file and checking the mtime.
If this file has been removed from disk then we print a message that
the file has been removed, however, if the objfile is within an
archive then we stat the archive itself, but then warn that the
component within the archive has disappeared.  I think it makes more
sense to say that the archive has disappeared.

The last related commit is this one:

  commit 02aeec7bde8ec8a04d14a5637e75f1c6ab899e23
  Date:   Tue Apr 27 21:01:30 2010 +0000

      Check library name rather than member name when rereading symbols.

Though this just makes the code to stat the archive unconditional, the
code in question existed before this commit.

However, the above commit doesn't include any tests, and seems to
indicate that the problem being addressed was seen on Darwin.  I'm not
sure how to setup a test where GDB is using an objfile from within an
archive, and so there's no tests for this commit...

... but if someone can let me know how I can setup a suitable test,
please let me know and I'll try to get something working.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: some additional filename styling
Andrew Burgess [Fri, 22 Sep 2023 10:04:44 +0000 (11:04 +0100)] 
gdb: some additional filename styling

Fix up another couple of places where we can apply filename styling.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agoFix: ld testsuite: 'Version' pattern grabs 'Version5 EABI', breaking test on arm...
A. Wilcox [Thu, 5 Oct 2023 11:13:08 +0000 (12:13 +0100)] 
Fix: ld testsuite: 'Version' pattern grabs 'Version5 EABI', breaking test on arm-linux-musleabihf

  PR 30924
  * testsuite/ld-elfvers/vers.exp (objdump_emptyverstuff): Handle EABI version information in objdump's output.

7 months agoaarch64: Enable Cortex-X4 CPU
Saurabh Jha [Thu, 5 Oct 2023 10:09:45 +0000 (11:09 +0100)] 
aarch64: Enable Cortex-X4 CPU

7 months agomicroblaze: Add address extension instructions
Neal frager [Thu, 5 Oct 2023 09:59:03 +0000 (10:59 +0100)] 
microblaze: Add address extension instructions

  * microblaze-opcm.h (struct op_code_struct): Tidy and remove redundant entries.
  * microblaze-opc.h (MAX_OPCODES): Increase to 300. (op_code_struct): Add address extension instructions.

7 months agoAutomatic date update in version.in
GDB Administrator [Thu, 5 Oct 2023 00:00:39 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agogdb/testsuite: XFAIL some gdb.base/fileio.exp
Guinevere Larsen [Fri, 11 Aug 2023 09:58:11 +0000 (11:58 +0200)] 
gdb/testsuite: XFAIL some gdb.base/fileio.exp

Some gdb.base/fileio.exp tests expect the inferior to not have write
access to some files. If the test is being run as root, this is never
possible. This commit adds a way to identify if the user is root and
xfails the tests that expect no write access.

Approved-By: Tom de Vries <tdevries@suse.de>
7 months agold: microblaze: ignore rwx segments
Neal Frager [Thu, 28 Sep 2023 05:57:37 +0000 (06:57 +0100)] 
ld: microblaze: ignore rwx segments

The linker will generate warnings if it is creating an executable
stack or a segment with all three read, write and execute permissions.
These settings are not appropriate for all targets including
MicroBlaze.

Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
7 months agoopcodes: microblaze: Add hibernate and suspend instructions
Neal frager [Wed, 4 Oct 2023 15:35:44 +0000 (16:35 +0100)] 
opcodes: microblaze: Add hibernate and suspend instructions

7 months agosme2: Document SME2 registers and features
Luis Machado [Thu, 22 Jun 2023 22:52:36 +0000 (23:52 +0100)] 
sme2: Document SME2 registers and features

Document changes introduced by gdb's SME2 support.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme2: Extend SME tests to include SME2
Luis Machado [Fri, 16 Jun 2023 14:02:39 +0000 (15:02 +0100)] 
sme2: Extend SME tests to include SME2

Reusing the SME tests, this patch introduces additional tests to exercise
reading/writing ZT0, availability of the register set, signal context reading
for ZT0 and also core file generation.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme2: Core file support for ZT register set
Luis Machado [Wed, 14 Jun 2023 08:28:35 +0000 (09:28 +0100)] 
sme2: Core file support for ZT register set

This patch adds support for ZT register dumps/reads for core files.  The
ZT register is available when the SME2 feature is advertised as available
by the Linux Kernel.

Unlike the enablement for SME1 and the ZA register, support for SME2 is rather
simple given the fixed size of the ZT0 register.

Validated on the Fast Models.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme2: signal frame support
Luis Machado [Tue, 13 Jun 2023 14:23:00 +0000 (15:23 +0100)] 
sme2: signal frame support

Teach gdb about the ZT state on signal frames and how to restore
the contents of the registers.

There is a new ZT_MAGIC context that the Linux Kernel uses to communicate
the ZT register state to gdb.

As mentioned before, the ZT state should only be available when the ZA state
is available.

Validated under Fast Models.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme2: Enable SME2 support in gdbserver
Luis Machado [Tue, 4 Apr 2023 16:28:51 +0000 (17:28 +0100)] 
sme2: Enable SME2 support in gdbserver

This patch teaches gdbserver about the SME2 and the ZT0 register.

Since most of the code used by gdbserver for SME2 is shared with gdb, this
is a rather small patch that reuses most of the code put in place for native
AArch64 Linux.

Validated under Fast Models.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme2: Enable SME2 for AArch64 gdb on Linux
Luis Machado [Tue, 4 Apr 2023 16:20:46 +0000 (17:20 +0100)] 
sme2: Enable SME2 for AArch64 gdb on Linux

SME2 defines a new 512-bit register named ZT0, and it is only available
if SME is also supported.  The ZT0 state is valid only if the SVCR ZA bit
is enabled.  Otherwise its contents are empty (0).

The target description is dynamic and gets generated at runtime based on the
availability of the feature.

Validated under Fast Models.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme: Document SME registers and features
Luis Machado [Tue, 31 Jan 2023 23:54:39 +0000 (23:54 +0000)] 
sme: Document SME registers and features

Provide documentation for the SME feature and other information that
should be useful for users that need to debug a SME-capable target.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme: Add SVE/SME testcases
Luis Machado [Mon, 10 Oct 2022 12:31:44 +0000 (13:31 +0100)] 
sme: Add SVE/SME testcases

Add 5 SVE/SME tests to exercise all the new features like reading/writing
registers, pseudo-registers, signal frames and core files.

- Sanity check for SME: Gives a brief smoke test to make sure the most basic
of features are working correctly.

- ZA unavailability tests: Validates the behavior/content of the ZA register
is correct when no payload is available.  It also exercises changing the
vector lengths.

- ZA availability tests: These tests exercise reading/writing to all the
possible ZA pseudo-registers, and validates the state is correct.

- Core file tests: Validates that core file reading and writing works
correctly and that all state dumped/loaded is sane.  This is exercised for
both Linux Kernel core files and gcore core files.

- Signal frame tests: Validates the correct restoration of SME/SVE/FPSIMD
values across signal frames.

Since some of these tests are very lengthy and take a little while to run
(under QEMU at the moment), I decided to parallelize them into smaller
chunks so we can throw some more CPU power at them so they run faster.

I'd still like to add a few more tests to give the testsuite more coverage
in the areas of SME/SVE.  Hopefully in the near future that will happen.

Just a reminder that these SME tests are currently unsupported when gdb is
connected to a remote target.  That's because the RSP doesn't support
communicating changes in vector lenghts mid-execution, so gdb will always
get wrong state from the remote target.

Co-Authored-By: Ezra Sitorus <ezra.sitorus@arm.com>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme: Core file support for Linux
Luis Machado [Tue, 7 Feb 2023 09:50:47 +0000 (09:50 +0000)] 
sme: Core file support for Linux

This patch enables dumping SME state via gdb's gcore command and also
enables gdb to read SME state from a core file generated by the Linux
Kernel.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agocorefile/bug: Add hook to control the use of target description notes from corefiles
Luis Machado [Thu, 7 Sep 2023 15:20:15 +0000 (16:20 +0100)] 
corefile/bug: Add hook to control the use of target description notes from corefiles

Due to the nature of the AArch64 SVE/SME extensions in GDB, each thread
can potentially have distinct target descriptions/gdbarches.

When loading a gcore-generated core file, at the moment GDB gives priority
to the target description dumped to NT_GDB_TDESC.  Though technically correct
for most targets, it doesn't work correctly for AArch64 with SVE or SME
support.

The correct approach for AArch64/Linux is to either have per-thread target
description notes in the corefiles or to rely on the
gdbarch_core_read_description hook, so it can figure out the proper target
description for a given thread based on the various available register notes.

The former, although more correct, doesn't address the case of existing gdb's
that only output a single target description note.

This patch goes for the latter, and adds a new gdbarch hook to conditionalize
the use of the corefile target description note. The hook is called
use_target_description_from_corefile_notes.

The hook defaults to returning true, meaning targets will use the corefile
target description note.  AArch64 Linux overrides the hook to return false
when it detects any of the SVE or SME register notes in the corefile.

Otherwise it should be fine for AArch64 Linux to use the corefile target
description note.

When we support per-thread target description notes, then we can augment
the AArch64 Linux hook to rely on those notes.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agocorefile/bug: Use thread-specific gdbarch when dumping register state to core files
Luis Machado [Tue, 31 Jan 2023 17:17:09 +0000 (17:17 +0000)] 
corefile/bug: Use thread-specific gdbarch when dumping register state to core files

When we have a core file generated by gdb (via the gcore command), gdb dumps
the target description to a note.  During loading of that core file, gdb will
first try to load that saved target description.

This works fine for almost all architectures. But AArch64 has a few
dynamically-generated target descriptions/gdbarch depending on the vector
length that was in use at the time the core file was generated.

The target description gdb dumps to the core file note is the one generated
at the time of attachment/startup.  If, for example, the SVE vector length
changed during execution, this would not reflect on the core file, as gdb
would still dump the initial target description.

Another issue is that the gdbarch potentially doesn't match the thread's
real gdbarch, and so things like the register cache may have different formats
and sizes.

To address this, fetch the thread's architecture before dumping its register
state.  That way we will always use the correct target description/gdbarch.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agoGet rid of linux-core-thread-data
Luis Machado [Mon, 11 Sep 2023 09:39:48 +0000 (10:39 +0100)] 
Get rid of linux-core-thread-data

This struct type seems to have been used in the past as a callback
parameter.  Now it seems that case is no longer true, so we can simplify
things by passing the individual parameters linux_core_thread_data
encapsulates directly to the functions.

This is just a cleanup before the next change.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
7 months agosme: Support TPIDR2 signal frame context
Luis Machado [Thu, 16 Mar 2023 12:14:18 +0000 (12:14 +0000)] 
sme: Support TPIDR2 signal frame context

The Linux Kernel defines a separate context for the TPIDR2 register in a
signal frame.  Handle this additional context in gdb so this register
gets restored properly when unwinding through signal frames.

The TPIDR2 register is closely related to SME, and is available when SME
support is reported.

This is tested by testcases that are available in a later patch in the series.

Regressions-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme: Fixup sigframe gdbarch when vg/svg changes
Luis Machado [Thu, 2 Feb 2023 14:00:58 +0000 (14:00 +0000)] 
sme: Fixup sigframe gdbarch when vg/svg changes

With SME, where you have two different vector lengths (vl and svl), it may be
the case that the current frame has a set of vector lengths (A) but the signal
context has a distinct set of vector lengths (B).

In this case, we may run into a situation where GDB attempts to use a gdbarch
created for set A, but it is really dealing with a frame that was using set
B.

This is problematic, specially with SME, because now we have a different
number of pseudo-registers and types that gets cached on creation of each
gdbarch variation.

For AArch64 we really need to be able to use the correct gdbarch for each
frame, and I noticed the signal frame (tramp-frame) doesn't have a settable
prev_arch field.  So it ends up using the default frame_unwind_arch function
and eventually calling get_frame_arch (next_frame).  That means the previous
frame will always have the same gdbarch as the current frame.

This patch first refactors the AArch64/Linux signal context code, simplifying
it and making it reusable for our purposes of calculating the previous frame's
gdbarch.

I introduced a struct that holds information that we have found in the signal
context, and with which we can make various decisions.

Finally, a small change to tramp-frame.c and tramp-frame.h to expose a
prev_arch hook that the architecture can set.

With this new field, AArch64/Linux can implement a hook that looks at the
signal context and infers the gdbarch for the previous frame.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme: Signal frame support
Luis Machado [Tue, 7 Feb 2023 09:47:27 +0000 (09:47 +0000)] 
sme: Signal frame support

Teach gdb about the ZA/SSVE state on signal frames and how to restore
the contents of the registers.

There is a new ZA_MAGIC context that the Linux Kernel uses to communicate
the ZA register state to gdb.

The SVE_MAGIC context has also been adjusted to contain a flag indicating
whether it is a SVE or SSVE state.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosve: Fix signal frame z/v register restore
Luis Machado [Mon, 20 Feb 2023 09:56:19 +0000 (09:56 +0000)] 
sve: Fix signal frame z/v register restore

While doing some SME work, I ran into the situation where the Z register
contents restored from a signal frame are incorrect if the signal frame
only contains fpsimd state and no sve state.

This happens because we only restore the v register values in that case,
and don't do anything for the z registers.

Fix this by initializing the z registers to 0 and then copying over the
overlapping part of the v registers to the z registers.

While at it, refactor the code a bit to simplify it and make it smaller.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosme: Add support for SME
Luis Machado [Tue, 15 Nov 2022 09:07:09 +0000 (09:07 +0000)] 
sme: Add support for SME

Enable SME support in gdbserver by adjusting the usual fields.  There is
not much to this patch because the code is either in gdb or it is shared
between gdbserver and gdb.  One exception is the bump to gdbserver's
PBUFSIZ from 18432 to 131104.

Since the ZA register can be quite big (256 * 256 bytes), the g/G remote
packet will also become quite big

From gdbserver/tdesc.cc:init_target_desc, I estimated the new size should
be at least (2 * 256 * 256 + 32), which yields 131104.

It is also unlikely we will find a process starting up with SVL set to 256.

Ideally we'd adjust the packet size dynamically based on what we need, but
for now this should do.

Please note we have the same limitation for SME that we have for SVE, and
that is the fact gdbserver cannot communicate vector length changes to gdb
via the remote protocol.

Thiago is working on this improvement, which hopefully will be able to be
adapted to SME in an easy way.

Co-Authored-By: Ezra Sitorus <ezra.sitorus@arm.com>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agorefactor: Adjust expedited registers dynamically
Luis Machado [Thu, 9 Feb 2023 10:55:26 +0000 (10:55 +0000)] 
refactor: Adjust expedited registers dynamically

Instead of using static arrays, build the list of expedited registers
dynamically using a std::vector.

This refactor shouldn't cause any user-visible changes.

Regression-tested for aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agoConvert tdesc's expedite_regs to a string vector
Luis Machado [Mon, 11 Sep 2023 11:42:00 +0000 (12:42 +0100)] 
Convert tdesc's expedite_regs to a string vector

Right now the list of expedited registers is stored as an array of char *,
with a nullptr element at the end to signal its last element.

Convert expedite_regs to a std::vector of std::string so it is easier to
manage the elements and the storage is handled automatically.

Eventually we might want to convert all the target functions so they pass a
std::vector of std::string as well. Or maybe expose an interface that target can
use to add expedited registers on-by-one depending on the target description
discovery needs, as opposed to just a static list of char *.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agosme: Enable SME registers and pseudo-registers
Luis Machado [Tue, 7 Feb 2023 09:36:23 +0000 (09:36 +0000)] 
sme: Enable SME registers and pseudo-registers

The SME (Scalable Matrix Extension) [1] exposes a new matrix register ZA with
variable sizes.  It also exposes a new mode called streaming mode.

Similarly to SVE, the ZA register size is dictated by a vector length, but the
SME vector length is called streaming vetor length. The total size for
ZA in a given moment is svl x svl.

In streaming mode, the SVE registers have their sizes based on svl rather than
the regular vector length (vl).

The feature detection is controlled by the HWCAP2_SME bit, but actual support
should be validated by attempting a ptrace call for one of the new register
sets: NT_ARM_ZA and NT_ARM_SSVE.

Due to its large size, the ZA register is exposed as a vector of bytes, but we
introduce a number of pseudo-registers that gives various different views
into the ZA contents. These can be arranged in a couple categories: tiles and
tile slices.

Tiles are matrices the same size or smaller than ZA.  Tile slices are vectors
which map to ZA's rows/columns in different ways.

A new dynamic target description is provided containing the ZA register, the SVG
register and the SVCR register.  The size of ZA, like the SVE vector registers,
is based on the vector length register SVG (VG for SVE).

This patch enables SME register support for gdb.

[1] https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/scalable-matrix-extension-armv9-a-architecture

Co-Authored-By: Ezra Sitorus <ezra.sitorus@arm.com>
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agosve: Fix return command when using V registers in a SVE-enabled target
Luis Machado [Thu, 30 Mar 2023 14:16:53 +0000 (15:16 +0100)] 
sve: Fix return command when using V registers in a SVE-enabled target

In a target without SVE support, the V registers have a size of 16 bytes,
otherwise they may have a size bigger than 16 bytes (depending on the current
vector length for the Z registers, as they overlap the V registers).

In aarch64-tdep.c:aarch64_store_return_value, the code is laid
out in a way that allocates the buffer with the size of the register, but
only updates the amount of bytes for the particular type we're returning.

This may cause a situation where we have a register size of 32 bytes but
are returning a floating point value of 8 bytes.  The temporary buffer
will therefore have 32 bytes, but we'll only update 8 bytes of it.

When we write the entire register back, it will have potentially 24 bytes
of garbage in it.

Fix this by first reading the original contents of the register and then
overriding only the bytes that we need for the return value.

Tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agorefactor: Simplify SVE interface to read/write registers
Luis Machado [Tue, 7 Feb 2023 10:08:23 +0000 (10:08 +0000)] 
refactor: Simplify SVE interface to read/write registers

This is a patch in preparation to upcoming patches enabling SME support.  It
attempts to simplify the gdb/gdbserver shared interface used to read/write
SVE registers.

Where the current code makes use of unique_ptr, allocating a new buffer by
hand and passing a buffer around, this patch makes that code use
gdb::byte_vector and passes a reference to this byte vector to the functions,
allowing the functions to have ready access to the size of the buffer.

It also shares a bit more code between gdb and gdbserver, in particular around
handling of ptrace get/set requests for SVE.

I think gdbserver could be refactored to handle register reads/writes more
like gdb's native layer as opposed to letting the generic linux-low layer do
the ptrace calls.  This is not very flexible and assumes one size for the
responses.  If you have something like NT_ARM_SVE, where you can have either
FPSIMD or SVE contents, it doesn't work that well.

I didn't want to change that interface right now as it is a bit too much work
and touches all the targets, some of which I can't easily test.

Hence the reason why the buffer the generic linux-now passes down to
linux-aarch64-low is unused or ignored.

No user-visible changes should happen as part of this refactor other than a
slightly reworded warning message.

While doing the refactor, I also noticed what seems to be a mistake in checking
if the register cache contains active (non-zero) SVE data.

For instance, the original code did something like this in
aarch64_sve_regs_copy_from_reg_buf:

has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_Z0_REGNUM + i
       reg, sizeof (__int128_t));

"reg" is a zeroed-out buffer that we compare the Z register contents
past the first 128 bits.  The problem here is that raw_compare returns
1 if the contents compare the same, which means has_sve_state will be
true.  But if we compared the Z register contents to 0, it means we
*do not* have SVE state, and therefore has_sve_state should be false.

The consequence of this mistake is that we convert the initial
FPSIMD-formatted data we get from ptrace for the NT_ARM_SVE register
set to a SVE-formatted one.

In the end, this doesn't cause user-visible differences because the
values of both the Z and V registers will still be the same.  But the
logic is not correct.

I used the opportunity to fix this, and it gets tested later on by
the additional SME tests.

I do plan on submitting some SVE-specific tests to make sure we have
a bit more coverage in GDB's testsuite.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agorefactor: Rename SVE-specific files
Luis Machado [Mon, 6 Feb 2023 17:24:32 +0000 (17:24 +0000)] 
refactor: Rename SVE-specific files

In preparation to the SME support patches, rename the SVE-specific files to
something a bit more meaningful that can be shared with the SME code.

In this case, I've renamed the "sve" in the names to "scalable".

No functional changes.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agoFix register fetch/store order for native AArch64 Linux
Luis Machado [Fri, 17 Mar 2023 21:23:59 +0000 (21:23 +0000)] 
Fix register fetch/store order for native AArch64 Linux

I noticed we don't handle register reads/writes in the best way for native
AArch64 Linux.  Some other registers are fetched/stored even if upper level
code told us to fetch a particular register number.

Fix this by being more strict about which registers we touch when
reading/writing them in the native AArch64 Linux layer.

There should be no user-visible changes due to this patch.

Regression-tested on aarch64-linux Ubuntu 22.04/20.04.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
7 months agoaarch64: Refactor system register data
Victor Do Nascimento [Mon, 2 Oct 2023 08:35:01 +0000 (09:35 +0100)] 
aarch64: Refactor system register data

This patch  moves instances of system register definitions, represented
by the SYSREG macro, out of their original place in `aarch64-opc.c'
and into a dedicated .def file, `aarch64-sys-regs.def'.

System register entries in this new file are ordered alphabetically by
name.  This choice is made to enable the use of fast search algorithms
such as binary search when validating register names.

The SYSREG macro, defined as SYSREG (name, encoding, flags, features)
is kept as is and used in the def file, but all other SR_* macros
which previously served as indirections to SYSREG are removed.

opcodes/ChangeLog:
* aarch64-opc.c (SR_CORE): Macro definition and uses deleted.
(SR_FEAT): Likewise.
(SR_FEAT2): Likewise.
(SR_V8_1_A): Likewise.
(SR_V8_4_A): Likewise.
(SR_V8A): Likewise.
(SR_V8R): Likewise.
(SR_V8_1A): Likewise.
(SR_V8_2A): Likewise.
(SR_V8_3A): Likewise.
(SR_V8_4A): Likewise.
(SR_V8_6A): Likewise.
(SR_V8_7A): Likewise.
(SR_V8_8A): Likewise.
(SR_GIC): Likewise.
(SR_AMU): Likewise.
(SR_LOR): Likewise.
(SR_PAN): Likewise.
(SR_RAS): Likewise.
(SR_RNG): Likewise.
(SR_SME): Likewise.
(SR_SSBS): Likewise.
(SR_SVE): Likewise.
(SR_ID_PFR2): Likewise.
(SR_PROFILE): Likewise.
(SR_MEMTAG): Likewise.
(SR_SCXTNUM): Likewise.
(SR_EXPAND_ELx): Likewise.
(SR_EXPAND_EL12): Likewise.
* opcodes/aarch64-sys-regs.def: New.

7 months agoaarch64: system register aliasing detection
Victor Do Nascimento [Mon, 2 Oct 2023 08:51:27 +0000 (09:51 +0100)] 
aarch64: system register aliasing detection

This patch adds a mechanism for system register name alias detection
to register-matching mechanisms.

A new `F_REG_ALIAS' flag is added to the set of register flags and
used to label which entries in aarch64_sys_regs[] correspond to
aliases (and thus which CPENC values are non-unique in this array).

Where this is used is, for example, in `aarch64_print_operand' where,
in the case of system register decoding, the aarch64_sys_regs[] array
is iterated through until a match in CPENC value is made and the first
match accepted.  If insufficient care is given in the ordering of
system registers in this array, the alias is encountered before the
"real" register and used incorrectly as the register name in the
disassembled output.

With this flag and the new `aarch64_sys_reg_alias_p' test, search
candidates corresponding to aliases can be conveniently skipped over.

One concrete example of where this is useful is with the
`trcextinselr0' system register.  It was initially placed in the
system register list before `trcextinselr', in contrast to a more
natural alphabetical order.

include/ChangeLog:
* opcode/aarch64.h: add `aarch64_sys_reg_alias_p' prototype.

opcodes/ChangeLog:
* aarch64-opc.c (aarch64_sys_reg_alias_p): New.
(aarch64_print_operand): add aarch64_sys_reg_alias_p check.
(aarch64_sys_regs): Add F_REG_ALIAS flag to "trcextinselr"
entry.
* aarch64-opc.h (F_REG_ALIAS): New.

7 months agoAutomatic date update in version.in
GDB Administrator [Wed, 4 Oct 2023 00:00:32 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agogdb/corefile: write NT_GDB_TDESC based on signalled thread
Andrew Burgess [Mon, 25 Sep 2023 09:32:14 +0000 (10:32 +0100)] 
gdb/corefile: write NT_GDB_TDESC based on signalled thread

When creating a core file from within GDB we include a NT_GDB_TDESC
that includes the target description of the architecture in use.

For architectures with dynamic architectures (e.g. AArch64 with
sve/sme) the original architecture, calculated from the original
target description, might not match the per-thread architecture.

In the general case, where each thread has a different architecture,
then we really need a separate NT_GDB_TDESC for each thread, however,
there's currently no way to read in multiple NT_GDB_TDESC.

This commit is a step towards per-thread NT_GDB_TDESC.  In this commit
I have updated the function that writes the NT_GDB_TDESC to accept a
gdbarch (rather than calling target_gdbarch() to find a gdbarch), and
I now pass in the gdbarch of the signalled thread.

In many cases (though NOT all) targets with dynamic architectures
really only use a single architecture, even when there are multiple
threads, so in the common case, this should ensure that GDB emits an
architecture that is more likely to be correct.

Additional work will be needed in order to support corefiles with
truly per-thread architectures, but that will need to be done in the
future.

7 months agoMIPS: Fix `readelf -S bintest' test for n64 targets
YunQiang Su [Tue, 3 Oct 2023 11:41:02 +0000 (12:41 +0100)] 
MIPS: Fix `readelf -S bintest' test for n64 targets

Add a 64-bit traditional MIPS dump variant for the `readelf -S bintest'
test from binutils-all/readelf.exp, using a filename suffix according to
the rules set there, removing:

FAIL: readelf -S bintest

regressions with `mips64-linux-gnuabi64', `mips64el-linux-gnuabi64',
`mips64-openbsd', and `mips64el-openbsd' targets, which default to the
n64 ABI and consequently produce a section layout that is different from
what the generic dump pattern covers.

Co-Authored-By: Maciej W. Rozycki <macro@orcam.me.uk>
binutils/
* testsuite/binutils-all/readelf.s-64-tmips: New test variant.

7 months agoFix: readelf..info misreports DW_FORM_loclistx, DW_FORM_rnglistx
Vsevolod Alekseyev [Tue, 3 Oct 2023 08:27:27 +0000 (09:27 +0100)] 
Fix: readelf..info misreports DW_FORM_loclistx, DW_FORM_rnglistx

  PR 29267
  * dwarf.c (fetch_indexed_value): Delete. (fetch_indexed_offset): Correct base address calculation. (read_and_display_attr_value): Replace uses of fetch_indexed_value with fetch_indexed_offset.

7 months agoAutomatic date update in version.in
GDB Administrator [Tue, 3 Oct 2023 00:00:46 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agogdb/python: reformat file with black
Andrew Burgess [Mon, 2 Oct 2023 20:08:26 +0000 (21:08 +0100)] 
gdb/python: reformat file with black

Reformat a Python file with black after this commit:

  commit 59912fb2d22f8a4bb0862487f12a5cc65b6a013f
  Date:   Tue Sep 19 11:45:36 2023 +0100

      gdb: add Python events for program space addition and removal

There should be no functional change with this commit.

7 months agoAdd regression test for instructionReference change
Tom Tromey [Thu, 21 Sep 2023 14:49:44 +0000 (08:49 -0600)] 
Add regression test for instructionReference change

Yesterday I pushed a patch to fix a small oversight in the DAP code
that caused an instructionReference to be an array instead of a
string.

This patch adds a test case for that regression.  This required
exposing the TON form of the response -- something I mentioned might
be necessary when this code was changed to return just the Tcl form.

I tested this by backing out yesterday's bug fix and verifying that a
failure is seen.

7 months agoClean up intermediate values in val_print_packed_array_elements
Tom Tromey [Fri, 15 Sep 2023 14:59:09 +0000 (08:59 -0600)] 
Clean up intermediate values in val_print_packed_array_elements

Following on Tom de Vries' work in the other array-printers, this
patch changes val_print_packed_array_elements to also avoid allocating
too many values when printing an Ada packed array.

7 months agogdb/testsuite: accept variable number of spaces in gdb.base/jit-reader-simple.exp...
Simon Marchi [Mon, 2 Oct 2023 18:22:26 +0000 (14:22 -0400)] 
gdb/testsuite: accept variable number of spaces in gdb.base/jit-reader-simple.exp regex

I see this failure:

    FAIL: gdb.base/jit-reader-simple.exp: standalone: change addr: initial run: maint info breakpoints shows jit breakpoint

The jit breakpoint expected by the test is there, it's just that the
number of spaces doesn't match what the test expects, after "jit
events":

    -2      jit events       keep y   0x0000555555555119 <__jit_debug_register_code> inf 1

Fix that by relaxing the regex a bit.

Change-Id: Ia3b04e6d5978399d940fd1a590f95f15275ca7ac

7 months agogdb: Add command 'maint set/show debuginfod download-sections'
Aaron Merey [Mon, 2 Oct 2023 17:59:57 +0000 (13:59 -0400)] 
gdb: Add command 'maint set/show debuginfod download-sections'

This setting controls whether GDB may attempt to download ELF/DWARF
sections from debuginfod servers.

This setting is enabled by default if gdb is built with debuginfod
section download support (requires libdebuginfod 0.188).

Also update debuginfod command help text and gdb.texinfo with
information on section downloading and the new command.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
7 months agogdb/debuginfod: Add debuginfod_section_query
Aaron Merey [Tue, 15 Aug 2023 16:17:48 +0000 (12:17 -0400)] 
gdb/debuginfod: Add debuginfod_section_query

Add new function debuginfod_section_query.  This function queries
debuginfod servers for an individual ELF/DWARF section associated with
a given build-id.

Approved-By: Andrew Burgess <aburgess@redhat.com>
7 months ago[gdb/testsuite] Handle older gcc in gdb.ada/import.exp
Tom de Vries [Mon, 2 Oct 2023 17:52:48 +0000 (19:52 +0200)] 
[gdb/testsuite] Handle older gcc in gdb.ada/import.exp

When running test-case gdb.ada/import.exp with gcc 7, most test fail:
...
FAIL: gdb.ada/import.exp: print imported_var_ada
FAIL: gdb.ada/import.exp: print local_imported_var
FAIL: gdb.ada/import.exp: print pkg.imported_var_ada
FAIL: gdb.ada/import.exp: print pkg.exported_var_ada
FAIL: gdb.ada/import.exp: print exported_var_ada
FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at pkg.imported_func_ada
FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at imported_func_ada
FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at local_imported_func
...

When running with gcc 8 or 9, only 2 tests fail:
...
FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at pkg.imported_func_ada
FAIL: gdb.ada/import.exp: gdb_breakpoint: set breakpoint at imported_func_ada
...

The test-case passes fully with gcc 10, 11, 12 and 13.

Debug info for pragma import seems to not have been supported before gcc 8, so
require that version.

The two FAILs with gcc 8 and 9 seem to be due to problems in debug info.  Add
an xfail for these.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
7 months ago[gdb/testsuite] Add KFAIL for PR ada/30908
Tom de Vries [Mon, 2 Oct 2023 17:48:21 +0000 (19:48 +0200)] 
[gdb/testsuite] Add KFAIL for PR ada/30908

With gcc 13.2.1, I run into a cluster of fails:
...
FAIL: gdb.ada/str_binop_equal.exp: print my_str = "ABCD"
FAIL: gdb.ada/widewide.exp: print my_wws = " helo"
FAIL: gdb.ada/widewide.exp: print my_ws = "wide"
...

The problem is that the debug info contains information about function
ada.strings.maps."=", and gdb uses it to implement the comparison.
The function is supposed to compare two char sets, not strings, so gdb
shouldn't use it.  This is PR ada/30908.

I don't see the same problem with gcc 7.5.0, because the exec doesn't contain
the debug info for the function, because the corresponding object is not
linked in.  Adter adding "with Ada.Strings.Maps; use Ada.Strings.Maps;" to
gdb.ada/widewide/foo.adb I run into the same problem with gcc 7.5.0.

Add KFAILs for the PR.

Tested on x86_64-linux:
- openSUSE Leap 15.4 (using gcc 7.5.0), and
- openSUSE Tumbleweed (using gcc 13.2.1).

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

7 months agogdb: add Python events for program space addition and removal
Andrew Burgess [Tue, 19 Sep 2023 10:45:36 +0000 (11:45 +0100)] 
gdb: add Python events for program space addition and removal

Initially I just wanted a Python event for when GDB removes a program
space, I'm writing a Python extension that caches information for each
program space, and need to know when I should discard entries for a
particular program space.

But, it seemed easy enough to also add an event for when GDB adds a
new program space, so I went ahead and added both new events.

Of course, we don't currently have an observable for program space
addition or removal, so I first needed to add these.  After that it's
pretty simple to add two new Python events and have these trigger.

The two new event registries are:

  events.new_progspace
  events.free_progspace

These emit NewProgspaceEvent and FreeProgspaceEvent objects
respectively, each of these new event types has a 'progspace'
attribute that contains the relevant gdb.Progspace object.

There's a couple of things to be mindful of.

First, it is not possible to catch the NewProgspaceEvent for the very
first program space, the one that is created when GDB first starts, as
this program space is created before any Python scripts are sourced.

In order to allow this event to be caught we would need to defer
creating the first program space, and as a consequence the first
inferior, until some later time.  But, existing scripts could easily
depend on there being an initial inferior, so I really don't think we
should change that -- and so, we end up with the consequence that we
can't catch the event for the first program space.

The second, I think minor, issue, is that GDB doesn't clean up its
program spaces upon exit -- or at least, they are not cleaned up
before Python is shut down.  As a result, any program spaces in use at
the time GDB exits don't generate a FreeProgspaceEvent.  I'm not
particularly worried about this for my use case, I'm using the event
to ensure that a cache doesn't hold stale entries within a single GDB
session.  It's also easy enough to add a Python at-exit callback which
can do any final cleanup if needed.

Finally, when testing, I did hit a slightly weird issue with some of
the remote boards (e.g. remote-stdio-gdbserver).  As a consequence of
this issue I see some output like this in the gdb.log:

  (gdb) PASS: gdb.python/py-progspace-events.exp: inferior 1
  step
  FreeProgspaceEvent: <gdb.Progspace object at 0x7fb7e1d19c10>
  warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running.
  Use the "interrupt" command to stop the target
  and then try again.
  warning: cannot close "target:/lib64/libc.so.6": Cannot execute this command while the target is running.
  Use the "interrupt" command to stop the target
  and then try again.
  warning: cannot close "target:/lib64/ld-linux-x86-64.so.2": Cannot execute this command while the target is running.
  Use the "interrupt" command to stop the target
  and then try again.
  do_parent_stuff () at py-progspace-events.c:41
  41        ++global_var;
  (gdb) PASS: gdb.python/py-progspace-events.exp: step

The 'FreeProgspaceEvent ...' line is expected, that's my test Python
extension logging the event.  What isn't expected are all the blocks
like:

  warning: cannot close "target:/lib64/libm.so.6": Cannot execute this command while the target is running.
  Use the "interrupt" command to stop the target
  and then try again.

It turns out that this has nothing to do with my changes, this is just
a consequence of reading files over the remote protocol.  The test
forks a child process which GDB stays attached too.  When the child
exits, GDB cleans up by calling prune_inferiors, which in turn can
result in GDB trying to close some files that are open because of the
inferior being deleted.

If the prune_inferiors call occurs when the remote target is
running (and in non-async mode) then GDB will try to send a fileio
packet while the remote target is waiting for a stop reply, and the
remote target will throw an error, see remote_target::putpkt_binary in
remote.c for details.

I'm going to look at fixing this, but, as I said, this is nothing to
do with this change, I just mention it because I ended up needing to
account for these warning messages in one of my tests, and it all
looks a bit weird.

Approved-By: Tom Tromey <tom@tromey.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
7 months agogdb: remove solib::pspace field
Simon Marchi [Wed, 27 Sep 2023 20:39:36 +0000 (16:39 -0400)] 
gdb: remove solib::pspace field

This backlink is not necessary, we always know the program space from
the context.  Pass it down the solib_unloaded observer.

Change-Id: I45a503472dc791f517558b8141901472634e0556
Approved-By: Tom Tromey <tom@tromey.com>
7 months agoFix memory leak in RiscV assembler.
Nick Clifton [Mon, 2 Oct 2023 15:23:14 +0000 (16:23 +0100)] 
Fix memory leak in RiscV assembler.

  PR 30861
  * config/tc-riscv.c (riscv_insert_uleb128_fixes): Release duplicated memory.

7 months agoUse bfd_get_current_time in places where it is suitable
Nick Clifton [Mon, 2 Oct 2023 12:24:05 +0000 (13:24 +0100)] 
Use bfd_get_current_time in places where it is suitable

7 months agoAutomatic date update in version.in
GDB Administrator [Mon, 2 Oct 2023 00:00:41 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoAutomatic date update in version.in
GDB Administrator [Sun, 1 Oct 2023 00:00:30 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoAutomatic date update in version.in
GDB Administrator [Sat, 30 Sep 2023 00:00:28 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoSupport the NO_COLOR environment variable
Tom Tromey [Fri, 15 Sep 2023 23:24:26 +0000 (17:24 -0600)] 
Support the NO_COLOR environment variable

I ran across this site:

    https://no-color.org/

... which lobbies for tools to recognize the NO_COLOR environment
variable and disable any terminal styling when it is seen.

This patch implements this for gdb.

Regression tested on x86-64 Fedora 38.

Co-Authored-By: Andrew Burgess <aburgess@redhat.com>
Reviewed-by: Kevin Buettner <kevinb@redhat.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Andrew Burgess <aburgess@redhat.com>
7 months agotc-microblaze.c - int compare for X_add_number.
Neal Frager [Fri, 29 Sep 2023 15:45:46 +0000 (08:45 -0700)] 
tc-microblaze.c - int compare for X_add_number.

The range check should be checking for the range
ffffffff80000000..7fffffff, not ffffffff70000000.

This patch has been tested for years of AMD Xilinx Yocto
releases as part of the following patch set:

https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils

Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
7 months agobfd: microblaze: Fix bug in TLSTPREL Relocation
Neal Frager [Wed, 27 Sep 2023 12:49:18 +0000 (13:49 +0100)] 
bfd: microblaze: Fix bug in TLSTPREL Relocation

Fixed the problem related to the fixup/relocations TLSTPREL.
When the fixup is applied the addend is not added at the correct offset
of the instruction. The offset is hard coded considering its big endian
and it fails for Little endian. This patch allows support for both
big & little-endian compilers.

This patch has been tested for years of AMD Xilinx Yocto
releases as part of the following patch set:

https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils

Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
7 months agox86-64: Add -z mark-plt and -z nomark-plt
H.J. Lu [Tue, 1 Nov 2022 18:36:04 +0000 (11:36 -0700)] 
x86-64: Add -z mark-plt and -z nomark-plt

The PLT entry in executables and shared libraries contains an indirect
branch, like

  jmp *foo@GOTPCREL(%rip)
push $index_foo
jmp .PLT0

or

endbr64
  jmp *foo@GOTPCREL(%rip)
  NOP padding

which is used to branch to the function, foo, defined in another object.
Each R_X86_64_JUMP_SLOT relocation has a corresponding PLT entry.

The dynamic tags have been added to the x86-64 psABI to mark such PLT
entries:

https://gitlab.com/x86-psABIs/x86-64-ABI/-/commit/6d824a52a42d173eb838b879616c1be5870b593e

Add an x86-64 linker option, -z mark-plt, to mark PLT entries with

 #define DT_X86_64_PLT     (DT_LOPROC + 0)
 #define DT_X86_64_PLTSZ   (DT_LOPROC + 1)
 #define DT_X86_64_PLTENT  (DT_LOPROC + 3)

1. DT_X86_64_PLT: The address of the procedure linkage table.
2. DT_X86_64_PLTSZ: The total size, in bytes, of the procedure linkage
table.
3. DT_X86_64_PLTENT: The size, in bytes, of a procedure linkage table
entry.

and set the r_addend field of the R_X86_64_JUMP_SLOT relocation to the
memory offset of the indirect branch instruction.  The dynamic linker
can use these tags to update the PLT section to direct branch.

bfd/

* elf-linker-x86.h (elf_linker_x86_params): Add mark_plt.
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Set the
r_addend of R_X86_64_JUMP_SLOT to the indirect branch offset
in PLT entry for -z mark-plt.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Add
DT_X86_64_PLT, DT_X86_64_PLTSZ and DT_X86_64_PLTENT for
-z mark-plt.
(_bfd_x86_elf_finish_dynamic_sections): Set DT_X86_64_PLT,
DT_X86_64_PLTSZ and DT_X86_64_PLTENT.
(_bfd_x86_elf_get_synthetic_symtab): Ignore addend for
JUMP_SLOT relocation.
(_bfd_x86_elf_link_setup_gnu_properties): Set
plt_indirect_branch_offset.
* elfxx-x86.h (elf_x86_plt_layout): Add plt_indirect_branch_offset.

binutils/

* readelf.c (get_x86_64_dynamic_type): New function.
(get_dynamic_type): Call get_x86_64_dynamic_type.

include/

* elf/x86-64.h (DT_X86_64_PLT): New.
(DT_X86_64_PLTSZ): Likewise.
(DT_X86_64_PLTENT): Likewise.

ld/

* ld.texi: Document -z mark-plt and -z nomark-plt.
* emulparams/elf32_x86_64.sh: Source x86-64-plt.sh.
* emulparams/elf_x86_64.sh: Likewise.
* emulparams/x86-64-plt.sh: New file.
* testsuite/ld-x86-64/mark-plt-1.s: Likewise.
* testsuite/ld-x86-64/mark-plt-1a-x32.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1a.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1b-x32.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1b.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1c-x32.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1c.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1d-x32.d: Likewise.
* testsuite/ld-x86-64/mark-plt-1d.d: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run -z mark-plt tests.

7 months agoFix: Segmentation fault caused by npd in objdump
Nick Clifton [Fri, 29 Sep 2023 14:24:26 +0000 (15:24 +0100)] 
Fix: Segmentation fault caused by npd in objdump

  PR 30906
  * elf.c (_bfd_elf_slurp_version_tables): Test that the verref section header has been initialised before using it.

7 months agoUpdate README file's installation instructions
Nick Clifton [Fri, 29 Sep 2023 10:23:25 +0000 (11:23 +0100)] 
Update README file's installation instructions

7 months agogdb: add Sam James to MAINTAINERS
Sam James [Fri, 29 Sep 2023 04:35:36 +0000 (05:35 +0100)] 
gdb: add Sam James to MAINTAINERS

Acked-by: Tom de Vries <tdevries@suse.de>
7 months agogdb/testsuite: Add relative versus absolute LD_LIBRARY_PATH test
Kevin Buettner [Fri, 22 Sep 2023 00:58:05 +0000 (17:58 -0700)] 
gdb/testsuite: Add relative versus absolute LD_LIBRARY_PATH test

At one time, circa 2006, there was a bug, which was presumably fixed
without adding a test case:

    If you provided some relative path to the shared library, such as
    with

export LD_LIBRARY_PATH=.

    then gdb would fail to match the shared library name during the
    TLS lookup.

I think there may have been a bit more to it than is provided by that
explanation, since the test also takes care to split the debug info
into a separate file.

In any case, this commit is based on one of Red Hat's really old
local patches.  I've attempted to update it and remove a fair amount
of cruft, hopefully without losing any critical elements from the
test.

Testing on Fedora 38 (correctly) shows 1 unsupported test for
native-gdbserver and 5 PASSes for the native target as well as
native-extended-gdbserver.

In his review of v1 of this patch, Lancelot SIX observed that
'thread_local' could be used in place of '__thread' in the C source
files.  But it only became available via the standard in C11, so I
used additional_flags=-std=c11 for compiling both the shared object
and the main program.

Also, while testing with CC_FOR_TARGET=clang, I found that
'additional_flags=-Wl,-soname=${binsharedbase}' caused clang
to complain that this linker flag was unused when compiling
the source file, so I moved this linker option to 'ldflags='.

My testing for this v2 patch shows the same results as with v1,
but I've done additional testing with CC_FOR_TARGET=clang as
well.  The results are the same as when gcc is used.

Co-Authored-by: Jan Kratochvil <jan@jankratochvil.net>
Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agogdb: remove nbsd_{ilp32,lp64}_solib_svr4_fetch_link_map_offsets
Simon Marchi [Thu, 28 Sep 2023 17:47:46 +0000 (13:47 -0400)] 
gdb: remove nbsd_{ilp32,lp64}_solib_svr4_fetch_link_map_offsets

They are unused.

Change-Id: I9b78837d41126ce1957aa1e8b08c82a422f06cbf
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
7 months agogdb: remove unused imports in solib*.[ch]
Simon Marchi [Thu, 28 Sep 2023 17:47:45 +0000 (13:47 -0400)] 
gdb: remove unused imports in solib*.[ch]

I'm starting to work on these files, I thought it would be a good time
to remove unused imports.  These were identified by
include-what-you-use.  Tested by rebuilding.

Change-Id: I3eaf3fa0ea3506c7ecfbc8ecff5031433b1dadb8
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
7 months agoAutomatic date update in version.in
GDB Administrator [Fri, 29 Sep 2023 00:00:25 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoAdded support in gas for mlittle-endian and mbig-endian flags as options.
Michael J. Eager [Thu, 28 Sep 2023 20:08:49 +0000 (13:08 -0700)] 
Added support in gas for mlittle-endian and mbig-endian flags as options.

Updated show usage for MicroBlaze specific assembler options
to include new entries.

This patch has been tested for years of AMD Xilinx Yocto
releases as part of the following patch set:

https://github.com/Xilinx/meta-xilinx/tree/master/meta-microblaze/recipes-devtools/binutils/binutils

Signed-off-by: nagaraju <nagaraju.mekala@amd.com>
Signed-off-by: Neal Frager <neal.frager@amd.com>
---
V1->V2:
 - removed new options which were unnecessary
 - added documentation for MicroBlaze specific options

Signed-off-by: Michael J. Eager <eager@eagercon.com>
7 months ago[gdb/tui] Fix segfault in tui_find_disassembly_address
Tom de Vries [Thu, 28 Sep 2023 18:17:33 +0000 (20:17 +0200)] 
[gdb/tui] Fix segfault in tui_find_disassembly_address

PR29040 describes a FAIL for test-case gdb.threads/next-fork-other-thread.exp
and target board unix/-m32.

The FAIL happens due to the test executable running into an assert, which is
caused by a forked child segfaulting, like so:
...
 Program terminated with signal SIGSEGV, Segmentation fault.
 #0  0x00000000 in ?? ()
...

I tried to reproduce the segfault with exec next-fork-other-thread-fork, using
TUI layout asm.

I set a breakpoint at fork and ran to the breakpoint, and somewhere during the
following session I ran into a gdb segfault here in
tui_find_disassembly_address:
...
  /* Disassemble forward.  */
  next_addr = tui_disassemble (gdbarch, asm_lines, new_low, max_lines);
  last_addr = asm_lines.back ().addr;
...
due to asm_lines being empty after the call to tui_disassemble, while
asm_lines.back () assumes that it's not empty.

I have not been able to reproduce that segfault in that original setting, I'm
not sure of the exact scenario (though looking back it probably involved
"set detach-on-fork off").

What likely happened is that I managed to reproduce PR29040, and TUI (attempted
to) display the disassembly for address 0, which led to the gdb segfault.

When gdb_print_insn encounters an insn it cannot print because it can't read
the memory, it throws a MEMORY_ERROR that is caught by tui_disassemble.

The specific bit that causes the gdb segfault is that if gdb_print_insn throws
a MEMORY_ERROR for the first insn in tui_disassemble, it returns an empty
asm_lines.

FWIW, I did manage to reproduce the gdb segfault as follows:
...
$ gdb -q \
    -iex "set pagination off" \
    /usr/bin/rustc \
    -ex "set breakpoint pending on" \
    -ex "b dl_main" \
    -ex run \
    -ex "up 4" \
    -ex "layout asm" \
    -ex "print \$pc"
  ...
<TUI>
  ...
$1 = (void (*)()) 0x1
(gdb)
...
Now press <up>, and the segfault triggers.

Fix the segfault by handling asm_lines.empty () results of tui_disassemble in
tui_find_disassembly_address.

I've written a unit test that exercises this scenario.

Tested on x86_64-linux.

Reviewed-by: Kevin Buettner <kevinb@redhat.com>
PR tui/30823
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30823

7 months agoRemove old gdb_bfd_openr_iovec
Tom Tromey [Thu, 24 Aug 2023 15:25:10 +0000 (09:25 -0600)] 
Remove old gdb_bfd_openr_iovec

This removes the old gdb_bfd_openr_iovec entirely.  I think any new
code should use the type-safe approach.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agoConvert solib-rocm to new type-safe gdb_bfd_openr_iovec
Tom Tromey [Thu, 24 Aug 2023 15:23:46 +0000 (09:23 -0600)] 
Convert solib-rocm to new type-safe gdb_bfd_openr_iovec

This converts the solib-rocm BFD iovec implementations to the new
type-safe gdb_bfd_openr_iovec.  They were already essentially using
this approach, just without the type-safe wrapper.

Thanks to Lancelot Six for testing and fixing this patch.

Co-Authored-By: Lancelot Six <lancelot.six@amd.com>
Acked-by: Lancelot Six <lancelot.six@amd.com>
Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agoConvert minidebug to new type-safe gdb_bfd_openr_iovec
Tom Tromey [Thu, 24 Aug 2023 15:16:43 +0000 (09:16 -0600)] 
Convert minidebug to new type-safe gdb_bfd_openr_iovec

This converts the minidebug BFD iovec implementation to the new
type-safe gdb_bfd_openr_iovec.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agoConvert target fileio to new type-safe gdb_bfd_openr_iovec
Tom Tromey [Thu, 24 Aug 2023 15:11:16 +0000 (09:11 -0600)] 
Convert target fileio to new type-safe gdb_bfd_openr_iovec

This converts the target fileio BFD iovec implementation to use the
new type-safe gdb_bfd_openr_iovec.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agoConvert mem_bfd_iovec to new type-safe gdb_bfd_openr_iovec
Tom Tromey [Thu, 24 Aug 2023 14:59:14 +0000 (08:59 -0600)] 
Convert mem_bfd_iovec to new type-safe gdb_bfd_openr_iovec

This converts the mem_bfd_iovec / target_buffer code to use the new
type-safe gdb_bfd_openr_iovec.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agoSmall constructor change to target_buffer
Tom Tromey [Thu, 24 Aug 2023 14:53:30 +0000 (08:53 -0600)] 
Small constructor change to target_buffer

This changes the target_buffer constructor to initialize m_filename
rather than assign to it.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agoIntroduce type-safe variant of gdb_bfd_openr_iovec
Tom Tromey [Thu, 24 Aug 2023 14:47:54 +0000 (08:47 -0600)] 
Introduce type-safe variant of gdb_bfd_openr_iovec

This patch adds a new, type-safe variant of gdb_bfd_openr_iovec.  In
this approach, the underlying user data is simply an object, the
callbacks are methods, and the "open" function is a function view.
Nothing uses this new code yet.

Reviewed-By: Lancelot Six <lancelot.six@amd.com>
7 months agogdb: use reopen_exec_file from reread_symbols
Andrew Burgess [Fri, 15 Sep 2023 17:40:21 +0000 (18:40 +0100)] 
gdb: use reopen_exec_file from reread_symbols

This commit fixes an issue that was discovered while writing the tests
for the previous commit.

I noticed that, when GDB restarts an inferior, the executable_changed
event would trigger twice.  The first notification would originate
from:

  #0  exec_file_attach (filename=0x4046680 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513
  #1  0x00000000006f3adb in reopen_exec_file () at ../../src/gdb/corefile.c:122
  #2  0x0000000000e6a3f2 in generic_mourn_inferior () at ../../src/gdb/target.c:3682
  #3  0x0000000000995121 in inf_child_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/inf-child.c:192
  #4  0x0000000000995cff in inf_ptrace_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/inf-ptrace.c:125
  #5  0x0000000000a32472 in linux_nat_target::mourn_inferior (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/linux-nat.c:3609
  #6  0x0000000000e68a40 in target_mourn_inferior (ptid=...) at ../../src/gdb/target.c:2761
  #7  0x0000000000a323ec in linux_nat_target::kill (this=0x2fe95c0 <the_amd64_linux_nat_target>) at ../../src/gdb/linux-nat.c:3593
  #8  0x0000000000e64d1c in target_kill () at ../../src/gdb/target.c:924
  #9  0x00000000009a19bc in kill_if_already_running (from_tty=1) at ../../src/gdb/infcmd.c:328
  #10 0x00000000009a1a6f in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:381
  #11 0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527
  #12 0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95

While the second originates from:

  #0  exec_file_attach (filename=0x3d7a1d0 "/tmp/hello.x", from_tty=0) at ../../src/gdb/exec.c:513
  #1  0x0000000000dfe525 in reread_symbols (from_tty=1) at ../../src/gdb/symfile.c:2517
  #2  0x00000000009a1a98 in run_command_1 (args=0x0, from_tty=1, run_how=RUN_STOP_AT_MAIN) at ../../src/gdb/infcmd.c:398
  #3  0x00000000009a20a5 in start_command (args=0x0, from_tty=1) at ../../src/gdb/infcmd.c:527
  #4  0x000000000068dc5d in do_simple_func (args=0x0, from_tty=1, c=0x35c7200) at ../../src/gdb/cli/cli-decode.c:95

In the first case the call to exec_file_attach first passes through
reopen_exec_file.  The reopen_exec_file performs a modification time
check on the executable file, and only calls exec_file_attach if the
executable has changed on disk since it was last loaded.

However, in the second case things work a little differently.  In this
case GDB is really trying to reread the debug symbol.  As such, we
iterate over the objfiles list, and for each of those we check the
modification time, if the file on disk has changed then we reload the
debug symbols from that file.

However, there is an additional check, if the objfile has the same
name as the executable then we will call exec_file_attach, but we do
so without checking the cached modification time that indicates when
the executable was last reloaded, as a result, we reload the
executable twice.

In this commit I propose that reread_symbols be changed to
unconditionally call reopen_exec_file before performing the objfile
iteration.  This will ensure that, if the executable has changed, then
the executable will be reloaded, however, if the executable has
already been recently reloaded, we will not reload it for a second
time.

After handling the executable, GDB can then iterate over the objfiles
list and reload them in the normal way.

With this done I now see the executable reloaded only once when GDB
restarts an inferior, which means I can remove the kfail that I added
to the gdb.python/py-exec-file.exp test in the previous commit.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb/python: make the executable_changed event available from Python
Andrew Burgess [Mon, 28 Aug 2023 15:22:36 +0000 (16:22 +0100)] 
gdb/python: make the executable_changed event available from Python

This commit makes the executable_changed observable available through
the Python API as an event.  There's nothing particularly interesting
going on here, it just follows the same pattern as many of the other
Python events we support.

The new event registry is called events.executable_changed, and this
emits an ExecutableChangedEvent object which has two attributes, a
gdb.Progspace called 'progspace', this is the program space in which
the executable changed, and a Boolean called 'reload', which is True
if the same executable changed on disk and has been reloaded, or is
False when a new executable has been loaded.

One interesting thing did come up during testing though, you'll notice
the test contains a setup_kfail call.  During testing I observed that
the executable_changed event would trigger twice when GDB restarted an
inferior.  However, the ExecutableChangedEvent object is identical for
both calls, so the wrong information is never sent out, we just see
one too many events.

I tracked this down to how the reload_symbols function (symfile.c)
takes care to also reload the executable, however, I've split fixing
this into a separate commit, so see the next commit for details.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: pass more arguments to the executable_changed observer
Andrew Burgess [Fri, 8 Sep 2023 15:02:13 +0000 (16:02 +0100)] 
gdb: pass more arguments to the executable_changed observer

This commit continues the work of the previous few commits.

My goal is to expose the executable_changed observer through the
Python API as an event.

At this point adding executable_changed as an event to the Python API
is trivial, but before I do that I would like to add some additional
arguments to the observable, which currently has no arguments at all.

The new arguments I wish to add are:

 1. The program_space in which the executable was changed, and

 2. A boolean flag that will indicate if the executable changed to a
 whole new path, or if GDB just spotted that the executable changed on
 disk (e.g. the user recompiled the executable).

In this commit I change the signature of the observable and then pass
the arguments through at the one place where this observable is
notified.

As there are (currently) no users of this observable nothing else
needs updating.  In the next commit I'll add a listener for this
observable in the Python code, and expose this as an event in the
Python API.

Additionally, with this change, it should be possible to update the
insight debugger to make use of this observable rather than using the
deprecated_exec_file_display_hook (as it currently does), which will
then allow this hook to be removed from GDB.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: remove unnecessary notification of executable_changed observer
Andrew Burgess [Fri, 8 Sep 2023 14:50:19 +0000 (15:50 +0100)] 
gdb: remove unnecessary notification of executable_changed observer

This commit continues the work of the previous two commits.

My goal, in the next couple of commits, is to expose the
executable_changed observable in the Python API as an event.  However,
before I do that I want to remove the use of the executable_changed
observable from the reread_symbols function in symfile.c as this use
isn't directly associated with a change of the executable file, and so
seems wrong.

In the previous two commits I have removed all users of the
executable_changed observer as I believe those users can, and should,
actually be listening for the new_objfile observable instead, so now
there are no users of the executable_changed observable.

As such, I think removing the use of executable_changed from the
function reread_symbols is perfectly safe, and correct.  At this point
the executable has not been changed, so we shouldn't be sending an
executable_changed notification, and, as there is nobody listening to
this observable, we can't break anything by removing this call.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: remove final user of the executable_changed observer
Andrew Burgess [Fri, 8 Sep 2023 14:48:16 +0000 (15:48 +0100)] 
gdb: remove final user of the executable_changed observer

This commit continues with the task started in the previous commit,
and is similar in many ways.

The goal of the next couple of commits is to expose the
executable_changed observable in the Python API as an event.  Before I
do this I would like to remove the additional call to the
executable_changed observable which can be found in the reread_symbols
function in the symfile.c file, as I don't believe that this use
actually corresponds to a change in the current executable.

The previous commit removed one user of the executable_changed
observable and replaced it with a new_obfile observer instead, and
this commit does the same thing.

In auxv.c we use the executable_changed observable to call
invalidate_auxv_cache, which then calls:

  invalidate_auxv_cache_inf (current_inferior ());

The auxv cache is already (additionally) cleared when an inferior
exits and when an inferior appears.

As with the previous commit, I think we can safely replace the use of
the executable_changed observable with a use of the new_obfile
observable.  All the tests still pass, and with some locally placed
printf calls, I think that the cache is still being cleared in all the
cases that should matter.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb: remove one user of the executable changed observer
Andrew Burgess [Fri, 8 Sep 2023 14:44:40 +0000 (15:44 +0100)] 
gdb: remove one user of the executable changed observer

My goal for the next few commits is to expose the executable_changed
observable from the Python API.

However, there is call to the executable_changed observable in the
reread_symbols function (in symfile.c), and this doesn't actually
correspond to the executable changing.  My idea then, is to remove
this use of the executable_changed observable, but, before I can do
that, I need to check that nothing is going to break, and that
requires my to think about the current users of this observable.

One current user of executable_changed is in symtab.c.  We add an
executable_changed observer that calls:

  set_main_name (nullptr, language_unknown);

to discard all information about the main function when the executable
changes.

However, changing the executable doesn't actually change the debug
information.  The debug information changes when the symbol-file
changes, so I think this observer is in slightly the wrong place.

The new_objfile observable is (unfortunately) overloaded, it is called
when a new objfile is loaded, and also (when its argument is nullptr),
when all debug information should be discarded.

It turns out that there is already a new_objfile observer in
symtab.c.  I propose that, when the argument is nullptr (indicating
all debug info should be discarded), that we should call set_main_name
to discard the information about the main function.  We can then
remove the executable_changed observer from symtab.c.

All tests still pass, and, in my local world, I added some debug
printf calls, and I think we are still discarded the main information
everywhere we need to.

Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb/python: new Progspace.executable_filename attribute
Andrew Burgess [Thu, 7 Sep 2023 14:47:07 +0000 (15:47 +0100)] 
gdb/python: new Progspace.executable_filename attribute

Add a new Progspace.executable_filename attribute that contains the
path to the executable for this program space, or None if no
executable is set.

The path within this attribute will be set by the "exec-file" and/or
"file" commands.

Accessing this attribute for an invalid program space will raise an
exception.

This new attribute is similar too, but not the same as the existing
gdb.Progspace.filename attribute.  If I could change the past, I'd
change the 'filename' attribute to 'symbol_filename', which is what it
actually represents.  The old attribute will be set by the
'symbol-file' command, while the new attribute is set by the
'exec-file' command.  Obviously the 'file' command sets both of these
attributes.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb/python: new Progspace.symbol_file attribute
Andrew Burgess [Thu, 7 Sep 2023 10:18:16 +0000 (11:18 +0100)] 
gdb/python: new Progspace.symbol_file attribute

Add a new Progspace.symbol_file attribute.  This attribute holds the
gdb.Objfile object that corresponds to Progspace.filename, or None if
there is no main symbol file currently set.

Currently, to get this gdb.Objfile, a user would need to use
Progspace.objfiles, and then search for the objfile with a name that
matches Progspace.filename -- which should work just fine, but having
direct access seems a little nicer.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb/doc: extend the description for Progspace.filename
Andrew Burgess [Mon, 28 Aug 2023 15:58:12 +0000 (16:58 +0100)] 
gdb/doc: extend the description for Progspace.filename

Extend the description for Progspace.filename in the documentation to
mention what the returned string is actually the filename
for (e.g. that it is the filename passed to the 'symbol-file' or
'file' command).

Also document that this attribute will be None if no symbol file is
currently loaded.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
7 months agogdb/x86: use size of XSAVE area of enabled features
Simon Marchi [Wed, 27 Sep 2023 16:15:22 +0000 (12:15 -0400)] 
gdb/x86: use size of XSAVE area of enabled features

Since commit b42405a1594 ("gdb: Update x86 Linux architectures to
support XSAVE layouts."), the test gdb.base/gcore.exp fails on my AMD
Ryzen 3700X machine:

    FAIL: gdb.base/gcore.exp: corefile restored all registers

The test gets the register state (saves the output of "info
all-registers"), saves a core with the "gcore" command, loads the core,
and checks the register state against the one previously saved.  The
problem is that when reading registers from the core file, the last half
of ymm registers is unavailable:

    (gdb) print $ymm0.v32_int8
    $1 = {0, -77, -23, -9, -1, 127, 0, 0, 0, -77, -23, -9, -1, 127, 0, 0, <unavailable> <repeats 16 times>}

One strange thing with this machine is that the bitset of state
components supported by XCR0 is 0x207, meaning "x87 | SSE | AVX | PKRU",
but XCR0 at runtime is 0x7, meaning "x87 | SSE | AVX".  So, PKRU appears
to be supported by the processor, but disabled by the kernel.  I didn't
find why yet.

From CPUID leaf EAX=0Dh, ECX=00h, GDB can get:

 - from EBX: max size of the XSAVE area required by features currently
   enabled in XCR0.  On my machine, it's 0x340 (832).
 - from ECX: max size of the XSAVE area required by all features
   supported by XCR0.  On my machine, it's 0x380 (896).

At runtime, GDB uses ECX (max size required by all supported features)
to fill the x86_xsave_layout::sizeof_xsave.  So, when writing the core
file note for the XSAVE state, it writes a note of size 896, even though
it doesn't write the PKRU state.  When loading back the core, GDB tries
to figure out the layout of the XSAVE area based on what features are
enabled in XCR0 and the size of the note (the size of the XSAVE area).
Since my combination of XCR0 and size of XSAVE area doesn't match any
combination known by GDB, GDB falls back to a gdbarch supporting only
x87 and SSE.

This patch changes GDB to populate the x86_xsave_layout::sizeof_xsave
field (and consequently the size of the XSAVE state note in core files)
using EBX, the size of the XSAVE area required by currently enabled
features in XCR0.  This makes i387_guess_xsave_layout recognize my case
with this condition:

  else if (HAS_AVX (xcr0) && xsave_size == 832)
    {
      /* Intel and AMD CPUs supporting AVX.  */
      layout.avx_offset = 576;
    }

In other words, just as if my machine didn't support PKRU at all.

Another reason why I think this change makes sense is that XSAVE state
notes in kernel-generated cores on this machine have size 832.  So this
change makes GDB-generated cores more similar to kernel-generated ones,
reducing the diversity of XSAVE state notes that GDB needs to be able to
figure out.

Note that if PKRU was enabled on my machine, then the effective XSAVE
area size would be 896 bytes.  We would need to add a case in
i387_guess_xsave_layout for that combination, since there is no
currently.  But I don't have a way to test that right now, since I don't
know why PKRU is disabled.

Relevant review note from John Baldwin:

  One further note is that the Linux x86 arches use x86_xsave_length()
  to infer ("guess") the size of the XSAVE register set that the Linux
  kernel writes out in core dumps.  On FreeBSD x86 arches, GDB is able
  to query this size directly from the kernel via ptrace.  My use of ECX
  for this guess earlier was just not the best guess.  In the case that
  the kernel enables all of the available features, then ECX and EBX
  have the same values, so this only matters for a system where the
  kernel has enabled a subset of available XSAVE extensions.

Change-Id: If64f30307f3a2e5ca3e1fd1cb7379ea840805a85
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
7 months agoAdd support to readelf for the PT_OPENBSD_NOBTCFI segment type.
Frederic Cambus [Thu, 28 Sep 2023 12:39:01 +0000 (13:39 +0100)] 
Add support to readelf for the PT_OPENBSD_NOBTCFI segment type.

7 months agoFix: nm: SEGV on unknow address at nm.c:718 in print_symname
Nick Clifton [Thu, 28 Sep 2023 11:37:59 +0000 (12:37 +0100)] 
Fix: nm: SEGV on unknow address at nm.c:718 in print_symname

  PR 30886 * elf-bfd.h (struct elf_obj_tdata): Add dt_strsz field.
  * elf.c (_bfd_elf_get_dynamic_symbols): Add a NUL byte at the end of the string table. Initialise the dt_strsz field. (_bfd_elf_slurp_version_tables): Only free the contents if they were malloc'ed. Add checks before setting string pointers in the dt_strtab buffer.

7 months ago[gdb/testsuite] Add nopie to gdb.base/unwind-on-each-insn-amd64-2.exp
Tom de Vries [Thu, 28 Sep 2023 07:47:36 +0000 (09:47 +0200)] 
[gdb/testsuite] Add nopie to gdb.base/unwind-on-each-insn-amd64-2.exp

When running test-case gdb.base/unwind-on-each-insn-amd64-2.exp with target
board unix/-fPIE/-pie, I run into:
...
gdb compile failed, ld: unwind-on-each-insn-amd64-21.o: relocation \
  R_X86_64_32S against `.text' can not be used when making a PIE object; \
  recompile with -fPIE
ld: failed to set dynamic section sizes: bad value
...

Fix this by hardcoding nopie in the test-case, and for good measure in the
other test-cases that source unwind-on-each-insn.exp.tcl and use a .s file.

Tested on x86_64-linux.

Approved-by: Kevin Buettner <kevinb@redhat.com>
7 months agoAutomatic date update in version.in
GDB Administrator [Thu, 28 Sep 2023 00:00:33 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoconfig/debuginfod.m4: Add check for libdebuginfod 0.188
Aaron Merey [Wed, 27 Sep 2023 19:11:13 +0000 (15:11 -0400)] 
config/debuginfod.m4: Add check for libdebuginfod 0.188

Add check for libdebuginfod 0.188 in AC_DEBUGINFOD and if found
define macro HAVE_LIBDEBUGINFOD_FIND_SECTION.

This macro indicates support for downloading ELF sections from
debuginfod servers.

7 months agonm: heap-buffer-overflow at elfcode.h:1507 in bfd_elf64_slurp_symbol_table
Nick Clifton [Wed, 27 Sep 2023 15:09:06 +0000 (16:09 +0100)] 
nm: heap-buffer-overflow at elfcode.h:1507 in bfd_elf64_slurp_symbol_table

  PR 30885
  * elfcode.h (elf_slurp_symbol_table): Compute the symcount for non dynamic symbols in the same way as _bfd_elf_get_symtab_upper_bound.

7 months agox86: prefer VEX encodings over EVEX ones when possible
Jan Beulich [Wed, 27 Sep 2023 14:53:09 +0000 (16:53 +0200)] 
x86: prefer VEX encodings over EVEX ones when possible

AVX-* features / insns paralleling earlier introduced AVX512* ones can
be encoded more compactly when the respective feature was explicitly
enabled by the user.

7 months agox86: drop cpu_arch_tune_flags
Jan Beulich [Wed, 27 Sep 2023 14:52:08 +0000 (16:52 +0200)] 
x86: drop cpu_arch_tune_flags

Apparently from its introduction the variable was only ever written (the
only read is merely to determine whether to write it with another value).
(Since, due to the need to re-indent, the adjacent lines setting
cpu_arch_tune need touching anyway, switch to using PREOCESSOR_*
constants where applicable, to make more obvious what the resulting
state is going to be.)

7 months agox86: correct cpu_arch_isa_flags maintenance
Jan Beulich [Wed, 27 Sep 2023 14:51:46 +0000 (16:51 +0200)] 
x86: correct cpu_arch_isa_flags maintenance

These may not be set from a value derived from cpu_arch_flags: That
starts with (almost) all functionality enabled, while cpu_arch_isa_flags
is supposed to track features that were explicitly enabled (and perhaps
later disabled) by the user.

To avoid needing to do any such adjustment in two places (each),
introduce helper functions used by both command line handling and
directive processing.