]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
6 months agoAutomatic date update in version.in
GDB Administrator [Thu, 9 Jan 2025 00:00:14 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agoRename two Ada test suite functions
Tom Tromey [Wed, 8 Jan 2025 20:05:16 +0000 (13:05 -0700)] 
Rename two Ada test suite functions

I happened to notice that the Ada compiler emitted a warning when
compiling a couple of DAP tests.  This wasn't intentional, and this
patch renames the functions to match the filename.

6 months agoGDB, gdbserver: Convert regcache_register_size function to method
Thiago Jung Bauermann [Sat, 2 Nov 2024 02:56:21 +0000 (23:56 -0300)] 
GDB, gdbserver: Convert regcache_register_size function to method

The regcache_register_size function has one implementation in GDB, and
one in gdbserver.  Both of them have a gdb::checked_static_cast to their
corresponding regcache class.  This can be avoided by defining a
pure virtual register_size method in the
reg_buffer_common class, which is then implemented by the reg_buffer
class in GDB, and by the regcache class in gdbserver.

Calls to the register_size () function from methods of classes in the
reg_buffer_common hierarchy need to be changed to calls to the newly
defined method, otherwise the compiler complains that a matching method
cannot be found.

Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Reviewed-By: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Change-Id: I7f4f74a51e96c42604374e87321ca0e569bc07a3

6 months ago[gdb/testsuite] Check gnatmake version in gdb.ada/scalar_storage.exp
Tom de Vries [Wed, 8 Jan 2025 15:24:11 +0000 (16:24 +0100)] 
[gdb/testsuite] Check gnatmake version in gdb.ada/scalar_storage.exp

On a system with gcc 14.2.0 and gnatmake 13.3.0 I run into:
...
(gdb) PASS: gdb.ada/scalar_storage.exp: print V_LE
get_compiler_info: gcc-14-2-0
print V_BE^M
$2 = (value => 126, another_value => 12, color => red)^M
(gdb) FAIL: gdb.ada/scalar_storage.exp: print V_BE
...

The test-case contains a corresponding kfail:
...
 # This requires a compiler fix that is in GCC 14.
 if {[gcc_major_version] < 14} {
     setup_kfail "DW_AT_endianity on enum types" *-*-*
 }
...
which doesn't trigger because it checks the gcc version rather than the
gnatmake version.

Fix this by checking the gnatmake version instead.

Tested on aarch64-linux and x86_64-linux.

6 months ago[gdb/testsuite] Require can_spawn_for_attach in gdb.base/gstack.exp
Tom de Vries [Wed, 8 Jan 2025 15:07:08 +0000 (16:07 +0100)] 
[gdb/testsuite] Require can_spawn_for_attach in gdb.base/gstack.exp

I ran test-case gdb.base/gstack.exp on a machine with kernel.yama.ptrace_scope
set to 1 and ran into:
...
PASS: gdb.base/gstack.exp: spawn gstack
ptrace: Operation not permitted.^M
GSTACK-END^M
PASS: gdb.base/gstack.exp: gstack exits with no error
PASS: gdb.base/gstack.exp: gstack's exit status is 0
FAIL: gdb.base/gstack.exp: got backtrace
...

Fix this by requiring can_spawn_for_attach.

Tested on x86_64-linux.

6 months ago[gdb/testsuite] Require supports_process_record in gdb.reverse/test_ioctl_TCSETSW.exp
Tom de Vries [Wed, 8 Jan 2025 11:48:08 +0000 (12:48 +0100)] 
[gdb/testsuite] Require supports_process_record in gdb.reverse/test_ioctl_TCSETSW.exp

I ran test-case gdb.reverse/test_ioctl_TCSETSW.exp on riscv64-linux, and got:
...
(gdb) record full^M
Process record: the current architecture doesn't support record function.^M
(gdb) FAIL: gdb.reverse/test_ioctl_TCSETSW.exp: record full
...

Fix this by requiring supports_process_record.

Tested on riscv64-linux and x86_64-linux.

6 months ago[gdb/testsuite] Fix gdb.base/reset-catchpoint-cond.exp for !supports_catch_syscall
Tom de Vries [Wed, 8 Jan 2025 09:06:28 +0000 (10:06 +0100)] 
[gdb/testsuite] Fix gdb.base/reset-catchpoint-cond.exp for !supports_catch_syscall

I ran test-case gdb.base/reset-catchpoint-cond.exp on riscv64-linux, and got:
...
(gdb) catch syscall write^M
The feature 'catch syscall' is not supported on this architecture yet.^M
(gdb) FAIL: $exp: mode=syscall: catch syscall write
...

Fix this by checking for supports_catch_syscall.

Tested on riscv64-linux and x86_64-linux.

6 months agoFix 32085 Source file not recognized for gcc 11.4.0-compiled code
Vladimir Mezentsev [Tue, 7 Jan 2025 05:40:12 +0000 (21:40 -0800)] 
Fix 32085 Source file not recognized for gcc 11.4.0-compiled code

gprofng cannot read compressed section.
In the next release we plan to use libbfd everywhere instead of our ELF reader.
But in this release I use bfd_get_full_section_contents() only
when bfd_is_section_compressed() returns true.

gprofng/ChangeLog
2025-01-06  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR gprofng/32085
* src/Elf.cc: Use bfd_get_full_section_contents to decompress a section.
* src/Elf.h: Define SEC_DECOMPRESSED.

6 months agoSupport Intel AMX-FP8
Liwei Xu [Wed, 8 Jan 2025 03:38:48 +0000 (11:38 +0800)] 
Support Intel AMX-FP8

In this patch, we will support AMX-FP8 feature. Since in the
foreseeable future, only AMX-MOVRS will also use VEX_MAP5, we
currently will not add a table of 256 entries and handle just
like MAP7.

gas/ChangeLog:

* config/tc-i386.c: Add amx_fp8.
* doc/c-i386.texi: Document .amx_fp8.
* testsuite/gas/i386/x86-64.exp: Run AMX-FP8 tests.
* testsuite/gas/i386/x86-64-amx-fp8-bad.d: New test.
* testsuite/gas/i386/x86-64-amx-fp8-bad.s: Ditto.
* testsuite/gas/i386/x86-64-amx-fp8-intel.d: Ditto.
* testsuite/gas/i386/x86-64-amx-fp8-inval.l: Ditto.
* testsuite/gas/i386/x86-64-amx-fp8-inval.s: Ditto.
* testsuite/gas/i386/x86-64-amx-fp8.d: Ditto.
* testsuite/gas/i386/x86-64-amx-fp8.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (PREFIX_VEX_MAP5_FD_X86_64_L_0_W_0): New.
(X86_64_VEX_MAP5_FD): Ditto.
(VEX_LEN_MAP5_FD_X86_64): Ditto.
(VEX_W_MAP5_FD_X86_64_L_0):Ditto.
(prefix_table): Add PREFIX_VEX_MAP5_FD_X86_64_L_0_W_0.
(x86_64_table): Add X86_64_VEX_MAP5_FD.
(vex_len_table): Add VEX_LEN_MAP5_FD_X86_64.
(vex_w_table): Add VEX_W_MAP5_FD_X86_64_L_0.
* i386-gen.c: Add CPU_AMX_FP8_FLAGS and
CPU_ANY_AMX_FP8_FLAGS.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h: Add cpuamx_fp8.
* i386-opc.tbl: Add AMX_FP8 instructions.
* i386-tbl.h: Regenerated.

Co-authored-by: Haochen Jiang <haochen.jiang@intel.com>
6 months agoRename two maint commands
Tom Tromey [Sun, 5 Jan 2025 22:20:50 +0000 (15:20 -0700)] 
Rename two maint commands

This renames two maint commands, removing a hyphen from
"check-symtabs" and "check-psymtabs"; that is, moving them under the
existing "maint check" prefix.

Regression tested on x86-64 Fedora 40.

Reviewed-By: Tom de Vries <tdevries@suse.de>
Approved-By: Andrew Burgess <aburgess@redhat.com>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
6 months agoAutomatic date update in version.in
GDB Administrator [Wed, 8 Jan 2025 00:00:08 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agoUpdated Malay translation for the bfd sub-directory
Nick Clifton [Tue, 7 Jan 2025 15:01:05 +0000 (15:01 +0000)] 
Updated Malay translation for the bfd sub-directory

6 months agoFix crash in DWARF indexer
Tom Tromey [Mon, 6 Jan 2025 20:34:47 +0000 (13:34 -0700)] 
Fix crash in DWARF indexer

Iain pointed out a crash in the DWARF indexer when run on a certain D
program.  The DWARF in this case has a nameless enum class; this
causes an assertion failure.

This patch arranges to simply ignore such types.  The fact that an
enum class is nameless in this case appears to be a compiler bug.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32518
Approved-By: Tom de Vries <tdevries@suse.de>
6 months agotestsuite: adapt to new --debug command line option
Christina Schimpe [Tue, 26 Nov 2024 16:06:37 +0000 (08:06 -0800)] 
testsuite: adapt to new --debug command line option

Since commit "gdbserver: allow the --debug command line option to take a
value", gdbserver no longer supports
  --debug
  --remote-debug
  --event-loop-debug.

Instead, --debug now takes a comma separated list of components.

The make check parameter GDBSERVER_DEBUG doesn't support these changes
yet.  This patch fixes this, by adding the --debug gdbserver arguments,
as "debug-threads", "debug-remote", "debug-event-loop" or "debug-all" for
GDBSERVER_DEBUG.  Replay logging is still enabled by adding the
"replay" GDBSERVER_DEBUG argument.  We can also configure "all" to
enable all of the available options.

Now, for instance, we can use it as follows:

make check GDBSERVER_DEBUG="debug-remote,debug-event-loop,replay" RUNTESTFLAGS="--target_board=native-gdbserver" TESTS="gdb.trace/ftrace.exp"

or simply

make check GDBSERVER_DEBUG="all" RUNTESTFLAGS="--target_board=native-gdbserver" TESTS="gdb.trace/ftrace.exp"

to enable all debug options.

Approved-By: Tom Tromey <tom@tromey.com>
6 months agoClarify documentation of signal numbers
Tom Tromey [Fri, 20 Dec 2024 20:16:17 +0000 (13:16 -0700)] 
Clarify documentation of signal numbers

A user was confused by the meaning of signal numbers in the gdb CLI.
For instance, when using "signal 3", exactly which signal is
delivered?  Is it always 3, or is it always SIGQUIT?

This patch attempts to clarify the documentation here.

6 months agold/testsuite: move board flags to ld_link
Clément Chigot [Mon, 9 Dec 2024 10:00:07 +0000 (11:00 +0100)] 
ld/testsuite: move board flags to ld_link

Both CFLAGS and LDFLAGS provided by dejagnu board configuration could be
required to perform a link.

Up to now, those flags were pulled with run_cc_link_tests and
run_ld_link_exec_tests and then passed to ld_link process as arguments.
This means that calling `ld_link` outside those functions must remember
to manually pass them.

6 months agold/testsuite/lto: replace manual links by ld_link helper
Clément Chigot [Tue, 10 Dec 2024 13:08:44 +0000 (14:08 +0100)] 
ld/testsuite/lto: replace manual links by ld_link helper

Some tests are calling run_host_cmd in order to retrieve the
errors/warnings messages generated.
ld_link is also making them available through exec_output global
variable but as the advantages of taking the board configuration into
account unlike run_host_cmd.

6 months agold/testsuite: centralize board_cflags and board_ldflags
Clément Chigot [Mon, 9 Dec 2024 10:37:54 +0000 (11:37 +0100)] 
ld/testsuite: centralize board_cflags and board_ldflags

Those flags are retrieving the CFLAGS or LDFLAGS defined by the dejagnu
board. The same pattern was repeated many times.

6 months agoRemove dead code in bfd_check_format_matches
Alan Modra [Mon, 6 Jan 2025 12:12:10 +0000 (22:42 +1030)] 
Remove dead code in bfd_check_format_matches

Commit cb001c0d283d made code added in 64bfc2584c01 dead.  Remove it.

6 months agoAutomatic date update in version.in
GDB Administrator [Tue, 7 Jan 2025 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months ago[gdb/cli] Show LOC_CONST_BYTES var for info locals
Tom de Vries [Mon, 6 Jan 2025 17:48:58 +0000 (18:48 +0100)] 
[gdb/cli] Show LOC_CONST_BYTES var for info locals

PR cli/32525 reports that a variable with this DWARF:
..
<2><423>: Abbrev Number: 14 (DW_TAG_variable)
    <424>   DW_AT_name        : var1867
    <42a>   DW_AT_type        : <0x2f8>
    <42e>   DW_AT_const_value : 8 byte block: 0 0 0 0 0 0 0 0
...
is not shown by info locals.

Fix this by handling LOC_CONST_BYTES in iterate_over_block_locals.

Tested on x86_64-linux.

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

Approved-By: Tom Tromey <tom@tromey.com>
6 months agox86/APX: simplify ENQCMD[,S} opcode table entries
Jan Beulich [Mon, 6 Jan 2025 15:25:17 +0000 (16:25 +0100)] 
x86/APX: simplify ENQCMD[,S} opcode table entries

APX_F() makes sense to use only for dual VEX/EVEX templates; ENQCMD{,S}
are legacy encoded though in their original forms. Make the entries
match the MOVDIR{I,64B} sibling ones.

6 months agoFix procfs.c compilation
Rainer Orth [Mon, 6 Jan 2025 15:24:14 +0000 (16:24 +0100)] 
Fix procfs.c compilation

procfs.c compilation is currently broken on Solaris:

/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c: In member function ‘virtual ptid_t procfs_target::wait(ptid_t, target_waitstatus*, target_wait_flags)’:
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2067:34: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’?
 2067 |               wait_retval = gdb::wait (&wstat);
      |                                  ^~~~
In file included from ../gnulib/import/sys/wait.h:28,
                 from /usr/include/stdlib.h:16,
                 from /usr/gcc/14/include/c++/14.2.0/cstdlib:79,
                 from /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/../gdbsupport/common-defs.h:99,
                 from /vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/defs.h:26,
                 from <command-line>:
/usr/include/sys/wait.h:85:14: note: ‘wait’ declared here
   85 | extern pid_t wait(int *);
      |              ^~~~
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2154:41: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’?
 2154 |                         int temp = gdb::wait (&wstat);
      |                                         ^~~~
/usr/include/sys/wait.h:85:14: note: ‘wait’ declared here
   85 | extern pid_t wait(int *);
      |              ^~~~
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c: In function ‘void unconditionally_kill_inferior(procinfo*)’:
/vol/src/gnu/gdb/hg/gdb-16-branch/git/gdb/procfs.c:2566:12: error: ‘wait’ is not a member of ‘gdb’; did you mean ‘wait’?
 2566 |       gdb::wait (NULL);
      |            ^~~~
/usr/include/sys/wait.h:85:14: note: ‘wait’ declared here
   85 | extern pid_t wait(int *);
      |              ^~~~

The use of gdb::wait was introduced in

commit 4e4dfc4728622d83c5d600949024449e21de868a
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Nov 22 17:44:29 2024 +0100

    [gdb] Add gdb::wait

but obviously never tested.

Fixed by including gdbsupport/eintr.h to provide the declaration.

Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11.

6 months agox86/Intel: don't accept memory operands with J*CXZ and LOOP*
Jan Beulich [Mon, 6 Jan 2025 15:01:47 +0000 (16:01 +0100)] 
x86/Intel: don't accept memory operands with J*CXZ and LOOP*

PR gas/31887

Like for, in particular, J<cc> such should be rejected. Simplify the
respective conditional in i386_intel_operand(), leveraging that
JumpAbsolute will never occur in the first template of a mnemonic-
specific group (thus making it unnecessary to exclude that one case).

At this occasion do the same simplification later in the function as
well: The resulting two operands will uniformly be invalid for all
mnemonics other than CALL and JMP (and their AT&T counterparts, which
we've been wrongly accepting in Intel syntax) anyway.

6 months agogas: special-case division / modulo by ±1
Jan Beulich [Mon, 6 Jan 2025 15:01:07 +0000 (16:01 +0100)] 
gas: special-case division / modulo by ±1

Dividing the largest possible negative value by -1 generally is UB, for
the result not being representable at least in commonly used binary
notation. This UB on x86, for example, is a Floating Point Exception on
Linux, i.e. resulting in an internal error (albeit only when
sizeof(valueT) == sizeof(void *); the library routine otherwise involved
apparently deals with the inputs quite okay).

Leave original values unaltered for division by 1; this may matter down
the road, in case we start including X_unsigned and X_extrabit in
arithmetic. For the same reason treat modulo by 1 the same as modulo by
-1.

The quad and octa tests have more relaxed expecations than intended, for
X_unsigned and X_extrabit not being taken into account [yet]. The upper
halves can wrongly end up as all ones (for .octa, when !BFD64, even the
upper three quarters). Yet it makes little sense to address this just
for div/mod by ±1. quad-div2 is yet more special, to cover for most
32-bit targets being unable to deal with forward-ref expressions in
.quad even when BFD64; even ones being able to (like x86) then still
don't get the values right.

6 months agoHandle linesStartAt1 in DAP
Tom Tromey [Mon, 16 Dec 2024 17:44:55 +0000 (10:44 -0700)] 
Handle linesStartAt1 in DAP

The DAP initialize request has a "linesStartAt1" option, where the
client can indicate that it prefers whether line numbers be 0-based or
1-based.

This patch implements this.  I audited all the line-related code in
the DAP implementation.

Note that while a similar option exists for column numbers, gdb
doesn't handle these yet, so nothing is done here.

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

6 months agoDon't lex floating-point number in Rust field expression
Tom Tromey [Tue, 17 Dec 2024 19:35:44 +0000 (12:35 -0700)] 
Don't lex floating-point number in Rust field expression

Consider this Rust tuple:

    let tuple_tuple = ((23i32, 24i32), 25i32);

Here, the value is a tuple whose first element is also a tuple.
You should be able to print this with:

    (gdb) print tuple_tuple.0.1

However, currently the Rust lexer sees "0.1" as a floating-point
number.

This patch fixes the problem by introducing a special case in the
lexer: when parsing a field expression, the parser informs the lexer
that a number should be handled as a decimal integer only.

This change then lets us remove the decimal integer special case from
lex_number.

v2: I realized that the other DECIMAL_INTEGER cases aren't needed any
more.

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

6 months agoRemove "then" from test suite
Tom Tromey [Thu, 12 Dec 2024 14:54:51 +0000 (07:54 -0700)] 
Remove "then" from test suite

This removes the "then" keyword from the test suite.  Andrew did this
once before, but some new ones crept in.

This also adds braces to the "if" conditions and normalizes the
failures to just use "return".

6 months agoSimplify traits.h using C++17
Tom Tromey [Fri, 20 Dec 2024 20:45:51 +0000 (13:45 -0700)] 
Simplify traits.h using C++17

This patch simplifies gdbsupport/traits.h by reusing some C++17 type
traits.  I kept the local names, since they are generally better.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31423
Approved-By: Simon Marchi <simon.marchi@efficios.com>
6 months ago[gdb/build] Use const_cast in fd_copy
Tom de Vries [Mon, 6 Jan 2025 08:53:26 +0000 (09:53 +0100)] 
[gdb/build] Use const_cast in fd_copy

Recent commit 6ab5d62ebc5 ("[gdb] Fix compilation error in event-top.c") did:
...
 fd_copy (fd_set *dst, const fd_set *src, int n)
 {
   FD_ZERO (dst);
   for (int i = 0; i < n; ++i)
-    if (FD_ISSET (i, src))
+    if (FD_ISSET (i, (fd_set *)src))
...
but according to [1] only const_cast may be used to cast away constness.

Fix this by using const_cast.

Tested by rebuilding on x86_64-linux.

[1] https://en.cppreference.com/w/cpp/language/const_cast

6 months agoar and foreign object files
Alan Modra [Sun, 5 Jan 2025 11:14:06 +0000 (21:44 +1030)] 
ar and foreign object files

ar is supposed to make archives containing any sort of file, and it
generally does that.  It also tries to make archives suited to target
object files stored.  Some targets have peculiar archives.

In one particular case we get into trouble trying to suit archives to
object files: where the target object file is recognised but that
target doesn't happen to support archives, and the default target has
a special archive format.  For example, we'll get failures on
rs6000-aix if trying to add tekhex objects to a new archive.  What
happens in that the tekhex object is recognised and its target vector
used to create an empty archive, ie. with _bfd_generic_mkarchive and
_bfd_write_archive_contents.  An attempt is then made to open the
newly created archive.  The tekhex target vector does not have a
check_format function to recognise generic archives, nor as it happens
do any of the xcoff or other targets built for rs6000-aix.

It seems to me the simplest fix is to not use any target vector to
create archives where that vector can't also recognise them.  That's
what this patch does, and to reinforce that I've removed target vector
support for creating empty archives from such targets.

bfd/
* i386msdos.c (i386_msdos_vec): Remove support for creating
empty archives.
* ihex.c (ihex_vec): Likewise.
* srec.c (srec_vec, symbolsrec_vec): Likewise.
* tekhex.c (tekhex_vec): Likewise.
* wasm-module.c (wasm_vec): Likewise.
* ptrace-core.c (core_ptrace_vec): Tidy.
* targets.c (bfd_target_supports_archives): New inline function.
* bfd-in2.h: Regenerate.
binutils/
* ar.c (open_inarch): Don't select a target from the first
object file that can't read archives.  Set output_filename
earlier.
* testsuite/binutils-all/ar.exp (thin_archive_with_nested):
Don't repeat --thin test using T.
(foreign_object): New test.
* testsuite/binutils-all/tek1.obj,
* testsuite/binutils-all/tek2.obj: New files.

6 months agoRISC-V: Eliminate redundant instruction macro
Xiao Zeng [Mon, 6 Jan 2025 01:14:34 +0000 (09:14 +0800)] 
RISC-V: Eliminate redundant instruction macro

include/ChangeLog:

* opcode/riscv.h: Eliminate redundant instruction macro M_j.

Signed-off-by: Xiao Zeng <zengxiao@eswincomputing.com>
6 months agoAutomatic date update in version.in
GDB Administrator [Mon, 6 Jan 2025 00:00:37 +0000 (00:00 +0000)] 
Automatic date update in version.in

6 months agoSome small cleanups in add_symbol_overload_list_qualified
Tom Tromey [Sat, 7 Dec 2024 22:16:17 +0000 (15:16 -0700)] 
Some small cleanups in add_symbol_overload_list_qualified

This applies some more cleanups to add_symbol_overload_list_qualified,
consolidating calls to get_selected_block.

It also moves the symtab expansion call after the code that walks up
from the selected block, merging two loops.

6 months agoFix latent bug in Ada import symbol handling
Tom Tromey [Thu, 19 Dec 2024 01:49:45 +0000 (18:49 -0700)] 
Fix latent bug in Ada import symbol handling

The code in dwarf2/read.c:new_symbol that handles Ada 'import' symbols
has a bug.  It uses the current scope, which by default this is the
file scope -- even for a global symbol like:

 <1><1186>: Abbrev Number: 4 (DW_TAG_variable)
    <1187>   DW_AT_name        : (indirect string, offset: 0x1ad2): pkg__imported_var_ada
...
    <1196>   DW_AT_external    : 1

This disagrees with the scope computed by the DWARF indexer.

Now, IMO new_symbol and its various weirdness really has to go.  And,
ideally, this information would come from the indexer rather than
perhaps being erroneously recomputed.  But meanwhile, this patch fixes
the issue at hand.

This came up while working on another change that exposes the bug.

Reviewed-By: Tom de Vries <tdevries@suse.de>
7 months agoAutomatic date update in version.in
GDB Administrator [Sun, 5 Jan 2025 00:00:26 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months ago[gdb/testsuite] Add gdb.python/py-commands-breakpoint.exp
Tom de Vries [Sat, 4 Jan 2025 11:10:42 +0000 (12:10 +0100)] 
[gdb/testsuite] Add gdb.python/py-commands-breakpoint.exp

A recent discussion about what commands are allowed during
gdb.Breakpoint.stop, made me wonder if there would be less restrictions if
we'd do those commands as part of a breakpoint command list instead.

Attribute gdb.Breakpoint.commands is a string with gdb commands, so I
tried implementing a new class PyCommandsBreakpoint, derived from
gdb.Breakpoint, that supports a py_commands method.

My original idea was to forbid setting PyCommandsBreakpoint.commands, and do:
...
    def py_commands(self):
        print("VAR: %d" % self.var)
        self.var += 1
gdb.execute("continue")
...
but as it turns out 'gdb.execute("continue")' does not behave the same way as
continue.  I've filed PR python/32454 about this.

So the unsatisfactory solution is to first execute
PyCommandsBreakpoint.py_commands:
...
    def py_commands(self):
        print("VAR: %d" % self.var)
        self.var += 1
...
and then:
...
        self.commands = "continue"
...

I was hoping for a better outcome, but having done the work of writing this, I
suppose it has use as a test-case, perhaps also as an example of how to work
around PR python/32454.

Tested on x86_64-linux.

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

7 months ago[gdb/tdep] Fix gdb.base/finish-pretty.exp on s390x
Tom de Vries [Sat, 4 Jan 2025 10:31:02 +0000 (11:31 +0100)] 
[gdb/tdep] Fix gdb.base/finish-pretty.exp on s390x

On s390x-linux, with test-case gdb.base/finish-pretty.exp I ran into:
...
(gdb) finish
Run till exit from #0  foo () at finish-pretty.c:28
main () at finish-pretty.c:40
40   return v.a + v.b;
Value returned has type: struct s. Cannot determine contents
(gdb) FAIL: $exp: finish foo prettyprinted function result
...

The function being finished is foo, which returns a value of type struct s.

The ABI [1] specifies:
- that the value is returned in a storage buffer allocated by the caller, and
- that the address of this buffer is passed as a hidden argument in r2.

GDB fails to print the value when finishing foo, because it doesn't know the
address of the buffer.

Implement the gdbarch_get_return_buf_addr hook for s390x to fix this.

This is based on ppc_sysv_get_return_buf_addr, the only other implementation
of gdbarch_get_return_buf_addr.  For readability I've factored out
dwarf_reg_on_entry.

There is one difference with ppc_sysv_get_return_buf_addr: only
NO_ENTRY_VALUE_ERROR is caught.  If this patch is approved, I intend to submit
a follow-up patch to fix this in ppc_sysv_get_return_buf_addr as well.

The hook is not guaranteed to work, because it attempts to get the value r2
had at function entry.

The hook can be called after function entry, and the ABI doesn't guarantee
that r2 is the same throughout the function.

Using -fvar-tracking adds debug information, which allows the hook to succeed
more often, and indeed after adding this to the test-case, it passes.

Do likewise in one more test-case.

Tested on s390x-linux.

Fixes:
- gdb.ada/finish-large.exp
- gdb.base/finish-pretty.exp
- gdb.base/retval-large-struct.exp
- gdb.cp/non-trivial-retval.exp
- gdb.ada/array_return.exp

AFAICT, I've also enabled the hook for s390 and from the ABI I get the
impression that it should work, but I haven't been able to test it.

[1] https://github.com/IBM/s390x-abi

7 months ago[gdb/readline] Fix link error on MinGW due to missing 'alarm'
Eli Zaretskii [Sat, 4 Jan 2025 10:19:55 +0000 (12:19 +0200)] 
[gdb/readline] Fix link error on MinGW due to missing 'alarm'

  The previous solution used symbols that exist only in MinGW64.
  Add a stub implementation of 'alarm' for mingw.org's MinGW.

7 months ago[gdb/selftest] Fix 'help_doc_invariants' self-test
Eli Zaretskii [Sat, 4 Jan 2025 10:13:04 +0000 (12:13 +0200)] 
[gdb/selftest] Fix 'help_doc_invariants' self-test

  Running selftest help_doc_invariants.
  help doc broken invariant: command 'signal-event' help doc has over-long line
  Self test failed: self-test failed at unittests/command-def-selftests.c:121

  The reason is that doc string of 'signal-event' doesn't have
  newlines at end of its line.  Fix by adding newlines.

7 months ago[gdb] Fix compilation error in event-top.c
Eli Zaretskii [Sat, 4 Jan 2025 10:09:12 +0000 (12:09 +0200)] 
[gdb] Fix compilation error in event-top.c

       CXX    event-top.o
     In file included from d:\usr\include\winsock2.h:69,
      from ./../gdbsupport/gdb_select.h:30,
      from event-top.c:43:
     event-top.c: In function 'fd_set* fd_copy(fd_set*, const fd_set*, int)':
     event-top.c:1279:22: error: invalid conversion from 'const fd_set*' to 'fd_set*' [-fpermissive]
      1279 |     if (FD_ISSET (i, src))
   |                      ^
   |                      |
   |                      const fd_set*
     d:\usr\include\winsock.h:164:50: note:   initializing argument 2 of 'int __FD_ISSET(SOCKET, fd_set*)'
       164 | __CRT_ALIAS int __FD_ISSET( SOCKET __fd, fd_set *__set )
   |                                          ~~~~~~~~^~~~~

  Use an explicit type cast to prevent this.

      * gdb/event-top.c (fd_copy): Type-cast in call to FD_ISSET.

7 months ago[gdb/cli] Warn about forced return from signal trampoline
Tom de Vries [Sat, 4 Jan 2025 09:19:37 +0000 (10:19 +0100)] 
[gdb/cli] Warn about forced return from signal trampoline

The Linaro CI reported a regression on arm-linux in test-case
gdb.base/sigstep.exp following commit 7b46460a619 ("[gdb/symtab] Apply
workaround for PR gas/31115 a bit more") [1]:
...
(gdb) return^M
Make __default_sa_restorer return now? (y or n) n^M
Not confirmed^M
(gdb) FAIL: $exp: return from handleri: \
  leave signal trampoline (got interactive prompt)
...

After installing package glibc-debuginfo and adding --with-separate-debug-dir
to the configure flags, I managed to reproduce the FAIL.

The regression seems to be a progression in the sense that the function name
for the signal trampoline is found.

After reading up on the signal trampoline [2] and the return command [3], my
understanding is that forced returning from the signal trampoline is
potentially unsafe, given that for instance the process signal mask won't be
restored.

Fix this by:
- rather than using the name, using "signal trampoline" in the query, and
- adding a warning about returning from a signal trampoline,
giving us:
...
(gdb) return^M
warning: Returning from signal trampoline does not fully restore pre-signal \
  state, such as process signal mask.^M
Make signal trampoline return now? (y or n) y^M
87            dummy = 0; dummy = 0; while (!done);^M
(gdb) PASS: $exp: return from handleri: leave signal trampoline (in main)
...

Tested on x86_64-linux.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
[1] https://linaro.atlassian.net/browse/GNU-1459
[2] https://man7.org/linux/man-pages/man2/sigreturn.2.html
[3] https://sourceware.org/gdb/current/onlinedocs/gdb.html/Returning.html

7 months agoELF sec_info memory leaks
Alan Modra [Sat, 4 Jan 2025 03:09:20 +0000 (13:39 +1030)] 
ELF sec_info memory leaks

Use the bfd's objalloc memory so we don't need to free anything
attached to elf_section_data sec_info.  Other uses of sec_info that
need to allocate memory already use bfd_alloc.

* elf-eh-frame.c (_bfd_elf_parse_eh_frame): bfd_alloc sec_info.
* elf-sframe.c (_bfd_elf_parse_sframe): Likewise.

7 months ago_bfd_write_ar_hdr
Alan Modra [Sat, 4 Jan 2025 06:27:48 +0000 (16:57 +1030)] 
_bfd_write_ar_hdr

This has been broken since commit 8f95b6e44955 in 2010, and apparently
nobody has noticed.  How we write archive headers depends on the
archive, not the contents.

* libbfd-in.h (_bfd_write_ar_hdr): Correct.
* libbfd.h: Regenerate.

7 months ago[gdb/testsuite] Skip stabs board in make-check-all.sh
Tom de Vries [Sat, 4 Jan 2025 08:41:35 +0000 (09:41 +0100)] 
[gdb/testsuite] Skip stabs board in make-check-all.sh

I ran make-check-all.sh with gdb.linespec/explicit.exp, and the only problems
were found with target board stabs.

With target board unix the test-case runs in two seconds, but with target
board stabs it takes 12 seconds due to a timeout.

Stabs support in gdb has been unmaintained for a while, and there's an ongoing
discussion to deprecate and remove it (PR symtab/31210).

It seems unnecessary to excercise this unmaintained feature in
make-check-all.sh, so drop it.

Tested on x86_64-linux.

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

7 months agoskip -gfile: call fnmatch without FNM_FILE_NAME
Fangrui Song [Sun, 29 Dec 2024 22:57:44 +0000 (14:57 -0800)] 
skip -gfile: call fnmatch without FNM_FILE_NAME

fnmatch is called with the FNM_FILE_NAME flag so that `skip -gfi /usr/*`
doesn't match /usr/include/*.  This makes the file matching feature not
useful for STL headers that reside in multiple directories.  In
addition, the user cannot use a single `*` to match multiple leading
path components.

Let's drop the FNM_FILE_NAME flag and remove the assertion from
gdb_filename_fnmatch (originally for the auto-load feature).

7 months agobfd_set_input_error
Alan Modra [Fri, 3 Jan 2025 23:10:21 +0000 (09:40 +1030)] 
bfd_set_input_error

My recent change to closing archives showed some problems with the way
we stash errors for archive elements.  The most obvious thing found
by oss-fuzz, is that if output archive elements are closed during
bfd_close of an archive, then we can't access the element filename
when printing the element.  So change bfd_set_input_error to stash the
entire error message instead of input bfd and input error.

* bfd.c (input_bfd, input_error): Delete.
(bfd_error, _bfd_error_buf): Move.
(_bfd_clear_error_data): Move.  Make static.  Clear bfd_error too.
(bfd_set_input_error): Print the error use bfd_asprintf here..
(bfd_errmsg): ..not here.
(bfd_init): Update.
* opncls.c (bfd_close_all_done): Don't call _bfd_clear_error_data.
* libbfd.h: Regenerate.

7 months agoAutomatic date update in version.in
GDB Administrator [Sat, 4 Jan 2025 00:00:32 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agomacro nesting testcases
Alan Modra [Fri, 3 Jan 2025 02:18:51 +0000 (12:48 +1030)] 
macro nesting testcases

Fix a bunch of regressions.  Don't start anything besides a label in
first column, don't name macros the same as directives, and make
labels global.

7 months agoAutomatic date update in version.in
GDB Administrator [Fri, 3 Jan 2025 00:00:39 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agogprofng: remove the old archiver
Vladimir Mezentsev [Thu, 2 Jan 2025 05:40:05 +0000 (21:40 -0800)] 
gprofng: remove the old archiver

The first versions of Performance Analyzer archived only function names.
This is no longer used. We need a real elf-file.

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

* src/LoadObject.cc: Remove LoadObject::read_archive.
* src/LoadObject.h: Likewise.
* src/data_pckts.h: Remove unused declarations.
* src/parse.cc (process_seg_map_cmd): Don't look for the old archive.

7 months agonesting[123].d: Replace Sone with Some in comment
H.J. Lu [Thu, 2 Jan 2025 22:25:57 +0000 (06:25 +0800)] 
nesting[123].d: Replace Sone with Some in comment

* testsuite/gas/macros/nesting1.d: Replace Sone with Some in
comment.
* testsuite/gas/macros/nesting2.d: Likewise.
* testsuite/gas/macros/nesting3.d: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
7 months agogas: Revert PR 32391 related commits to fix 3 regressions
H.J. Lu [Wed, 1 Jan 2025 22:09:30 +0000 (06:09 +0800)] 
gas: Revert PR 32391 related commits to fix 3 regressions

9f2e3c21f65 Fix the handling or arguments and macro pseudo-variables inside nested assembler macros.

introduced 3 regressions of PR gas/32484, PR gas/32486 and PR gas/32487.
Revert all PR 32391 related commits and add tests for PR gas/32484,
PR gas/32486, PR gas/32487.

PR gas/32484
PR gas/32486
PR gas/32487
* testsuite/gas/macros/macros.exp: Run nesting1, nesting2 and
nesting3.
* testsuite/gas/macros/nesting1.d: New file.
* testsuite/gas/macros/nesting1.s: Likewise.
* testsuite/gas/macros/nesting2.d: Likewise.
* testsuite/gas/macros/nesting2.s: Likewise.
* testsuite/gas/macros/nesting3.d: Likewise.
* testsuite/gas/macros/nesting3.s: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
7 months agoSupport Intel AMX-TF32
Haochen Jiang [Thu, 2 Jan 2025 02:17:39 +0000 (10:17 +0800)] 
Support Intel AMX-TF32

In this patch, we will support AMX-TF32. It is a simple ISA
comparing to the previous ones, so there is no special handling.

gas/ChangeLog:

* config/tc-i386.c: Add amx_tf32.
* doc/c-i386.texi: Document .amx_tf32.
* testsuite/gas/i386/x86-64.exp: Run AMX-TF32 tests.
* testsuite/gas/i386/x86-64-amx-tf32-bad.d: New test.
* testsuite/gas/i386/x86-64-amx-tf32-bad.s: Ditto.
* testsuite/gas/i386/x86-64-amx-tf32-intel.d: Ditto.
* testsuite/gas/i386/x86-64-amx-tf32-inval.l: Ditto.
* testsuite/gas/i386/x86-64-amx-tf32-inval.s: Ditto.
* testsuite/gas/i386/x86-64-amx-tf32.d: Ditto.
* testsuite/gas/i386/x86-64-amx-tf32.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (PREFIX_VEX_0F3848_X86_64_W_0_L_0): New.
(X86_64_VEX_0F3848): Ditto.
(VEX_LEN_0F3848_X86_64_W_0): Ditto.
(VEX_W_0F3848_X86_64): Ditto.
(prefix_table): Add PREFIX_VEX_0F3848_X86_64_W_0_L_0.
(x86_64_table): Add X86_64_VEX_0F3848.
(vex_len_table): Add VEX_LEN_0F3848_X86_64_W_0.
(vex_w_table): Add VEX_W_0F3848_X86_64.
* i386-gen.c (isa_dependencies): Add AMX_TF32.
(cpu_flags): Ditto.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h (CpuAMX_TF32): New.
(i386_cpu_flags): Add cpuamx_tf32.
* i386-opc.tbl: Add AMX-TF32 instructions.
* i386-tbl.h: Regenerated.

7 months agoSupport Intel AMX-TRANSPOSE
Haochen Jiang [Thu, 2 Jan 2025 02:14:37 +0000 (10:14 +0800)] 
Support Intel AMX-TRANSPOSE

In this patch, we will support AMX-TRANSPOSE. Since AMX-TRANSPOSE
will be used with other CPUIDs very often, we put it into
CPU_FLAGS_COMMON.

To implement TMM pair, we reused ImplicitGroup and adjust the condition
in process_operands for the instructions.

APX_F extension is also handled in this patch, where it extends
T2RPNTLVW[Z0,Z1][,T1] to EVEX.128.NP/66.0F38.W0 6E/6F !(11):rrr:100
with NF=0.

Also, TTDPFP16PS should base on AMX_FP16, not AMX_BF16 in ISE055.
It would be fixed in ISE056.

gas/ChangeLog:

* config/tc-i386.c (cpu_arch): Add amx_transpose.
(_is_cpu): Ditto.
(process_operands): Adjust the condition for AMX-TRANSPOSE.
* doc/c-i386.texi: Document .amx_transpose.
* testsuite/gas/i386/x86-64.exp: Run AMX-TRANSPOSE tests.
* testsuite/gas/i386/x86-64-amx-transpose-bad.d: New test.
* testsuite/gas/i386/x86-64-amx-transpose-bad.s: Ditto.
* testsuite/gas/i386/x86-64-amx-transpose-intel.d: Ditto.
* testsuite/gas/i386/x86-64-amx-transpose-inval.l: Ditto.
* testsuite/gas/i386/x86-64-amx-transpose-inval.s: Ditto.
* testsuite/gas/i386/x86-64-amx-transpose.d: Ditto.
* testsuite/gas/i386/x86-64-amx-transpose.s: Ditto.

opcodes/ChangeLog:

* i386-dis.c (MOD_VEX_0F386E_X86_64_W_0): New.
(MOD_VEX_0F386F_X86_64_W_0): Ditto.
(PREFIX_VEX_0F385F_X86_64_W_0_L_0): Ditto.
(PREFIX_VEX_0F386B_X86_64_W_0_L_0): Ditto.
(PREFIX_VEX_0F386E_X86_64_W_0_M_0_L_0): Ditto.
(PREFIX_VEX_0F386F_X86_64_W_0_M_0_L_0): Ditto.
(X86_64_VEX_0F385F): Ditto.
(X86_64_VEX_0F386B): Ditto.
(X86_64_VEX_0F386E): Ditto.
(X86_64_VEX_0F386F): Ditto.
(VEX_LEN_0F385F_X86_64_W_0): Ditto.
(VEX_LEN_0F386B_X86_64_W_0): Ditto.
(VEX_LEN_0F386E_X86_64_W_0_M_0): Ditto.
(VEX_LEN_0F386F_X86_64_W_0_M_0): Ditto.
(VEX_W_0F385F_X86_64): Ditto.
(VEX_W_0F386B_X86_64): Ditto.
(VEX_W_0F386E_X86_64): Ditto.
(VEX_W_0F386F_X86_64): Ditto.
(mod_table): Add MOD_VEX_0F386E_X86_64_W_0,
MOD_VEX_0F386F_X86_64_W_0.
(prefix_table): Add PREFIX_VEX_0F386E_X86_64_W_0_M_0_L_0,
PREFIX_VEX_0F386F_X86_64_W_0_M_0_L_0.
Add new instructions for PREFIX_VEX_0F386C_X86_64_W_0_L_0.
(x86_64_table): Add X86_64_VEX_0F385F, X86_64_VEX_0F386B,
X86_64_VEX_0F386E, X86_64_VEX_0F386F.
(vex_len_table): Add VEX_LEN_0F385F_X86_64_W_0,
VEX_LEN_0F386B_X86_64_W_0, VEX_LEN_0F386E_X86_64_W_0_M_0,
VEX_LEN_0F386F_X86_64_W_0_M_0.
(vex_w_table): Add VEX_W_0F385F_X86_64, VEX_W_0F386B_X86_64,
VEX_W_0F386E_X86_64, VEX_W_0F386F_X86_64.
* i386-gen.c (cpu_flag_init): Add AMX_TRANSPOSE.
(cpu_flags): Add CpuAMX_TRANSPOSE.
* i386-init.h: Regenerated.
* i386-mnem.h: Ditto.
* i386-opc.h (CpuAMX_TRANSPOSE): New.
(i386_cpu): Add cpuamx_transpose.
* i386-opc.tbl: Add AMX-TRANSPOSE instructions.
* i386-tbl.h: Regenerated.

Co-authored-by: Hu, Lin1 <lin1.hu@intel.com>
7 months agoAutomatic date update in version.in
GDB Administrator [Thu, 2 Jan 2025 00:00:25 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoreadelf memory leaks
Alan Modra [Wed, 1 Jan 2025 12:22:59 +0000 (22:52 +1030)] 
readelf memory leaks

This fixes multiple readelf memory leaks:
- The check functions used to validate separate debug info files
  opened and read file data but didn't release the memory nor close
  the file.
- A string table was being re-read into a buffer, leaking the old
  contents.
- Decompressed section contents leaked.

* dwarf.c (check_gnu_debuglink): Always call close_debug_file.
(check_gnu_debugaltlink): Likewise.
* readelf.c (process_section_headers): Don't read string_table
again if we already have it.
(maybe_expand_or_relocate_section): Add decomp_buf param to
return new uncompressed buffer.
(dump_section_as_strings, filedata->string_table): Free any
uncompressed buffer.
(process_file): Call close_debug_file rather than freeing
various filedata components.

7 months agoobjdump sym memory leak
Alan Modra [Wed, 1 Jan 2025 12:22:51 +0000 (22:52 +1030)] 
objdump sym memory leak

The sym array should be freed even with a symcount of zero.

* objdump.c (dump_bfd): Free syms before replacing with
extra_syms.  Free extra_syms after adding to syms.

7 months agognu_debuglink related memory leak
Alan Modra [Wed, 1 Jan 2025 12:22:41 +0000 (22:52 +1030)] 
gnu_debuglink related memory leak

* opncls.c (bfd_fill_in_gnu_debuglink_section): Free section
contents on success too.

7 months agoClose elements of output archive
Alan Modra [Wed, 1 Jan 2025 12:22:06 +0000 (22:52 +1030)] 
Close elements of output archive

When cleaning up an archive, close all its elements.  This fixes a
number of ar memory leaks.

bfd/
* archive.c (_bfd_archive_close_and_cleanup): Close elements
of an archive open for writing.
binutils/
* objcopy.c (copy_archive): Don't close output archive
elements here.
* dlltool.c (gen_lib_file): Likewise.
ld/
* pe-dll.c (pe_dll_generate_implib): Don't close output
archive elements here.

7 months agoar.c memory leak fixme
Alan Modra [Wed, 1 Jan 2025 12:21:53 +0000 (22:51 +1030)] 
ar.c memory leak fixme

Cure the leak by always mallocing the string in output_filename,
and freeing the old one any time we assign output_filename.

7 months agobfdtest1 loop check
Alan Modra [Wed, 1 Jan 2025 12:21:44 +0000 (22:51 +1030)] 
bfdtest1 loop check

Add a check that next_archived_file doesn't return the same element.
Seen with the following, which I think shows a bug with "ar r" and
thin archives as you get two copies of artest.a in artest2.a.

$ rm tmpdir/artest*
$ ./ar rc tmpdir/artest.a tmpdir/bintest.o
$ ./ar rcT tmpdir/artest2.a tmpdir/artest.a
$ ./bfdtest1 tmpdir/artest.a
$ ./bfdtest1 tmpdir/artest2.a
$ ./ar rcT tmpdir/artest2.a tmpdir/artest.a
$ ./bfdtest1 tmpdir/artest2.a
oops: next_archived_file

7 months agothin archive with nested archive memory leak
Alan Modra [Wed, 1 Jan 2025 12:21:34 +0000 (22:51 +1030)] 
thin archive with nested archive memory leak

The only reason to keep new_areldata around was for access to the
filename, but we now always take a copy in alloc'd memory.

* archive.c (_bfd_get_elt_at_filepos): Free new_areldata when
it is not attached to bfd.

7 months agomemory leak in gas dwarf2dbg.c
Alan Modra [Wed, 1 Jan 2025 12:20:29 +0000 (22:50 +1030)] 
memory leak in gas dwarf2dbg.c

Found when running the pr27355 testcase.

PR 27355
PR 27426
* dwarf2dbg.c (allocate_filename_to_slot): Update dirs_in_use.

7 months agogas obj-elf.c memory leaks
Alan Modra [Wed, 1 Jan 2025 12:20:17 +0000 (22:50 +1030)] 
gas obj-elf.c memory leaks

* config/obj-elf.c (obj_elf_section): Use notes_memdup for
linked_to_symbol_name.
(obj_elf_find_and_add_versioned_name): Use notes_alloc for
versioned_name.

7 months agoPR 32391 memory leak
Alan Modra [Wed, 1 Jan 2025 12:19:59 +0000 (22:49 +1030)] 
PR 32391 memory leak

* macro.c (sub_actual): Free newadd.

7 months agogas reloc_list memory leaks
Alan Modra [Wed, 1 Jan 2025 12:19:48 +0000 (22:49 +1030)] 
gas reloc_list memory leaks

Put these on the notes obstack too.

* config/tc-wasm32.c (wasm32_leb128): Use notes_alloc for
reloc_list vars.
* read.c (s_reloc): Likewise.
* write.c (create_note_reloc): Likewise.
(write_object_file): Reset reloc_list after write_relocs.

7 months agogas tc_gen_reloc memory leaks
Alan Modra [Wed, 1 Jan 2025 12:19:04 +0000 (22:49 +1030)] 
gas tc_gen_reloc memory leaks

This makes all the tc_gen_reloc functions and the associated array in
write.c:write_relocs use notes_alloc rather than malloc.  tc-hppa.c
tc_gen_reloc gets a few more changes, deleting some dead code, and
tidying code that duplicates prior initialisation.

7 months agogas gen-sframe memory leaks
Alan Modra [Wed, 1 Jan 2025 12:18:38 +0000 (22:48 +1030)] 
gas gen-sframe memory leaks

More freeing required.

* gen-sframe.c (all_sframe_fdes, last_sframe_fde): Move earlier,
make file scope.
(sframe_row_entry_new): Move earlier.
(sframe_row_entry_free): New function.
(sframe_fde_alloc, sframe_fde_free): Move earlier.
(sframe_fde_link): Delete.  Expand into..
(create_sframe_all): ..here.
(output_sframe_internal): Delete silly sframe_flags init.
Free fdes.  Reset static vars.
(sframe_xlate_ctx_cleanup): Use sframe_row_entry_free.  Free
remember_fre too.  Don't re-init xlate_ctx we're about to drop.
* gen-sframe.h (all_sframe_fdes): Don't declare.

7 months agogas dw2gencfi memory leaks
Alan Modra [Wed, 1 Jan 2025 12:17:16 +0000 (22:47 +1030)] 
gas dw2gencfi memory leaks

Some of these could have remained as malloc'd memory, but that would
require quite a bit of code to traverse frch_cfi_data for example, and
would rely on matching cfi directives (ie. valid input).  Just put
them on the notes obstack instead.

* dw2gencfi.c (alloc_fde_entry): Use notes_calloc.
(alloc_cfi_insn_data): Likewise.
(cfi_end_fde): Don't free frch_cfi_data.
(cfi_add_label): Use notes_strdup.
(cfi_add_CFA_remember_state): Use notes_alloc.
(cfi_add_CFA_restore_state): Don't free.
(dot_cfi_escape): Use notes_alloc.
(cfi_finish): Free cies after each pass, not before.  Clear
out static vars too.

7 months agogas include_dirs memory leak
Alan Modra [Wed, 1 Jan 2025 12:08:44 +0000 (22:38 +1030)] 
gas include_dirs memory leak

This is the first of a series of patches aimed at making it possible
to configure with CFLAGS="-g -O2 -fsanitize=address,undefined" and run
the binutils and gas testsuite on x86_64-linux without using
ASAN_OPTIONS=detect_leaks=0.  ie. the patch series is aimed at fixing
common gas, ar, objcopy, objdump, and readelf leaks.

* config/tc-tic54x.c (md_begin): Make use of notes_strdup rather
than xstrdup to copy entries added to include_dirs.
* read.c (read_end): Free include_dirs array.

7 months agogas totalfrags
Alan Modra [Wed, 1 Jan 2025 12:08:03 +0000 (22:38 +1030)] 
gas totalfrags

Avoid any possibility of signed overflow.  (Seen on oss-fuzz).

* frags.c (totalfrags): Make unsigned.
(get_frag_count): Return unsigned.
* frags.h (get_frag_count): Likewise.

7 months agoPR 32507, PRIx64 in error messages on 32-bit mingw
Alan Modra [Wed, 1 Jan 2025 12:01:50 +0000 (22:31 +1030)] 
PR 32507, PRIx64 in error messages on 32-bit mingw

People, including me, had forgotten that the bfd_error_handler just
handled standard printf format strings, not MSC %I64 and suchlike.
Using PRIx64 and similar in errors does not work if the host compiler
headers define those formats as the Microsoft %I64 variety.  (We
handled %ll OK, editing it to %I64 on such hosts.)

PR 32507
* bfd.c (_bfd_doprnt, _bfd_doprnt_scan): Handle %I64 and %I32
in input strings if the host defines PRId64 as "I64d".
Edit %ll to %I64 on detecting PRId64 as "I64d" rather than on
a preprocessor define.

7 months agoRegen gprofng after copyright update
Alan Modra [Wed, 1 Jan 2025 11:48:49 +0000 (22:18 +1030)] 
Regen gprofng after copyright update

7 months agoUpdate year range in copyright notice of binutils files
Alan Modra [Wed, 1 Jan 2025 07:47:28 +0000 (18:17 +1030)] 
Update year range in copyright notice of binutils files

7 months agoAutomatic date update in version.in
GDB Administrator [Wed, 1 Jan 2025 00:00:37 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoUse 'flags' when expanding symtabs in gdbpy_lookup_static_symbols
Tom Tromey [Thu, 19 Dec 2024 00:36:09 +0000 (17:36 -0700)] 
Use 'flags' when expanding symtabs in gdbpy_lookup_static_symbols

This changes gdbpy_lookup_static_symbols to pass the 'flags' parameter
to expand_symtabs_matching.  This should refine the search somewhat.
Note this is "just" a performance improvement, as the loop over
symtabs already checks 'flags'.

v2 also removes 'SEARCH_GLOBAL_BLOCK' and updates py-symbol.exp to
verify that this works properly.  Thanks to Tom for this insight.

Co-Authored-By: Tom de Vries <tdevries@suse.de>
7 months agoAutomatic date update in version.in
GDB Administrator [Tue, 31 Dec 2024 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoAutomatic date update in version.in
GDB Administrator [Mon, 30 Dec 2024 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoUpdate gdb/NEWS after GDB 16 branch creation.
Joel Brobecker [Sun, 29 Dec 2024 02:58:08 +0000 (06:58 +0400)] 
Update gdb/NEWS after GDB 16 branch creation.

This commit a new section for the next release branch, and renames
the section of the current branch, now that it has been cut.

7 months agoBump version to 17.0.50.DATE-git.
Joel Brobecker [Sun, 29 Dec 2024 02:51:26 +0000 (06:51 +0400)] 
Bump version to 17.0.50.DATE-git.

Now that the GDB 16 branch has been created,
this commit bumps the version number in gdb/version.in to
17.0.50.DATE-git

For the record, the GDB 16 branch was created
from commit ee29a3c4ac7adc928ae6ed1fed3b59c940a519a4.

Also, as a result of the version bump, the following changes
have been made in gdb/testsuite:

* gdb.base/default.exp: Change $_gdb_major to 17.

7 months agoAutomatic date update in version.in gdb-16-branchpoint
GDB Administrator [Sun, 29 Dec 2024 00:00:18 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoAutomatic date update in version.in
GDB Administrator [Sat, 28 Dec 2024 00:00:19 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agobfd/ELF: refine segment index in filepos assignment diag
Jan Beulich [Fri, 27 Dec 2024 10:37:42 +0000 (11:37 +0100)] 
bfd/ELF: refine segment index in filepos assignment diag

Reporting an internal loop index isn't helpful for the user to determine
which segment the problem is with. Report the PHDR index instead.

7 months agold/testsuite: replace aarch64 uses of load_lib
Jan Beulich [Fri, 27 Dec 2024 10:37:05 +0000 (11:37 +0100)] 
ld/testsuite: replace aarch64 uses of load_lib

Using $srcdir/$subdir directly doesn't work, at least not with expect
5.45, dejagnu 1.6, and an out-of-tree build (I assume it's the latter
aspect which is crucial here). Make use of load_file instead.

7 months agoLoongArch: Reword message for unresolvable relocs
Xi Ruoyao [Wed, 25 Dec 2024 04:41:45 +0000 (12:41 +0800)] 
LoongArch: Reword message for unresolvable relocs

For PDE, "recompiling with -fPIE" just makes no sense.

For PIE, "recompiling with -fPIE" makes sense for unresolvable absolute
relocs, but not unresolveable PC-relative relocs: if the reloc is
already PC-relative, the problem is not the reloc is PC-relative or
absolute, but the reloc is not applicable for external symbols.

If we hit an unresolvable reloc in PDE or an unresolvable PC-relative
reloc in PIE, it means the programmer has somehow wrongly instructed the
compiler to treat external symbols as local symbols.  A misuse of
-mdirect-extern-access can cause the issue, so we can suggest
-mno-direct-extern-access.  And in all cases (DSO/PIE/PDE) a mismatching
symbol visibility can also cause the issue, so we should also suggest to
check the visibility.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
7 months agoLoongArch: Allow R_LARCH_PCALA_HI20 or R_LARCH_PCREL20_S2 against undefined weak...
Xi Ruoyao [Wed, 25 Dec 2024 04:41:44 +0000 (12:41 +0800)] 
LoongArch: Allow R_LARCH_PCALA_HI20 or R_LARCH_PCREL20_S2 against undefined weak symbols for static PIE

In a static PIE, undefined weak symbols should be just resolved to
runtime address 0, like those symbols with non-default visibility.  This
was silently broken in all prior Binutils releases with "-static-pie
-mdirect-extern-access":

    $ cat t.c
    int x (void) __attribute__ ((weak));

    int
    main (void)
    {
      __builtin_printf("%p\n", x);
    }
    $ gcc t.c -static-pie -mdirect-extern-access
    $ ./a.out
    0x7ffff1d64000

Since commit 4cb77761d687 ("LoongArch: Check PC-relative relocations for
shared libraries), the situation has been improved: the linker errors
out instead of silently producing a wrong output file.

But logically, using -mdirect-extern-access for a static PIE perfectly
makes sense, and we should not prevent that even if the programmer uses
weak symbols.  Linux kernel is such an example, and Linux < 6.10 now
fails to build with Binutils trunk.  (The silent breakage with prior
Binutils releases was "benign" due to some blind luck.)

While since the 6.10 release Linux has removed those potentially
undefined weak symbols (due to performance issue), we still should
support weak symbols in -mdirect-extern-access -static-pie and unbreak
building old kernels.

Link: https://lore.kernel.org/loongarch/20241206085810.112341-1-chenhuacai@loongson.cn/
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
7 months agoLoongArch: Fix resolution of undefined weak hidden/protected symbols
Xi Ruoyao [Wed, 25 Dec 2024 04:41:43 +0000 (12:41 +0800)] 
LoongArch: Fix resolution of undefined weak hidden/protected symbols

An undefined weak hidden/protect symbol should be resolved to runtime
address 0, but we were actually resolving it to link-time address 0.  So
in PIE or DSO the runtime address would be incorrect.

Fix the issue by rewriting pcalau12i to lu12i.w, and pcaddi to addi.w.
The latter does not always work because the immediate field of addi.w is
narrower, report an error in the case the addend is too large.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
7 months agoAutomatic date update in version.in
GDB Administrator [Fri, 27 Dec 2024 00:00:26 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agoAutomatic date update in version.in
GDB Administrator [Thu, 26 Dec 2024 00:00:20 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agomacro.c:871 heap-buffer-overflow
Alan Modra [Wed, 25 Dec 2024 20:49:24 +0000 (07:19 +1030)] 
macro.c:871 heap-buffer-overflow

PR 32391 commit 9f2e3c21f6 fallout again.  Also fix another 'macro'
may be used uninitialized.

7 months agobuffer overflow in gas/app.c
Alan Modra [Wed, 25 Dec 2024 08:47:24 +0000 (19:17 +1030)] 
buffer overflow in gas/app.c

This testcase:
 .irp x x x "
 .end #
 .endr
manages to access lex[EOF].

xxx: Warning: end of file in string; '"' inserted
xxx:1: Warning: missing closing `"'
gas/app.c:844:16: runtime error: index -1 out of bounds for type 'char [256]
Following that there is a buffer overflow.

Stop this happening, and in other similar places, by checking for EOF.

7 months agoAutomatic date update in version.in
GDB Administrator [Wed, 25 Dec 2024 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

7 months agogdb/testsuite: add some xfail in gdb.base/startup-with-shell.exp
Andrew Burgess [Fri, 15 Dec 2023 13:03:26 +0000 (13:03 +0000)] 
gdb/testsuite: add some xfail in gdb.base/startup-with-shell.exp

There are two tests that fail in gdb.base/startup-with-shell.exp when
using the native-extended-remote board.  I plan to fix these issues,
and I've posted a series that does just that:

  https://inbox.sourceware.org/gdb-patches/cover.1730731085.git.aburgess@redhat.com

But until that series is reviewed, I thought I'd merge this commit,
which marks the FAIL as XFAIL and links them to the relevant bug
number.

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

Tested-By: Guinevere Larsen <guinevere@redhat.com>
7 months agogdb/freebsd: port core file context parsing to FreeBSD
Andrew Burgess [Mon, 21 Oct 2024 15:41:54 +0000 (16:41 +0100)] 
gdb/freebsd: port core file context parsing to FreeBSD

This commit implements the gdbarch_core_parse_exec_context method for
FreeBSD.

This is much simpler than for Linux.  On FreeBSD, at least the
version (13.x) that I have installer, there are additional entries in
the auxv vector that point directly to the argument and environment
vectors, this makes it trivial to find this information.

If these extra auxv entries are not available on earlier FreeBSD, then
that's fine.  The fallback behaviour will be for GDB to act as it
always has up to this point, you'll just not get the extra
functionality.

Other differences compared to Linux are that FreeBSD has
AT_FREEBSD_EXECPATH instead of AT_EXECFN, the AT_FREEBSD_EXECPATH is
the full path to the executable.  On Linux AT_EXECFN is the command
the user typed, so this can be a relative path.

This difference is handy as on FreeBSD we don't parse the mapped files
from the core file (are they even available?).  So having the EXECPATH
means we can use that as the absolute path to the executable.

However, if the user ran a symlink then AT_FREEBSD_EXECPATH will be
the absolute path to the symlink, not to the underlying file.  This is
probably a good thing, but it does mean there is one case we test on
Linux that fails on FreeBSD.

On Linux if we create a symlink to an executable, then run the symlink
and generate a corefile.  Now delete the symlink and load the core
file.  On Linux GDB will still find (and open) the original
executable.  This is because we use the mapped file information to
find the absolute path to the executable, and the mapped file
information only stores the real file names, not symlink names.

This is a total edge case, I only added the deleted symlink test
originally because I could see that this would work on Linux.  Though
it is neat that Linux finds this, I don't feel too bad that this fails
on FreeBSD.

Other than this, everything seems to work on x86-64 FreeBSD (13.4)
which is all I have setup right now.  I don't see why other
architectures wouldn't work too, but I haven't tested them.

7 months agogdb: improve GDB's ability to auto-load the exec for a core file
Andrew Burgess [Thu, 2 May 2024 14:37:42 +0000 (15:37 +0100)] 
gdb: improve GDB's ability to auto-load the exec for a core file

GDB already has a limited mechanism for auto-loading the executable
corresponding to a core file, this can be found in the function
locate_exec_from_corefile_build_id in corelow.c.

However, this approach uses the build-id of the core file to look in
either the debug directory (for a symlink back to the executable) or
by asking debuginfod.  This is great, and works fine if the core file
is a "system" binary, but often, when I'm debugging a core file, it's
part of my development cycle, so there's no build-id symlink in the
debug directory, and debuginfod doesn't know about the binary either,
so GDB can't auto load the executable....

... but the executable is right there!

This commit builds on the earlier commits in this series to make GDB
smarter.

On GNU/Linux, when we parse the execution context from the core
file (see linux-tdep.c), we already grab the command pointed to by
AT_EXECFN.  If this is an absolute path then GDB can use this to
locate the executable, a build-id check ensures we've found the
correct file.  With this small change GDB suddenly becomes a lot
better at auto-loading the executable for a core file.

But we can do better!  Often the AT_EXECFN is not an absolute path.

If it is a relative path then we check for this path relative to the
core file.  This helps if a user does something like:

  $ ./build/bin/some_prog
  Aborted (core dumped)
  $ gdb -c corefile

In this case the core file in the current directory will have an
AT_EXECFN value of './build/bin/some_prog', so if we look for that
path relative to the location of the core file this might result in a
hit, again, a build-id check ensures we found the right file.

But we can do better still!  What if the user moves the core file?  Or
the user is using some tool to manage core files (e.g. the systemd
core file management tool), and the user downloads the core file to a
location from which the relative path no longer works?

Well in this case we can make use of the core file's mapped file
information (the NT_FILE note).  The executable will be included in
the mapped file list, and the path within the mapped file list will be
an absolute path.  We can search for mapped file information based on
an address within the mapped file, and the auxv vector happens to
include an AT_ENTRY value, which is the entry address in the main
executable.  If we look up the mapped file containing this address
we'll have the absolute path to the main executable, a build-id check
ensures this really is the file we're looking for.

It might be tempting to jump straight to the third approach, however,
there is one small downside to the third approach: if the executable
is a symlink then the AT_EXECFN string will be the name of the
symlink, that is, the thing the user asked to run.  The mapped file
entry will be the name of the actual file, i.e. the symlink target.
When we auto-load the executable based on the third approach, the file
loaded might have a different name to that which the user expects,
though the build-id check (almost) guarantees that we've loaded the
correct binary.

But there's one more thing we can check for!

If the user has placed the core file and the executable into a
directory together, for example, as might happen with a bug report,
then neither the absolute path check, nor the relative patch check
will find the executable.  So GDB will also look for a file with the
right name in the same directory as the core file.  Again, a build-id
check is performed to ensure we find the correct file.

Of course, it's still possible that GDB is unable to find the
executable using any of these approaches.  In this case, nothing
changes, GDB will check in the debug info directory for a build-id
based link back to the executable, and if that fails, GDB will ask
debuginfod for the executable.  If this all fails, then, as usual, the
user is able to load the correct executable with the 'file' command,
but hopefully, this should be needed far less from now on.

7 months agogdb/testsuite: make some of the core file / build-id tests harder
Andrew Burgess [Thu, 24 Oct 2024 21:04:10 +0000 (22:04 +0100)] 
gdb/testsuite: make some of the core file / build-id tests harder

We have a few tests that load core files, which depend on GDB not
auto-loading the executable that matches the core file.  One of these
tests (corefile-buildid.exp) exercises GDB's ability to load the
executable via the build-id links in the debug directory, while the
other two tests are just written assuming that GDB hasn't auto-loaded
the executable.

In the next commit, GDB is going to get better at finding the
executable for a core file, and as a consequence these tests could
start to fail if the testsuite is being run using a compiler that adds
build-ids by default, and is on a target (currently only Linux) with
the improved executable auto-loading.

To avoid these test failures, this commit updates some of the tests.

coredump-filter.exp and corefile.exp are updated to unload the
executable should it be auto-loaded.  This means that the following
output from GDB will match the expected patterns.  If the executable
wasn't auto-loaded then the new step to unload is harmless.

The corefile-buildid.exp test needed some more significant changes.
For this test it is important that the executable be moved aside so
that GDB can't locate it, but we do still need the executable around
somewhere, so that the debug directory can link to it.  The point of
the test is that the executable _should_ be auto-loaded, but using the
debug directory, not using GDB's context parsing logic.

While looking at this test I noticed two additional problems, first we
were creating the core file more times than we needed.  We only need
to create one core file for each test binary (total two), while we
previously created one core file for each style of debug info
directory (total four).  The extra core files should be identical, and
were just overwriting each other, harmless, but still pointless work.

The other problem is that after running an earlier test we modified
the test binary in order to run a later test.  This means it's not
possible to manually re-run the first test as the binary for that test
is destroyed.

As part of the rewrite in this commit I've addressed these issues.

This test does change many of the test names, but there should be no
real changes in what is being tested after this commit.  However, when
the next commit is added, and GDB gets better at auto-loading the
executable for a core file, these tests should still be testing what
is expected.

7 months agogdb: parse and set the inferior environment from core files
Andrew Burgess [Sat, 8 Jun 2024 10:06:02 +0000 (11:06 +0100)] 
gdb: parse and set the inferior environment from core files

Extend the core file context parsing mechanism added in the previous
commit to also store the environment parsed from the core file.

This environment can then be injected into the inferior object.

The benefit of this is that when examining a core file in GDB, the
'show environment' command will now show the environment extracted
from a core file.

Consider this example:

  $ env -i GDB_TEST_VAR=FOO ./gen-core
  Segmentation fault (core dumped)
  $ gdb -c ./core.1669829
  ...
  [New LWP 1669829]
  Core was generated by `./gen-core'.
  Program terminated with signal SIGSEGV, Segmentation fault.
  #0  0x0000000000401111 in ?? ()
  (gdb) show environment
  GDB_TEST_VAR=foo
  (gdb)

There's a new test for this functionality.

7 months agogdb: add gdbarch method to get execution context from core file
Andrew Burgess [Thu, 25 Apr 2024 08:36:43 +0000 (09:36 +0100)] 
gdb: add gdbarch method to get execution context from core file

Add a new gdbarch method which can read the execution context from a
core file.  An execution context, for this commit, means the filename
of the executable used to generate the core file and the arguments
passed to the executable.

In later commits this will be extended further to include the
environment in which the executable was run, but this commit is
already pretty big, so I've split that part out into a later commit.

Initially this new gdbarch method is only implemented for Linux
targets, but a later commit will add FreeBSD support too.

Currently when GDB opens a core file, GDB reports the command and
arguments used to generate the core file.  For example:

  (gdb) core-file ./core.521524
  [New LWP 521524]
  Core was generated by `./gen-core abc def'.

However, this information comes from the psinfo structure in the core
file, and this struct only allows 80 characters for the command and
arguments combined.  If the command and arguments exceed this then
they are truncated.

Additionally, neither the executable nor the arguments are quoted in
the psinfo structure, so if, for example, the executable was named
'aaa bbb' (i.e. contains white space) and was run with the arguments
'ccc' and 'ddd', then when this core file was opened by GDB we'd see:

  (gdb) core-file ./core.521524
  [New LWP 521524]
  Core was generated by `./aaa bbb ccc ddd'.

It is impossible to know if 'bbb' is part of the executable filename,
or another argument.

However, the kernel places the executable command onto the user stack,
this is pointed to by the AT_EXECFN entry in the auxv vector.
Additionally, the inferior arguments are all available on the user
stack.  The new gdbarch method added in this commit extracts this
information from the user stack and allows GDB to access it.

The information on the stack is writable by the user, so a user
application can start up, edit the arguments, override the AT_EXECFN
string, and then dump core.  In this case GDB will report incorrect
information, however, it is worth noting that the psinfo structure is
also filled (by the kernel) by just copying information from the user
stack, so, if the user edits the on stack arguments, the values
reported in psinfo will change, so the new approach is no worse than
what we currently have.

The benefit of this approach is that GDB gets to report the full
executable name and all the arguments without the 80 character limit,
and GDB is aware which parts are the executable name, and which parts
are arguments, so we can, for example, style the executable name.

Another benefit is that, now we know all the arguments, we can poke
these into the inferior object.  This means that after loading a core
file a user can 'show args' to see the arguments used.  A user could
even transition from core file debugging to live inferior debugging
using, e.g. 'run', and GDB would restart the inferior with the correct
arguments.

Now the downside: finding the AT_EXECFN string is easy, the auxv entry
points directly too it.  However, finding the arguments is a little
trickier.  There's currently no easy way to get a direct pointer to
the arguments.  Instead, I've got a heuristic which I believe should
find the arguments in most cases.  The algorithm is laid out in
linux-tdep.c, I'll not repeat it here, but it's basically a search of
the user stack, starting from AT_EXECFN.

If the new heuristic fails then GDB just falls back to the old
approach, asking bfd to read the psinfo structure for us, which gives
the old 80 character limited answer.

For testing, I've run this series on (all GNU/Linux) x86-64. s390,
ppc64le, and the new test passes in each case.  I've done some very
basic testing on ARM which does things a little different than the
other architectures mentioned, see ARM specific notes in
linux_corefile_parse_exec_context_1 for details.

7 months agoarc: add_to_decodelist
Alan Modra [Tue, 24 Dec 2024 00:58:46 +0000 (11:28 +1030)] 
arc: add_to_decodelist

Given objdump -Mcpu=archs -D or similar, add_to_decodelist adds three
entries to decodelist for each instruction disassembled.  That can
waste a lot of cpu when the list grows large.  What's more,
decodelist is static and nothing clears the list.  So the list
persists from one file to the next if objdump is disassembling
multiple files in one invocation.  Wrong disassembly might result.

To fix this problem, I've moved decodelist to the arc private_data and
made it an array.  I believe that init_disassemble_data will be
called, clearing private_data, for each file disassembled.  That's
certainly true for objdump, and if I can see my way around gdb
constructors, it's also true for gdb.  I don't think there is a
possibility of info.disassembler_options changing unless there is
first a call to init_disassebled_data.  That means all of the option
parsing and bfd mach and e_flags decoding need only be done when
initialising the arc private_data.

* arc-dis.c (addrtypenames_max, addrtypeunknown): Delete..
(get_addrtype): ..substitute values here.  Tidy.
(skipclass_t, linkclass, decodelist): Delete.
(enforced_isa_mask, print_hex): Delete.
(struct arc_disassemble_info): Add decode[], decode_count,
isa_mask, print_hex.
(init_arc_disasm_info): Tidy.
(add_to_decodelist): Delete, replacing with..
(add_to_decode): ..this.  Don't duplicate entries.
(skip_this_opcode): Adjust to suit.
(find_format_from_table, parse_option): Likewise.
(parse_disassembler_options): Likewise.  Move code dealing
with bfd mach and eflags from..
(print_insn_arc): ..here.  Adjust for other changes.