Commit Graph

123040 Commits

Author SHA1 Message Date
Simon Marchi
94de78f9d0 gdb/dwarf: clear per_bfd::num_{comp,type}_units on error
Commit bedd6a7a44 ("gdb/dwarf: track compilation and type unit count")
causes this internal error:

    $ ./gdb -nx -q --data-directory=data-directory testsuite/outputs/gdb.dwarf2/debug-names-duplicate-cu/debug-names-duplicate-cu -ex "save gdb-index -dwarf-5 /tmp" -batch

    warning: Section .debug_names has incorrect number of CUs in CU table, ignoring .debug_names.
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/index-write.c:1454: internal-error: write_debug_names: Assertion `comp_unit_counter == per_bfd->num_comp_units' failed.

This is visible when running this test:

    $ make check TESTS="gdb.dwarf2/debug-names-duplicate-cu.exp" RUNTESTFLAGS="--target_board=cc-with-debug-names"
    ...
    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.dwarf2/debug-names-duplicate-cu.exp ...
    gdb compile failed, warning: Section .debug_names has incorrect number of CUs in CU table, ignoring .debug_names.
    /home/smarchi/src/binutils-gdb/gdb/dwarf2/index-write.c:1454: internal-error: write_debug_names: Assertion `comp_unit_counter == per_bfd->num_comp_units' failed.
    ...
                    === gdb Summary ===

    # of untested testcases         1

However, it's easy to miss because it only causes an "UNTESTED" to be
recorded, not a FAIL or UNRESOLVED.  This is because the problem happens
while trying to create the .debug_names index, as part of the test case
compilation.

The problem is: when we bail out from using .debug_names because we
detect it is inconsistent with the units in .debug_info, we clear
per_bfd->all_units, to destroy all units previously created, before
proceeding to read the units with an index.  However, we don't clear
per_bfd->num_{comp,type}_units.  As a result, per_bfd->all_units
contains one unit, while per_bfd->num_comp_units is 2.  Whenever we
clear per_bfd->all_units, we should also clear
per_bfd->num_{comp,type}_units.

While at it, move this logic inside a scoped object.

I added an assertion in finalize_all_units to verify that the size of
per_bfd->all_units equals per_bfd->num_comp_units +
per_bfd->num_type_units.  This makes the problem (if omitting the fix)
visible when running gdb.dwarf2/debug-names-duplicate-cu.exp with the
unix (default) target board:

    ERROR: Couldn't load debug-names-duplicate-cu into GDB (GDB internal error).
    FAIL: gdb.dwarf2/debug-names-duplicate-cu.exp: find index type (GDB internal error)
    FAIL: gdb.dwarf2/debug-names-duplicate-cu.exp: find index type, check type is valid

                    === gdb Summary ===

    # of expected passes            1
    # of unexpected failures        2
    # of unresolved testcases       1

I considered changing the code to build a local vector of units first,
then move it in per_bfd->all_units on success, that would avoid having
to clean it up on error.  I did not do it because it's a much larger
change, but we could consider it.

Change-Id: I49bcc0cb4b34aba3d882b27c8a93c168e8875c08
Approved-By: Tom Tromey <tom@tromey.com>
2025-08-14 12:49:20 -04:00
Tom de Vries
903ea49d47 [gdb/testsuite] Fix gdb.base/condbreak-multi-context.exp on native-gdbserver
With test-case gdb.base/condbreak-multi-context.exp on target board
native-gdbserver, I run into:
...
(gdb) continue
Continuing.
gdb/ax-gdb.c:542: internal-error: gen_var_ref: \
  LOC_CONST_BYTES symbols are not supported
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
FAIL: $exp: start_before=true: scenario_1: run until A::func (GDB internal error)
Resyncing due to internal error.
0x64cfa9 gdb_internal_backtrace_1
	gdb/bt-utils.c:122
0x64d047 _Z22gdb_internal_backtracev
	gdb/bt-utils.c:175
0x10cfdf1 internal_vproblem
	gdb/utils.c:423
0x10d020b _Z15internal_verrorPKciS0_P13__va_list_tag
	gdb/utils.c:503
0x19a6b4e _Z18internal_error_locPKciS0_z
	gdbsupport/errors.cc:57
0x5b76f9 gen_var_ref
	gdb/ax-gdb.c:541
0x5b9565 gen_static_field
	gdb/ax-gdb.c:1460
0x5b91c9 gen_struct_ref_recursive
	gdb/ax-gdb.c:1357
0x5b93f8 gen_struct_ref
	gdb/ax-gdb.c:1427
0x5bba0d _Z17gen_expr_structopP10expression10exp_opcodePN4expr9operationEPKcP10agent_exprP9axs_value
	gdb/ax-gdb.c:2253
0x678d94 _ZN4expr22structop_ptr_operation14do_generate_axEP10expressionP10agent_exprP9axs_valueP4type
	gdb/expop.h:1089
0x5b9ab6 _ZN4expr9operation11generate_axEP10expressionP10agent_exprP9axs_valueP4type
	gdb/ax-gdb.c:1602
0x5bb905 _Z14gen_expr_binopP10expression10exp_opcodePN4expr9operationES4_P10agent_exprP9axs_value
	gdb/ax-gdb.c:2233
0x69815c _ZN4expr24usual_ax_binop_operationIL10exp_opcode14EXadL_Z13eval_op_equalP4typeP10expression6nosideS1_P5valueS8_EEE14do_generate_axES5_P10agent_exprP9axs_valueS3_
	gdb/expop.h:1291
