]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
2 months agoThis commit adds record full support for rv64gc instruction set
Timur [Tue, 18 Mar 2025 18:49:44 +0000 (21:49 +0300)] 
This commit adds record full support for rv64gc instruction set

It includes changes to the following files:
- gdb/riscv-linux-tdep.c, gdb/riscv-linux-tdep.h: adds facilities to record
syscalls.
- gdb/riscv-tdep.c, gdb/riscv-tdep.h: adds facilities to record execution of
rv64gc instructions.
- gdb/configure.tgt: adds new files for compilation.
- gdb/testsuite/lib/gdb.exp: enables testing of full record mode for RISC-V
targets.
- gdb/syscalls/riscv-canonicalize-syscall-gen.py: a script to generate
function that canonicalizes RISC-V syscall. This script can simplify support
for syscalls on rv32 and rv64 system (currently support only for rv64).  To
use this script you need to pass a path to a file with syscalls description
from riscv-glibc (example is in the help message). The script produces a
mapping from syscall names to gdb_syscall enum.
- gdb/riscv-canonicalize-syscall.c: the file generated by the previous script.
- gdb/doc/gdb.texinfo: notification that record mode is enabled in RISC-V.
- gdb/NEWS: notification of new functionality.

Approved-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2 months agogdb: fix bashism in configure.ac
Sam James [Wed, 23 Apr 2025 09:57:00 +0000 (10:57 +0100)] 
gdb: fix bashism in configure.ac

Use '=', not '==', as configure has a #!/bin/sh shebang and must work
with non-bash shells.

Fixes: c4375bc51c861dfa384a01bdb2e460e115710bf9
2 months ago[gdb/testsuite] Add selftest disassemble-s390x
Tom de Vries [Wed, 23 Apr 2025 09:02:53 +0000 (11:02 +0200)] 
[gdb/testsuite] Add selftest disassemble-s390x

In commit a98a6fa2d8e ("s390: Add arch15 instructions"), support for
new instructions was added to libopcodes, but the added tests only exercise
this for gas.

Add a unit test disassemble-s390x that checks gdb's ability to
disassemble one of these instructions:
...
$ gdb -q -batch -ex "maint selftest -v disassemble-s390x"
Running selftest disassemble-s390x.
0xb9 0x68 0x00 0x03 -> clzg %r0,%r3
Ran 1 unit tests, 0 failed
...

Tested on x86_64-linux and s390x-linux.

2 months ago[gdb/testsuite] Update regexp in gdb.debuginfod/fetch_src_and_symbols.exp
Tom de Vries [Wed, 23 Apr 2025 08:07:28 +0000 (10:07 +0200)] 
[gdb/testsuite] Update regexp in gdb.debuginfod/fetch_src_and_symbols.exp

Since commit 7b80401da00 ("Handle DWARF 5 separate debug sections"), test-case
gdb.debuginfod/fetch_src_and_symbols.exp fails here:
...
(gdb) file fetch_src_and_symbols_alt.o^M
Reading symbols from fetch_src_and_symbols_alt.o...^M
warning: could not find supplementary DWARF file \
  (fetch_src_and_symbols_dwz.o) for fetch_src_and_symbols_alt.o^M
(gdb) FAIL: $exp: no_url: file fetch_src_and_symbols_alt.o
...
because this is expected:
...
(gdb) file fetch_src_and_symbols_alt.o^M
Reading symbols from fetch_src_and_symbols_alt.o...^M
warning: could not find '.gnu_debugaltlink' file for \
  fetch_src_and_symbols_alt.o^M
(gdb) PASS: $exp: no_url: file fetch_src_and_symbols_alt.o
...

Fix this by updating the regexp.

Tested on x86_64-linux.

2 months agoLoongArch: Add test for divide by zero in instructions
Lulu Cai [Mon, 21 Apr 2025 02:47:43 +0000 (10:47 +0800)] 
LoongArch: Add test for divide by zero in instructions

Added tests for division/modulo by zero for instruction expressions.

2 months agostring merge section map output
Alan Modra [Wed, 23 Apr 2025 01:20:18 +0000 (10:50 +0930)] 
string merge section map output

This fixes an inconsistency in the linker map file, where string merge
sections (other than the first) kept their sizes.  String merge
sections of like entsize all are accounted in the fisrt string merge
section size.

* ldlang.c (print_input_section): Print SEC_EXCLUDE section size
as zero.

