Tom de Vries [Thu, 16 Oct 2025 10:09:57 +0000 (12:09 +0200)]
[pre-commit] Add check-gnu-style
I got a review comment [1] because I forgot to do "space before paren".
I realized I forgot to run check_GNU_style.py, a script from the GCC repo,
which warns about things like this.
[ The python script has been around since 2017 (and an earlier version written
in shell script since 2010). ]
So for this change in gdb/gdb.c:
...
- return gdb_main (&args);
+ return gdb_main(&args);
...
we get:
...
$ ./contrib/check_GNU_style.py <(git diff)
=== ERROR type #1: there should be exactly one space between function name \
and parenthesis (1 error(s)) ===
gdb/gdb.c:38:17: return gdb_main(&args);
...
Add a pre-commit hook to do this automatically.
This copies two files from the GCC repo to root-level contrib, and adds a
wrapper script gdb/contrib/check-gnu-style-pre-commit.sh (checked with
shellcheck).
The wrapper script is setup to not fail on violations, so the messages are
informational at this point. I'm not sure all checks are 100% applicable to
our coding style.
The python script check_GNU_style.py has two dependencies: unidiff and
termcolor, which users need to install themselves.
The check is added at the pre-commit stage. I also considered post-commit,
and I'm still not sure what is the better choice.
As with all pre-commit checks, if the check is not to your liking, you can
use SKIP=check-gnu-style to skip it.
In summary, with the new pre-commit check we get:
...
$ git commit -a -m "style error"
black...............................................(no files to check)Skipped
flake8..............................................(no files to check)Skipped
isort...............................................(no files to check)Skipped
codespell...........................................(no files to check)Skipped
check-include-guards................................(no files to check)Skipped
check-gnu-style.........................................................Passed
- hook id: check-gnu-style
- duration: 0.04s
=== ERROR type #1: there should be exactly one space between function name \
and parenthesis (1 error(s)) ===
gdb/gdb.c:38:17: return gdb_main(&args);
tclint..............................................(no files to check)Skipped
black...............................................(no files to check)Skipped
flake8..............................................(no files to check)Skipped
codespell...........................................(no files to check)Skipped
check-include-guards................................(no files to check)Skipped
codespell-log...........................................................Passed
- hook id: codespell-log
- duration: 0.19s
tclint...............................................(no files to check)Skipped
[master $hex] style error
...
Approved-By: Simon Marchi <simon.marchi@efficios.com>
[1] https://sourceware.org/pipermail/gdb-patches/2025-September/220983.html
Tom de Vries [Thu, 16 Oct 2025 09:38:53 +0000 (11:38 +0200)]
[gdb/c++] Fix hang on whatis std::string::npos
Consider the following scenario, exercising "whatis std::string::npos":
...
$ cat test.cc
int main (void) {
std::string foo = "bar";
return foo.size ();
}
$ g++ test.cc -g
$ gdb -q -batch -iex "set trace-commands on" a.out -x gdb.in
+start
Temporary breakpoint 1 at 0x4021c7: file test.cc, line 3.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Temporary breakpoint 1, main () at test.cc:3
3 std::string foo = "bar";
+info auto-load python-scripts
No auto-load scripts.
+whatis std::string
type = std::__cxx11::basic_string<char, std::char_traits<char>, \
std::allocator<char> >
+whatis std::string::npos
type = const std::__cxx11::basic_string<char, std::char_traits<char>, \
std::allocator<char> >::size_type
...
After installing the package containing the pretty-printers:
...
$ zypper install libstdc++6-pp
...
and adding some commands to use them, we get instead:
...
$ gdb -q -batch -iex "set trace-commands on" a.out -x gdb.in
+add-auto-load-safe-path /usr/share/gdb/auto-load
+add-auto-load-scripts-directory /usr/share/gdb/auto-load
+start
...
+info auto-load python-scripts
Loaded Script
Yes /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.34-gdb.py
+whatis std::string
type = std::string
+whatis std::string::npos
type = const std::__cxx11::basic_string<char, std::char_traits<char>, \
std::allocator<char> >::size_type
...
Note that "whatis std::string" now prints "std::string", but that
"whatis std::string::npos" still uses the longer name for std::string.
This is when compiling gdb with -O0. With -O2 -fstack-protector-strong, we
have a hang instead:
...
+whatis std::string
type = std::string
+whatis std::string::npos
<HANG>
...
Valgrind complains about an uninitialized field
demangle_component::d_counting, which is fixed by using
cplus_demangle_fill_name in replace_typedefs_qualified_name.
After fixing that, the hang is also reproducible at -O0.
The hang happens because we're stuck in the while loop in
replace_typedefs_qualified_name, replacing "std::string::size_type" with
"std::string::size_type".
Fix this in inspect_type by checking for this situation, getting us instead:
...
+whatis std::string
type = std::string
+whatis std::string::npos
type = const std::string::size_type
$
...
The test-case is a bit unusual:
- pretty-print.cc is a preprocessed c++ source, reduced using cvise [1], then
hand-edited to fix warnings with gcc and clang.
- the pretty-printer .py file is a reduced version of
/usr/share/gcc-15/python/libstdcxx/v6/printers.py.
Using the test-case (and the cplus_demangle_fill_name fix), I managed to
reproduce the hang on both:
- openSUSE Leap 15.6 with gcc 7, and
- openSUSE Tumbleweed with gcc 15.
The test-case compiles with clang, but the hang didn't reproduce.
Jens Remus [Thu, 16 Oct 2025 09:09:06 +0000 (11:09 +0200)]
s390: Do not rewrite insns and their relocs in linker if --no-relax
Under certain conditions the linker rewrites:
- GOT access using lgrl to larl, changing the GOTENT to a PC32DBL reloc
- GOT access using lg to larl, changing the GOT20 to a PC32DBL reloc
- Relative long addressing instructions of weak symbols, which
definitively resolve to zero to either (1) load address of zero,
(2) a NOP, or (3) a trapping instruction, changing the relocation to
a NONE reloc.
Suppress rewriting of non-TLS instructions and related relocations in
linker if option --no-relax is specified. This aligns with LLVM linker
behavior on s390.
Like x86-64 do not actually enable the linker relaxation option by
default, as other targets would do using ENABLE_RELAXATION or
TARGET_ENABLE_RELAXATION in their linker emulation scripts. Instead
perform linker instruction/relocation rewrites by default unless linker
option --no-relax is explicitly specified by the user. This ensures no
functional change unless --no-relax is used.
bfd/
* elf64-s390.c (elf_s390_relocate_section): Do not rewrite
non-TLS instructions and related relocations if --no-relax.
* elf32-s390.c (elf_s390_relocate_section): Likewise.
ld/testsuite/
* ld-s390/s390.exp: New tests. Same as gotreloc_*-1a and
weakundef-*a, but with linker option --no-relax, to verify
suppression of linker non-TLS insn and reloc rewrites.
* ld-s390/gotreloc_31-1b.dd: Likewise.
* ld-s390/gotreloc_31-no-pie-1b.dd: Likewise.
* ld-s390/gotreloc_64-no-pie-1b.dd: Likewise.
* ld-s390/gotreloc_64-norelro-1b.dd: Likewise.
* ld-s390/gotreloc_64-relro-1b.dd: Likewise.
* ld-s390/weakundef-1b.d: Likewise. Check for expected reloc
overflows.
* ld-s390/weakundef-2b.d: Likewise.
Jens Remus [Thu, 16 Oct 2025 09:06:17 +0000 (11:06 +0200)]
s390: Rewrite emitted relocations when rewriting instructions
When the linker rewrites instructions it may need to rewrite the
associated relocations, so that when emitted with option --emit-relocs,
they make sense with the rewritten instructions. Otherwise post link
analysis and optimization tools may not be able to perform correct
modifications of executables.
Under certain conditions the linker rewrites:
- GOT access using lgrl to larl, changing the GOTENT to a PC32DBL reloc
- GOT access using lg to larl, changing the GOT20 to a PC32DBL reloc
- Relative long addressing instructions of weak symbols, which
definitively resolve to zero, to either (1) load address of zero,
(2) a NOP, or (3) a trapping instruction.
In case of a rewrite of GOT access using lgrl/lg to larl emit the
PC32DBL relocation. In case of a rewrite of relative long addressing
instructions of weak symbols, which definitively resolve to zero, emit
a NONE relocation and reset the symbol table index and addend. Update
the gotreloc* and weakundef* tests to check for the respective
relocations.
This aligns with how GNU linker behaves on x86-64, when rewriting
instructions/relocations in elf_x86_64_convert_load_reloc().
Andrew Burgess [Mon, 13 Oct 2025 13:44:56 +0000 (14:44 +0100)]
gdb/testsuite: remove incorrect global variable accesses
I noticed in gdb.replay/missing-thread.exp a reference to $testfile in
a location where 'testfile' had not been made available via a use of
'global'. The uses looked like this:
I think there are three problems here, the $testfile is invalid
because there's no 'global testfile' making the variable available.
The use of $testfile is redundant anyway as 'unsupported' already adds
the script name to the output line. The final text within parenthesis
is bad style that's an important part of the output, but GDB test name
style is that text in parenthesis is additional text that could be
ignored, e.g. "(timeout)".
Replace the above with just:
unsupported "couldn't start gdbreplay"
This same construct has been copied into multiple gdb.replay/ tests,
so fix them all.
There's no change to what is actually tested after this commit.
hppa64: Fix addition of symbols to local dynamic table
This fixes lookup failure in elf64_hppa_finalize_dynreloc.
2025-10-15 John David Anglin <danglin@gcc.gnu.org>
bfd/ChangeLog:
* elf64-hppa.c (elf64_hppa_check_relocs): Record local
dynamic symbol if a dynamic relocation is needed.
(allocate_global_data_dlt) Fix typo.
(allocate_dynrel_entries): Don't record symbol.
(elf64_hppa_finalize_dynreloc): Assert dynindx is not -1.
Jens Remus [Wed, 15 Oct 2025 15:45:48 +0000 (17:45 +0200)]
gas: sframe: Represent .cfi_undefined RA as FRE without offsets
In DWARF CFI an "undefined" register rule for the return address (RA)
register indicates that there is no return address and the stack trace
is complete.
Represent DW_CFA_undefined as SFrame FRE without any offsets, so that a
stack tracer implementation can use this as indication that an outermost
frame has been reached and the stack trace is complete.
This representation is backward compatible, as existing stack tracers
should already deal with the case, that an SFrame FRE a so far invalid
offset count of zero and stop the trace.
include/
* sframe.h (SFRAME_V2_FRE_RA_UNDEFINED_P): New macro to test
FRE info word for RA undefined (FRE without any offsets).
binutils/
* NEWS: Mention SFrame can represent an undefined RA as FRE
without any offsets.
gas/
* gen-sframe.h (struct sframe_row_entry): Add ra_undefined_p
flag.
* gen-sframe.c (sframe_row_entry_new): Initialize ra_undefined_p
flag to not set.
(sframe_row_entry_initialize): Treat ra_undefined_p flag as
sticky.
(sframe_fre_set_ra_track): Reset ra_undefined_p flag.
(sframe_xlate_do_restore): Reset ra_undefined_p flag to saved
state.
(sframe_xlate_do_same_value): Reset ra_undefined_p flag.
(sframe_xlate_do_cfi_undefined): For RA set ra_undefined_p flag.
(output_sframe_row_entry): Represent RA undefined as SFrame FRE
without any offsets and FRE info word fields zeroed.
* NEWS: Mention assembler represents .cfi_undefined RA in SFrame
as FRE without any offsets.
libsframe/
* doc/sframe-spec.texi (Changes from Version 1 to Version 2):
Mention that a SFrame FRE without any offsets flag indicates an
outermost frame with an undefined RA.
(fre_offset_count): Document that a FRE offset count of zero
indicates an outermost frame with an undefined RA.
* sframe.c (sframe_get_fre_ra_undefined_p): Use macro
SFRAME_V2_FRE_RA_UNDEFINED_P.
(sframe_fre_get_fp_offset, sframe_fre_get_ra_offset): Do not
return fixed FP/RA offset if RA undefined.
* sframe-dump.c (dump_sframe_func_with_fres): Show FRE without
any offsets as "RA undefined".
gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: Run tests for .cfi_undefined RA
on AArch64, s390x, and x86-64.
* gas/cfi-sframe/cfi-sframe-aarch64-ra-undefined-1.d: Add test
for .cfi_undefined RA on AArch64.
* gas/cfi-sframe/cfi-sframe-aarch64-ra-undefined-1.s: Likewise.
* as/cfi-sframe/cfi-sframe-s390x-ra-undefined-1.d: Add test
for .cfi_undefined RA on s390x.
* gas/cfi-sframe/cfi-sframe-s390x-ra-undefined-1.s: Likewise.
* gas/cfi-sframe/cfi-sframe-x86_64-ra-undefined-1.d: Add test
for .cfi_undefined RA on x86-64.
* gas/cfi-sframe/cfi-sframe-x86_64-ra-undefined-1.s: Likewise.
Jens Remus [Wed, 15 Oct 2025 15:45:48 +0000 (17:45 +0200)]
include: libsframe: Add API to get RA undefined
SFrame FREs without any offsets will later be used to represent an
undefined return address (RA) in SFrame. This API can then be used,
for instance by libsframe when dumping SFrame stack trace information
(e.g. in objdump and readelf), to test for RA undefined. Other users
of libsframe need the same capability.
include/
* sframe-api.h (sframe_fre_get_ra_undefined_p): New declaration.
libsframe/
* libsframe.ver (sframe_fre_get_ra_undefined_p): List new API.
* sframe.c (sframe_fre_get_ra_undefined_p): New definition.
Jens Remus [Wed, 15 Oct 2025 15:45:48 +0000 (17:45 +0200)]
libsframe: s390: No further decode if sframe_get_fre_offset returns err
SFrame FREs without any offsets will later be used to represent
.cfi_undefined RA in SFrame.
As a result the API to get the CFA offset can return an error value, if
there are no offsets. Do not apply the s390x-specific decoding of CFA
offset on the error return value.
libsframe/
* sframe.c (sframe_fre_get_cfa_offset): Do not apply s390x-
specific decoding to error return value.
Jens Remus [Wed, 15 Oct 2025 15:45:48 +0000 (17:45 +0200)]
gas: ld: libsframe: Support for SFrame FDEs without any FREs
Allow SFrame sections without any FREs, that can occur if they solely
contain FDEs without any FREs. For FDEs without and FREs set the
offset to the first FRE to zero.
libsframe/
* sframe.c (sframe_encoder_write_sframe): Allow SFrame sections
without any FREs. For FDEs without any FREs set the offset to
the first FRE to zero.
gas/
* gen-sframe.c (output_sframe_funcdesc): For FDEs without any
FREs set the offset to the first FRE to zero.
Today, GDB links against the Python library using the unstable API. This
approach causes portability issues of the generated GDB artifact. Indeed
the built artifact is tighly coupled with the specific version of Python
that it was compiled with. Using a slighly minor version of Python can
cause unpredictable crashes at runtime due to ABI instability between
the Python versions, even minor ones.
The solution would consist in restricting the usage of Python functions
to the limited C API controlled via Py_LIMITED_API that must be defined
before the inclusion of <Python.h>.
This patch does not aim at porting the whole GDB codebase to the Python
limited C API, but rather enabling a development mode where developers
can experiment with the Python limited C API, and fix issues.
This development mode is accessible with the configure option
--enable-py-limited-api which is set by default to 'no'.
Note: the version of the Python limited API is currently set to 3.11
because of PyBuffer_FillInfo and PyBuffer_Release. This choice is not
frozen, and could be reviewed later on depending on newly discovered
issues during the migration.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830 Approved-By: Tom Tromey <tom@tromey.com>
Matthieu Longo [Wed, 16 Jul 2025 16:17:36 +0000 (17:17 +0100)]
gdb: make Python conftest compatible with Python limited C API
The current test to check the support of '--dynamic-list' linker flag
uses PyRun_SimpleString (), which is part of the unstable API. As it is
now, the test will systematically fail due to the undefined symbol
rather than testing the import of ctypes.
This patch replaces PyRun_SimpleString () by an equivalent code relying
on the limited C API, and compatible with Python 3.4.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23830 Approved-By: Tom Tromey <tom@tromey.com>
Simon Marchi [Sat, 11 Oct 2025 04:08:49 +0000 (00:08 -0400)]
gdb/linespec: take some parameters by reference
Change the `sal` parameter of add_sal_to_sals to be a reference. This
will make things a bit cleaner in a following patch (and it would be a
good change on its own anyway).
Change the `sals` parameter to a reference as well, while at it, which
trickles up to minsym_found.
Change-Id: I348414308940c14fa6030bc41c52f507aa6d1c12 Approved-By: Tom Tromey <tom@tromey.com>
Simon Marchi [Sat, 11 Oct 2025 04:06:20 +0000 (00:06 -0400)]
gdb: remove unnecessary use of symtab_and_line in create_sals_line_offset
create_sals_line_offset uses a symtab_and_line essentially just to hold
a line number and pass it down to decode_digits_list_mode. Change the
local variable to be an int, and change decode_digits_list_mode to
accept an int, instead of a symtab_and_line. I think this makes the
code a bit simpler.
Change-Id: I445d2473f042693c3a4f2693877408f85100cd1f Approved-By: Tom Tromey <tom@tromey.com>
Tom Tromey [Mon, 22 Sep 2025 15:08:46 +0000 (09:08 -0600)]
Fix use of "main" marker in gdb index
Tom de Vries noticed that with .gdb_index, the "main" marker would
sometimes seemingly be ignored.
I tracked this down to an interaction between the rewritten reader and
the "main"-finding code in cooked_index. With the ordinary DWARF
scanner, a C "main" won't be marked as IS_MAIN; whereas with
.gdb_index this can happen. In this case, the code thinks that C
requires canonicalization (which is only true for types), and skips
using the symbol.
This patch fixes the problem and adds some comments explaining what is
going on.
Tom de Vries [Tue, 14 Oct 2025 16:00:48 +0000 (18:00 +0200)]
[gdb/testsuite] Fix xfail in gdb.ada/variant_record_field.exp
On ppc64-linux (debian 14) I run into:
...
(gdb) print p_record^M
$1 = (kind => five, i => <error reading variable: \
access outside bounds of object>^M
(gdb) gdb_do_cache: get_compiler_info_1 ( c )
get_compiler_info: gcc-15-2-0
gdb_do_cache: get_compiler_info_1 ( c )
FAIL: gdb.ada/variant_record_field.exp: print p_record
...
The test-case contains an xfail for "[gcc_major_version] <= 14", which doesn't
trigger because gcc has version 15.2.0, while gnatmake does have version
14.3.0:
...
$ gcc --version
gcc (Debian 15.2.0-4) 15.2.0
...
$ gnatmake --version
GNATMAKE 14.3.0
...
Fix this by using "[gnat_version_compare < 15]" instead.
Lancelot SIX [Mon, 13 Oct 2025 14:11:09 +0000 (15:11 +0100)]
gdb/corelow: Fix use-after-free in gdb_read_core_file_mappings
A recent refactor (fc8e5a565b3 -- gdb: make structured core file
mappings processing global) in gdb/corelow.c:gdb_read_core_file_mappings
introduced a use-after-free bug detected by address sanitizer.
In this change, a cache is built which holds addresses to elements of a
std::vector. However, as elements as inserted in the vector, the
addresses in the cache should be invalidated, but are not, leading to
the use-after-free issue.
This patch proposes to store the index in the vector in the cache
instead of the address of the element, solving the invalidation issue.
An alternative approach could be to use a std::list which does not need
invalidation of addresses/references/iterators as the container is
grown.
Change-Id: Ib57d87c5d0405ffa3b7d38557fb33f7283c5d063 Approved-By: Andrew Burgess <aburgess@redhat.com>
Tom de Vries [Tue, 14 Oct 2025 09:51:50 +0000 (11:51 +0200)]
[gdb/build] Fix buildbreaker on x86_64-freebsd in gdb/fbsd-nat.c
Following commit 1ad8737b3c5 ("gdb: change inf_threads_iterator to yield
references"), we're running into a build breaker on x86_64-freebsd, in
gdb/fbsd-nat.c.
Fix this.
Tested by completing a build on x86_64-freebsd and running the TUI test-cases.
Tom de Vries [Tue, 14 Oct 2025 09:34:51 +0000 (11:34 +0200)]
[gdb/testsuite] Fix ERROR in gdb.tui/corefile-run.exp
When running test-case gdb.tui/corefile-run.exp on x86_64-freebsd, we run into
PR tdep/33176:
...
PASS: gdb.tui/corefile-run.exp: load corefile
run<SNIP>gdb/fbsd-nat.c:1381: internal-error: wait_1: \
Assertion `fbsd_inf != nullptr || pl.pl_flags & PL_FLAG_CHILD' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
ERROR: FIXME scroll
...
Skip the ERROR by:
- running the test-case twice, once with CLI and once with TUI, and
- only running the TUI variant if the CLI one succeeds.
Tom Tromey [Tue, 14 Oct 2025 03:36:56 +0000 (21:36 -0600)]
Fix use-after-free when destroying objfile
The recent patch to heap-allocate compunit_symtabs introduced a
use-after-free that can occur when destroying an objfile. The bug
here is that the objfile obstack is destroyed before compunit_symtabs;
but the compunit_symtabs destructor refers to the symtabs, which are
allocated on the obstack.
This patch fixes the problem. This was reported using ASAN, but I
reproduced it with valgrind and verified that this fixes the problem.
Support for ECOFF MIPS targets, including `mips*-*-pe*' among others,
has been removed from GAS and LD with commit e8044f355dc9 ("Remove gas
and ld support for MIPS ECOFF"),
<https://inbox.sourceware.org/binutils/8761x65bzx.fsf@talisman.default/>.
However bits in PEI-format DLL support code have been left behind.
Remove the relevant pieces then, originally from commit 344a211f9995
("Add support for WinCE based toolchains."), including MIPS architecture
parts and HIGHADJ relocation support in particular. Retain code for LOW
relocation however, even though included with said commit, as it remains
usable by ARM, i386 and x86-64 targets.
Add test cases for LOW, HIGHLOW, and DIR64 relocations handled by code
being modified. The MCore target currently fails to produce a .reloc
image section owing to missing support, so XFAIL the HIGHLOW test.
LD/PE: Make arch identifiers enumeration constants
Convert internal PE architecture identifiers from macros to enumeration
constants so as to make any further updates less disruptive to code.
Add a PE_ARCH_none dummy placeholder so as to start the numbering of
actual architectures from 1 without the need to specify the numeric
value for any of the constants.
No functional change. Suggested by Richard Earnshaw.
Tom de Vries [Mon, 13 Oct 2025 18:54:43 +0000 (20:54 +0200)]
[gdb/testsuite] Use expect_build_id_in_core_file a bit more
Recent commit c1950dcc04c ("gdb/testsuite: fix failure from
gdb.python/py-corefile.exp") introduced proc expect_build_id_in_core_file,
which detects the problem that:
...
... some versions of the linker didn't place the build-id within the first
page of an ELF. As a result, the Linux kernel would not include the
build-id in the generated core file, ...
...
Use this proc in a few more test-cases, to deal with the same problem.
Tested on x86_64-linux, openSUSE Tumbleweed with ld 2.43.1.
Approved-By: Andrew Burgess <aburgess@redhat.com>
PR testsuite/33528
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33528
gdb: detect when gdbserver has no default executable set
Introduced a use of std::pair as a data structure to hold some per
program space information within the program space registry.
It was pointed out during review of a later patch[1][2] that the code
would be easier to understand if the std::pair was replaced with a
struct with named fields.
That is what this commit does. Replace the std::pair with a struct,
and update all accesses to use the named fields.
There should be no user visible changes after this commit.
Tom Tromey [Mon, 15 Sep 2025 22:46:25 +0000 (16:46 -0600)]
Allocate compunit_symtab on heap
This patch changes compunit_symtab to be allocated on the heap, using
'new'. It also changes the container that holds these in the objfile.
I chose to use an intrusive_list to store compunit_symtab because I
think pointer stability is needed here.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33435 Approved-By: Simon Marchi <simon.marchi@efficios.com>
Jan Vrany [Fri, 10 Oct 2025 20:38:44 +0000 (21:38 +0100)]
gdb: introduce new function create_function_type
While working on new Python API to create new function types I realized
that there's no easy way to create a new function type and control where
it is going to be allocated (whether in gdbarch's obstack or objfile's).
Functions lookup_function_type and lookup_function_type_with_arguments
always allocate at the same obstack as its return type.
This is not sufficient for the new Python API - the user may use any
type it can get hold of. For example, one may want to create a function
returning arch-owned type and taking one argument of objfile-owned type.
In that case we need to allocate the new type on that very objfile's
obstack.
This commit introduces new function - create_function_type - that takes
type_allocator as first parameter, allowing caller to control the
allocation. Existing functions (lookup_function_type and
lookup_function_type_with_arguments) are reimplemented by means of new
create_function_type.
Jan Beulich [Fri, 10 Oct 2025 14:03:15 +0000 (16:03 +0200)]
bfd/PE: make local array in _bfd_XXi_swap_scnhdr_out() static
... and const. There's no reason to have the compiler copy an anonymous
.rodata object onto the stack. And there's also no reason to allow the
array to be modifiable.
Jan Beulich [Fri, 10 Oct 2025 14:02:50 +0000 (16:02 +0200)]
bfd/PE: respect SEC_ALLOC when deciding whether to force IMAGE_SCN_MEM_DISCARDABLE
While in the common case sections like .reloc don't need to be accessed
by a binary (that's the job of the loader), there are rare cases where
the situation is different. Unconditionally forcing the discardable flag
is therefore unhelpful. Avoid doing so when SEC_ALLOC is set, which
would in particular be the case when .reloc isn't (solely) linker-
generated.
While adjusting the comment, drop the wrong (stale?) following sentence:
.rsrc, as per its table entry, doesn't need to be writable. And
commenting on it wanting to be readable would then need to be repeated
for all other sections as well.
Jan Beulich [Fri, 10 Oct 2025 14:01:16 +0000 (16:01 +0200)]
bfd / PE/COFF: permit SEC_READONLY and consolidate
Without SEC_READONLY, even the default .text section would end up with
the IMAGE_SCN_MEM_WRITE flag, which is clearly wrong. (Afaict the flag,
oddly enough, doesn't affect the final linked binary, so there likely
are more anomalies.)
However, as suggested by Richard Earnshaw, PE's requirements are really
target independent. Consolidate SEC_CODE, SEC_DATA, SEC_READONLY,
SEC_LINK_ONCE, and SEC_LINK_DUPLICATES into target-independent code. Yet
of course targets not using CREATE_*_COFF_TARGET_VEC() won't benefit.
Note that in coff-arm.c the EXTRA_S_FLAGS conditional was also stale
(leftover from EPOC removal), and hence can go away.
Jan Beulich [Fri, 10 Oct 2025 14:00:44 +0000 (16:00 +0200)]
gas/SH: respect --no-pad-sections
This is once again just so the target won't need excluding in a
forthcoming new testcase, which requires no padding at the end of at
least some of the sections.
Jan Beulich [Fri, 10 Oct 2025 13:59:44 +0000 (15:59 +0200)]
ld/PE: adjust pe_detail_list[]
M*Core uses pe-dll.c, but has no entry in the table. Add both big and
little endian ones. Many of the entries aren't relevant when targeting
PE+; move the #endif accordingly. The MIPS entry is actually
questionable altogether: No mips*-*-* target uses pe-dll.c or pep-dll.c.
As I lack sufficient knowledge of the target, introduction of
jmp_mcore_bytes[] will need to be handled by someone else.
Jan Beulich [Fri, 10 Oct 2025 13:59:18 +0000 (15:59 +0200)]
objdump: enable PE support for Interix
This is just so the target won't need excluding in a forthcoming new
testcase. Without doing so objdump would fail saying "option -P/--private
not supported by this file".
Jan Beulich [Fri, 10 Oct 2025 13:58:55 +0000 (15:58 +0200)]
bfd/COFF: optionally pass BFD section into swap_scnhdr_out() hook
_bfd_XXi_swap_scnhdr_out() will want to use the section's flags. Some
call sites don't have a BFD section available, and hence pass NULL. Code
using the parameter will therefore need to apply appropriate care.
Jan Beulich [Fri, 10 Oct 2025 13:58:30 +0000 (15:58 +0200)]
bfd / PE/COFF: avoid setting SEC_ALLOC when finding IMAGE_SCN_MEM_DISCARDABLE
Before teaching _bfd_XXi_swap_scnhdr_out() to respect SEC_ALLOC when
considering whether to force IMAGE_SCN_MEM_DISCARDABLE for a section,
make sure we won't "invert" present wrong behavior when transforming an
incoming object's section attributes to an outgoing one's (objcopy or
"ld -r"): Right now, IMAGE_SCN_MEM_DISCARDABLE would appear out of the
blue for certain sections. We don't want the opposite, though, i.e. we
want avoid silently dropping IMAGE_SCN_MEM_DISCARDABLE when it's present
for an incoming object's section.
Jan Beulich [Fri, 10 Oct 2025 13:58:03 +0000 (15:58 +0200)]
gas/COFF: extend use of SEC_ALLOC
In line with bfd's styp_to_sec_flags(), set SEC_ALLOC for code/data
sections. Tie the setting to SEC_LOAD, not avoid inadvertently producing
a .bss-like section.
Jan Beulich [Fri, 10 Oct 2025 13:57:36 +0000 (15:57 +0200)]
ld/PE: adjust .reloc and .edata section flags
Both really want to be SEC_DATA, even if _bfd_XXi_swap_scnhdr_out()
makes sure that IMAGE_SCN_CNT_INITIALIZED_DATA is set in the final
section header. Otoh, .reloc - being IMAGE_SCN_MEM_DISCARDABLE at least
by default - shouldn't have SEC_ALLOC set.
In an early form of the patch I also dropped SEC_ALLOC for .reloc. While
I've undone that, I think the then necessary testsuite adjustments still
want retaining:
1) I can't explain why the removal of _both_ SEC_ALLOC and SEC_LOAD for
.reloc causes ld-scripts/provide-8 to XPASS on PE targets. Placing a
symbol outside of the image isn't well-defined in PE anyway though, so
convert the xfail-s to notarget-s.
2) The ld-pe/pe-aarch64 fragility is now dealt with in a separate patch.
The error is as follows:
--------------------------------
aix-thread.c: In function 'void sync_threadlists(pid_t)':
aix-thread.c:857:53: error: cannot convert 'thread_info' to 'thread_info*' in initialization
857 | for (struct thread_info *it : all_threads_safe ())
| ^
aix-thread.c: In lambda function:
aix-thread.c:899:61: warning: declaration of 'thread' shadows a previous local [-Wshadow=compatible-local]
899 | thread = iterate_over_threads ([&] (struct thread_info *thread)
----------------------------------
This patch is similar to the commit https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceware.org_git_-3Fp-3Dbinutils-2Dgdb.git-3Ba-3Dcommitdiff-3Bh-3D675a17a8a5cde1d8be86536df2ae6366ef0ec759&d=DwIDAg&c=BSDicqBQBDjDI9RkVyTcHQ&r=f-oUQ8ByG1nZ71OI9p76qywCPh7mxzU69hBYnkP9Nis&m=qpgW6gyN_lC_b0fBRhcWkqlvNDmUtHBTvyqGcCZxnuN6vnvJaehZ2WVuFVicJ9oD&s=UtdzAKmXnBH1ZTFOUTmFC9vTwxxralJIDjbYWsCsLYA&e=
all_threads_safe() returns an all_threads_safe_range which is like an iterator to iterate for loops.
AIX is adjusting its code in aix-thread.c for the same.
After applying this patch,
Sample test case output:
Running target unix
Using /opt/freeware/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /opt/freeware/share/dejagnu/config/unix.exp as generic interface file for target.
Using /upstream_gdb/binutils-gdb/gdb/testsuite/config/unix.exp as tool-and-target-specific interface file.
Running /upstream_gdb/binutils-gdb/gdb/testsuite/gdb.threads/thread_events.exp ...
Jan Beulich [Fri, 10 Oct 2025 07:26:24 +0000 (09:26 +0200)]
x86: PadLock adjustments
For one, all PadLock insns depend on CR4.FXSR to be enabled, which means
they ought to be taking FXSR as a prereq.
Furthermore none of them permits a REPNE prefix; such forms are documented
to cause #UD. (This is mainly relevant for XSTORE, which doesn't include a
REP prefix in its base encoding. For the others this merely is a change in
what diagnostic is issued.)
Finally it is documented that an operand size prefix also causes #UD.
Jan Beulich [Fri, 10 Oct 2025 07:25:31 +0000 (09:25 +0200)]
bfd/ELF: don't lose trailing globals from SHF_MERGE sections
_bfd_merged_section_offset() treats trailing symbols specially: That of
the retained section will be assigned the section size, while all ones in
replaced sections will be set to zero (which will then have output offset
added, i.e. generally the size of the retained section). However, in
neither case will the function change the section. Hence such trailing
symbols, when not originating from the retained section, will appear to
live in excluded sections, when they really belong to the sole retained
one.
Replace the section in all cases, and uniformly return section size.
Alice Carlotti [Tue, 7 Oct 2025 04:02:11 +0000 (05:02 +0100)]
aarch64: Remove incorrect disassembly constraint
A check in print_insn_aarch64_word asserted that part of the encoding
space couldn't contain any valid encodings, and then returned ERR_NYI
("Not Yet Implemented", perhaps?) for these values. However, some of
the new FEAT_MOP4 instructions will trigger the assert. The check seems
to be outdated, and is clearly no longer valid, so it can just be
deleted.
Additionally, there are no other assignments of ERR_NYI, so delete all
remaining references to this error type.
Alice Carlotti [Fri, 3 Oct 2025 04:50:44 +0000 (05:50 +0100)]
aarch64: Use constant fields in simple_index operands
Update aarch64_{ins|ext}_simple_index to use constant fields, and swap
the order of the index and regno fields, so that the regno occupies the
last five bits. (Splitting/combining a variable length value and a
fixed length value is easiest if the fixed length value occupies the
least significant bits.)
Alice Carlotti [Thu, 2 Oct 2025 17:57:58 +0000 (18:57 +0100)]
aarch64: Extend aarch64_field to support constants
Many instructions have constraints on the range of registers they can
use. This means that some bits in the register number are fixed, and
therefore aren't mapped to a field in the instruction encoding.
Currently we use various adhoc rules to handle these fixed bits, but
this doesn't handle all cases and we often have to write new code to
support new combinations of permitted registers.
This patch allows these constant bits to instead be specified in the
same structure used to represent instruction fields. Uses of the new
constant fields will be introduced in subsequent patches.
Tom Tromey [Mon, 29 Sep 2025 15:31:59 +0000 (09:31 -0600)]
Remove linespec.c:symtab_collector class
linespec.c has a symtab_collector class that is readily replaced by a
lambda. I think the result is more clear.
I considered using the unordered_dense 'extract' method as well, to
make the code a bit more efficient -- but it wasn't clear to me if the
ordering of the vector mattered, and so I've just added a comment.
Tom Tromey [Sun, 28 Sep 2025 04:29:24 +0000 (22:29 -0600)]
Clean up iterate_over_symtabs
After the "search via psyms" series, there's no need for
iterate_over_symtabs to first check the expanded symtabs -- the
callback will now be called for every relevant symtab, including ones
that were already expanded before the search.
Cleaning this up enables some other cleanups. In particular,
iterate_over_some_symtabs is not needed in its current form, so here
I've renamed it, made it static, and made it search just a single
compunit symtab.
While there I cleaned up the "invert" logic in
objfile::map_symtabs_matching_filename.
Tom Tromey [Sat, 27 Sep 2025 21:12:34 +0000 (15:12 -0600)]
Remove an extraneous 'return' from void method
cooked_index_functions::map_symbol_filenames returns 'void' but also
does "return ... expression". While valid, this seems strange. This
patch removes the unnecessary 'return'.
Tom Tromey [Sat, 27 Sep 2025 21:11:13 +0000 (15:11 -0600)]
Convert map_symbol_filenames to method
This patch changes the free function map_symbol_filenames to be a
method of program_space. This seems a bit cleaner, and also lets us
hoist a use of the global into the callers.
Yodel Eldar [Wed, 8 Oct 2025 16:34:55 +0000 (11:34 -0500)]
doc/gdb.texinfo: Add EIO and ENOSYS errno values
This patch adds the EIO and ENOSYS errno values supported by GDB's
File-I/O to section E.14.9: Errno Values of the GDB manual [1] that were
presumably inadvertently omitted; both can be seen in the enum
fileio_error:gdbsupport/fileio.h and corresponding function
host_to_fileio_error:gdbsupport/fileio.cc as FILEIO_{EIO,ENOSYS}.
FILEIO_SUCCESS remains excluded from the manual, because its stated
purpose (commit b872057a6) is to internally represent the absence of an
error value from the remote, and it's not actually an error number.
Alan Modra [Thu, 9 Oct 2025 04:16:39 +0000 (14:46 +1030)]
gas/macro.c getstring
This code:
if (in->ptr[idx] == '!')
{
idx++;
sb_add_char (acc, in->ptr[idx++]);
}
and similar code in the other loop, blindly accessed the next element
of the string buffer without first checking idx against in->len,
leading to uninitialised accesses or buffer overruns. Fix that, and
tidy the loops so that the function always returns the index one past
the last char consumed. (It could return idx == in->len + 1).
* macro.c (getstring): Don't access past end of input string
buffer. Tidy loops. Don't return an index past in->len.
In testsuite/gdb.tui/gdb.sh line 20:
read
^--^ SC3061 (warning): In POSIX sh, read without a variable is undefined.
^--^ SC2162 (info): read without -r will mangle backslashes.
Fix the issue by passing the `_` dummy variable. Using that particular
variable will not cause shellcheck to whine about it being unused. Also
add `-r` to make it happy.
hppa64: Fix relocation handling for global data and a couple of thinkos
This fixes relocation handling in situations where hh->owner and
hh->sym_indx were not initialized.
2025-10-08 John David Anglin <danglin@gcc.gnu.org>
bfd/ChangeLog:
PR binutils/6511
* elf64-hppa.c (global_sym_index): New from ia64.
(elf64_hppa_check_relocs): Only set hh->eh.ref_regular if we
have a regular definition.
(elf64_hppa_check_relocs): Add missing NEED_DYNREL to need_entry
assignment.
(elf64_hppa_check_relocs): Stash symbol index and section
earlier.
(allocate_global_data_dlt): Initialize hh->owner and hh->sym_indx
if not initialized.
(allocate_global_data_opd): Likewise. Remove redundant checks
for NULL hh.
(allocate_dynrel_entries): Check for discarded
hppa_info->other_rel_sec section. Add assert rent->sec->owner
== hh->owner.
(elf64_hppa_finalize_dynreloc): Check for discarded
hppa_info->other_rel_sec section.
(elf_hppa_final_link_relocate): Return bfd_reloc_ok if we
have R_PARISC_NONE relocation.
Tom de Vries [Wed, 8 Oct 2025 20:32:00 +0000 (22:32 +0200)]
[gdb/testsuite] Fix bp loc in gdb.server/fetch-exec-and-args.exp
With test-case gdb.server/fetch-exec-and-args.exp, on aarch64-linux I run into:
...
(gdb) break 28^M
Breakpoint 1 at 0xfffff7fd7b8c: file ../sysdeps/aarch64/dl-start.S, line 30.^M
(gdb) continue^M
Continuing.^M
^M
Breakpoint 1, _start () at ../sysdeps/aarch64/dl-start.S:30^M
30 mov x0, sp^M
(gdb) PASS: $exp: packet=on: test_exec_and_arg_fetch: \
continue to breakpoint: run to breakpoint
print argc^M
No symbol "argc" in current context.^M
(gdb) FAIL: $exp: packet=on: test_exec_and_arg_fetch: print argc
...
The problem is that the "break 28" is not specific about the file.
Fix this by setting the breakpoint on fetch-exec-and-args.c:28.
Tom de Vries [Wed, 8 Oct 2025 20:08:49 +0000 (22:08 +0200)]
[gdb/testsuite] Fix ERROR in expect_build_id_in_core_file
With test-case gdb.python/py-corefile.exp I run into:
...
PASS: $exp: test mapped files data: show-build-ids
ERROR: tcl error sourcing gdb.python/py-corefile.exp.
ERROR: bad option "0x1fa178": \
must be -nobackslashes, -nocommands, or -novariables
while executing
"subst 0x$offset + 0"
...
I am currently upstreaming some patches from ROCgdb that were made a few
years ago. This series cleans up how the CLI and MI access parameters
for multiple inferiors.
A preceding patch (702991711a91 ("gdb: Have setter and getter callbacks
for settings")) allowed for per-inferior getter/setter functions of some
inferior-specific settings. Over the years a few changes were accepted
upstream (cc09d372f664 ("gdb: make set/show args work with
$_gdb_setting_str")) that implemented those capabilities.
This patch adds a few tests to verify that those settings are properly
set and accessed from the CLI, MI as well as the python interface.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I7a5eab210c84d6a6782a32125f68bde34d9a2339 Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb: make deprecated_show_value_hack use its ui_file parameter
If a setting does not provide a "show" function, we fall back to the
deprecated_show_value_hack function to print the value in a generic
way. The current version ignores the `file` parameter specifying the
output file in favor of always using gdb_stdout.
To make things consistent with how the values are printed using a
regular show command, the proposed change makes the function use the
ui_file parameter it receives (even though do_show_command passes
gdb_stdout).
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I54028ed654a1fa4d955e6e46f979472c8d98ace9 Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb: do not recompute values for inferior parameters when showing them
When calling the `show` command on a few inferior-specific settings
(inferior-tty, args, cwd), GDB will recompute the values despite them
being provided by a getter.
For instance, When `show cwd` is called, `do_show_command` will query
the value of the `cwd` through `get_inferior_cwd`, which already gets
the per-inferior value. The current version seems to be a workaround
from when settings could not provide a getter function and per-inferior
settings could thus not be implemented properly, forcing the `show`
implementation to recompute the value itself.
The changes clean up the code and makes the show command trust the
values it is being forwarded, as they will always be computed by the
getter function.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I3b25f61f9101d98a6df7d50cee50131aec7e25c9 Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb: use getter/setter command styles for "set tdesc filename"
The target description filename command pair ("(set|get) tdesc
filename") uses a rather indirect way to set the variable for the
inferior, using a scratch variable to pass the value. While most other
inferior-specific parameters were updated to the more direct
getter/setter style functions, I believe this parameter was an
oversight.
This patch removes the intermediate string and directly accesses the
tdesc filename for the current inferior.
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Change-Id: I2a87c65c9931ec91d15f854b32ac8279fe7077be Approved-By: Andrew Burgess <aburgess@redhat.com>
A test case in gdb.server/server-kill.exp attempts to query the server
status after the server it is connected to has been killed. The
connection is reset as expected, but the regex on the error message
seems to be out-of-date. The test expects:
Remote communication error. Target disconnected: Connection reset by peer.
But a modern build of gdb yields :
Remote communication error. Target disconnected: error while reading: Connection reset by peer.
I presume this is due to change 0da23004a064 ("Change serial_readchar to
throw") which added exceptions to the control flow handling instead of
relying on perror(). The exception error string inserts "error while
reading" to the perror message.
The test appeared to fail intermittently, sometimes matching the first
part of the regex ("Remote connection closed"). It now passes
consistently.
Change-Id: I3bf364b5d4b56de67f9ca30e9d636d3bb1be4119 Approved-by: Kevin Buettner <kevinb@redhat.com>
[gdb/testsuite] fix gdb.multi/checkpoint-multi.exp without symbols
The checkpoint-multi.exp test stops a program while it is sleeping
using a call to the usleep() function from libc. The test checks whether
the inferior is running by matching for "<running>" (if the inferior
is running) or a hex address followed by a function name, ideally, if
the inferior is stopped.
On most systems this works fine :
(gdb) info checkpoints
Id Active Target Id Frame
* 1.0 y process 1546841 at 0x00007ffff7ceca7a, <clock_nanosleep>
1.1 n process 1547177 at 0x00005555555551f0, file /home/sdarche/binutils-gdb/build-x86/gdb/testsuite/../../../gdb/testsuite/gdb.multi/hello.c, line 51
2.0 y process 1547076 at 0x0000555555555243, file /home/sdarche/binutils-gdb/build-x86/gdb/testsuite/../../../gdb/testsuite/gdb.multi/goodbye.c, line 46
2.1 n process 1547120 at 0x0000555555555285, file /home/sdarche/binutils-gdb/build-x86/gdb/testsuite/../../../gdb/testsuite/gdb.multi/goodbye.c, line 61
I have found however that the output from `info checkpoints` is
different on some systems with (stripped) versions of the libc without
debug infos :
(gdb) info checkpoints
Id Active Target Id Frame
* 1.0 y process 979642 at 0x00007ffff7e49687
1.1 n process 979647 at 0x00005555555551ac, file /home/sdarche/binutils-gdb/build/gdb/testsuite/../../../gdb/testsuite/gdb.multi/hello.c, line 51
2.0 y process 979645 at 0x000055555555523b, file /home/sdarche/binutils-gdb/build/gdb/testsuite/../../../gdb/testsuite/gdb.multi/goodbye.c, line 46
2.1 n process 979646 at 0x0000555555555271, file /home/sdarche/binutils-gdb/build/gdb/testsuite/../../../gdb/testsuite/gdb.multi/goodbye.c, line 61
Where the frame can be found, but GDB cannot find the function. This
fails the last two tests in checkpoint-multi.exp on those system, even
though the behaviour is as expected.
This patch removes the comma from the regex that matches with the frame
number. The test now passes fine on the system.
Change-Id: Iced4931d77f647046c87889455264cb169f480ff Approved-by: Kevin Buettner <kevinb@redhat.com>
Simon Marchi [Wed, 8 Oct 2025 15:53:10 +0000 (11:53 -0400)]
gdb/python: cast to ui_file_style::intensity after validating value
When GDB is built with undefined behavior sanitizer,
gdb.python/py-style.exp fails because of this:
$ ./gdb -q -nx --data-directory=data-directory -ex "python filename_style = gdb.Style('filename')" -ex "python filename_style.intensity = -3"
/home/simark/src/binutils-gdb/gdb/python/py-style.c:239:11: runtime error: load of value 4294967293, which is not a valid value for type 'intensity'
Fix it by casting the value to ui_file_style::intensity only after
validating the raw value.
Change-Id: I38eb471a9cb3bfc3bb8b2c88afa76b8025e4e893 Approved-By: Tom Tromey <tom@tromey.com>
First, there is an issue where some versions of the linker didn't
place the build-id within the first page of an ELF. As a result, the
Linux kernel would not include the build-id in the generated core
file, and so GDB cannot to find the build-id.
In this patch I've added mitigation for this problem.
I changed the 'check-build-ids' command (added via Python as part of
the test) to 'show-build-ids'. The updated command prints a table
containing the build-ids for each objfile as found via GDB's
Progspace.objfiles, and via the Corefile.mapped_files. This table is
then read by the TCL test script, and the build-ids are checked. If
there's a difference, then GDB can analyse the on disk ELF and work
out if the difference is due to the linker issue mentioned above. If
it is, then the difference is ignored.
In order to check for this linker issue I added a new helper proc to
lib/gdb.exp, expect_build_id_in_core_file.
The second problem with the original test is that it would consider
separate debug files as files that should appear in the core file.
There was Python code in the test that filtered the objfile list to
disregard entries that would not appear in the core file, but this
code needed extending to cover separate debug files.
The final issue is that I'm only aware of GNU/Linux forcing the first
page of every mapped ELF into the generated core files, so this test
would likely fail on non-Linux systems. I've made the part of the
test that relies on this behaviour Linux only.
This change should resolve the FAIL that Tom reported. Giving Tom a
Co-Author credit as he fixed the second issue, and helped a lot
debugging the first issue.
Andrew Burgess [Wed, 10 Sep 2025 10:04:45 +0000 (11:04 +0100)]
gdb: remove program_space::core_bfd member function
This commit removes the program_space::core_bfd member function, which
was left in place as a temporary hack in the last commit in order to
reduce the size of the last commit.
In every place that 'current_program_space->core_bfd ()' was used I
now call 'get_inferior_core_bfd (current_inferior ())'.
I think there is further scope for improving things in the future,
reducing the number of times we access the core file via global state,
but doing that cleanup might be more involved than the clean up I've
done up to this point. So I'm leaving that work for the future.
But I think in some places, at the top level (e.g. user command
functions), there's always going to be some cases where we just need
to access the current global state, this is just the nature of the
command handlers.
There should be no user visible changes after this commit.
Andrew Burgess [Wed, 8 Oct 2025 10:18:07 +0000 (11:18 +0100)]
gdb: move core file bfd from program_space into core_target
This commit moves the 'gdb_bfd_ref_ptr cbfd' out of program_space and
into core_target, where it is now called m_core_bfd.
I believe this change makes sense as the core_target instance holds
additional information that is parsed from the core file BFD, and so
storing the parsed information separately from the BFD doesn't make
much sense to me.
To minimise the churn in this commit, I have retained the
program_space::core_bfd member function as a temporary hack. This
function forwards the request to the new function
get_inferior_core_bfd. This works fine for now as
program_space::core_bfd is, after this commit, only called on the
current_program_space. If this all seems like a total hack, then it
is, but don't worry too much, the next commit will clean this all up.
I was tempted to make the new function get_inferior_core_bfd, a member
function of the inferior class, inferior::core_bfd. In fact, that
would have been my preferred change. However, the new function needs
visibility of the core_target class, which, right now is private
within the corelow.c file.
This shouldn't be a problem, we could just declare the member function
in inferior.h, and implement the function in corelow.c. But this
would mean the implementation of inferior::core_bfd, would not live in
inferior.c. Previously when I've implemented member functions outside
their natural home (e.g. an inferior function not in inferior.c) I've
received review feedback that this is not desirable. So, for now,
I've gone with a free function.
I also needed to change get_current_core_target, renaming it to
get_core_target, and taking an inferior as an argument. Existing call
sites are updated to pass 'current_inferior ()', but
get_inferior_core_bfd passes something that might not be the current
inferior.
There should be no user visible changes after this commit.
Andrew Burgess [Sun, 28 Sep 2025 15:16:53 +0000 (16:16 +0100)]
gdb: fix for 'set suppress-cli-notifications on' missed case
I noticed this behaviour:
(gdb) info threads
Id Target Id Frame
1 Thread 0xf7dbc700 (LWP 3161872) "thr" 0xf7eb2888 in clone () from /lib/libc.so.6
* 2 Thread 0xf7dbbb40 (LWP 3161884) "thr" breakpt () at thr.c:19
(gdb) set suppress-cli-notifications on
(gdb) thread 1
(gdb) thread 1
[Switching to thread 1 (Thread 0xf7dbc700 (LWP 3161872))]
#0 0xf7eb2888 in clone () from /lib/libc.so.6
(gdb)
I think that the second 'thread 1' should not produce any output just
like the 'inferior' command, continuing in the same GDB session:
(gdb) inferior 1
(gdb)
Without suppress-cli-notifications we would see an inferior, thread,
and frame being printed, but with suppress-cli-notifications set to
on, we get no output.
The difference in behaviours is that in inferior_command (inferior.c),
we always call notify_user_selected_context_changed, even in the case
where the inferior doesn't actually change.
In thread_command (thread.c), we have some code that catches the
thread not changed case, and calls print_selected_thread_frame. The
notify_user_selected_context_changed function is only called if the
thread actually changes.
I did consider simply extending thread_command to check the global
cli_suppress_notification.user_selected_context state and skipping the
call to print_selected_thread_frame if suppression is on.
However, I realised that calling print_selected_thread_frame actually
introduces a bug.
When the 'thread' command is used to select the currently selected
thread, GDB still calls 'thread_selected'. And 'thread_select' always
selects frame #0 within that thread, consider this session:
(gdb) info threads
Id Target Id Frame
1 Thread 0xf7dbc700 (LWP 723986) "thr" 0xf7eb2888 in clone () from /lib/libc.so.6
* 2 Thread 0xf7dbbb40 (LWP 723990) "thr" breakpt () at thr.c:19
(gdb) bt
#0 breakpt () at thr.c:19
#1 0x080491fd in thread_worker (arg=0xffff9514) at thr.c:31
#2 0xf7f7667e in start_thread () from /lib/libpthread.so.0
#3 0xf7eb289a in clone () from /lib/libc.so.6
(gdb) frame 3
#3 0xf7eb289a in clone () from /lib/libc.so.6
(gdb) thread 2
[Switching to thread 2 (Thread 0xf7dbbb40 (LWP 723990))]
#0 breakpt () at thr.c:19
19 while (stop)
(gdb) frame
#0 breakpt () at thr.c:19
19 while (stop)
(gdb)
Notice that the frame resets back to frame #0.
By only calling print_selected_thread_frame, and not calling
notify_user_selected_context_changed, this means that GDB will fail to
emit an MI async notification. It is this async notification which
tells MI consumers that the frame has been reset to #0.
And so, I think that the correct solution is, like with the 'inferior'
command, to always call notify_user_selected_context_changed.
This does mean that in some cases unnecessary MI notifications can be
emitted, however, an MI consumer should be able to handle these. We
could try to avoid these, but we would need to extend thread_command
to check that neither the thread OR frame has changed after the call
to thread_select, and right now, I'm not sure it's worth adding the
extra complexity.
I've rewritten the gdb.base/cli-suppress-notification.exp test to
cover more cases, especially the reselecting the same thread case.
And I've updated the gdb.mi/user-selected-context-sync.exp test to
allow for the additional MI notifications that are emitted, and to
check the frame reset case.
While working on this change, I did wonder about calls to
notify_user_selected_context_changed for frame related commands. In
places we do elide calls to notify_user_selected_context_changed if
the frame hasn't changed. I wondered if there were more bugs here?
I don't think there are though. While changing the inferior will also
change the selected thread, and the selected frame. And changing the
thread will also change the selected frame. Changing the frame is the
"inner most" context related thing that can be changed. There are no
side effect changes that also need to be notified, so for these cases,
I think we are fine.
Also in infrun.c I fixed a code style issue relating to
notify_user_selected_context_changed. It's not a functional change
required by this commit, but it's related to this patch, so I'm
including it here.
Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Tested-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> Approved-By: Tom Tromey <tom@tromey.com>
cris: bfd: Default selected target to the configured target
Whether targ_defvec is set to the best match for the configured target
or some of the other supported targets usually doesn't matter, as the
actual target being used, usually is set by some other mechanism, like
an input object file.
In some situations it matters though: it might be confusing to see
--help output not showing the configured target first in the list of
supported targets. Also, some corner cases risk running into bugs like
PR33485, for cris-elf and cris-linux because cris_aout_vec is the
default target where instead the bug-free behavior of
cris_elf32_us_vec or cris_elf32_vec would be expected.
The test just verifies that the target list emitted for the --help
option has the expected target first.
bfd:
* config.bfd <cris-*-* | crisv32-*-*>: Split into <cris-*-*aout*>,
<cris-*-linux-* | crisv32-*-linux-*>, <cris-*-* | crisv32-*-*> cases
respectively setting targ_defvec per the target instead of always
cris_aout_vec.
binutils:
* testsuite/binutils-all/cris: New directory intended for
tests focused on behavior of the binutils programs, not the assembler
or linker.
* testsuite/binutils-all/cris/cris.exp: New file with run_dump_test
loop.
testsuite/binutils-all/cris/tgt-a.d,
testsuite/binutils-all/cris/tgt-e.d,
testsuite/binutils-all/cris/tgt-l.d: New tests.
Co-authored-by: Maciej W. Rozycki <macro@redhat.com>
Simon Marchi [Wed, 3 Sep 2025 14:50:05 +0000 (10:50 -0400)]
gdbsupport: make reference_to_pointer_iterator's constructor non-variadic
For the same reason as the previous patches (making things easier to
understand, at the cost of being more explicit), change
reference_to_pointer_iterator's constructor to take an already built
underlying iterator.
There are no uses of this utility in the code base right now, so no
callers to update.
Change-Id: Ifadb4c3a5ee53a8d0eb6c0d79efcc92271492e8e Approved-By: Tom Tromey <tom@tromey.com>
Simon Marchi [Wed, 3 Sep 2025 14:50:04 +0000 (10:50 -0400)]
gdbsupport: remove variadicity from filtered_iterator constructor
For the same reason as the previous patches (making things easier to
understand, at the cost of being more explicit), remove
filtered_iterator's variadic constructor, forcing the callers to pass
already built underlying iterators.
Change-Id: I1a9b6d43f3f087579b61b90b6f8f4128d66e19a1 Approved-By: Tom Tromey <tom@tromey.com>