0x5b9ab6 _ZN4expr9operation11generate_axEP10expressionP10agent_exprP9axs_valueP4type
	gdb/ax-gdb.c:1602
0x5bc034 _Z17gen_eval_for_exprmP10expression
	gdb/ax-gdb.c:2396
0x5f16b6 parse_cond_to_aexpr
	gdb/breakpoint.c:2582
0x5f18a5 build_target_condition_list
	gdb/breakpoint.c:2640
0x5f2698 insert_bp_location
	gdb/breakpoint.c:2970
0x5f3916 insert_breakpoint_locations
	gdb/breakpoint.c:3400
0x60c1dd update_global_location_list
	gdb/breakpoint.c:11771
0x5f3421 _Z18insert_breakpointsv
	gdb/breakpoint.c:3293
0xaa0972 keep_going_pass_signal
	gdb/infrun.c:9131
0xa91b23 proceed_resume_thread_checked
	gdb/infrun.c:3579
0xa92490 _Z7proceedm10gdb_signal
	gdb/infrun.c:3780
0xa72b9b _Z10continue_1i
	gdb/infcmd.c:639
0xa72e4b continue_command
	gdb/infcmd.c:730
0x6c01d1 do_simple_func
	gdb/cli/cli-decode.c:95
0x6c683a _Z8cmd_funcP16cmd_list_elementPKci
	gdb/cli/cli-decode.c:2827
0xff11a9 _Z15execute_commandPKci
	gdb/top.c:565
0x959e0a _Z15command_handlerPKc
	gdb/event-top.c:613
0x95a3e7 _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
	gdb/event-top.c:849
0x102b645 tui_command_line_handler
	gdb/tui/tui-interp.c:101
0x959548 gdb_rl_callback_handler
	gdb/event-top.c:288
0x1186dfd rl_callback_read_char
	readline/readline/callback.c:302
0x95925a gdb_rl_callback_read_char_wrapper_sjlj
	gdb/event-top.c:197
0x95934a gdb_rl_callback_read_char_wrapper_noexcept
	gdb/event-top.c:240
0x9593c9 gdb_rl_callback_read_char_wrapper
	gdb/event-top.c:252
0x1071253 stdin_event_handler
	gdb/ui.c:154
0x19a7c80 handle_file_event
	gdbsupport/event-loop.cc:551
0x19a825b gdb_wait_for_event
	gdbsupport/event-loop.cc:672
0x19a711c _Z16gdb_do_one_eventi
	gdbsupport/event-loop.cc:263
0x6ce4e3 _ZN6interp12do_one_eventEi
	gdb/interps.h:87
0xb74717 start_event_loop
	gdb/main.c:402
0xb748b6 captured_command_loop
	gdb/main.c:467
0xb7638f captured_main
	gdb/main.c:1345
0xb76438 _Z8gdb_mainP18captured_main_args
	gdb/main.c:1364
0x41a411 main
	gdb/gdb.c:38
...

This reproduces with gcc 7, not with gcc 8 or later.

Fix this by throwing an error instead of asserting, getting us instead:
...
(gdb) continue^M
Continuing.^M
^M
Breakpoint 2.2, A::func (this=$hex) at condbreak-multi-context.cc:31^M
31        void func () {}^M
(gdb) PASS: $exp: start_before=true: scenario_1: run until A::func
...

Tested on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

PR gdb/32012
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32012
2025-08-14 18:43:22 +02:00
Guinevere Larsen
a1be365e22 gdb: modernize get_frame_pc_if_available
The convenience function get_frame_pc_if_available would take a pointer
to a variable that should be set if available, and would return a
boolean indicating whether that action was successful or not.

Now that GDB supports C++17 features, this indirection of a pointer and
returning boolean is unnecessary, since the function can return an
optional, and code that calls it can check if the optional contains a
value.

This commit makes that modernization. It should have no visible
effects.

Approved-By: Tom Tromey <tom@tromey.com>
2025-08-14 13:40:19 -03:00
Tom de Vries
5ed142657c [gdb/testsuite] Remove useless indentation in lib/tuiterm.exp
In lib/tuiterm.exp we have:
...
namespace eval Term {
    variable ...
    ...
}
...
with everything within the namespace (which is basically the entire file)
indented, which wastes screen space and makes editing more involved.

We could maybe fix this by moving the "namespace eval Term" to tuiterm_env,
but I don't think it's a good idea to move it out of the file.

Another idea is to have the file include itself, wrapped in the namespace:
...
if { ![info exists Term::_in_namespace] } {
    namespace eval Term {
       # Read the rest of this file, wrapped in this namespace.
       variable _in_namespace
       set _in_namespace 1
       source $::srcdir/lib/tuiterm.exp
       unset _in_namespace
       return
    }
}

variable ...
...
but this was considered unnecessarily complex.

Fix this in the style of lib/ton.tcl and lib/completion-support.exp:
- only declare the variables in the namespace, and
- define the procs using a Term:: prefix.

As a side-effect, this works around an emacs bug that makes editing
lib/tuiterm.exp in its current form problematic because the auto-indentation
keeps removing required indentation of all but the first proc [1].

Tested on x86_64-linux.

[1] https://lists.gnu.org/archive/html/bug-gnu-emacs/2020-11/msg01674.html
2025-08-14 18:38:30 +02:00
Guinevere Larsen
809c1abc19 gdb, configure: Add enable-binary-file-format option for configure
GDB has support for many binary file formats, some which might be very
unlikely to be found in some situations (such as the XCOFF format in
an x86 system). This commit introduces the option for a user to choose
which formats GDB will support at build configuration time.

