]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
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.

2 months agos390: Add support for z17 as CPU name
Jens Remus [Wed, 9 Apr 2025 06:59:24 +0000 (08:59 +0200)] 
s390: Add support for z17 as CPU name

So far IBM z17 was identified as arch15.  Add the real name, as it has
been announced. [1]

[1]: IBM z17 announcement letter, AD25-0015,
     https://www.ibm.com/docs/en/announcements/z17-makes-more-possible

gas/
* config/tc-s390.c (s390_parse_cpu): Add z17 as alternate CPU
name for arch15.
* doc/c-s390.texi: Likewise.
* doc/as.texi: Likewise.

opcodes/
* s390-mkopc.c (main): Add z17 as alternate CPU name for arch15.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 months ago[gdb/tdep] Handle ldaex and stlex in {thumb,arm}_deal_with_atomic_sequence_raw
Tom de Vries [Wed, 9 Apr 2025 06:59:42 +0000 (08:59 +0200)] 
[gdb/tdep] Handle ldaex and stlex in {thumb,arm}_deal_with_atomic_sequence_raw

The Linaro CI reported a regression [1] in test-case
gdb.base/step-over-syscall.exp due to commit 674d4856730 ("[gdb/testsuite] Fix
gdb.base/step-over-syscall.exp with glibc 2.41").

Investigation shows that it's a progression in the sense that the test-case
fails at a later point than before.

The cause for the test-case failure is that an atomic sequence
ldaex/adds/strex is not skipped over when instruction stepping, leading to a
hang (in the sense of not being able to instruction-step out of the loop
containing the atomic sequence).

The arm target does have support for recognizing atomic sequences, but it
fails because it doesn't recognize the ldaex insn.

Fix this by:
- adding a new function ldaex_p which recognizes ldaex instructions, based
  on information found in opcodes/arm-dis.c, and
- using ldaex_p in thumb_deal_with_atomic_sequence_raw.

I was not able to reproduce the failure in its original setting, but I
was able to do so using a test.c:
...
static void exit (int status) {
  while (1)
    ;
}
void _start (void) {
  int a = 0;
  __atomic_fetch_add (&a, 1, __ATOMIC_ACQUIRE);
  exit (0);
}
...
compiled like this:
...
$ gcc test.c -march=armv8-a -mfloat-abi=soft -nostdlib -static
...
giving this atomic sequence of 32-bit Thumb-2 instructions:
...
   100ce:       e8d3 1fef       ldaex   r1, [r3]
   100d2:       f101 0101       add.w   r1, r1, #1
   100d6:       e843 1200       strex   r2, r1, [r3]
...

Without the fix, after 100 stepi's we're still in _start (and likewise with
10.000 stepi's):
...
$ gdb -q -batch a.out -ex 'display /i $pc' -ex starti -ex "stepi 100"
  ...
0x000100dc in _start ()
1: x/i $pc
=> 0x100dc <_start+26>: bne.n 0x100ce <_start+12>
...
but with the fix we've managed to progress to exit:
...
$ gdb -q -batch a.out -ex 'display /i $pc' -ex starti -ex "stepi 100"
  ...
0x000100c0 in exit ()
1: x/i $pc
=> 0x100c0 <exit+8>: b.n 0x100c0 <exit+8>
...

Having addressed the "-mthumb" case, do we need a similar fix for "-marm"?

Adding "-marm" in the compilation line mentioned above gives the following
atomic sequence:
...
   100e4:       e1931e9f        ldaex   r1, [r3]
   100e8:       e2811001        add     r1, r1, #1
   100ec:       e1832f91        strex   r2, r1, [r3]
...
and gdb already recognizes it as such because of this statement:
...
  if ((insn & 0xff9000f0) != 0xe1900090)
    return {};
...

The trouble with this statement is that it requires knowledge of arm
instruction encoding to understand which cases it does and doesn't cover.

Note that the corresponding comment only mentions ldrex:
...
  /* Assume all atomic sequences start with a ldrex{,b,h,d} instruction. ... */
...
but evidently at least some forms of ldaex are also detected.

So, also use ldaex_p in arm_deal_with_atomic_sequence_raw.  This may or may
not be redundant, but at least ldaex_p is explicit and precise about what it
supports.

Likewise for stlex (generated when using __ATOMIC_RELEASE instead of
__ATOMIC_ACQUIRE in the example above).

Tested in arm-linux chroot on aarch64-linux.

Reviewed-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Co-Authored-By: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Luis Machado <luis.machado@arm.com>
PR tdep/32796
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32796

[1] https://linaro.atlassian.net/browse/GNU-1541

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

2 months agoSimplify print_doc_line
Tom Tromey [Sun, 6 Apr 2025 18:58:55 +0000 (12:58 -0600)] 
Simplify print_doc_line

print_doc_line uses a static buffer and manually manages memory.  I
think neither of these is really needed, so this patch rewrites the
function to use std::string.  The new implementation tries to avoid
copying when possible.

Regression tested on x86-64 Fedora 40.

Reviewed-By: Keith Seitz <keiths@redhat.com>
2 months agogdb: remove unused includes in maint.c
Simon Marchi [Tue, 8 Apr 2025 18:11:15 +0000 (18:11 +0000)] 
gdb: remove unused includes in maint.c

These includes are reported as unused by clangd.

Change-Id: I1cde043244f9efe350310955b2a02ac874be12b3

2 months agogdb/dwarf2: pass correct dwarf2_cu to lookup_dwo_id in create_cus_hash_table
Simon Marchi [Mon, 7 Apr 2025 17:52:01 +0000 (13:52 -0400)] 
gdb/dwarf2: pass correct dwarf2_cu to lookup_dwo_id in create_cus_hash_table

Commit 71a48752660b ("gdb/dwarf: remove create_dwo_cu_reader")
introduced a regression when handling files compiled with "-gsplit-dwarf
-fdebug-types-section" (at least with clang):

    $ cat test.cpp
    #include <vector>

    int main()
    {
      std::vector<int> v;
      return v.size ();
    }
    $ clang++ -O0 test.cpp -g -gdwarf-5 -gsplit-dwarf -fdebug-types-section -o test
    $ ./gdb -nx -q --data-directory=data-directory ./test -ex "maint expand-symtabs"
    Reading symbols from ./test...
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/read.c:6159: internal-error: setup_type_unit_groups: Assertion `per_cu->is_debug_types' failed.

In the main file, we have a skeleton CU with a certain DWO ID:

    0x00000000: Compile Unit: ..., unit_type = DW_UT_skeleton, ..., DWO_id = 0x146eaa4daf5deef2, ...

In the .dwo file, the first unit is a type unit with a certain type
signature:

    0x00000000: Type Unit: ..., unit_type = DW_UT_split_type, ..., type_signature = 0xb499dcf29e2928c4, ...

and the split compile unit matching the DWO ID from the skeleton from
the main file comes later:

    0x0000117f: Compile Unit: ..., unit_type = DW_UT_split_compile, ..., DWO_id = 0x146eaa4daf5deef2, ...

The problem introduced by the aforementioned commit is that when
creating a dwo_unit structure representing the type unit, we use the
signature (DWO id) from the skeleton, instead of the signature from the
type unit's header.  As a result, all dwo_units get created with the
same signature (the DWO id) and only the first unit gets inserted in the
hash table.  When looking up the comp unit by DWO ID later on, we
wrongly find the type unit, and try to expand a type unit as a comp
unit, hitting the assert.

Before that commit, we passed `reader.cu ()` to lookup_dwo_id, which
yields a dwarf2_cu built from parsing the type unit's header.  This
dwarf2_cu contains the comp_unit_header with the correct signature.  Fix
the code to use `reader.cu ()` again.

Another thing that enables this bug is the fact that since DWARF 5, type
and compile units are all in .debug_info, and therefore read by
create_cus_hash_table, so they both end up in dwo_file::cus.  Type units
should end up in dwo_file::tus, otherwise they won't be found by
lookup_dwo_cutu.  This bug hasn't given me trouble so far, so I'm not
fixing it right now, but it's on my todo list.

The problem can be seen with some tests, when using the
dwarf5-fission-debug-types board:

    $ make check TESTS="gdb.cp/expand-sals.exp" RUNTESTFLAGS="--target_board=dwarf5-fission-debug-types CC_FOR_TARGET=clang CXX_FOR_TARGET=clang++"
    Running /home/simark/src/binutils-gdb/gdb/testsuite/gdb.cp/expand-sals.exp ...
    FAIL: gdb.cp/expand-sals.exp: gdb_breakpoint: set breakpoint at main (GDB internal error)

But this patch also adds a DWARF assembler-based test that triggers the
internal error.

Note that the new test does not use the build_executable_and_dwo_files
proc, because I found that it is subtly broken and doesn't work to put
multiple units in a single .dwo file.  The debug abbrev offset field in
the second unit's header would be 0, when it should have been something
else.  The problem is that no linking is ever done to generate the .dwo
file, so the relocation that would apply for this field is never
applied.  Instead, I generate two DWARF debug infos separately and link
the .dwo file using gdb_compile, it seems to work fine.

Change-Id: I96f809c56f703e25f72b8622c32e6bb91de20d6a
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/testsuite/dwarf: fix abbrev section name when putting type unit in DWO file
Simon Marchi [Mon, 7 Apr 2025 17:52:00 +0000 (13:52 -0400)] 
gdb/testsuite/dwarf: fix abbrev section name when putting type unit in DWO file

Fix what looks like a copy paste error resulting in the wrong abbrev
section name.  The resulting section name in my test was
".debug_info.dwo.dwo", when it should have been ".debug_abbrev.dwo".

Change-Id: I82166d8ac6eaf3c3abc15d2d2949d00c31fe79f4
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/testsuite/dwarf: add support to generate DWARF 5 split compile units
Simon Marchi [Mon, 7 Apr 2025 17:51:59 +0000 (13:51 -0400)] 
gdb/testsuite/dwarf: add support to generate DWARF 5 split compile units

Add support to the DWARF assembler to generate DWARF 5 split compile
units.  The assembler knows how to generate DWARF < 5 split compile
units (fission), DWARF 5 compile units, but not DWARF 5 split compile
units.  What's missing is:

 - using the right unit type in the header: skeleton for the unit in the
   main file and split_compile for the unit in the DWO file
 - have a way for the caller to specify the DWO ID that will end up in
   the unit header

Add a dwo_id parameter to the cu proc.  In addition to specifying the
DWO ID, the presence of this parameter tells the assembler to use the
skeleton or split_compile unit type.

This is used in a subsequent patch.

Change-Id: I05d9b189a0843ea6c2771b1d5e5a91762426dea9
Approved-By: Tom Tromey <tom@tromey.com>
2 months agogdb/testsuite: add DWARF 5 + split DWARF + type units board
Simon Marchi [Mon, 7 Apr 2025 17:51:58 +0000 (13:51 -0400)] 
gdb/testsuite: add DWARF 5 + split DWARF + type units board

I'm currently fixing bugs and performance issues when GDB encounters
this particular configuration.  Since split DWARF + type units makes GDB
take some code paths not taken by any other board files, I think it
deserves to be its own board file.  One particularity is that the
produced .dwo files have a .debug_info.dwo section that contains some
ype units, in addition to the compile unit.

Add that board to make-check-all.sh.

Change-Id: I245e6f600055a27e0c31f1a4a9af1f68292fe18c
Approved-By: Tom Tromey <tom@tromey.com>
2 months agoUpdate copyright dates to include 2025
Tom Tromey [Wed, 2 Apr 2025 19:30:10 +0000 (13:30 -0600)] 
Update copyright dates to include 2025

This updates the copyright headers to include 2025.  I did this by
running gdb/copyright.py and then manually modifying a few files as
noted by the script.

Approved-By: Eli Zaretskii <eliz@gnu.org>
2 months agoRename set-solib-absolute-prefix.exp to x86-set-solib-absolute-prefix.exp
Alexandra Hájková [Mon, 7 Apr 2025 11:55:06 +0000 (13:55 +0200)] 
Rename set-solib-absolute-prefix.exp to x86-set-solib-absolute-prefix.exp

and move it from gdb.base to gdb.arch as it's a target specific test.

Reviewed-by: Maciej W. Rozycki <macro@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
2 months agoLoongArch: Warn about right shifts of negative numbers
Lulu Cai [Wed, 2 Apr 2025 02:23:40 +0000 (10:23 +0800)] 
LoongArch: Warn about right shifts of negative numbers

The GNU Assembler User Guide says that the right shift operator ">>"
in an expression is the same as the C operator.

On LoongArch the assembler directives and instructions do not treat
negative numbers ">>" the same way. The directives treats negative
numbers ">>" as logical right shifts while the instructions treats them
as arithmetic right shifts.

The right shift of negative numbers in the instructions may be changed
from an arithmetic right shift to a logical right shift in the future,
and a warning is issued for this.

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

2 months ago[gdb/cli] Use debug info language to pick pygments lexer
Tom de Vries [Mon, 7 Apr 2025 20:40:04 +0000 (22:40 +0200)] 
[gdb/cli] Use debug info language to pick pygments lexer

Consider the following scenario:
...
$ cat hello

int
main (void)
{
  printf ("hello\n");
  return 0;
}
$ gcc -x c hello -g
$ gdb -q -iex "maint set gnu-source-highlight enabled off" a.out
Reading symbols from a.out...
(gdb) start
Temporary breakpoint 1 at 0x4005db: file hello, line 6.
Starting program: /data/vries/gdb/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at hello:6
6   printf ("hello\n");
...

This doesn't produce highlighting for line 6, because:
- pygments is used for highlighting instead of source-highlight, and
- pygments guesses the language for highlighting only based on the filename,
  which in this case doesn't give a clue.

Fix this by:
- adding a language parameter to the extension_language_ops.colorize interface,
- passing the language as found in the debug info, and
- using it in gdb.styling.colorize to pick the pygments lexer.

The new test-case gdb.python/py-source-styling-2.exp excercises a slightly
different scenario: it compiles a c++ file with a .c extension, and checks
that c++ highlighting is done instead of c highlighting.

Tested on x86_64-linux.

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

2 months ago[gdb/tui] Don't try deferred curses initialization twice
Tom de Vries [Mon, 7 Apr 2025 20:27:39 +0000 (22:27 +0200)] 
[gdb/tui] Don't try deferred curses initialization twice

I noticed that if deferred curses initialization fails, for instance when
using TERM=dumb, and we try the same again, we run into the same error:
...
$ TERM=dumb gdb -batch -ex "tui enable" -ex "tui enable"
Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
...

I think it's better to try deferred curses initialization only once.

Fix this by changing bool tui_finish_init into a tribool, and using
TRIBOOL_UNKNOWN to represent the "initialization failed" state, such that we
get instead:
...
$ TERM=dumb gdb -batch -ex "tui enable" -ex "tui enable"
Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
Cannot enable the TUI
...

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2 months ago[lto] Fix symlookup in archives vs shared
Michael Matz [Mon, 31 Mar 2025 13:57:08 +0000 (15:57 +0200)] 
[lto] Fix symlookup in archives vs shared

when a shared library defines 'foo@@FOO' (default version),
a static archive defines 'foo', the shared lib comes in front
of the archive and under effect of --as-needed, and the requesting
object file uses LTO, then the link editor was wrongly including
the definition from the static archive.  It must use the one
from the shared lib, like in the non-LTO or the --no-as-needed case.
See the added testcase that would wrongly print "FAIL" before
this patch.

The problem stems from several connected problems:
(1) only the decorated symbol was entered into first_hash (the hash
    table designed to handle definition order in the pre-LTO-plugin
    phase of the symbol table walks)
(2) in the archive symbol walk only the undecorated name would be
    looked up in first_hash (and hence not found due to (1))
(3) in the archive symbol walk first_hash would only be consulted
    when the linker hash table had a defined symbol.  In pre-LTO
    phase shared lib symbols aren't entered into the linker symbol
    table.

So: add also the undecorated name into first_hash when it stems from
a default version and consult first_hash in the archive walker also
for currently undefined symbols.  If it has an entry which doesn't
point to the archive, then it comes from an earlier library (shared or
static), and so _this_ archive won't provide the definition.

2 months agoxcoff dynamic symbol string sanity
Alan Modra [Mon, 7 Apr 2025 00:37:51 +0000 (10:07 +0930)] 
xcoff dynamic symbol string sanity

Sanity check symbol string table offsets, and tidy structs.  "long"
isn't a good choice for _l_zeroes and _l_offset since it can be 64
bits which blows out the size of the symbol struct unnecessarily.
Also, all of the sizes in internal_ldsym need only be 32 bits, but I
made them size_t because I didn't want to audit all expressions using
them for overflow.

bfd/
* xcofflink.c (_bfd_xcoff_canonicalize_dynamic_symtab): Sanity
check symbol _l_offset.
(xcoff_link_add_dynamic_symbols),
(xcoff_link_check_dynamic_ar_symbols): Likewise.
include/
* coff/xcoff.h (struct internal_ldhdr): Tidy types.
(struct internal_ldsym): Use uint32_t for _l_zeroes and _l_offset.

2 months agoxcoff buffer overflow
Alan Modra [Sun, 6 Apr 2025 08:31:33 +0000 (18:01 +0930)] 
xcoff buffer overflow

Much of the xcoff code is not well protected against fuzzed object file
attacks.  This sanity checks some values in ".loader".

* xcofflink.c (xcoff_get_ldhdr): New function.
(_bfd_xcoff_get_dynamic_symtab_upper_bound),
(_bfd_xcoff_canonicalize_dynamic_symtab),
(_bfd_xcoff_get_dynamic_reloc_upper_bound),
(_bfd_xcoff_canonicalize_dynamic_reloc),
(xcoff_link_add_dynamic_symbols),
(xcoff_link_check_dynamic_ar_symbols): Use xcoff_get_ldhdr.

2 months agobuffer overflow in nds32_elf_do_9_pcrel_reloc
Alan Modra [Sun, 6 Apr 2025 03:51:21 +0000 (13:21 +0930)] 
buffer overflow in nds32_elf_do_9_pcrel_reloc

* elf32-nds32.c (nds32_elf_do_9_pcrel_reloc): Properly bounds
check relocation field.
(nds32_elf_hi20_reloc, nds32_elf_generic_reloc): Likewise.
(nds32_elf_final_link_relocate): Likewise.

2 months agogdb: Introduce user-friendly namespace identifier for "info shared"
Guinevere Larsen [Thu, 13 Mar 2025 13:20:53 +0000 (10:20 -0300)] 
gdb: Introduce user-friendly namespace identifier for "info shared"

GDB has had basic support for linkage namespaces for some time already,
but only in the sense of managing multiple copies of the same shared
object being loaded, and a very fragile way to find the correct copy of
a symbol (see PR shlibs/32054).

This commit is the first step in improving the user experience around
multiple namespace support. It introduces a user-friendly identifier for
namespaces, in the format [[<number>]], that will keep consistent between
dlmopen and dlclose calls. The plan is for this identifier to be usable
in expressions like `print [[1]]::var` to find a specific instance of a
symbol, and so the identifier must not be a valid C++ or Ada namespace
identifier, otherwise disambiguation becomes a problem. Support for
those expressions has not been implemented yet, it is only mentioned to
explain why the identifier looks like this.

This syntax was chosen based on the C attributes, since nothing in GDB
uses a similar syntax that could confuse users. Other syntax options
that were explored were "#<number>" and "@<number>". The former was
abandoned because when printing a frame, the frame number is also
printed with #<number>, so in a lot of the context in which that the
identifier would show up, it appears in a confusing way. The latter
clashes with the array printing syntax, and I believe that the having
"@N::foo" working completely differently to "foo@2" would also lead to a
bad user experience.

The namespace identifiers are stored via a vector inside svr4_info
object. The vector stores the address of the r_debug objects used by
glibc to identify each namespace, and the user-friendly ID is the index
of the r_debug in the vector. This commit also introduces a set storing
the indices of active namespaces. The glibc I used to develop this patch
(glibc 2.40 on Fedora 41) doesn't allow an SO to be loaded into a
deactivated namespace, and requesting a new namespace when a namespace
was previously closed will reuse that namespace. Because of how this is
implemented, this patch lets GDB easily track the exact namespace IDs
that the inferior will see.

Finally, two new solib_ops function pointers were added, find_solib_ns
and num_active_namespaces, to allow code outside of solib-svr4 to find
and use the namespace identifiers and the number of namespaces,
respectively. As a sanity check, the command `info sharedlibrary` has
been changed to display the namespace identifier when the inferior has
more than one active namespace. With this final change, a couple of tests
had to be tweaked to handle the possible new column, and a new test has
been created to make sure that the column appears and disappears as
needed, and that GDB can track the value of the LMID for namespaces.

Approved-by: Kevin Buettner <kevinb@redhat.com>
2 months agobfd: add load config size workaround for i386 XP and earlier
Jeremy Drake [Mon, 7 Apr 2025 11:19:28 +0000 (13:19 +0200)] 
bfd: add load config size workaround for i386 XP and earlier

Per the Microsoft PE documentation, XP and earlier on i686 require the
Size field to be 64, rather than the actual size as required on other
architectures.  I have confirmed Windows 11 accepts either 64 or the
actual size for i386 images, but only the actual size for x86_64 images.

Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2 months agobfd: fill in PE load config directory entry
Jeremy Drake [Mon, 7 Apr 2025 11:19:19 +0000 (13:19 +0200)] 
bfd: fill in PE load config directory entry

This is filled in with the rva of _load_config_used if defined (much
like _tls_used), and the size is the first 32-bit value at that symbol.

Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2 months agobfd: adjust a few error messages
Jeremy Drake [Mon, 7 Apr 2025 11:19:10 +0000 (13:19 +0200)] 
bfd: adjust a few error messages

Rationalize the error messages in _bfd_XXi_final_link_postscript().
They now all correctly refer to DataDirectory instead of DataDictionary,
and use unified format strings, so fewer translations are needed.

Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2 months agobfd: properly use bfd_get_symbol_leading_char() in peXXigen
Jeremy Drake [Mon, 7 Apr 2025 11:18:46 +0000 (13:18 +0200)] 
bfd: properly use bfd_get_symbol_leading_char() in peXXigen

This function returns the leading char to use, so we cannot just assume
it will always be '_' or '\0'.

Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2 months agobfd/COFF: drop link_add_one_symbol() hook
Jan Beulich [Mon, 7 Apr 2025 10:46:16 +0000 (12:46 +0200)] 
bfd/COFF: drop link_add_one_symbol() hook

The need for this has disappeared with dc12032bca08 ("Remove m68k-aout
and m68k-coff support"); avoid the unnecessary indirection.

Sadly, with ld/pe-dll.c using the wrapper, the removal requires moving
the declaration out of libcoff.h, to properly export the underlying BFD
function.

2 months agonm: fall back to heuristic when ELF symbol has zero size
Jan Beulich [Mon, 7 Apr 2025 10:45:30 +0000 (12:45 +0200)] 
nm: fall back to heuristic when ELF symbol has zero size

Size being set for a symbol isn't a strict requirement in ELF. For ones
not having their size set, fall back to the same logic as used for non-
ELF, non-COFF symbols.

While there switch to using elf_symbol_from() instead of kind of open-
coding it.

2 months agonm: also retrieve size for COFF function symbols
Jan Beulich [Mon, 7 Apr 2025 10:45:11 +0000 (12:45 +0200)] 
nm: also retrieve size for COFF function symbols

Like ELF for all symbols, COFF can record size for at least function
ones. Use that - if available - in preference to the distance-to-next-
symbol heuristic.

To be able to use the new test there, make TI C54x follow TI C4x in
providing .sdef to cover for .def already having different meaning.

2 months agogprofng: Remove duplicate symbols
Claudiu Zissulescu [Mon, 31 Mar 2025 11:17:17 +0000 (14:17 +0300)] 
gprofng: Remove duplicate symbols

Remove all duplicate symbols which can be in SymLst.  The duplication
is due to processing of both static and dynamic symbols.  The
Stabs::removeDupSyms function is called before computing symbol
aliases.

Introduce a new vector function (i.e., truncate()), that truncates a
vector lenght to the given new count.  This functionis used by
removeDupSyms function.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2 months agogprofng: Refactor readSymSec for using BFD's asymbol struct
Claudiu Zissulescu [Fri, 28 Mar 2025 11:33:26 +0000 (13:33 +0200)] 
gprofng: Refactor readSymSec for using BFD's asymbol struct

This patch refactors a number of gprofng internal functions for using
more BFD data types and functions.
Stabs::readSymSec is a function which reads the symbols of an ELF file
mapping them into an internal structure. To use BFD asymbols, the
Elf::elf_getsym is changed from custom reading of the symbols from
.symtab and .dynsym section to BFD enable functions. A new function is
introduced which returns the number of either static or dynamic symbols,
named Elf::elf_getSymCount. Both Elf functions are used by
Stabs::readSymSec refactoring.

Also, this patch removes reading symbols, SUNW_ldnsym section as it is
only used by now defunct Studio compiler. However, it adds the reading
of both static and dynamic symbols, previously, only either one was
processed.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2 months agogprofng: Remove check_Relocs() function
Claudiu Zissulescu [Fri, 28 Mar 2025 11:25:19 +0000 (13:25 +0200)] 
gprofng: Remove check_Relocs() function

check_Relocs() function is not anylonger required as it can only
handle Studio compiler relocs, now defunct. Remove this function.

Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-ianculescu@oracle.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Mon, 7 Apr 2025 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

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

2 months agogdbserver: regcache: Update comment in supply_regblock
Thiago Jung Bauermann [Sat, 5 Apr 2025 23:40:08 +0000 (20:40 -0300)] 
gdbserver: regcache: Update comment in supply_regblock

Since commit 84da4a1ea0ae ("gdbserver: refactor the definition and uses of
supply_regblock") there is no case where supply_regblock is passed a
nullptr for the BUF argument, and there is even a gdb_assert to make
sure of it.

Therefore remove that part of the documentation comment.

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

2 months agoobjcopy: also check --file-alignment option argument
Jan Beulich [Fri, 4 Apr 2025 08:25:31 +0000 (10:25 +0200)] 
objcopy: also check --file-alignment option argument

... to be a power of two, just like --section-alignment does.

2 months agobinutils: run objcopy set-section-alignment also for COFF
Jan Beulich [Fri, 4 Apr 2025 08:25:16 +0000 (10:25 +0200)] 
binutils: run objcopy set-section-alignment also for COFF

There's no reason to limit this to just ELF. TI C30 and Z8k don't encode
section alignment in the section entries though (which can't be quite
right, or there would need to be another means by which to express
alignment needs), so --set-section-alignment simply has no effect there.

2 months agoobjcopy: constrain --section-alignment to PE binaries again
Jan Beulich [Fri, 4 Apr 2025 08:24:56 +0000 (10:24 +0200)] 
objcopy: constrain --section-alignment to PE binaries again

PR binutils/32732

The --set-section-alignment option is what ought to be used on object
files; --section-alignment should be affecting PE binaries only, and
only the value stored in the header. Sections don't individually have
alignment recorded there; see 6f8f6017a0c4 ("PR27567, Linking PE files
adds alignment section flags to executables").

Undo the core part of 121a3f4b4f4a ("Update objcopy's
--section-alignment option so that it sets the alignment flag on..."),
which includes removing the testcase again, while leaving all secondary
changes in place. (Note that the testcase did fail anyway for
i?86-interix, with objdump saying "option -P/--private not supported by
this file".)

2 months agoar/objcopy: harmonize .exe suffix stripping
Jan Beulich [Fri, 4 Apr 2025 08:20:31 +0000 (10:20 +0200)] 
ar/objcopy: harmonize .exe suffix stripping

With it only being the tail of the name which wants checking, using
lbasename() isn't helpful. Mirror what objcopy.c:main() does to ar.c,
merely chaning the plain int of the local variable to size_t.

2 months agobinutils: properly split ar and ranlib
Jan Beulich [Fri, 4 Apr 2025 08:20:14 +0000 (10:20 +0200)] 
binutils: properly split ar and ranlib

By not linking the exact same object file twice, in particular ranlib can
benefit quite a bit from the compiler eliminating dead code.

2 months agobinutils: properly split objcopy and strip
Jan Beulich [Fri, 4 Apr 2025 08:19:51 +0000 (10:19 +0200)] 
binutils: properly split objcopy and strip

By not linking the exact same object file twice, in particular strip can
benefit quite a bit from the compiler eliminating dead code.

2 months agoMake gdb/guile codespell-clean
Tom Tromey [Thu, 3 Apr 2025 18:11:15 +0000 (12:11 -0600)] 
Make gdb/guile codespell-clean

This cleans up the last codespell reports in the Guile directory and
adds gdb/guile to pre-commit.

It also tells codespell to ignore URLs.  I think this is warranted
because many URLs don't really contain words per se; and furthermore
if any URL-checking is needed at all, it would be for liveness and not
spelling.

Also I was wondering why the codespell config is in contrib and not
gdb/setup.cfg.

Approved-By: Tom de Vries <tdevries@suse.de>
2 months agoMake gdb/python codespell-clean
Tom Tromey [Thu, 3 Apr 2025 18:01:48 +0000 (12:01 -0600)] 
Make gdb/python codespell-clean

This cleans up the last codespell report in the Python directory and
adds gdb/python to pre-commit.

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

2 months agogdb/dwarf: rename cache -> abbrev_cache
Simon Marchi [Wed, 26 Mar 2025 19:55:37 +0000 (15:55 -0400)] 
gdb/dwarf: rename cache -> abbrev_cache

"cache" is just a bit too generic to be clear.

Change-Id: I8bf01c5fe84e076af1afd2453b1a115777630271

2 months agoMany minor typo fixes
Tom Tromey [Thu, 3 Apr 2025 14:33:58 +0000 (08:33 -0600)] 
Many minor typo fixes

I ran codespell on gdb/*.[chyl] and fixed a bunch of simple typos.
Most of what remains is trickier, i.e., spots where a somewhat natural
name of something in the code is flagged as a typo.

Reviewed-By: Tom de Vries <tdevries@suse.de>
2 months ago[gdb/testsuite] Fix xfail in gdb.ada/array_of_variant.exp
Tom de Vries [Thu, 3 Apr 2025 15:13:12 +0000 (17:13 +0200)] 
[gdb/testsuite] Fix xfail in gdb.ada/array_of_variant.exp

In commit af2b87e649b ("[gdb/testsuite] Add xfail for PR gcc/101633"), I added
an xfail that was controlled by variable old_gcc, triggering the xfail for
gcc 7 and before, but not for gcc 8 onwards:
...
set old_gcc [expr [test_compiler_info {gcc-[0-7]-*}]]
...

In commit 1411185a57e ("Introduce and use gnat_version_compare"), this changed
to:
...
set old_gcc [gnat_version_compare <= 7]
...
which still triggered the xfail for gcc 7, because of a bug in
gnat_version_compare.

After that bug got fixed, the xfail was no longer triggered because the gnatmake
version is 7.5.0, and [version_compare {7 5 0} <= {7}] == 0.

We could have the semantics for version_compare where we clip the input
arguments to the length of the shortest, and so we'd have
[version_compare {7 5 0} <= {7}] == [version_compare {7} <= {7}] == 1.

But let's stick with the current version-sort semantics, and fix this by
using [gnat_version_compare < 8] instead.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2 months ago[gdb/testsuite] Add gdb.testsuite/version-compare.exp
Tom de Vries [Thu, 3 Apr 2025 15:13:12 +0000 (17:13 +0200)] 
[gdb/testsuite] Add gdb.testsuite/version-compare.exp

Add a test-case gdb.testsuite/version-compare.exp that excercises proc
version_compare, and a note to proc version_compare that it considers
v1 < v1.0 instead of v1 == v1.0.

Tested on x86_64-linux.

Approved-By: Tom Tromey <tom@tromey.com>
2 months agoFix parsing .debug_aranges section for signed addresses.
Martin Simmons [Thu, 27 Mar 2025 16:03:45 +0000 (16:03 +0000)] 
Fix parsing .debug_aranges section for signed addresses.

Some architectures, such as MIPS, have signed addresses and this changes
read_addrmap_from_aranges to record them as signed when required.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32658
Approved-By: Tom Tromey <tom@tromey.com>
2 months agoFix pp.rs test for gccrs
Tom Tromey [Mon, 17 Mar 2025 18:57:34 +0000 (12:57 -0600)] 
Fix pp.rs test for gccrs

gccrs still can't process all of gdb's Rust tests, but I did manage to
manually test it on a few.  In addition to filing some bug reports, I
came up with this patch.

There are two fixes here.  First, gccrs emits tuple field names as
integers ("0", "1", etc) whereas rustc uses a leading double
underscore ("__0", "__1", etc).  This patch changes gdb to accept the
gccrs output, which IMO makes sense (and for which there's already a
rustc feature request).

Second, it changes rust_struct_anon::evaluate to use check_typedef.
This is a gdb necessity in general, so could be described as an
oversight; but in this case it works around the gccrs oddity that most
named types are emitted as DW_TAG_typedef.  I've filed a gccrs bug
report for that.

2 months ago[pre-commit] Add codespell-clean gdb subdirs
Tom de Vries [Thu, 3 Apr 2025 13:56:49 +0000 (15:56 +0200)] 
[pre-commit] Add codespell-clean gdb subdirs

As an alternative to adding the gdb dir to codespell while it's still not
codespell-clean [1], add gdb subdirs which are codespell-clean.

Found using:
...
$ for d in $(find gdb -maxdepth 1 -type d | egrep -v "testsuite|gdb$"); do \
      echo -n "$d: "; \
      codespell --config gdb/contrib/setup.cfg $d 2>/dev/null \
          | wc -l; \
  done 2>&1 \
      | grep ": 0"
gdb/tui: 0
gdb/target: 0
gdb/data-directory: 0
gdb/po: 0
gdb/system-gdbinit: 0
gdb/mi: 0
gdb/syscalls: 0
gdb/arch: 0
gdb/regformats: 0
gdb/compile: 0
...

Verified using:
...
$ pre-commit run codespell --all-files
codespell................................................................Passed
...

Approved-By: Tom Tromey <tom@tromey.com>
[1] https://sourceware.org/pipermail/gdb-patches/2025-March/216781.html

2 months agold/testsuite/ld-pe: Escape dots in regular expressions
LIU Hao [Mon, 31 Mar 2025 07:41:09 +0000 (15:41 +0800)] 
ld/testsuite/ld-pe: Escape dots in regular expressions

Signed-off-by: LIU Hao <lh_mouse@126.com>
ld/ChangeLog:
* testsuite/ld-pe/secidx.d: Escape dots in regular expressions.

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

2 months agoClean up cooked_index::done_reading
Tom Tromey [Fri, 28 Mar 2025 16:26:36 +0000 (10:26 -0600)] 
Clean up cooked_index::done_reading

The cooked index worker maintains the state for the various state
transition in the scanner.  It is held by the cooked_index while
scanning is in progress, then deleted once this has completed.

I noticed that none of the arguments to cooked_index::done_reading
were really needed -- the cooked_index already has access to the
worker should it need it.  Removing these parameters makes the code a
bit simpler and also cleans up some confusing code around the use of
the deferred warnings object.

Regression tested on x86-64 Fedora 40.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoUpdate copyright.py
Tom Tromey [Tue, 1 Apr 2025 18:30:33 +0000 (12:30 -0600)] 
Update copyright.py

copyright.py needed an addition for unordered_dense.h.

Then, when running it, I saw it complain about some .pyc files I had
in the source tree.  I don't know why I had these, but the script
should ignore them.

For this, Kévin suggested using "git ls-files" to determine which
files to update -- that should automatically exclude any random files
in the tree.  This version of the patch makes this change.

There were complaints about some sim/ppc files that were renamed.
Ignoring the entire directory seems simpler given the comment.

I also made a few more minor changes:

* Removed the 'CVS' exclusion, as this hasn't been relevant in years.

* Moved the 'copying.c' exclusion to EXCLUDE_LIST

* Changed the script to run from the top level (we could have it
  automatically find this if we really wanted).

After this lands, I plan to run it and check in the result.  The patch
may be too large (and certainly too uninteresting) to post, so if/when
this happens I will send a brief note to the list about it.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agogdb/dwarf2: remove unused includes
Simon Marchi [Wed, 2 Apr 2025 16:42:35 +0000 (12:42 -0400)] 
gdb/dwarf2: remove unused includes

Remove some includes reported as unused by clangd.

Change-Id: I841938c3c6254e4f0d154a1e172c4968ff326333

2 months agogdb: remove unused includes in dbxread.c
Simon Marchi [Wed, 2 Apr 2025 16:36:08 +0000 (12:36 -0400)] 
gdb: remove unused includes in dbxread.c

Remove includes reported as unused by clangd.

Change-Id: I12e5cf254d211f42f3cfdab90d1f42a5986e53a3

2 months agoFix gdbserver crashes on SVE/SME-enabled systems
Luis Machado [Fri, 28 Feb 2025 09:36:42 +0000 (09:36 +0000)] 
Fix gdbserver crashes on SVE/SME-enabled systems

Commit 51e6b8cfd649013ae16a3d00f1451b2531ba6bc9 fixed a
regression for SVE/SME registers on gdb's side by using a <= comparison for
regcache's raw_compare assertion check. We seem to have failed to do the same
for gdbserver's raw_compare counterpart.

With the code as it is, I'm seeing a lot of crashes for gdbserver on a machine
with SVE enabled. For instance, with the following invocation:

make check-gdb RUNTESTFLAGS="--target_board=native-gdbserver" TESTS=gdb.base/break.exp

Running /work/builds/binutils-gdb/gdb/testsuite/../../../../repos/binutils-gdb/gdb/testsuite/gdb.base/break.exp ...
FAIL: gdb.base/break.exp: test_break: run until function breakpoint
FAIL: gdb.base/break.exp: test_break: run until breakpoint set at a line number (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:function(6) breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:function(5) breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:function(4) breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:function(3) breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:function(2) breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:function(1) breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until quoted breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: run until file:linenum breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: breakpoint offset +1
FAIL: gdb.base/break.exp: test_break: step onto breakpoint (the program is no longer running)
FAIL: gdb.base/break.exp: test_break: setting breakpoint at }
FAIL: gdb.base/break.exp: test_break: continue to breakpoint at } (the program is no longer running)
FAIL: gdb.base/break.exp: test_no_break_on_catchpoint: runto: run to main
FAIL: gdb.base/break.exp: test_break_nonexistent_line: runto: run to main
FAIL: gdb.base/break.exp: test_break_default: runto: run to main
FAIL: gdb.base/break.exp: test_break_silent_and_more: runto: run to main
FAIL: gdb.base/break.exp: test_break_line_convenience_var: runto: run to main
FAIL: gdb.base/break.exp: test_break_user_call: runto: run to main
FAIL: gdb.base/break.exp: test_finish_arguments: runto: run to main
FAIL: gdb.base/break.exp: test_next_with_recursion: kill program
FAIL: gdb.base/break.exp: test_next_with_recursion: run to factorial(6)
FAIL: gdb.base/break.exp: test_next_with_recursion: continue to factorial(5) (the program is no longer running)
FAIL: gdb.base/break.exp: test_next_with_recursion: backtrace from factorial(5)
FAIL: gdb.base/break.exp: test_next_with_recursion: next to recursive call (the program is no longer running)
FAIL: gdb.base/break.exp: test_next_with_recursion: next over recursive call (the program is no longer running)
FAIL: gdb.base/break.exp: test_next_with_recursion: backtrace from factorial(5.1)
FAIL: gdb.base/break.exp: test_next_with_recursion: continue until exit at recursive next test (the program is no longer running)
FAIL: gdb.base/break.exp: test_break_optimized_prologue: run until function breakpoint, optimized file
FAIL: gdb.base/break.exp: test_break_optimized_prologue: run until breakpoint set at small function, optimized file (the program is no longer running)
FAIL: gdb.base/break.exp: test_rbreak_shlib: rbreak junk

Adjusting the regcache raw_compare assertion check to use <= fixes
the problem on aarch64-linux on a SVE-capable system.

This patch also adds a simple selftest to gdbserver that validates this
particular case by simulating a raw_compare operation.

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

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoAdd optional filename argument to the linker's --stats option, allowing extra resourc...
Nick Clifton [Wed, 2 Apr 2025 09:56:16 +0000 (10:56 +0100)] 
Add optional filename argument to the linker's --stats option, allowing extra resource use information to be reported.

2 months agoAdd gdb.base/set-solib-absolute-prefix.exp
Alexandra Hajkova [Fri, 27 Oct 2017 19:07:50 +0000 (21:07 +0200)] 
Add gdb.base/set-solib-absolute-prefix.exp

Compile a 32-bit x86 executable and then stop within a system call.
Change the sysroot to a non-existent directory, GDB should try (and
fail) to reload the currently loaded shared libraries.  However, GDB
should retain the symbols for the vDSO library as that is not loaded
from the file system.

Check the backtrace to ensure that the __kernel_vsyscall symbol is
still in the backtrace, this indicates GDB still has the vDSO
symbols available.

This test was present in Fedora for a long time and was
originally written by Jan Kratochvil for this fix
829a902da291e72ad17e8c44fa8d9ead3db41b1f.

Co-Authored-By: Jan Kratochvil <jan.kratochvil@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
2 months agoAutomatic date update in version.in
GDB Administrator [Wed, 2 Apr 2025 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 months agogdb: move addrmap::relocate method to addrmap_fixed
Simon Marchi [Mon, 31 Mar 2025 20:09:42 +0000 (16:09 -0400)] 
gdb: move addrmap::relocate method to addrmap_fixed

The relocate method of addrmap is unnecessarily virtual.  Only
addrmap_fixed provides a meaningful implementation.  Move the method to
addrmap_fixed only and make it non-virtual.

Change-Id: If61d5e70abc12c17d1e600adf0dd0707e77a6ba2
Approved-By: Tom Tromey <tom@tromey.com>
2 months ago[gdb/contrib] Support gdb in codespell section of setup.cfg
Tom de Vries [Tue, 1 Apr 2025 13:47:55 +0000 (15:47 +0200)] 
[gdb/contrib] Support gdb in codespell section of setup.cfg

Add support for the gdb dir in the codespell section of gdb/contrib/setup.cfg,
specifically adding files in the skip line.

This allows us to run codespell from the command line on the gdb dir:
...
$ codespell --config gdb/contrib/setup.cfg gdb 2>/dev/null | wc -l
1665
...
without running into warnings in generated files.

Approved-By: Tom Tromey <tom@tromey.com>
2 months agoUpdate cooked_index comment
Tom Tromey [Tue, 25 Mar 2025 23:11:24 +0000 (17:11 -0600)] 
Update cooked_index comment

This updates the cooked_index comment with some notes about object
lifetimes, in an attempt to make navigating this code a bit simpler.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoAdd cooked_index_worker::done_reading
Tom Tromey [Tue, 25 Mar 2025 23:41:13 +0000 (17:41 -0600)] 
Add cooked_index_worker::done_reading

The two readers currently using cooked_index_worker shared some code.
This patch factors this out into a new "done_reading" method.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoRemove cooked_index_worker::result_type
Tom Tromey [Tue, 25 Mar 2025 13:17:38 +0000 (07:17 -0600)] 
Remove cooked_index_worker::result_type

cooked_index_worker::result_type is an ad hoc tuple type used for
transferring data between phases of the indexer.  It's a bit unwieldy
and another patch I'm working on would be somewhat nicer without it.

This patch removes the type.  Now cooked_index_ephemeral objects are
transferred instead, which is handy because they already hold the
needed state.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoAdd addrmap_mutable::clear
Tom Tromey [Tue, 25 Mar 2025 19:25:39 +0000 (13:25 -0600)] 
Add addrmap_mutable::clear

It was convenient to add a 'clear' method to addrmap_mutable.  The
cleanest way to do this was to change the class to lazily initialize
its 'tree' member.  This also makes addrmap_mutable::operator= a bit
less weird.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoUpdate comments from moved methods
Tom Tromey [Wed, 26 Mar 2025 00:51:51 +0000 (18:51 -0600)] 
Update comments from moved methods

This updates the "See xyz.h" comments for all the methods that were
moved earlier in this series.  Perhaps I should have removed them
instead.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoMove cooked_index_worker to cooked-index-worker.[ch]
Tom Tromey [Mon, 24 Mar 2025 21:34:39 +0000 (15:34 -0600)] 
Move cooked_index_worker to cooked-index-worker.[ch]

This moves the cooked_index_worker class to cooked-index-worker.[ch].

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoChange includes in cooked-index-worker.h
Tom Tromey [Mon, 24 Mar 2025 21:30:07 +0000 (15:30 -0600)] 
Change includes in cooked-index-worker.h

This changes cooked-index-worker.h to include the new header files.
This breaks the circular dependency that would otherwise be introduced
in the next patch.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoMove cooked_index_shard to new files
Tom Tromey [Mon, 24 Mar 2025 21:19:20 +0000 (15:19 -0600)] 
Move cooked_index_shard to new files

This moves cooked_index_shard to a couple of new files,
dwarf2/cooked-index-shard.[ch].  The rationale is the same as the
previous patch: cooked-index.h had to be split to enable other
cleanups.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoMove cooked_index_entry to new files
Tom Tromey [Mon, 24 Mar 2025 21:11:02 +0000 (15:11 -0600)] 
Move cooked_index_entry to new files

This moves cooked_index_entry and some related helper code to a couple
of new files, dwarf2/cooked-index-entry.[ch].

The main rationale for this is that in order to finish this series and
remove "cooked_index_worker::result_type", I had to split
cooked-index.h into multiple parts to avoid circular includes.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoMake language_requires_canonicalization 'static'
Tom Tromey [Mon, 31 Mar 2025 22:46:23 +0000 (16:46 -0600)] 
Make language_requires_canonicalization 'static'

language_requires_canonicalization is only called from cooked-index.c,
so mark it as static.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoRename cooked_index_storage
Tom Tromey [Mon, 24 Mar 2025 21:08:37 +0000 (15:08 -0600)] 
Rename cooked_index_storage

This renames cooked_index_storage to cooked_index_worker_result,
making its function more clear.  It also updates the class comment to
as well.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoRename cooked-index-storage.[ch]
Tom Tromey [Mon, 24 Mar 2025 21:03:04 +0000 (15:03 -0600)] 
Rename cooked-index-storage.[ch]

A discussion with Simon made me realize that cooked_index_storage
isn't a very clear name, especially now that it's escaped from read.c.
While it does provide some storage (I guess any object does in a
sense), it is really a helper for cooked_index_worker -- a temporary
object that is destroyed after reading has completed.

This patch renames this file.  Later patches will rename the class and
move cooked_index_worker here, something I think is reasonable given
that cooked_index_storage is really something of a helper class for
cooked_index_worker.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2 months agoPR32829, SEGV on objdump function debug_type_samep
Alan Modra [Tue, 1 Apr 2025 12:06:54 +0000 (22:36 +1030)] 
PR32829, SEGV on objdump function debug_type_samep

u.kenum is always non-NULL, see debug_make_enum_type.

PR 32829
* debug.c (debug_type_samep): Correct incomplete enum test.
(debug_write_type): Remove dead code.

2 months agoubsan: nds32 undefined shift
Alan Modra [Mon, 31 Mar 2025 08:49:28 +0000 (19:19 +1030)] 
ubsan: nds32 undefined shift

Avoid implementation defined behaviour right shift of negative values,
and undefined behaviour left shift of negative values.  While this
change might give different results in the top bit of a bfd_vma
(rightshift is 1), that doesn't matter as only the bottom 8 bits of
the relocation are used.

* elf32-nds32.c (nds32_elf_do_9_pcrel_reloc): Calculate relocation
using a bfd_vma type.

2 months agoFormatting fixes for elf-attrs.c
Alan Modra [Sun, 9 Mar 2025 22:47:11 +0000 (09:17 +1030)] 
Formatting fixes for elf-attrs.c

2 months agoCheck gnatmake version in gnat_version_compare
Tom Tromey [Mon, 31 Mar 2025 17:53:53 +0000 (11:53 -0600)] 
Check gnatmake version in gnat_version_compare

Tom de Vries pointed out that my earlier change to
gnat_version_compare made it actually test gcc's version -- not
gnat's.

This patch changes gnat_version_compare to examine gnatmake's version,
while preserving the nicer API.

Approved-By: Tom de Vries <tdevries@suse.de>
2 months agobinutils/testsuite: don't tail the same input and output file
Clément Chigot [Mon, 31 Mar 2025 08:42:43 +0000 (10:42 +0200)] 
binutils/testsuite: don't tail the same input and output file

The output file could be created before the input is gathered by tail,
erasing the later before it's being proceeded.

This happened on rare cases when performing remote tests on
Ubuntu 24.04.

2 months agobinutils/testsuite: move objdump test output into tmpdir
Clément Chigot [Mon, 31 Mar 2025 08:40:37 +0000 (10:40 +0200)] 
binutils/testsuite: move objdump test output into tmpdir

"objdump.out" is a testsuite trace and thus should be created within the
tmpdir.