2 months agoAutomatic date update in version.in
GDB Administrator [Wed, 23 Apr 2025 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoPR 32603 followup, remove %F from einfo
Alan Modra [Tue, 22 Apr 2025 03:06:47 +0000 (12:36 +0930)] 
PR 32603 followup, remove %F from einfo

No uses of %F remain.

* ldmisc.c (vfinfo): Remove %F handling.

2 months agoAdd "-5" flag to cc-with-tweaks
Tom Tromey [Sun, 23 Mar 2025 16:21:25 +0000 (10:21 -0600)] 
Add "-5" flag to cc-with-tweaks

This adds a "-5" flag to cc-with-tweaks, mirroring dwz's "-5" flag,
and also adds a new cc-with-dwz-5 target board.

The "-5" flag tells dwz to use the DWARF 5 .debug_sup section in
multi-file mode.

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

2 months agoHandle DWARF 5 separate debug sections
Tom Tromey [Wed, 19 Mar 2025 20:47:29 +0000 (14:47 -0600)] 
Handle DWARF 5 separate debug sections

DWARF 5 standardized the .gnu_debugaltlink section that dwz emits in
multi-file mode.  This is handled via some new forms, and a new
.debug_sup section.

This patch adds support for this to gdb.  It is largely
straightforward, I think, though one oddity is that I chose not to
have this code search the system build-id directories for the
supplementary file.  My feeling was that, while it makes sense for a
distro to unify the build-id concept with the hash stored in the
.debug_sup section, there's no intrinsic need to do so.

This in turn means that a few tests -- for example those that test the
index cache -- will not work in this mode.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32808
Acked-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoRemove 'read' call from dwz_file::read_string
Tom Tromey [Sat, 22 Mar 2025 16:39:43 +0000 (10:39 -0600)] 
Remove 'read' call from dwz_file::read_string

dwz_file::read_string calls 'read' on the section, but this isn't
needed as the sections have all been pre-read.

This patch makes this change, and refactors dwz_file a bit to make
this more obvious -- by making it clear that only the "static
constructor" can create a dwz_file.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2 months agogdb/testsuite: fix incorrect comment in py-color.exp
Andrew Burgess [Tue, 22 Apr 2025 18:45:57 +0000 (19:45 +0100)] 
gdb/testsuite: fix incorrect comment in py-color.exp

There was a comment in gdb.python/py-color.exp that was probably left
over from a copy & paste, it incorrectly described what the test
script was testing.

Fixed in this commit.

There's no change in what is tested with this commit.

2 months agogdb/python: address some coding style issues in py-color.c
Andrew Burgess [Sat, 19 Apr 2025 21:33:32 +0000 (22:33 +0100)] 
gdb/python: address some coding style issues in py-color.c

A few minor GNU/GDB coding style issues in py-color.c:

  - Space after '&' reference operator in one place.
  - Some excessive indentation on a couple of lines.
  - Spaces after '!' logical negation operator.
  - Using a pointer as a bool in a couple of places.

There should be no functional changes after this commit.

2 months agogdb/python: remove stray white space in error message
Andrew Burgess [Sat, 19 Apr 2025 21:03:15 +0000 (22:03 +0100)] 
gdb/python: remove stray white space in error message

Spotted a stray white space at the end of an error message.  Removed,
and updated the py-breakpoint.exp test to check this case.

2 months agogdb/doc: use @samp{} in Python docs
Andrew Burgess [Tue, 22 Apr 2025 16:32:53 +0000 (17:32 +0100)] 
gdb/doc: use @samp{} in Python docs

In this review:

  https://inbox.sourceware.org/gdb-patches/86sem6ase5.fsf@gnu.org

it was pointed out that I should use @samp{} around some text I was
adding to the documentation.  However, the offending snippet of
documentation was something I copied from elsewhere in python.texi.
This commit fixes the original to use @samp{}.

2 months agogdb/python: fix memory leak of gdb.Color objects
Andrew Burgess [Fri, 18 Apr 2025 21:42:17 +0000 (22:42 +0100)] 
gdb/python: fix memory leak of gdb.Color objects

I noticed that this commit:

  commit 6447969d0ac774b6dec0f95a0d3d27c27d158690
  Date:   Sat Oct 5 22:27:44 2024 +0300

      Add an option with a color type.

has an unnecessary `Py_INCREF (self);` in gdb.Color.__init__.  This
means that the reference count on all gdb.Color objects (that pass
through __init__) will be +1 from where they should normally be, and
this will stop the gdb.Color objects from being deallocated.

Fix by removing the Py_INCREF call.

Add a test which exposes the memory leak.

Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/python: restructure the existing memory leak tests
Andrew Burgess [Sat, 19 Apr 2025 13:41:17 +0000 (14:41 +0100)] 
gdb/python: restructure the existing memory leak tests

We currently have two memory leak tests in gdb.python/ and there's a
lot of duplication between these two.

In the next commit I'd like to add yet another memory leak test, which
would mean a third set of scripts which duplicate the existing two.
And three is where I draw the line.

This commit factors out the core of the memory leak tests into a new
module gdb_leak_detector.py, which can then be imported by each
tests's Python file in order to make writing the memory leak tests
easier.

I've also added a helper function to lib/gdb-python.exp which captures
some of the common steps needed in the TCL file in order to run a
memory leak test.

Finally, I use this new infrastructure to rewrite the two existing
memory leak tests.

What I considered, but ultimately didn't do, is merge the two memory
leak tests into a single TCL script.  I did consider this, and for the
existing tests this would be possible, but future tests might require
different enough setup that this might not be possible for all future
tests, and now that we have helper functions in a central location,
the each individual test is actually pretty small now, so leaving them
separate seemed OK.

There should be no change in what is actually being tested after this
commit.

Approved-By: Tom Tromey <tom@tromey.com>
2 months agoRemove ui_file::reset_style
Tom Tromey [Wed, 9 Apr 2025 23:34:10 +0000 (17:34 -0600)] 
Remove ui_file::reset_style

ui_file::reset_style doesn't seem to be needed.  This patch removes
it.  Regression tested on x86-64 Fedora 40.

2 months agogdb: fix ui-style regex initializing order
ZENG Hao [Fri, 18 Apr 2025 22:41:28 +0000 (06:41 +0800)] 
gdb: fix ui-style regex initializing order

This fixes a crash on Windows NT 4.0, where windows-nat failed dynamic loading
some Win32 functions and print a warning message with styled string, which
depends on ui-style regex. By using `compiled_regex` constructor, the regex is
guaranteed to be initialized before `_initialize_xxx` functions.

Approved-By: Tom Tromey <tom@tromey.com>
2 months agogas: sframe: Fix typo in comment on SFrame identifier
Jens Remus [Tue, 22 Apr 2025 13:48:28 +0000 (15:48 +0200)] 
gas: sframe: Fix typo in comment on SFrame identifier

gas/config/
* tc-aarch64.c (aarch64_sframe_get_abi_arch): Fix typo in
comment on SFrame identifier.
* tc-aarch64.h (aarch64_sframe_get_abi_arch,
sframe_get_abi_arch): Likewise.
* tc-i386.c (x86_sframe_get_abi_arch): Likewise.
* tc-i386.h (x86_sframe_get_abi_arch, sframe_get_abi_arch):
Likewise.

Reported-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 months agogprofng: fix 32889 Typo in documentation
Vladimir Mezentsev [Fri, 18 Apr 2025 21:08:20 +0000 (14:08 -0700)] 
gprofng: fix 32889 Typo in documentation

gprofng/ChangeLog
2025-04-18  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* doc/gprofng_ug.texi: Fix typo.

2 months agogprofng: fix 32886 wrong mapping from instruction to line number
Vladimir Mezentsev [Fri, 18 Apr 2025 21:00:59 +0000 (14:00 -0700)] 
gprofng: fix 32886 wrong mapping from instruction to line number

On Intel, gprofng should adjusts return addresses, including user leaf functions.

gprofng/ChangeLog
2025-04-18  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* src/CallStack.cc (add_stack): Adjust return addresses on Intel.

2 months agoMicroBlaze: Make sure we see memory breakpoints before reading
Michael J. Eager [Tue, 22 Apr 2025 00:44:08 +0000 (17:44 -0700)] 
MicroBlaze: Make sure we see memory breakpoints before reading

For linux target, when trying to run a program from gdb, the
following defect is seen:

Program received signal SIGILL, Illegal instruction.
0x48004674 in _dl_debug_state () from target:/lib/ld.so.1

* microblaze-linux-tdep.c (microblaze_linux_memory_remove_breakpoint):
  Call make_scoped_restore_show_memory_breakpoints

Signed-off-by: Gopi Kumar Bulusu <gopi@sankhya.com>
Signed-off-by: Michael J. Eager <eager@eagercon.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Tue, 22 Apr 2025 00:00:36 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoAutomatic date update in version.in
GDB Administrator [Mon, 21 Apr 2025 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoavoid bogus format-overflow error
Alan Modra [Sun, 20 Apr 2025 23:33:52 +0000 (09:03 +0930)] 
avoid bogus format-overflow error

Seen on x86_64-linux Ubuntu 24.04.2 using gcc-13.3.0 with
CFLAGS="-m32 -g -O2 -fsanitize=address,undefined"

In function ‘sprintf’,
    inlined from ‘s_mri_for’ at gas/config/tc-m68k.c:6941:5:
/usr/include/bits/stdio2.h:30:10: error: null destination pointer [-Werror=format-overflow=]
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~

Rewrite the code without sprintf, as in other parts of s_mri_for.
See also commit 760fb390fd4c and following commits.

Note that adding -D_FORTIFY_SOURCE=0 to CFLAGS (which is a good idea
when building with sanitizers) merely transforms the sprintf_chk error
here into one regarding plain sprintf.

2 months agobfd_check_format_matches error paths
Alan Modra [Sat, 19 Apr 2025 05:12:23 +0000 (14:42 +0930)] 
bfd_check_format_matches error paths

Tidy early out errors which didn't free matching_vector.  Don't
bfd_preserve_restore if we get to err_ret from the first
bfd_preserve_save, which might fail from a memory allocation leaving
preserve.marker NULL.  Also take bfd_lock a little earlier before
modifying abfd->format to simplify error return path from a lock
failure.

2 months agorescoff: close bfd on failure paths
Alan Modra [Sat, 19 Apr 2025 00:55:01 +0000 (10:25 +0930)] 
rescoff: close bfd on failure paths

Also free malloc'd relocs.

2 months agogdb/dwarf: make some more functions methods of cutu_reader
Simon Marchi [Thu, 17 Apr 2025 19:37:26 +0000 (15:37 -0400)] 
gdb/dwarf: make some more functions methods of cutu_reader

These are only used by cutu_reader, so make them methods of cutu_reader.
This makes it a bit more obvious in which context this code is called.

lookup_dwo_unit_in_dwp can't be made a method of cutu_reader, as it is
used in another context (lookup_dwp_signatured_type /
lookup_signatured_type), which happens during CU expansion.

Change-Id: Ic62c3119dd6ec198411768323aaf640ed165f51b
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/dwarf: look up .dwp file ahead of time
Simon Marchi [Thu, 17 Apr 2025 19:37:25 +0000 (15:37 -0400)] 
gdb/dwarf: look up .dwp file ahead of time

get_dwp_file lazily looks for a .dwp file for the given objfile.  It is
called by indexing workers, when a cutu_reader object looks for a DWO
file.  It is called with the "dwo_lock" held, meaning that the first
worker to get there will do the work, while the others will wait at the
lock.

I'm trying to reduce the time where this lock is taken and do other
refactorings to make it easier to reason about the DWARF reader code.
Moving the lookup of the .dwp file ahead, before we start parallelizing
work, helps makes things simpler, because we can then assume everywhere
else that we have already checked for a .dwp file.

Put the call to open_and_init_dwp_file in dwarf2_has_info, right next to
where we look up .dwz files.  I used the same try-catch pattern as for
the .dwz file lookup.

Change-Id: I615da85f62a66d752607f0dbe9f0372dfa04b86b
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/dwarf: replace some per_objfile parameters with per_bfd
Simon Marchi [Thu, 17 Apr 2025 19:37:24 +0000 (15:37 -0400)] 
gdb/dwarf: replace some per_objfile parameters with per_bfd

Following a previous patch, these functions can accept a per_bfd
instead of a per_objfile.

Change-Id: Iacc8924d2e49a05920d9a7fde2f7584f709fbdd2
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/dwarf: pass section to create_dwp_hash_table
Simon Marchi [Thu, 17 Apr 2025 19:37:23 +0000 (15:37 -0400)] 
gdb/dwarf: pass section to create_dwp_hash_table

Instead of passing a boolean to create_dwp_hash_table to select the
section to read, it's simpler to just pass the section.

Change-Id: Ie043c31e80518239f6403288dcf03f7769c58e8c
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/dwarf: remove unnecessary dwarf2_section_info:::read calls
Simon Marchi [Thu, 17 Apr 2025 19:37:22 +0000 (15:37 -0400)] 
gdb/dwarf: remove unnecessary dwarf2_section_info:::read calls

The sections would have been read already in
dwarf2_locate_common_dwp_sections or dwarf2_locate_dwo_sections, with
this call:

    dw_sect->read (objfile);

Change-Id: Ice0ed5d9a2070967826a59b2d6f724451ace22f4
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/dwarf: remove per_objfile parameter from read_and_check_comp_unit_head
Simon Marchi [Thu, 17 Apr 2025 19:37:21 +0000 (15:37 -0400)] 
gdb/dwarf: remove per_objfile parameter from read_and_check_comp_unit_head

It is no longer needed.

Change-Id: I22b21b12dc9f74a423bca355d4d83f0167e75f34
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/dwarf: remove dwarf2_section_info::get_size
Simon Marchi [Thu, 17 Apr 2025 19:37:20 +0000 (15:37 -0400)] 
gdb/dwarf: remove dwarf2_section_info::get_size

The comment over dwarf2_section_info::get_size says:

    In other cases, you must call this function, because for compressed
    sections the size field is not set correctly until the section has
    been read

From what I can see (while debugging a test case compiled with -gz on
Linux), that's not true.  For compressed sections, bfd_section_size
returns the uncompressed size.  asection::size contains the uncompressed
size while asection::compressed_size contains the compressed size:

    (top-gdb) p sec
    $13 = (asection *) 0x521000119778
    (top-gdb) p sec.compressed_size
    $14 = 6191
    (top-gdb) p sec.size
    $15 = 12116

I therefore propose to remove dwarf2_section_info::get_size, as it
appears that reading in the section is orthogonal to knowing its size.

If the assumption above is false, it would be nice to document in which
case it's false.

I checked the callers, and I don't think that we need to add any
dwarf2_section_info::read calls to compensate for the fact that get_size
used to do it.

Change-Id: I428571e532301d49f1d8242d687e1fcb819b75c1
Approved-By: Tom Tromey <tom@tromey.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Sun, 20 Apr 2025 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoRemove some obsolete comments from ada-varobj.c
Tom Tromey [Sat, 19 Apr 2025 17:33:12 +0000 (11:33 -0600)] 
Remove some obsolete comments from ada-varobj.c

I noticed a few spots in ada-varobj.c that refer to calling xfree,
where the type in question has changed to std::string.  This patch
removes these obsolete comments.

2 months agoAutomatic date update in version.in
GDB Administrator [Sat, 19 Apr 2025 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoFix 32885 gprofng --help should state where to report bugs
Vladimir Mezentsev [Fri, 18 Apr 2025 03:28:33 +0000 (20:28 -0700)] 
Fix 32885 gprofng --help should state where to report bugs

gprofng/ChangeLog
2025-04-17  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* src/gp-archive.cc: Fix the --help output.
* src/gp-collect-app.cc: Likewise.
* src/gp-display-src.cc: Likewise.
* src/gp-display-text.cc: Likewise.
* src/gprofng.cc: Likewise.

2 months agobuild error with 32-bit host and 64-bit time_t
Alan Modra [Fri, 18 Apr 2025 09:01:30 +0000 (18:31 +0930)] 
build error with 32-bit host and 64-bit time_t

A fix for commit c4fce3ef2927.

2 months agoloongarch gas resolving constant expressions
Alan Modra [Tue, 15 Apr 2025 21:42:46 +0000 (07:12 +0930)] 
loongarch gas resolving constant expressions

The test added in commit 4fe96ddaf614 results in an asan complaint:
loongarch-parse.y:225:16: runtime error: left shift of negative value -1
To avoid the complaint, perform left shifts as unsigned (which gives
the same result on 2's complement machines).  Do the same for
addition, subtraction and multiplication.  Furthermore, warn on
divide/modulus by zero.

2 months agoAutomatic date update in version.in
GDB Administrator [Fri, 18 Apr 2025 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months ago[gdb/testsuite] Don't run to main in gdb.cp/cplusfuncs.exp
Tom de Vries [Thu, 17 Apr 2025 15:57:29 +0000 (17:57 +0200)] 
[gdb/testsuite] Don't run to main in gdb.cp/cplusfuncs.exp

After building gdb with -fsanitize=threads, and running test-case
gdb.cp/cplusfuncs.exp, I run into a single timeout:
...
FAIL: gdb.cp/cplusfuncs.exp: info function operator=( (timeout)
...
and the test-case takes 2m33s to finish.

This is due to expanding CUs from libstdc++.

After de-installing package libstdc++6-debuginfo, the timeout disappears and
testing time goes down to 9 seconds.

Fix this by not running to main, which brings testing time down to 3 seconds.

With a gdb built without -fsanitize=threads, testing time goes down from 11
seconds to less than 1 second.

Tested on x86_64-linux.

Reviewed-By: Keith Seitz <keiths@redhat.com>
2 months agoClean up value_struct_elt_bitpos
Tom Tromey [Tue, 15 Apr 2025 18:29:50 +0000 (12:29 -0600)] 
Clean up value_struct_elt_bitpos

value_struct_elt_bitpos is weird: it takes an in/out value parameter,
and it takes an error string parameter.  However, it only has a single
caller, which never uses the "out" value.

I think it was done this way to mimic value_struct_elt.  However,
value_struct_elt is pretty ugly and I don't think it's worth
imitating.

This patch cleans up value_struct_elt_bitpos a bit.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agotestsuite: fix typo in bti-plt-1-b.d test
Yury Khrustalev [Wed, 2 Apr 2025 12:53:26 +0000 (13:53 +0100)] 
testsuite: fix typo in bti-plt-1-b.d test

This test is not supposed to use -z force-bti

2 months agoaarch64: ld: add tests for combination of bti and memory-seal
Yury Khrustalev [Tue, 1 Apr 2025 14:42:18 +0000 (15:42 +0100)] 
aarch64: ld: add tests for combination of bti and memory-seal

Both BTI and memory sealing require use of GNU properties and
we should check that there is no interference.

2 months agoaarch64: ld: Fix scanning of GNU properties for AARCH64_FEATURE_1_AND
Yury Khrustalev [Thu, 27 Mar 2025 16:48:24 +0000 (16:48 +0000)] 
aarch64: ld: Fix scanning of GNU properties for AARCH64_FEATURE_1_AND

Fixes [1]. Previously iteration over GNU properties of an input file
could stop before reaching GNU_PROPERTY_AARCH64_FEATURE_1_AND which
would result in incorrect inference of properties of the output file.

In the particular use case described in [1], the memory seal property
GNU_PROPERTY_MEMORY_SEAL with number 3, if present in the input file,
prevented reading information from GNU_PROPERTY_AARCH64_FEATURE_1_AND
property due to filtering by property number.

[1] PR32818 https://sourceware.org/bugzilla/show_bug.cgi?id=32818

2 months ago[gdb/testsuite] Fix gdb.threads/clone-attach-detach.exp
Tom de Vries [Thu, 17 Apr 2025 07:51:46 +0000 (09:51 +0200)] 
[gdb/testsuite] Fix gdb.threads/clone-attach-detach.exp

With test-case gdb.threads/clone-attach-detach.exp I usually get:
...
(gdb) attach <pid> &^M
Attaching to program: clone-attach-detach, process <pid>^M
[New LWP <lwp>]^M
(gdb) PASS: $exp: bg attach <n>: attach
[Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
...
but sometimes I run into:
...
(gdb) attach <pid> &^M
Attaching to program: clone-attach-detach, process <pid>^M
[New LWP <lwp>]^M
(gdb) [Thread debugging using libthread_db enabled]^M
Using host libthread_db library "/lib64/libthread_db.so.1".^M
FAIL: $exp: bg attach <n>: attach (timeout)
...

I managed to reproduce this using make target check-readmore and
READMORE_SLEEP=100.

Fix this using -no-prompt-anchor.

Tested on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agogdb: fix bugs in gdb/copyright.py, make it use glob patterns
Simon Marchi [Fri, 11 Apr 2025 15:08:06 +0000 (11:08 -0400)] 
gdb: fix bugs in gdb/copyright.py, make it use glob patterns

gdb/copyright.py currently changes some files that it shouldn't:

 - despite having a `gnulib/import` entry in EXCLUDE_LIST, it does
   change the files under that directory
 - it is missing `sim/Makefile.in`

Change the exclude list logic to use glob patterns.  This makes it
easier to specify exclusions of full directories or files by basename,
while simplifying the code.

Merge EXCLUDE_LIST and NOT_FSF_LIST, since there's no fundamental reason
to keep them separate (they are treated identically).  I kept the
comment that explains that some files are excluded due to not being
FSF-licensed.

Merge EXCLUDE_ALL_LIST in EXCLUDE_LIST, converting the entries to glob
patterns that match everywhere in the tree (e.g. `**/configure`).

Tested by running the script on the parent commit of d01e823438c7
("Update copyright dates to include 2025") and diff'ing the result with
d01e823438c7.  The only differences are:

 - the files that we don't want to modify (gnulib/import and
   sim/Makefile.in)
 - the files that need to be modified by hand

Running the script on latest master produces no diff.

Change-Id: I318dc3bff34e4b3a9b66ea305d0c3872f69cd072
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2 months agogdb: make typing strict in gdb/copyright.py
Simon Marchi [Fri, 11 Apr 2025 15:08:05 +0000 (11:08 -0400)] 
gdb: make typing strict in gdb/copyright.py

Add `pyright: strict` at the top of the file, then adjust the fallouts.
This annotation is understood by pyright, and thus any IDE using pyright
behind the scenes (VSCode and probably others).

I presume that any GDB developer running this script is using a recent
enough version of Python, so specify the type annotations using the
actual types when possible (e.g. `list[str]` instead of
`typing.List[str]`).  I believe this required Python 3.9.

Change-Id: I3698e28555e236a03126d4cd010dae4b5647ce48
Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Thu, 17 Apr 2025 00:00:23 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months ago[gdb/testsuite] Fix another timeout in gdb.base/bg-execution-repeat.exp
Tom de Vries [Wed, 16 Apr 2025 15:39:41 +0000 (17:39 +0200)] 
[gdb/testsuite] Fix another timeout in gdb.base/bg-execution-repeat.exp

With test-case gdb.base/bg-execution-repeat.exp, occasionally I run into a
timeout:
...
(gdb) c 1&
Will stop next time breakpoint 1 is reached.  Continuing.
(gdb) PASS: $exp: c 1&: c 1&

Breakpoint 2, foo () at bg-execution-repeat.c:23
23        return 0; /* set break here */
PASS: $exp: c 1&: breakpoint hit 1

Will stop next time breakpoint 2 is reached.  Continuing.
(gdb) PASS: $exp: c 1&: repeat bg command
print 1
$1 = 1
(gdb) PASS: $exp: c 1&: input still accepted
interrupt
(gdb) PASS: $exp: c 1&: interrupt

Program received signal SIGINT, Interrupt.
foo () at bg-execution-repeat.c:24
24      }
PASS: $exp: c 1&: interrupt received
set var do_wait=0
(gdb) PASS: $exp: c 1&: set var do_wait=0
continue&
Continuing.
(gdb) PASS: $exp: c 1&: continue&
FAIL: $exp: c 1&: breakpoint hit 2 (timeout)
...

I can reproduce it reliably by adding a "sleep (1)" before the "do_wait = 1"
in the .c file.

The timeout happens as follows:
- with the inferior stopped at main, gdb continues (command c 1&)
- the inferior hits the breakpoint at foo
- gdb continues (using the repeat command functionality)
- the inferior is interrupted
- inferior variable do_wait gets set to 0.  The assumption here is that the
  inferior has progressed enough that do_wait is set to 1 at that point, but
  that happens not to be the case.  Consequently, this has no effect.
- gdb continues
- the inferior sets do_wait to 1
- the inferior enters the wait function, and wait for do_wait to become 0,
  which never happens.

Fix this by moving the "do_wait = 1" to before the first call to foo.

Tested on x86_64-linux.

Reviewed-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
2 months agobuffer overrun in read_coff_res_dir
Alan Modra [Wed, 16 Apr 2025 00:50:33 +0000 (10:20 +0930)] 
buffer overrun in read_coff_res_dir

* rescoff.c (read_coff_res_dir): Add more sanity checking.
Tidy and correct existing checks.

2 months agoresbin.c formatting fixes
Alan Modra [Wed, 16 Apr 2025 00:07:34 +0000 (09:37 +0930)] 
resbin.c formatting fixes

Also remove unnecessary casts on memory alloc function returns.

2 months agoRe: windres: buffer overflow in bin_to_res_toolbar
Alan Modra [Tue, 15 Apr 2025 23:25:04 +0000 (08:55 +0930)] 
Re: windres: buffer overflow in bin_to_res_toolbar

Commit 9e68cae4fdfb broke the check I added in commit 4846e543de95.
Add missing "return NULL".

2 months agoAutomatic date update in version.in
GDB Administrator [Wed, 16 Apr 2025 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoUse gdb::unordered_set for Ada symbol cache
Tom Tromey [Wed, 12 Mar 2025 20:45:23 +0000 (14:45 -0600)] 
Use gdb::unordered_set for Ada symbol cache

This changes the Ada symbol cache to use gdb::unordered_set rather
than an htab.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoUse gdb::string_set for decoded_names_store
Tom Tromey [Tue, 11 Mar 2025 19:56:57 +0000 (13:56 -0600)] 
Use gdb::string_set for decoded_names_store

This patch changes decoded_names_store to use a gdb::string_set rather
than an htab.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months ago[gdb/ada] Fix gdb.ada/overloads.exp on s390x
Tom de Vries [Tue, 15 Apr 2025 14:59:32 +0000 (16:59 +0200)] 
[gdb/ada] Fix gdb.ada/overloads.exp on s390x

On s390x-linux, with test-case gdb.ada/overloads.exp and gcc 7.5.0 I run into:
...
(gdb) print Oload(CA)^M
Could not find a match for oload^M
(gdb) FAIL: $exp: print Oload(CA)
...

The mismatch happens here in ada_type_match:
...
      return ftype->code () == atype->code ();
...
with:
...
(gdb) p ftype->code ()
$3 = TYPE_CODE_TYPEDEF
(gdb) p atype->code ()
$4 = TYPE_CODE_ARRAY
...

At the start of ada_type_match, typedefs are skipped:
...
  ftype = ada_check_typedef (ftype);
  atype = ada_check_typedef (atype);
...
but immediately after this, refs are skipped:
...
  if (ftype->code () == TYPE_CODE_REF)
    ftype = ftype->target_type ();
  if (atype->code () == TYPE_CODE_REF)
    atype = atype->target_type ();
...
which in this case makes ftype a typedef.

Fix this by using ada_check_typedef after skipping the refs as well.

Tested on x86_64-linux and s390x-linux.

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

2 months ago[gdb/testsuite] Fix gdb.ada/scalar_storage.exp on s390x
Tom de Vries [Tue, 15 Apr 2025 14:59:32 +0000 (16:59 +0200)] 
[gdb/testsuite] Fix gdb.ada/scalar_storage.exp on s390x

On s390x-linux, with test-case gdb.ada/scalar_storage.exp we have:
...
(gdb) print V_LE^M
$1 = (value => 126, another_value => 12, color => 3)^M
(gdb) FAIL: gdb.ada/scalar_storage.exp: print V_LE
print V_BE^M
$2 = (value => 125, another_value => 9, color => green)^M
(gdb) KFAIL: $exp: print V_BE (PRMS: DW_AT_endianity on enum types)
...

The KFAIL is incorrect in the sense that gdb is behaving as expected.

The problem is incorrect debug info, so change this into an xfail.

Furthermore, extend the xfail to cover V_LE.

Tested on s390x-linux and x86_64-linux.

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

2 months agogdb/dwarf: skip type units in create_dwo_cus_hash_table
Simon Marchi [Fri, 11 Apr 2025 20:38:04 +0000 (16:38 -0400)] 
gdb/dwarf: skip type units in create_dwo_cus_hash_table

When compiling with -gsplit-dwarf -fdebug-types-section, DWARF 5
.debug_info.dwo sections may contain some type units:

    $ llvm-dwarfdump -F -color a-test.dwo | head -n 5
    a-test.dwo:     file format elf64-x86-64

    .debug_info.dwo contents:
    0x00000000: Type Unit: length = 0x000008a0, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_type, abbr_offset = 0x0000, addr_size = 0x08, name = 'vector<int, std::allocator<int> >', type_signature = 0xb499dcf29e2928c4, type_offset = 0x0023 (next unit at 0x000008a4)

In this case, create_dwo_cus_hash_table wrongly creates a dwo_unit for
it and adds it to dwo_file::cus.  create_dwo_debug_type_hash_table later
correctly creates a dwo_unit that it puts in dwo_file::tus.

This can be observed with:

    $ ./gdb  -nx -q --data-directory=data-directory -ex 'maint set dwarf sync on' -ex "maint set worker-threads 0" -ex "set debug dwarf-read 2" -ex "file a.out" -batch
    ...
    [dwarf-read] create_dwo_cus_hash_table: Reading .debug_info.dwo for /home/smarchi/build/binutils-gdb/gdb/a-test.dwo:
    [dwarf-read] create_dwo_cus_hash_table:   offset 0x0, dwo_id 0xb499dcf29e2928c4
    [dwarf-read] create_dwo_cus_hash_table:   offset 0x8a4, dwo_id 0x496a8791a842701b
    [dwarf-read] create_dwo_cus_hash_table:   offset 0x941, dwo_id 0xefd13b3f62ea9fea
    ...
    [dwarf-read] create_dwo_debug_type_hash_table: Reading .debug_info.dwo for /home/smarchi/build/binutils-gdb/gdb/a-test.dwo
    [dwarf-read] create_dwo_debug_type_hash_table:   offset 0x0, signature 0xb499dcf29e2928c4
    [dwarf-read] create_dwo_debug_type_hash_table:   offset 0x8a4, signature 0x496a8791a842701b
    [dwarf-read] create_dwo_debug_type_hash_table:   offset 0x941, signature 0xefd13b3f62ea9fea
    ...

Fix it by skipping anything that isn't a compile unit in
create_dwo_cus_hash_table.  After this patch, the debug output of
create_dwo_cus_hash_table only shows one created dwo_unit, as we expect.

I couldn't find any user-visible problem related to this, I just noticed
it while debugging.

Change-Id: I7dddf766fe1164123b6702027b1beb56114f25b1
Reviewed-By: Tom de Vries <tdevries@suse.de>
2 months agogdb/dwarf: rename some functions to specify "dwo"
Simon Marchi [Fri, 11 Apr 2025 20:38:03 +0000 (16:38 -0400)] 
gdb/dwarf: rename some functions to specify "dwo"

Rename some functions to make it clearer that they are only relevant
when dealing with DWO files.

Change-Id: Ia0cd3320bf16ebdbdc3c09d7963f372e6679ef7c
Reviewed-By: Tom de Vries <tdevries@suse.de>
2 months agoRISC-V: Add missing disassembler option `max`
Marek Pikuła [Tue, 1 Apr 2025 15:43:16 +0000 (17:43 +0200)] 
RISC-V: Add missing disassembler option `max`

The flag already exists but it's not been exposed to user.

Signed-off-by: Marek Pikuła <m.pikula@partner.samsung.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Tue, 15 Apr 2025 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoPR 32871 ld/ldmain.c#L425 incorrect location of #endif
Alan Modra [Mon, 14 Apr 2025 21:32:40 +0000 (07:02 +0930)] 
PR 32871 ld/ldmain.c#L425 incorrect location of #endif

Fix commit c4fce3ef2927 brace position.

2 months agowindres: don't exit so much on errors in read_coff_rsrc
Alan Modra [Mon, 14 Apr 2025 09:41:53 +0000 (19:11 +0930)] 
windres: don't exit so much on errors in read_coff_rsrc

windres code has the habit of exiting on any error.  That's not so
bad, but it does make oss-fuzz ineffective when testing windres.  Fix
many places that print errors and exit to instead print the error and
pass status up the call chain.  In the process of doing this, I
noticed write_res_file was calling bfd_close without checking return
status.  Fixing that resulted in lots of testsuite failures.  The
problem was a lack of bfd_set_format in windres_open_as_binary, which
leaves the output file as bfd_unknown format.  As it happens this
doesn't make any difference in writing the output binary file, except
for the bfd_close return status.

2 months agowindres: buffer overflow in bin_to_res_toolbar
Alan Modra [Mon, 14 Apr 2025 01:01:32 +0000 (10:31 +0930)] 
windres: buffer overflow in bin_to_res_toolbar

oss-fuzz testcase manages to hit a buffer overflow.  Sanity check
by passing the buffer length to bin_to_res_toolbar and ensuring reads
don't go off the end of the buffer.

2 months agoRe: ld: Skip the LTO archive member only for the earlier DSO
Alan Modra [Mon, 14 Apr 2025 00:33:22 +0000 (10:03 +0930)] 
Re: ld: Skip the LTO archive member only for the earlier DSO

Add -fPIC when compiling the test, to fix complaints on some targets
about certains relocation not being valid for shared libraries.

2 months agogdb/testsuite: Add gdb.arch/aarch64-sve-sigunwind.exp
Thiago Jung Bauermann [Sat, 12 Apr 2025 05:03:38 +0000 (02:03 -0300)] 
gdb/testsuite: Add gdb.arch/aarch64-sve-sigunwind.exp

There's currently no test for unwinding the SVE registers from a signal
frame, so add one.

Tested on aarch64-linux-gnu native.

Tested-By: Luis Machado <luis.machado@arm.com>
Approved-By: Luis Machado <luis.machado@arm.com>
2 months agold/PE: restrict non-zero default DLL characteristics to MinGW
Jan Beulich [Mon, 14 Apr 2025 12:24:28 +0000 (14:24 +0200)] 
ld/PE: restrict non-zero default DLL characteristics to MinGW

While commit ef6379e16dd1 ("Set the default DLL chracteristics to 0 for
Cygwin based targets") tried to undo the too broad earlier 514b4e191d5f
("Change the default characteristics of DLLs built by the linker to more
secure settings"), it didn't go quite far enough. Apparently the
assumption was that if it's not MinGW, it must be Cygwin. Whether it
really is okay to default three of the flags to non-zero on MinGW also
remains unclear - sadly neither of the commits came with any description
whatsoever. (Documentation also wasn't updated to indicate the restored
default.)

Setting effectively any of the DLL characteristics flags depends on
properties of the binary being linked. While defaulting to "more secure"
is a fair goal, it's only the programmer who can know whether their code
is actually compatible with the respective settings. On the assumption
that the change of defaults was indeed deliberate (and justifiable) for
MinGW, limit them to just that. In particular, don't default any of the
flags to set also for non-MinGW, non-Cygwin targets, like e.g. UEFI. At
least the mere applicability of the high-entropy-VA bit is pretty
questionable there in the first place - UEFI applications, after all,
run in "physical mode", i.e. either unpaged or (where paging is a
requirement, like for x86-64) direct-mapped.

The situation is particularly problematic with NX-compat: Many UEFI
implementations respect the "physical mode" property, where permissions
can't be enforced anyway. Some, like reportedly OVMF, even have a build
option to behave either way. Hence successfully testing a UEFI binary on
any number of systems does not guarantee it won't crash elsewhere if the
flag is wrongly set.

Get rid of excess semicolons as well.

2 months agobfd/ELF/x86: avoid layering violation in link hash table entry init
Jan Beulich [Mon, 14 Apr 2025 12:23:53 +0000 (14:23 +0200)] 
bfd/ELF/x86: avoid layering violation in link hash table entry init

There's no reason not to do as the comment says, just like all other
architectures do when they need custom field: Call the allocation method
of the "superclass". Which is the ELF one, of which in turn the BFD one
is the "superclass", dealt with accordingly by
_bfd_elf_link_hash_newfunc().

2 months agobfd/aout: drop add_one_symbol() hook
Jan Beulich [Mon, 14 Apr 2025 12:23:29 +0000 (14:23 +0200)] 
bfd/aout: drop add_one_symbol() hook

The need for this has disappeared with c65c21e1ffd1 ("various i386-aout
and i386-coff target removal"), with a few other users having got
removed just a few days earlier; avoid the unnecessary indirection.

2 months agobfd/COFF: propagate function size when copying/linking ELF objects
Jan Beulich [Mon, 14 Apr 2025 12:22:49 +0000 (14:22 +0200)] 
bfd/COFF: propagate function size when copying/linking ELF objects

While COFF, unlike ELF, doesn't have a generic way to express symbol
size, there is a means to do so for functions. When inputs are ELF,
propagate function sizes, including the fact that a symbol denotes a
function, to the output's symbol table.

Note that this requires hackery (cross-object-format processing) in two
places - when linking, global symbols are entered into a global hash
table, and hence relevant information needs to be updated there in that
case, while otherwise the original symbol structures can be consulted.

For the setting of ->u.syment.n_type the later writing of the field to
literal 0 needs to be dropped from coff_write_alien_symbol(). It was
redundant anyway with an earlier write of the field using C_NUL.

2 months agox86: move PadLock enumerators
Jan Beulich [Mon, 14 Apr 2025 12:22:21 +0000 (14:22 +0200)] 
x86: move PadLock enumerators

... to be all in one group. This helps code generation for code like

      || is_cpu (&i.tm, CpuPadLock)
      || is_cpu (&i.tm, CpuPadLockRNG2)
      || is_cpu (&i.tm, CpuPadLockPHE2)
      || is_cpu (&i.tm, CpuPadLockXMODX)

that we have (effectively) twice.

2 months agogdb: add check for empty array
Piotr Rudnicki [Wed, 9 Apr 2025 13:17:31 +0000 (15:17 +0200)] 
gdb: add check for empty array

With the command before the change, gdb crashes with message:
(gdb) p 1 == { }
Fatal signal: Segmentation fault

After the fix in this commit, gdb shows following message:
(gdb) p 1 == { }
size of the array element must not be zero

Add new test cases to file gdb.base/printcmds.exp to test this change

Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb: add an assert to cmd_list_element constructor
Andrew Burgess [Sun, 13 Apr 2025 13:01:59 +0000 (14:01 +0100)] 
gdb: add an assert to cmd_list_element constructor

The cmd_list_element::doc variable must be non-nullptr, otherwise, in
`help_cmd` (cli/cli-decode.c), we will trigger an assert when we run
one of these lines:

      gdb_puts (c->doc, stream);

or,

      gdb_puts (alias->doc, stream);

as gdb_puts requires that the first argument (the doc string) be
non-nullptr.

Better, I think, to assert when the cmd_list_element is created,
rather than catching an assert later when 'help CMD' is used.

I only ran into this case when messing with the Python API command
creation code, I accidentally created a command with a nullptr doc
string, and only found out when I ran 'help CMD' and got an
assertion.

While I'm adding this assertion, I figure I should also assert that
the command name is not nullptr too.  Looking through cli-decode.c,
there seems to be plenty of places where we assume a non-nullptr name.

Built and tested on x86-64 GNU/Linux with an all-targets build; I
don't see any regressions, so (I hope) there are no commands that
currently violate this assertion.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Mon, 14 Apr 2025 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoLoongArch: Support LA32R aliases rdcnt{vl,vh,id}.w
WANG Xuerui [Sun, 23 Mar 2025 09:30:38 +0000 (17:30 +0800)] 
LoongArch: Support LA32R aliases rdcnt{vl,vh,id}.w

These LA32R instructions are in fact special cases of the LA32S/LA64
rdtime{l,h}.w (with only one output operand instead of two, the other
one being forced to $zero), but are named differently in the LA32R
ISA manual nevertheless.

As the LA32R names are more memorable to a degree (especially for those
having difficulties remembering which operand corresponds to the node
ID), support them by making them aliases of the corresponding LA32S/LA64
instruction respectively, and make them render as such in disassembly.

Signed-off-by: WANG Xuerui <git@xen0n.name>
2 months agoAutomatic date update in version.in
GDB Administrator [Sun, 13 Apr 2025 00:00:17 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agogdb: add Piotr Rudnicki to gdb/MAINTAINERS
Piotr Rudnicki [Sat, 12 Apr 2025 14:46:09 +0000 (16:46 +0200)] 
gdb: add Piotr Rudnicki to gdb/MAINTAINERS

2 months agoAutomatic date update in version.in
GDB Administrator [Sat, 12 Apr 2025 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agogdb: silence some 'Can't open file' warnings from core file loading
Andrew Burgess [Wed, 12 Mar 2025 11:16:42 +0000 (11:16 +0000)] 
gdb: silence some 'Can't open file' warnings from core file loading

But PR gdb/20126 highlights a case where GDB emits a large number of
warnings like:

  warning: Can't open file /anon_hugepage (deleted) during file-backed mapping note processing
  warning: Can't open file /dev/shm/PostgreSQL.1150234652 during file-backed mapping note processing
  warning: Can't open file /dev/shm/PostgreSQL.535700290 during file-backed mapping note processing
  warning: Can't open file /SYSV604b7d00 (deleted) during file-backed mapping note processing
  ... etc ...

when opening a core file.  This commit aims to avoid at least some of
these warnings.

What we know is that, for at least some of these cases, (e.g. the
'(deleted)' mappings), the content of the mapping will have been
written into the core file itself.  As such, the fact that the file
isn't available ('/SYSV604b7d00' at least is a shared memory mapping),
isn't really relevant, GDB can still provide access to the mapping, by
reading the content from the core file itself.

What I propose is that, when processing the file backed mappings, if
all of the mappings for a file are covered by segments within the core
file itself, then there is no need to warn the user that the file
can't be opened again.  The debug experience should be unchanged, as
GDB would have read from the in-core mapping anyway.

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

2 months agogdb: add forward declarations in maint.h
Simon Marchi [Fri, 11 Apr 2025 17:07:26 +0000 (13:07 -0400)] 
gdb: add forward declarations in maint.h

Editing maint.h with clangd shows some errors about obj_section and
objfile being unknown.  Add some forward declarations for them.

Change-Id: Ic4dd12a371198fdf740892254a8f2c1fae2846b9

2 months agobfd: fix missing warnings from bfd_check_format_matches
Andrew Burgess [Sun, 6 Apr 2025 20:52:50 +0000 (21:52 +0100)] 
bfd: fix missing warnings from bfd_check_format_matches

In PR gdb/31846 the user reported an issue where GDB is unable to find
the build-id within an ELF, despite the build-id being
present (confirmed using readelf).

The user was able to try several different builds of GDB, and in one
build they observed the warning:

  warning: BFD: FILENAME: unable to decompress section .debug_info

But in may other builds of GDB this warning was missing.

There are, I think, a couple of issues that the user is running into,
but this patch is about why the above warning is often missing from
GDB's output.

I wasn't able to reproduce a corrupted .debug_info section such that
the above warning would be triggered, but it is pretty easy to patch
the _bfd_elf_make_section_from_shdr function (in bfd/elf.c) such that
the call to bfd_init_section_decompress_status is reported as a
failure, thus triggering the warning.  There is a patch that achieves
this in the bug report.

I did this, and can confirm that on my build of GDB, I don't see the
above warning, even though I can confirm that the _bfd_error_handler
call (in _bfd_elf_make_section_from_shdr) is being reached.

The problem is back in format.c, in bfd_check_format_matches.  This
function intercepts all the warnings and places them into a
per_xvec_messages structure.  These warnings are then printed with a
call to print_and_clear_messages.

If bfd_check_format_matches finds a single matching format, then
print_and_clear_messages, will print all warnings associated with that
single format.

But if no format matches, print_and_clear_messages will print all the
warnings, so long as all targets have emitted the same set of
warnings, and unfortunately, that is not the case for me.

The warnings are collected by iterating over bfd_target_vector and
trying each target.  My target happens to be x86_64_elf64_vec, and, as
expected this target appears in bfd_target_vector.

However, bfd_target_vector also includes DEFAULT_VECTOR near the top.
And in my build, DEFAULT_VECTOR is x86_64_elf64_vec.  Thus, for me,
the x86_64_elf64_vec entry appears twice in bfd_target_vector, this
means that x86_64_elf64_vec ends up being tried twice, and, as each
try generates one warning, the x86_64_elf64_vec entry in the
per_xvec_messages structure, has two warnings, while the other
per_xvec_messages entries only have one copy of the warning.

Because of this difference, print_and_clear_messages decides not to
print any of the warnings, which is not very helpful.

I considered a few different approaches to fix this issue:

We could de-duplicate warnings in the per_xvec_messages structure as
new entries are added.  So for any particular xvec, each time a new
warning arrives, if the new warning is identical to an existing
warning, then don't record it.  This might be an interesting change in
the future, but for now I rejected this solution as it felt like a
bodge, the duplicate warnings aren't really from a single attempt at
an xvec, but are from two distinct attempts at the same xvec. And so:

I wondered if we could remove the duplicate entries from
bfd_target_vector.  Or if we could avoid processing the same xvec
twice maybe?  For the single DEFAULT_VECTOR this wouldn't be too hard
to do, but bfd_target_vector also includes SELECT_VECS, which I think
could contain more duplicates.  Changing bfd_check_format_matches to
avoid attempting any duplicate vectors would now require more
complexity than a single flag, and I felt there was an easier
solution, which was:

I propose that within bfd_check_format_matches, within the loop that
tries each entry from bfd_target_vector, as we switch to each vector
in turn, we should delete any existing warnings within the
per_xvec_messages structure for the target vector we are about to try.

This means that, if we repeat a target, only the last set of warnings
will survive.

With this change in place, print_and_clear_messages now sees the same
set of warnings for each target, and so prints out the warning
message.

Additionally, while I was investigating this issue I managed to call
print_and_clear_messages twice.  This caused a crash because the first
call to print_and_clear_messages frees all the associated memory, but
leaves the per_xvec_messages::next field pointing to the now
deallocated object.  I'd like to propose that we set the next field to
NULL in print_and_clear_messages.  This clearly isn't needed so long
as print_and_clear_messages is only called once, but (personally) I
like to set pointers back to NULL if the object they are pointing to
is free and the parent object is going to live for some additional
time.  I can drop this extra change if people don't like it.

This change doesn't really "fix" PR gdb/31846, but it does mean that
the warning about being unable to decompress .debug_info should now be
printed consistently, which is a good thing.

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

Reviewed-By: Alan Modra <amodra@gmail.com>
2 months agogdb/testsuite: fix gdb.base/dlmopen-ns-ids.exp racy test
Guinevere Larsen [Wed, 9 Apr 2025 18:08:13 +0000 (15:08 -0300)] 
gdb/testsuite: fix gdb.base/dlmopen-ns-ids.exp racy test

The recently included gdb.base/dlmopen-ns-ids.exp test can sometimes
fail the call to get_integer_valueof when trying to check the namespace
ID of the fourth dlopened SO, for apparently no reason.

What's happening is that the call to get_first_so_ns doesn't necessarily
consume the GDB prompt, and so get_integer_valueof will see the prompt
immediately and not find the value the test is looking for.

To fix this, the test was changed so that we consume all of the output
of the command "info sharedlibrary", but only set the namespace ID for
the first occurrence of the SO we're looking for.  The command now also
gets the solib name as a parameter, to reduce the amount of output.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
Approved-By: Tom de Vries <tdevries@suse.de>
2 months agoAutomatic date update in version.in
GDB Administrator [Fri, 11 Apr 2025 00:00:09 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agold: Skip the LTO archive member only for the earlier DSO
H.J. Lu [Tue, 8 Apr 2025 20:10:02 +0000 (13:10 -0700)] 
ld: Skip the LTO archive member only for the earlier DSO

commit 2707d55e539ef323dd14a1293e762bf3d9739ee7
Author: Michael Matz <matz@suse.de>
Date:   Mon Mar 31 15:57:08 2025 +0200

skipped the LTO archive member even when the earlier item is also an
archive.  Instead, skip the LTO archive member only if the earlier item
is a shared library.

bfd/

PR ld/32846
PR ld/32854
* elflink.c (elf_link_add_archive_symbols): Skip the LTO archive
member only if the earlier item is a shared library.

ld/

PR ld/32846
PR ld/32854
* testsuite/ld-plugin/lto.exp: Run ld/32846 test.
* testsuite/ld-plugin/pr32846a.c: New file.
* testsuite/ld-plugin/pr32846b.c: Likewise.
* testsuite/ld-plugin/pr32846c.c: Likewise.
* testsuite/ld-plugin/pr32846d.c: Likewise.
* testsuite/ld-plugin/pr32846e.c: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2 months ago[gdb/cli] Fix typo in cli-dump.c
Tom de Vries [Thu, 10 Apr 2025 16:42:06 +0000 (18:42 +0200)] 
[gdb/cli] Fix typo in cli-dump.c

Fix the folowing typo:
...
$ codespell --config gdb/contrib/setup.cfg gdb/cli
gdb/cli/cli-dump.c:400: useable ==> usable
...
and add gdb/cli to the pre-commit codespell configuration.

Approved-By: Tom Tromey <tom@tromey.com>
2 months ago[gdb/unittests] Ignore spellcheck warning in rsp-low-selftests.c
Tom de Vries [Thu, 10 Apr 2025 16:42:06 +0000 (18:42 +0200)] 
[gdb/unittests] Ignore spellcheck warning in rsp-low-selftests.c

Ignore the following spellcheck warning:
...
$ codespell --config gdb/contrib/setup.cfg gdb/unittests
gdb/unittests/rsp-low-selftests.c:54: fo ==> of, for, to, do, go
...
and add gdb/unittests to the pre-commit codespell configuration.

Approved-By: Tom Tromey <tom@tromey.com>
2 months ago[gdb/config] Fix codespell warnings
Tom de Vries [Thu, 10 Apr 2025 16:42:06 +0000 (18:42 +0200)] 
[gdb/config] Fix codespell warnings

Fix the following codespell warnings:
...
$ codespell --config gdb/contrib/setup.cfg gdb/config
gdb/config/djgpp/README:178: unitialized ==> uninitialized
gdb/config/djgpp/djconfig.sh:126: conatain ==> contain
...
and add gdb/config to the pre-commit codespell configuration.

Approved-By: Tom Tromey <tom@tromey.com>
2 months agoPR32858 ld segfault on fuzzed object
Alan Modra [Thu, 10 Apr 2025 10:11:49 +0000 (19:41 +0930)] 
PR32858 ld segfault on fuzzed object

We missed one place where it is necessary to check for empty groups.

PR 32858
* elflink.c (elf_gc_sweep): Protect against empty group.

2 months ago[gdb/testsuite] Fix gdb.dwarf2/fission-with-type-unit.exp with remote host
Tom de Vries [Thu, 10 Apr 2025 02:50:26 +0000 (04:50 +0200)] 
[gdb/testsuite] Fix gdb.dwarf2/fission-with-type-unit.exp with remote host

When running test-case gdb.dwarf2/fission-with-type-unit.exp with a remote
host configuration, say host board local-remote-host and target board
remote-gdbserver-on-localhost, I run into:
...
(gdb) maint expand-symtabs^M
During symbol reading: Could not find DWO CU \
  fission-with-type-unit.dwo(0xf00d) referenced by CU at offset 0x2d7 \
  [in module /home/remote-host/fission-with-type-unit]^M
warning: Could not find DWO CU fission-with-type-unit.dwo(0xf00d) referenced \
  by CU at offset 0x2d7 [in module /home/remote-host/fission-with-type-unit]^M
(gdb) FAIL: gdb.dwarf2/fission-with-type-unit.exp: maint expand-symtabs
...

Fix this by adding the missing download to remote host of the .dwo file.

Tested by running make-check-all.sh on x86_64-linux.

2 months agoAutomatic date update in version.in
GDB Administrator [Thu, 10 Apr 2025 00:00:53 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agoaarch64 tests: escape dot in regex pattern to really match a dot
Matthieu Longo [Fri, 13 Dec 2024 14:32:52 +0000 (14:32 +0000)] 
aarch64 tests: escape dot in regex pattern to really match a dot

2 months agogdb/testsuite: fix copyright years in gdb.dwarf2/fission-with-type-unit.{c,exp}
Simon Marchi [Wed, 9 Apr 2025 14:37:07 +0000 (10:37 -0400)] 
gdb/testsuite: fix copyright years in gdb.dwarf2/fission-with-type-unit.{c,exp}

When writing the test, I copied these copyright entries from another
file but forgot to adjust the dates, do that now.

Change-Id: Ie458ad4ec81062b5ef24f78334f3d0920c99b318

2 months agogdbsupport: fix Makefile.in copyright dates
Simon Marchi [Tue, 8 Apr 2025 18:23:28 +0000 (14:23 -0400)] 
gdbsupport: fix Makefile.in copyright dates

Commit d01e823438 ("Update copyright dates to include 2025") incorrectly
changed the dates in Makefile.in.  Re-run `autoreconf` in the gdbsupport
directory to fix that up.

Change-Id: Ifcdb6f2257e7a456439dfc3e7848db934a4b16b4

2 months agosim: fix Makefile.in copyright dates
Simon Marchi [Tue, 8 Apr 2025 18:23:27 +0000 (14:23 -0400)] 
sim: fix Makefile.in copyright dates

Commit d01e823438 ("Update copyright dates to include 2025") incorrectly
changed the dates in Makefile.in.  Re-run `autoreconf` in the sim
directory to fix that up.

Change-Id: Ia02a54e5330d77b490cc7745eee3d281c7888eec

2 months agognulib: revert copyright date changes in imported files
Simon Marchi [Tue, 8 Apr 2025 18:23:26 +0000 (14:23 -0400)] 
gnulib: revert copyright date changes in imported files

Commit d01e823438 ("Update copyright dates to include 2025") changed the
dates in the gnulib imported source files, it probably shouldn't have.
Re-run update-gnulib.sh to restore those files.

gnulib/Makefile.in was also incorrectly modified, running the script
fixes that too.

Change-Id: I5d081f3438b9480130a92f59fd9fede33c121f9c

2 months ago[gdb/testsuite] Allow thread exited message in gdb.threads/infcall-from-bp-cond-simpl...
Tom de Vries [Wed, 9 Apr 2025 10:10:10 +0000 (12:10 +0200)] 
[gdb/testsuite] Allow thread exited message in gdb.threads/infcall-from-bp-cond-simple.exp

With a gdb 15.2 based package and test-case
gdb.threads/infcall-from-bp-cond-simple.exp, I ran into:
...
Thread 2 "infcall-from-bp" hit Breakpoint 3, function_with_breakpoint () at \
  infcall-from-bp-cond-simple.c:51
51        return 1;     /* Nested breakpoint.  */
Error in testing condition for breakpoint 2:
The program being debugged stopped while in a function called from GDB.
Evaluation of the expression containing the function
(function_with_breakpoint) will be abandoned.
When the function is done executing, GDB will silently stop.
[Thread 0x7ffff73fe6c0 (LWP 951822) exited]
(gdb) FAIL: $exp: target_async=on: target_non_stop=on: \
  run_bp_cond_hits_breakpoint: continue
...

The test fails because it doesn't expect the "[Thread ... exited]" message.

I have tried to reproduce this test failure, both using 15.2 and current
trunk, but haven't managed.

Regardless, I think the message is harmless, so allow it to occur, both in
run_bp_cond_segfaults and run_bp_cond_hits_breakpoint.

Tested on x86_64-linux.

PR testsuite/32785
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32785

2 months ago[gdb/symtab] Handle DW_OP_entry_value at function entry
Tom de Vries [Wed, 9 Apr 2025 10:02:18 +0000 (12:02 +0200)] 
[gdb/symtab] Handle DW_OP_entry_value at function entry

On riscv64-linux, with test-case gdb.base/vla-optimized-out.exp I ran into:
...
(gdb) p sizeof (a)^M
$2 = <optimized out>^M
(gdb) FAIL: $exp: o1: printed size of optimized out vla
...

The variable a has type 0xbf:
...
 <1><bf>: Abbrev Number: 12 (DW_TAG_array_type)
    <c0>   DW_AT_type        : <0xe3>
    <c4>   DW_AT_sibling     : <0xdc>
 <2><c8>: Abbrev Number: 13 (DW_TAG_subrange_type)
    <c9>   DW_AT_type        : <0xdc>
    <cd>   DW_AT_upper_bound : 13 byte block:
                               a3 1 5a 23 1 8 20 24 8 20 26 31 1c
       (DW_OP_entry_value: (DW_OP_reg10 (a0));
        DW_OP_plus_uconst: 1; DW_OP_const1u: 32;
DW_OP_shl; DW_OP_const1u: 32; DW_OP_shra;
DW_OP_lit1; DW_OP_minus)
...
which has an upper bound using a DW_OP_entry_value, and since the
corresponding call site contains no information to resolve the value of a0 at
function entry:
...
 <2><6b>: Abbrev Number: 6 (DW_TAG_call_site)
    <6c>   DW_AT_call_return_pc: 0x638
    <74>   DW_AT_call_origin : <0x85>
...
evaluting the dwarf expression fails, and we get <optimized out>.

My first thought was to try breaking at *f1 instead of f1 to see if that would
help, but actually the breakpoint resolved to the same address.

In other words, the inferior is stopped at function entry.

Fix this by resolving DW_OP_entry_value when stopped at function entry by
simply evaluating the expression.

This handles these two cases (x86_64, using reg rdi):
- DW_OP_entry_value: (DW_OP_regx: 5 (rdi))
- DW_OP_entry_value: (DW_OP_bregx: 5 (rdi) 0; DW_OP_deref_size: 4)

Tested on x86_64-linux.

Tested gdb.base/vla-optimized-out.exp on riscv64-linux.

Tested an earlier version of gdb.dwarf2/dw2-entry-value-2.exp on
riscv64-linux, but atm I'm running into trouble on that machine (cfarm92) so
I haven't tested the current version there.