This is especially useful to avoid possible security concerns with
readers that aren't expected to be used at all, as they are one of
the simplest vectors for an attacker to try and hit GDB with.  This
change can also reduce the size of the final binary, if that is a
concern.

This commit adds a switch to the configure script allowing a user to
only enable selected file formats, called --enable-binary-file-formats.
The default behavior when the switch is omitted is to compile all file
formats, keeping the original behavior of the script. At the time of
this commit, the valid options for this option are: dbx, coff (which
includes coff-pe), xcoff, mips, elf, macho and all. All is treated
especially, activating all supported readers.

A few targets may require specific binary file format support, as they
directly call functions defined by the file reader. Specifically,
windows targets require coff support, and rs6000 aix and lynx178 targets
require xcoff support. Considering that those formats are the main - or
only - one available in those targets, I believe it makes sense to
re-enable those readers. If that happens, the script will emit the
following warning:

  FOO is required to support one or more requested targets. Adding it

Users aren't able to force the disabling of those formats, since GDB
will not compile without those readers. Ideally we'd like to be able
to disable even those formats, in case a user wants to build GDB only
to examine remote files for example, but the current infrastructure
for the file format readers doesn't allow us to do it.

Mach-O and elf support are also dependent on BFD support being compiled
in.  In case one of those was requested and BFD does not support them,
the following error is emitted:

    FOO was requested, but BFD does not support it.

Finally, this configure switch is also printed by the "show
configuration" command in GDB.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
2025-08-14 13:23:52 -03:00
Indu Bhagat
cfebee1869 bfd: sframe: fix PR ld/33199
Fix PR ld/33199 SEGV in _bfd_x86_elf_create_sframe_plt

Currently, the selection for sframe_plt was not being done (and simply
set to NULL) for the case when !normal_target, causing SEGV on Solaris.
Initialize sframe_plt to init_table->sframe_lazy_plt when lazy_plt is
true, and NULL otherwise.  This is in line with htab->non_lazy_plt being
set to NULL for !normal_target.

bfd/
	PR ld/33199
	* elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties):
	Setup sframe_plt for !normal_target.
2025-08-14 09:08:31 -07:00
Andrew Burgess
ea6ec00ff4 bfd: support for NT_386_TLS notes
In a later commit I'd like to add support to GDB for including the
NT_386_TLS note in the core files that GDB creates (using 'gcore'
command).

To achieve this we need some standard boilerplate code added to bfd.

The only part of this patch which I think needs consideration is the
name I selected for the pseudo section to hold the note contents when
a core file is loaded.  I chose '.reg-i386-tls'.  The '.reg' prefix is
the standard used by most other pseudo sections, and the '-i386-tls'
suffix seemed to match the note name, though I added the 'i' to
'i386', instead of just using '.reg-386-tls'.  I thought 'i386' seemed
clearer.

There's no test included here, but when I merge the NT_386_TLS
creation to GDB it will depend on this and act as a test.  I plan to
post that work to the GDB list once this patch is merged.
2025-08-14 16:06:47 +01:00
H.J. Lu
d048eee291 ld: Use stat to check if linker script appears multiple times
Use stat, instead of strcmp, to check if the same linker script file
appears multiple times for

$ ld -L... -T ././/script.t -T script.t ...

Although ././/script.t and script.t access the same file, but their
filenames are different.  strcmp won't work here.

Copy gnulib/import/same-inode.h to include since the gnulib directory
isn't included in the binutils tarball.

include/

	PR ld/24576
	* same-inode.h: New file.  Copied from gnulib/import/same-inode.h.

ld/

	PR ld/24576
	* ldfile.c: Include "same-inode.h".
	(ldfile_find_command_file): Change the second argument from bool
	to enum script_open_style.  Check if the same linker script file
	appears multiple times by using stat, instead using strcmp.
	(ldfile_open_command_file_1): Don't check if the same linker
	script file appears multiple times here.
	* testsuite/ld-scripts/pr24576-1.d: Adjusted.
	* testsuite/ld-scripts/pr24576-2.d: New.
	* testsuite/ld-scripts/script.exp: Run pr24576-2.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-14 08:00:04 -07:00
Tom de Vries
546ddc53ee [gdb/testsuite] Disable CLI styling by default in Term::prepare_tui
On x86_64-freebsd, with test-case gdb.tui/main.exp, I ran into a failure to
match the output of the file command, for which I submitted a patch [1].

However, after switching to TERM=ansiw for bsd, I could no longer reproduce
the problem.

Investigation showed that the difference was caused by CLI styling.

A command:
...
(gdb) file <filename>
...
gives an output:
...
Reading symbols from <filename>...
(gdb)
...

On x86_64-linux, with CLI styling I get:
...
Reading symbols from ^[[32m/data/vries/gdb/leap-15-6/build/gdb/testsuite/outputs/gdb.tui/main/main^[[39m^[[0;10m...
...

After disabling CLI styling using "set style enabled off", I simply get:
...
Reading symbols from /data/vries/gdb/leap-15-6/build/gdb/testsuite/outputs/gdb.tui/main/main...
...
and run into the same failure as on x86_64-freebsd.

The extra csi sequence "^[[32m" causes an additional matching attempt in
Term::wait_for, and the way we're currently matching relies on this:
...
send_gdb "file [standard_output_file $testfile]\n"
gdb_assert { [Term::wait_for "Reading symbols from"] } "file command"
...

Make the TUI testsuite more stable and matching more simple by disabling CLI
styling by default, and:
- fix the resulting fallout in test-cases gdb.tui/main.exp and
  gdb.tui/new-layout.exp, and
- re-enable CLI styling in the one test-case that needs it:
  gdb.tui/tui-disasm-styling.exp.

Tested on x86_64-linux.

[1] https://sourceware.org/pipermail/gdb-patches/2025-June/218942.html
2025-08-14 15:49:20 +02:00
Alan Modra
b3f31f8eea Recognise ECOFF armap in bfd_slurp_armap
Recognise ECOFF archives and reject them so that the ecoff archive
support has a chance to handle the archive.  Also use memcmp rather
than startswith (strncmp) as we know the string length.

	* archive.c (bfd_slurp_armap): Recognize ECOFF armap.  Use memcmp
	to match names, and tidy buffer sizes.
2025-08-14 23:06:39 +09:30
Alan Modra
9adb8ba865 objcopy/strip of IR files and is_strip_input
This tidies objcopy/strip handling of IR objects, in the process of
removing the unnecessary is_strip_input flag.

The first thing I noticed when looking at is_strip_input code was that
the abfd->my_archive test in bfd_check_format_matches meant that
plugins were disabled when reading archive elements.  We can instead
disable plugins by setting bfd_no_plugin, so there doesn't seem to be
a need for is_strip_input in objcopy.c:copy_archive.  This isn't
exactly the same, because bfd_no_plugin prevents the plugin target
recognising archive elements in the bfd_check_format_matches loop over
all targets as well as just the first !target_defaulted test.  But
that turns out to be fine.  IR code is handled in copy_archive as for
other unknown format files.  In fact, the only need for the plugin
target when copying archives is when reading symbols for the archive
map.  I've made that plain by moving the plugin target override and
commenting on why it is really needed.

So on to plain object files.  Here, IR code is also copied unchanged,
so there doesn't seem a need for the plugin target there either.  It
isn't quite so simple though, because the objcopy/strip code handling
object files wants to verify the format of the object file.  Allowing
objcopy/strip to copy unknown format files would be a change in
behaviour (and results in mmix testsuite fails, ld-mmix/b-badfil1 and
others).  However, always excluding the plugin target results in a
fail of tests added in commit c2729c37f1.  So I've enabled a plugin
format check only for files that are otherwise unrecognised, and
commented why this is done.  I question the need to objcopy LLVM
bytecode files.

bfd/
	* bfd.c (struct bfd<is_strip_input>): Delete.
	* format.c (bfd_check_format_matches): Delete is_strip_input
	special case code.
	* bfd-in2.h: Regenerate.
binutils/
	* objcopy.c (copy_archive): Don't set is_strip_input.  Always
	set bfd_plugin_no when reading elements.  Enable plugins when
	opening copied elements.
	(check_format_object): Delete.
	(copy_file): Don't enable plugin target here.  Don't set
	is_strip_input.  Set bfd_plugin_no.  Move bfd_core handling
	code earlier to remove goto.  Enable plugin for llvm bytecode.
	Copy slim IR files as unknown objects.
2025-08-14 22:53:46 +09:30
Alan Modra
58abb43bc5 Correct readelf thin archive test
If we have an existing archive, the test may fail due to it being the
wrong format.  Also, downloading bintest.thin.a from a remote host
(before creating it!) is wrong.

	* testsuite/binutils-all/readelf.exp (readelf_thin_archive_test):
	Don't remote_download bintest.thin.a.  Delete lib before
	creating.
2025-08-14 22:53:46 +09:30
Tom de Vries
588f68cd3e [gdb/testsuite] Make prompt matching in Term::wait_for more strict
On x86_64-freebsd, I run into:
...
Box Dump (80 x 24) @ (0, 0):
    0 (gdb) maint info screen
    1 Number of characters gdb thinks are in a line is 90.
    2 Number of characters readline reports are in a line is 89.
    3 Number of characters curses thinks are in a line is 90.
    4 Number of characters environment thinks are in a line is 90 (COLUMNS).
    5 Number of lines gdb thinks are in a page is 40.
    6 Number of lines readline reports are in a page is 40.
    7 Number of lines curses thinks are in a page is 40.
    8 Number of lines environment thinks are in a page is 40 (LINES).
    9 Readline wrapping mode: readline (terminal is not auto wrap capable, last column
   10 .
   11 (gdb) tui disable
   12 (gdb) tui disable
   13 (gdb) maint info screen
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
FAIL: gdb.tui/resize-2.exp: again: curses width 80
...

The problem is that the prompt matching in Term::wait for is not strict enough.

It will accept a line:
...
(gdb) foo
...
as long as the cursor is pointing just after the prompt, like so:
...
(gdb) foo
      ^
...

Fix this by also checking that the line is empty.

Tested on x86_64-linux.
2025-08-14 15:18:34 +02:00
Tom de Vries
76060b138d [gdb/testsuite] Stop on main in gdb.gdb/{python-helper,selftest}.exp
With a gdb build with gcc 15.1.1 and "-O2 -flto=auto -g", I run into:
...
UNTESTED: gdb.gdb/selftest.exp: \
  Cannot set breakpoint at captured_main, skipping testcase.
UNTESTED: gdb.gdb/python-helper.exp: \
  Cannot set breakpoint at captured_main, skipping testcase.
...

I don't know why we're trying to stop in captured_main.

Stopping in main also works, and main is more likely to be present in an lto
build.

Fix this by using main instead.

This requires us to update the expected file name from main.c to gdb.c in
selftest_setup.

After doing so, we get:
...
XFAIL: gdb.gdb/selftest.exp: \
  run until breakpoint at main (line numbers scrambled?)
XFAIL: gdb.gdb/python-helper.exp: \
run until breakpoint at main (line numbers scrambled?)
...
because main is reported to be in run-on-main-thread.c instead of gdb.c:
.
Breakpoint 1, main (...) at gdb/run-on-main-thread.c:120^M
...

This is due to picking the last line entry for pc == 0x455e40 that has
is_stmt == true:
...
File name                      Line number    Starting address    View    Stmt

gdb/gdb.c:
gdb.c                                   25            0x455e40               x
gdb.c                                   30            0x455e40       1       x

gdb/run-on-main-thread.c:
run-on-main-thread.c                   116            0x455e40       2       x
run-on-main-thread.c                   120            0x455e40       3       x

gdb/gdb.c:
gdb.c                                   25            0x455e40       4

/usr/include/c++/15/bits/std_thread.h:
std_thread.h                           366            0x455e4b
...

While we're at it, update the corresponding gdb_test_multiple in
selftest_setup using multi_line and -wrap.

Tested on x86_64-linux.
2025-08-14 14:53:19 +02:00
Tom de Vries
73432d71de [gdb/testsuite] Make ^C cancel i-search
PR cli/21690 reports the following: say we start gdb:
...
$ gdb -q
(gdb)
...
and press ^R for reverse-i-search:
...
(reverse-i-search)`':
...

Pressing the p key has the effect of showing both the pressed key and a
matching entry, which happens to be up:
...
(reverse-i-search)`p': up
...

Now we press ^C to cancel the search:
...
(reverse-i-search)`p': u️ Quit
(gdb)
...
and type "down".

We expected to get:
...
(gdb) down
...
but instead we get:
...
(failed reverse-i-search)`pdown':
...

So we're stuck in reverse-i-search, until we use the workaround of ^G.

The same problem happened with python [1], was reported upstream [2], and
fixed in cpython commit d6990d221b0 ("Issue #24266: Cancel history search mode
with Ctrl+C in Readline 7") using rl_callback_sigcleanup.

Fix this likewise in quit using rl_callback_sigcleanup, a new callback
function in readline 7.0:
...
i.  rl_callback_sigcleanup: a new application function that can clean up and
    unset any state set by readline's callback mode.  Intended to be used
    after a signal.
...
giving us instead:
...
$ gdb
(gdb) u️ Quit
(gdb) down
...

Remove the corresponding kfail in gdb.tui/pr30056.exp.

Tested on x86_64-linux.

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

[1] https://bugs.python.org/issue24266
[2] https://lists.gnu.org/archive/html/bug-readline/2015-05/msg00014.html
2025-08-14 13:54:54 +02:00
Nelson Chu
28520d7eed RISC-V: PR33216, Allow c.slli, c.srai, c.srli with 0 immediate as a hint
The original patch,
e6f372ba66

Since recently c.slli64, c.srai64, and c.srli64 have been removed from the
riscv-isa-manual, c.slli, c.srli, and c.srai with 0 immediate are now listed
as hints,
https://github.com/riscv/riscv-isa-manual/pull/1942 and https://github.com/riscv/riscv-isa-manual/pull/2093

So allow c.slli, c.srli, and c.srai with 0 immediate as a hint.  Also allow to
assemble slli, srli and srai with 0 immediate to hint c.slli, c.srli and c.srai
when rvc is enabled.  The c.slli64, c.srai64, and c.srli64 should be kept as
aliases, so dis-assembler should disassemble to c.slli, c.srli, and c.srai with
0 immediate.

Passed rv32/64-elf/linux binutils testcases.

gas/
	PR 33216
	* testsuite/gas/riscv/c-zero-imm.d: Updated since allow c.slli64,
	c.srai64, and c.srli64 with 0 immediate as a hint.
	* testsuite/gas/riscv/c-zero-imm.s: Likewise.
	* testsuite/gas/riscv/zca.d: Likewise.
opcodes/
	PR 33216
	* riscv-opc.c (riscv_opcodes): Updated since allow c.slli64, c.srai64,
	and c.srli64 with 0 immediate as a hint.
2025-08-14 12:10:49 +08:00
GDB Administrator
ad9f79ec39 Automatic date update in version.in 2025-08-14 00:00:44 +00:00
Tom Tromey
421c4a00d9 Refine range check in create_addrmap_from_gdb_index
PR symtab/33247 points out that this check in
create_addrmap_from_gdb_index:

      if (lo > hi)
	{
	  complaint (_(".gdb_index address table has invalid range (%s - %s)"),
		     hex_string (lo), hex_string (hi));

... should probably use ">=" instead.  Reading a bit further the
reason seems obvious:

      mutable_map.set_empty (lo, hi - 1, index->units[cu_index]);

Here if lo==hi, then this will insert a "reversed" range into the
addrmap.

Apparently some LLVM tool can erroneously create a .gdb_index like
this.

No test because it seems like more trouble to write than it's worth.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33247
Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-08-13 14:36:04 -06:00
Tom Tromey
73dcc5e15b Remove cast from captured_main
captured_main takes a 'void *', but then immediately casts it to the
correct type.  There's no reason for this any more, the caller passes
in the correct type.  This patch cleans this up.  Tested by
rebuilding.
2025-08-13 12:08:59 -06:00
Pietro Monteiro
02d9fa7cc2 gnulib: Update obsolete autoconf macros
Remove AM_PROG_CC_STDC, the correct macro AC_PROG_CC is already being
used.

Update AC_OUTPUT (file list, [cmd list]) by adding the file list to
the previous AC_CONFIG_FILES and using AC_CONFIG_COMMANDS to output
the command list.

Approved-By: Tom Tromey <tom@tromey.com>
2025-08-12 21:12:50 -04:00
GDB Administrator
437d1e5e8f Automatic date update in version.in 2025-08-13 00:00:27 +00:00
Tom de Vries
96d90166e8 [gdb/tui] Make tui_disassemble more efficient
Function tui_disassemble (with addr_size parameter) has two modes of
operation:
- addr_size != nullptr, and
- addr_size == nullptr.

I noticed that for the addr_size == nullptr case, more than necessary is done.

Fix this by using continue and null_stream.

While we're at it, eliminate the unnecessary variables new_size and orig_pc.

Tested on x86_64-linux.

Approved-By: Andrew Burgess <aburgess@redhat.com>
2025-08-12 18:47:01 +02:00
Tom de Vries
6f9909c417 [gdb/tdep] Handle M1 ldp in aarch64_stopped_data_address
In test-case gdb.base/watchpoint-unaligned.exp, in function write_size8twice,
two adjacent 8-byte vars are written.  For aarch64, we use a single stp
instruction for that.

If we do the same in function read_size8twice for two adjacent 8-byte var reads
using aarch64 insn ldp, on an aarch64-linux M1 system we get a hang:
...
(gdb) continue^M
Continuing.^M
FAIL: $exp: fun=read_size8twice: offset=0: index=1: continue (timeout)
FAIL: $exp: fun=read_size8twice: offset=0: index=1: $got_hit
...

The same problem was observed for stp in PR tdep/29423, fixed by commit
9a03f21853 ("[gdb/tdep] Fix gdb.base/watchpoint-unaligned.exp on aarch64").

See that commit for an explanation of the hang.

That commit introduced max_access_size in aarch64_stopped_data_address:
...
	   The access size also can be larger than that of the watchpoint
	   itself.  For instance, the access size of an stp instruction is 16.
	   So, if we use stp to store to address p, and set a watchpoint on
	   address p + 8, the reported ADDR_TRAP can be p + 8 (observed on
	   RK3399 SOC). But it also can be p (observed on M1 SOC).  Checking
	   for this situation introduces the possibility of false positives,
	   so we only do this for hw_write watchpoints.  */
	const CORE_ADDR max_access_size = type == hw_write ? 16 : 8;
...

If we say that hangs are worse than false positives, then we should also fix
this case.

Fix this by setting max_access_size to 16 for all watchpoint types.

Tested on aarch64-linux, both on an M1 SOC and an RK3399 SOC.

Approved-By: Luis Machado <luis.machado.foss@gmail.com>
2025-08-12 16:35:05 +02:00
Tom de Vries
3769fe5ed3 [gdb/testsuite] Extend gdb.base/watchpoint-unaligned.exp
Extend the part of gdb.base/watchpoint-unaligned.exp handling
write_size8twice to also check read hardware watchpoints.

Tested on x86_64-linux.

Approved-By: Luis Machado <luis.machado.foss@gmail.com>
2025-08-12 16:35:05 +02:00
Tom de Vries
d737aae03b [gdb/testsuite] Improve gdb.base/watchpoint-unaligned.exp
Improve the part of gdb.base/watchpoint-unaligned.exp handling
write_size8twice:
- move the code into a proc
- use -wrap
- use $decimal more often
- don't use gdb_test_multiple $test $test
- add comments
- start test when entering write_size8twice function, instead of main
- finish test when leaving write_size8twice function, instead of main
- add insn in between:
  - insn triggering watchpoint, and
  - insn triggering breakpoint
  to ensure that the watchpoint triggers before the breakpoint, and
  add a comment explaining this.

Tested on x86_64-linux.
2025-08-12 16:35:05 +02:00
Tom Tromey
89495c3326 Change type::fields to return an array_view
This patch changes type::fields to return an array_view of the fields,
then fixes up the fallout.

More cleanups would be possible here (in particular in the field
initialization code) but I haven't done so.

The main motivation for this patch was to make it simpler to iterate
over the fields of a type.

Regression tested on x86-64 Fedora 41.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
2025-08-12 08:30:37 -06:00
H.J. Lu
55c91b7e5c x86: Always treat protected symbols as local
Since linker never generates dynamic relocation for protected symbol in:

__attribute__((visibility("protected"))) int my_data;

int *
func (void)
{
  return &my_data;
}

we should always treat protected symbols as local.

bfd/

	PR ld/33260
	* elfxx-x86.h (COPY_INPUT_RELOC_P): Always treat protected symbols
	as local.

ld/

	PR ld/33260
	* testsuite/ld-i386/i386-export-class.rd: Updated.
	* testsuite/ld-i386/i386-export-class.xd: Likewise.
	* testsuite/ld-i386/i386.exp: Run pr33260-2.
	* testsuite/ld-i386/pr33260-2.d: New file.
	* testsuite/ld-i386/pr33260-2.s: Likewise.
	* testsuite/ld-i386/pr33260.d: Remove "-z indirect-extern-access".
	* testsuite/ld-x86-64/pr33260-x32.d: Likewise.
	* testsuite/ld-x86-64/pr33260.d: Likewise.
	* testsuite/ld-x86-64/pr33260-2-x32.d: New file.
	* testsuite/ld-x86-64/pr33260-2.d: Likewise.
	* testsuite/ld-x86-64/pr33260-2.s: Likewise.
	* testsuite/ld-x86-64/x86-64-64-export-class.rd: Updated.
	* testsuite/ld-x86-64/x86-64-x32-export-class.rd: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr33260-2 and
	pr33260-2-x32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-12 06:34:40 -07:00
Tom Tromey
2bbe3bb5d9 Avoid scopes.exp failure on certain architectures
A buildbot pointed out that my changes to gdb.dap/scopes.exp caused a
test failure.  The new code iterates over all the registers, fetching
their children (when possible).  The failure comes because this code
failed to consider that a register might have "indexed" children,
which I believe can occur when a register is vector-like.

This patch fixes the problem by arranging to fetch indexed children
when indicated.
2025-08-12 07:18:42 -06:00
GDB Administrator
bbb7a2e2c5 Automatic date update in version.in 2025-08-12 00:00:14 +00:00
H.J. Lu
d02a868372 i386: Add Linux/x86-64 support to export-class.exp
Add Linux/x86-64 support to export-class.exp by passing --32 to assembler
and passing  -melf_i386 to linker.

	* testsuite/ld-i386/export-class.exp: Run for Linux/x86-64.
	Pass --32 to assembler.  Pass -melf_i386 to linker.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-11 12:34:20 -07:00
H.J. Lu
cbb91fe382 ld: Add a test for PR ld/24576
PR ld/24576
	* testsuite/ld-scripts/pr24576-1.d: New.
	* testsuite/ld-scripts/script.exp: Run pr24576-1.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-11 08:25:01 -07:00
Tom Tromey
9ef3249a00 Emit DAPException when too many variable children are reqeusted
PR dap/33228 points out a failure that occurs when the DAP client
requests more children of a variable than actually exist.  Currently,
gdb throws a somewhat confusing exception.  This patch changes this
code to throw a DAPException instead, resulting in a more ordinary and
readable failure.

The spec seems to be silent on what to do in this case.  I chose an
exception on the theory that it's easier to be strict now and lift the
restriction later (if needed) than vice versa.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33228
2025-08-11 07:39:10 -06:00
Tom Tromey
ddd2795c52 Do not allow DAP clients to dereference "void *"
While investigating a different bug, I noticed that the DAP code would
report a "void *"-typed register as having children -- however,
requesting the children of this register would fail.

The issue here is that a plain "void *" can't be dereferenced.  This
patch changes the default visualizer to treat a "void *" as a scalar.

This adds a new test; but also arranges to examine all the returned
registers -- this was the first thing I attempted and it seemed
reasonable to have a test that double-checks that all the registers
really can be dereferenced as appropriate.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33228
2025-08-11 07:39:10 -06:00
GDB Administrator
3c64cee815 Automatic date update in version.in 2025-08-11 00:00:22 +00:00
GDB Administrator
ab9cd086d8 Automatic date update in version.in 2025-08-10 00:00:09 +00:00
H.J. Lu
ff3b64d944 x86: Treat protected symbols with indirect external access as local
If all external symbol accesses are indirect, we can treat protected
symbols as local since there will be no copy relocation for data and
external function pointer access will go through GOT, instead of PLT.
No PLT slot should be used for external function pointer in executable.

bfd/

	PR ld/33260
	* elfxx-x86.h (COPY_INPUT_RELOC_P): Treat protected symbols with
	indirect external access as local.

ld/

	PR ld/33260
	* testsuite/ld-i386/i386.exp: Run PR ld/33260 test.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.
	* testsuite/ld-i386/pr33260.d: New file.
	* testsuite/ld-i386/pr33260.s: Likewise.
	* testsuite/ld-x86-64/pr33260-x32.d: Likewise.
	* testsuite/ld-x86-64/pr33260.d: Likewise.
	* testsuite/ld-x86-64/pr33260.s: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-09 08:56:43 -07:00
GDB Administrator
a65d0a4325 Automatic date update in version.in 2025-08-09 00:00:07 +00:00
Sam James
fb04a67e6f binutils: add ia64 marker in name of testranges-ia64
Otherwise, the same test appears twice, once with PASS, once with UNSUPPORTED
on non-ia64. Just add '(ia64)' to the name so binutils.log is clearer.

	* testsuite/binutils-all/testranges-ia64.d (#name): Add suffix.
2025-08-08 23:17:32 +01:00
H.J. Lu
f5b1b0288a run_lto_binutils_test: Pass $plug_opt to nm
Pass $plug_opt to nm when setting dump_prog to nm to load plugin.

	PR binutils/21479
	* testsuite/ld-plugin/lto-binutils.exp (run_lto_binutils_test):
	Pass $plug_opt to nm.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-08 12:06:12 -07:00
Keith Seitz
be10a32638 should_validate_memtags: Do not dereference references
should_validate_memtags uses value_as_address to evalute
whether an address for a value is tagged. The comments for
that function simply say, "Extract a value as a C pointer."

While that sounds innoncuous, that function calls coerce_array,
which will dereference any references.  This is not what is
desired here.

This can be demonstrated on an MTE-enabled host, such as aarch64-
based Ampere (example taken from tests introduced in this patch):

(gdb) p b.get_foo ()
Could not validate memory tag: Value can't be converted to integer.
$2 = (const foo &) @0xffffffffed88: {m_a = 42}

While the command completes, gdb didn't actually attempt to
evaluate any memory tags.

Fix this by using unpack_pointer instead.

Tested on x86_64 Fedora 40 and aarch64 RHEL 9.6.
2025-08-08 11:01:54 -07:00
Tom de Vries
a99fc443dc [gdb/testsuite] Fix gdb.tui/basic.exp for TERM=ansis
With test-case gdb.tui/basic.exp and TERM=ansis, I run into (with some logging
added):
...
status line: '<reverse:1><intensity:dim>exec No process (asm) In:
             L??   PC: ?? <reverse:0><intensity:normal>'
FAIL: gdb.tui/basic.exp: status window: reverse
...

The status window uses ncurses attribute standout, which can differ between
different terminal settings.

Fix this by making the matching less strict.

Tested on x86_64-linux.
2025-08-08 13:51:00 +02:00
Tom de Vries
3aeec96467 [gdb/testsuite] Fix gdb.tui/main-2.exp for TERM=ansis
When running test-case gdb.tui/main-2.exp with TERM=ansis, I get:
...
screen line 6: 'B+><fg:black><intensity:bold>    21 <reverse:1><fg:default><intensity:normal>  return 0;<reverse:0>                                                         '
FAIL: gdb.tui/main-2.exp: highlighted line in middle of source window
...

The test tries to check the highlighting of the source line, but also gets the
part with the line number, which makes it more complicated to parse.

Fix this by getting just the part with the source line:
...
screen line 6: '<reverse:1>  return 0;<reverse:0>                                     \
                    '
...

Tested on x86_64-linux.
2025-08-08 13:51:00 +02:00
Tom de Vries
fee476d2fc [gdb/testsuite] Initial TERM=ansis support in tuiterm
While investigating using TERM=ansiw for freebsd, I also came across
TERM=ansis which unlike ansiw is present on both linux and freebsd.

Add initial support for TERM=ansi in tuiterm:
- handle ansis in Term::_have_bw
- add Term::_csi_x to support (well, ignore) DECREQTPARM
  (Request Terminal Parameters)

This is sufficient to make the TUI testsuite pass on x86_64-freebsd.
2025-08-08 13:51:00 +02:00
Tom de Vries
81bf57ecb8 [gdb/testsuite] Fix gdb.tui/tui-layout-asm-short-prog.S compilation
The test-case gdb.tui/tui-layout-asm-short-prog.exp uses an assembly file
gdb.tui/tui-layout-asm-short-prog.S that it compiles using -nostdlib and
-nostartfiles.

However, on x86_64-linux the resulting executable still has dependencies on
libm and libc:
...
$ ldd outputs/gdb.tui/tui-layout-asm-short-prog/tui-layout-asm-short-prog
	linux-vdso.so.1 (0x00007ffddf3ec000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f8b13406000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f8b13000000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f8b1350f000)
...
due -lm being added by default_target_compile.

On x86_64-freebsd, using -nostdlib and -nostartfiles in combination with -lm
causes the compilation to fail.

Fix this by using -static as well.

Tested on x86_64-linux and x86_64-freebsd.
2025-08-08 13:23:51 +02:00
Tom de Vries
2e0582e017 [gdb/testsuite] Fix gdb.base/exprs.exp for gdb build with byacc
On x86_64-freebsd, with test-case gdb.base/exprs.exp I get:
...
(gdb) print 23
yydebug: state 0, reading 257 (INT)
yydebug: state 0, shifting to state 1
yydebug: state 1, reducing by rule 94 (exp : INT)
yydebug: after reduction, shifting from state 0 to state 59
yydebug: state 59, reading 0 (end-of-file)
yydebug: state 59, reducing by rule 7 (exp1 : exp)
yydebug: after reduction, shifting from state 0 to state 60
yydebug: state 60, reducing by rule 1 (start : exp1)
yydebug: after reduction, shifting from state 0 to state 58
$220 = 23
(gdb) FAIL: gdb.base/exprs.exp: print with debugging
...

The test fails because it's not finding the string "Starting parse".

In this case, the .y files are processed used byacc.  I suppose the testcase
matches the case that bison is used.

Fix this by grepping for something more generic: shift or Shift.

Tested on x86_64-linux and x86_64-freebsd.
2025-08-08 12:57:01 +02:00
Jan Beulich
49e51dd7a2 bfd/ELF/Arm: make various arrays static / const
There's no reason to have the compiler materialize objects onto the
stack. And there's also no reason to allow comb[] and name_table[] to be
modifiable.
2025-08-08 11:45:03 +02:00
Jan Beulich
608c6df447 bfd/ELF/RISC-V: make one local array static and several const
There's no reason for riscv_all_supported_ext[] to appear in libbfd.so's
dynamic symbol table. There's also no reason for various pieces of data
to live in .data, when .data.rel.ro or even .rodata can do.
2025-08-08 11:44:39 +02:00
Jan Beulich
1e118fe363 bfd/ELF: make three local arrays static
... and const. There's no reason to have the compiler copy anonymous
objects onto the stack. And there's also no reason to allow the arrays
to be modifiable.
2025-08-08 11:44:12 +02:00
Jan Beulich
d582b4eb1b Arm: parse_neon_type() weaknesses
The custom parsing done there and in one of its callers allowed various
bogus constructs to be accepted. Insist on a non-zero leading digit when
parsing numbers, don't lose upper bits, and insist on proper separation
of operands.
2025-08-08 11:43:02 +02:00
Jan Beulich
7ec7556f86 opcodes/aarch64: shrink aarch64_ext_ldst_reglist()'s data[]
The values are all pretty small; one is even a boolean. No point in
wasting 32 bits for every one of the fields.
2025-08-08 11:42:32 +02:00