binutils-gdb.git
17 months agoAutomatic date update in version.in
GDB Administrator [Fri, 2 Jun 2023 00:01:12 +0000 (00:01 +0000)]
Automatic date update in version.in

17 months agolibsframe: avoid using magic number
Indu Bhagat [Thu, 1 Jun 2023 16:41:04 +0000 (09:41 -0700)]
libsframe: avoid using magic number

Define a new constant for the maximum number of stack offsets handled in
libsframe, and use it.  Note that the SFrame format does not define such
a constant (limit).  This is an implmentation-defined constant in
libsframe.

include/
* sframe-api.h (MAX_NUM_STACK_OFFSETS): New definition.
libsframe/
* sframe.c (sframe_fre_sanity_check_p): Use it.

17 months agolibsframe: minor fixups in flip_fre related functions
Indu Bhagat [Thu, 1 Jun 2023 05:55:41 +0000 (22:55 -0700)]
libsframe: minor fixups in flip_fre related functions

libsframe/
* sframe.c (flip_fre_start_address): Remove unnecessary type
cast.  Use uint16_t instead of unsigned short.
(flip_fre_stack_offsets): Likewise.

17 months agoRISC-V: PR30449, Add lga assembler macro support.
Jim Wilson [Thu, 1 Jun 2023 04:10:16 +0000 (12:10 +0800)]
RISC-V: PR30449, Add lga assembler macro support.

Originally discussion, https://github.com/riscv/riscv-isa-manual/pull/539

Added new load address pseudo instruction which is always expanded to GOT
access, no matter the .option rvc is set or not.

gas/
PR 30449
* config/tc-riscv.c (macro): Add M_LGA support.
* testsuite/gas/riscv/la-variants.d: New.
* testsuite/gas/riscv/la-variants.s: New.
include/
PR 30449
* opcode/riscv.h (M_LGA): New.
opcodes/
PR 30449
* riscv-opc.c (riscv_opcodes): Add lga support.

17 months ago[PR ld/22263][PR ld/24676] RISC-V: Avoid spurious R_RISCV_NONE for TLS GD/IE.
Nelson Chu [Fri, 26 May 2023 10:05:34 +0000 (18:05 +0800)]
[PR ld/22263][PR ld/24676] RISC-V: Avoid spurious R_RISCV_NONE for TLS GD/IE.

For TLS GD/IE, add the same condition with the relocate_section in the
allocate_dynrelocs, to make sure we won't reserve redundant spaces
for dynamic relocations since the conservative estimatation.

After applying this patch, ld seems no longer generate the spurious
R_RISCV_NONE for pr22263-1 test, and the test in pr24676.

bfd/
PR ld/22263
PR ld/24676
* elfnn-riscv.c (RISCV_TLS_GD_IE_NEED_DYN_RELOC): New defined.
Set NEED_RELOC to true if TLS GD/IE needs dynamic relocations,
and INDX will be the dynamic index.
(allocate_dynrelocs): Don't reserve extra spaces in the rela.got
if RISCV_TLS_GD_IE_NEED_DYN_RELOC set need_reloc to false.  This
condition needs to be same as relocate_section.
(relocate_section): Likewise, use the same condition as
allocate_dynrelocs.

17 months agoHarden PowerPC64 OPD handling against fuzzers
Alan Modra [Wed, 31 May 2023 05:41:34 +0000 (15:11 +0930)]
Harden PowerPC64 OPD handling against fuzzers

PowerPC64 ELFv1 object files should have at most one .opd section, and
OPD handling in elf64-ppc.c makes use of this fact by caching some
.opd section info in the per-object bfd.tdata.  This was done to avoid
another word in the target specific section data.  Of course, fuzzers
don't respect the ABI, and even non-malicious users can accidentally
create multiple .opd sections.  So it is better to avoid possible
buffer overflows and other confusion when OPD handling for a second
.opd section references data for the first .opd section, by keeping
the data per-section.

The patch also fixes a memory leak, and a corner case where I think we
could hit an assertion in opd_entry_value or read out of bounds in
ppc64_elf_branch_reloc doing a final link producing non-ppc64 output.
(It's a really rare corner case because not only would you need to be
linking ppc64 objects to non-ppc64 output, you'd also need a branch
reloc symbol to be defined in a .opd section of a non-ppc64 input.)

* elf64-ppc.c (is_ppc64_elf): Move earlier in file.
(ppc64_elf_branch_reloc): Check symbol bfd before accessing
ppc64 elf specific data structures.
(struct ppc64_elf_obj_tdata): Move opd union..
(struct _ppc64_elf_section_data): ..to here.
(ppc64_elf_before_check_relocs): Allow for opd sec_type
already set to sec_opd.
(ppc64_elf_check_relocs): Only set sec_type to sec_toc when
unset.  Error for unexpected toc relocs.
(opd_entry_value): Return -1 when non-ppc64 rather than
asserting.  Check and set sec_type too.  Adjust for changed
location of contents and relocs.
(ppc64_elf_relocate_section): Adjust for changed location of
cached .opd relocs.
(ppc64_elf_free_cached_info): New function.
(bfd_elf64_bfd_free_cached_info): Define.

17 months agobfd_close and target free_cached_memory
Alan Modra [Wed, 31 May 2023 11:47:48 +0000 (21:17 +0930)]
bfd_close and target free_cached_memory

bfd_free_cached_info is used in just one place in archive.c, which
means most times we reach bfd_close the function isn't called.  On the
other hand, if bfd_free_cached_info is called we can't do much on the
bfd since it loses all its obj_alloc memory.  This restricts what can
be done in a target _close_and_cleanup.  In particular you can't look
at sections, which leads to duplication of code in target
close_and_cleanup and free_cached_info, eg. elfnn-aarch64.c.

* opncls.c (_bfd_delete_bfd): Call bfd_free_cached_info.
* elfnn-aarch64.c (elfNN_aarch64_close_and_cleanup): Delete.
(bfd_elfNN_close_and_cleanup): Don't define.
* som.c (som_bfd_free_cached_info): Don't call
_bfd_generic_close_and_cleanup here.
(som_close_and_cleanup): Define as _bfd_generic_close_and_cleanup.

17 months agosection_by_target_index memory leak
Alan Modra [Tue, 30 May 2023 10:35:38 +0000 (20:05 +0930)]
section_by_target_index memory leak

The rs6000 backend can call coff_section_from_bfd_index from its
object_p function via coff_set_alignment_hook.  If the object doesn't
match, or another target matches too, then the hash table needs to be
freed via a cleanup.

* coffgen.c (coff_object_cleanup): New function.
(coff_real_object_p): Return coff_object_cleanup, and call on
failure path.  Move declaration to..
* libcoff-in.h: ..here.
(coff_object_cleanup): Declare.
* coff-stgo32.c (go32exe_cleanup): Call coff_object_cleanup.
(go32exe_check_format): Adjust assertion.
* libcoff.h: Regenerate.

17 months agoRemove BFD_FAIL in cpu-sh.c
Alan Modra [Tue, 30 May 2023 10:16:24 +0000 (19:46 +0930)]
Remove BFD_FAIL in cpu-sh.c

The assertions in cpu-sh.c can be triggered by passing bogus values
in disassemble_info.mach.  This doesn't cause any bfd misbehaviour.

* cpu-sh.c (sh_get_arch_from_bfd_mach): Remove BFD_FAIL.
(sh_get_arch_up_from_bfd_mach): Likewise.

17 months agoAutomatic date update in version.in
GDB Administrator [Thu, 1 Jun 2023 00:00:39 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months agogprofng: Fix -Wsign-compare warning
Vladimir Mezentsev [Fri, 26 May 2023 02:06:52 +0000 (19:06 -0700)]
gprofng: Fix -Wsign-compare warning

gprofng/ChangeLog
2023-05-25  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR gprofng/30490
* src/LoadObject.cc: Fix -Wsign-compare warning.

17 months agogprofng: 29470 The test suite should be made more flexible
Vladimir Mezentsev [Fri, 26 May 2023 00:54:53 +0000 (17:54 -0700)]
gprofng: 29470 The test suite should be made more flexible

I add two new targets (check-extra, check-install) for gprofng testing:
  `make check` runs sanity testing for gprofng and takes ~30 secunds.
  `make check-extra` runs all gprofng tests and takes ~20 minutus.
  `make check-install` runs all gprofng tests and uses gprofng installation.

On aarch64, there are unwind problems in libgp-collector.so.
I set ACCT_FILTER to temporarily ignore problematic functions.

gprofng/ChangeLog
2023-05-25  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR gprofng/29470
* Makefile.am: Add check-extra, check-install.
* Makefile.in: Rebuild
* testsuite/config/default.exp: Set the GPROFNG variable.
* testsuite/gprofng.display/display.exp: Updated the test list.
* testsuite/gprofng.display/jsynprog/Intface.java: Correct copyright.
* testsuite/gprofng.display/jsynprog/Launcher.java: Likewise.
* testsuite/gprofng.display/jsynprog/Makefile: Likewise.
* testsuite/gprofng.display/jsynprog/Routine.java: Likewise.
* testsuite/gprofng.display/jsynprog/Sub_Routine.java: Likewise.
* testsuite/gprofng.display/jsynprog/cloop.cc: Likewise.
* testsuite/gprofng.display/jsynprog/jsynprog.h: Likewise.
* testsuite/gprofng.display/jsynprog/jsynprog.java: Correct copyright.
Add the -j option to run the selected functions.
* testsuite/gprofng.display/synprog/check_results.pl:
Remove unused environment variable.
* testsuite/gprofng.display/synprog/synprog.c: Updated DEFAULT_COMMAND.
* testsuite/lib/Makefile.skel: Apply $(ACCT_FILTER).
* testsuite/lib/acct.pm: Ignore errors when $(ACCT_FILTER) is set.
* testsuite/lib/display-lib.exp: Add TARGET_FLAGS in make_args.

17 months agoImprove MI -dprintf-insert documentation
Tom Tromey [Wed, 31 May 2023 14:26:37 +0000 (08:26 -0600)]
Improve MI -dprintf-insert documentation

I found the documentation for -dprintf-insert a bit unclear.  It
didn't mention the possibility of multiple arguments, and I also
noticed that it implied that the format parameter is optional, which
it is not.

While looking into this I also noticed a few comments in the
implementation that could also be improved.

Then, I noticed a repeated call to strlen in a loop condition, so I
fixed this up as well.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
17 months agoPass correct name to @value in gdb.texinfo
Tom Tromey [Wed, 31 May 2023 14:28:01 +0000 (08:28 -0600)]
Pass correct name to @value in gdb.texinfo

I noticed a couple instance of this warning when rebuilding the gdb
info files:

    warning: undefined flag: GDB

The problem is that the wrong argument was passed to @value.  This
patch fixes the problem.

17 months ago[gdb/testsuite] Fix gdb.tui/wrap-line.exp with --disable-tui
Tom de Vries [Wed, 31 May 2023 13:31:15 +0000 (15:31 +0200)]
[gdb/testsuite] Fix gdb.tui/wrap-line.exp with --disable-tui

When running the test-case gdb.tui/wrap-line.exp with a build configured with
--disable-tui, we run into:
...
(gdb) PASS: gdb.tui/wrap-line.exp: width-hard-coded: set width 50
tui new-layout command-layout cmd 1^M
Undefined command: "tui".  Try "help".^M
(gdb) ERROR: Undefined command "tui new-layout command-layout cmd 1".
...

Fix this by guarding the command with allow_tui_tests.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix gdb.tui/pr30056.exp for native-extended-gdbserver
Tom de Vries [Wed, 31 May 2023 13:06:40 +0000 (15:06 +0200)]
[gdb/testsuite] Fix gdb.tui/pr30056.exp for native-extended-gdbserver

When running test-case gdb.tui/pr30056.exp with target board
native-extended-gdbserver, I run into:
...
Quit^[[K^M^[[B(gdb) PASS: gdb.tui/pr30056.exp: Control-C
Remote debugging from host ::1, port 38810^M
^M(failed reverse-i-search)`xyz': ^M(gdb) target extended-remote \
  localhost:2346^[[7GWARNING: Timed out waiting for EOF in server after \
  monitor exit
...

This is due to the fact that ^C doesn't abort the reverse-i-search.  This
appears to be due to a readline problem.  A PR is open about this: PR
cli/30498.

Add a KFAIL for the PR, and ensure that the isearch is aborted by using ^G,
such that we have a responsive prompt to handle the "monitor exit" command
that native-extended-gdbserver issues.

Tested on x86_64-linux.

17 months agope/coff - add support for base64 encoded long section names
Tristan Gingold [Wed, 31 May 2023 10:20:55 +0000 (11:20 +0100)]
pe/coff - add support for base64 encoded long section names

  PR 30444
  * coffcode.h (coff_write_object_contents): Handle base64 encoding on PE.  Also check for too large string table.
  * coffgen.c (extract_long_section_name): New function extracted from ... (make_a_section_from_file): ... here.  Add support for base64 long section names. (decode_base64): New function.

17 months agoFix printf formating issues in elfxx-loongarch64.c
Nick Clifton [Wed, 31 May 2023 09:21:40 +0000 (10:21 +0100)]
Fix printf formating issues in elfxx-loongarch64.c

17 months agopython, btrace: Fix some small formatting issues.
Felix Willgerodt [Mon, 3 Apr 2023 14:13:49 +0000 (16:13 +0200)]
python, btrace: Fix some small formatting issues.

Reviewed-By: Tom Tromey <tom@tromey.com>
17 months ago[gdb/tui] Fix fingerprint for cmd-only layout
Tom de Vries [Wed, 31 May 2023 05:39:31 +0000 (07:39 +0200)]
[gdb/tui] Fix fingerprint for cmd-only layout

I added a cmd-only layout:
...
(gdb) tui new-layout cmd cmd 1
...
and set it:
...
(gdb) layout cmd
...
which gave me the expect result: only the cmd window in the screen.

However, after going back to layout src:
...
(gdb) layout src
...
I got a source window with only one line in it, and the cmd window taking most
of the screen.

I traced this back to tui_set_layout, where for both the old and the new
layout the fingerprint of the cmd window in the layout is taken.  If the
fingerprint is the same, an effort will be done to preserve the command
window size.

The fingerprint is "VC" for both the old (cmd) and new (src) layouts, which
explains the behaviour.

I think this is essentially a bug in the finger print calculation, and it
should be "C" for the cmd layout.

Fix this by not adding a V or H in the fingerprint if the list size is one.

Tested on x86_64-linux.

Reviewed-By: Tom Tromey <tom@tromey.com>
17 months agoAutomatic date update in version.in
GDB Administrator [Wed, 31 May 2023 00:00:47 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months agogdb: add support for %V to printf command
Andrew Burgess [Thu, 23 Mar 2023 12:12:38 +0000 (12:12 +0000)]
gdb: add support for %V to printf command

This commit adds a new format for the printf and dprintf commands:
'%V'.  This new format takes any GDB expression and formats it as a
string, just as GDB would for a 'print' command, e.g.:

  (gdb) print a1
  $a = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}
  (gdb) printf "%V\n", a1
  {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}
  (gdb)

It is also possible to pass the same options to %V as you might pass
to the print command, e.g.:

  (gdb) print -elements 3 -- a1
  $4 = {2, 4, 6...}
  (gdb) printf "%V[-elements 3]\n", a1
  {2, 4, 6...}
  (gdb)

This new feature would effectively replace an existing feature of GDB,
the $_as_string builtin convenience function.  However, the
$_as_string function has a few problems which this new feature solves:

1. $_as_string doesn't currently work when the inferior is not
running, e.g:

  (gdb) printf "%s", $_as_string(a1)
  You can't do that without a process to debug.
  (gdb)

The reason for this is that $_as_string returns a value object with
string type.  When we try to print this we call value_as_address,
which ends up trying to push the string into the inferior's address
space.

Clearly we could solve this problem, the string data exists in GDB, so
there's no reason why we have to push it into the inferior, but this
is an existing problem that would need solving.

2. $_as_string suffers from the fact that C degrades arrays to
pointers, e.g.:

  (gdb) printf "%s\n", $_as_string(a1)
  0x404260 <a1>
  (gdb)

The implementation of $_as_string is passed a gdb.Value object that is
a pointer, it doesn't understand that it's actually an array.  Solving
this would be harder than issue #1 I think.  The whole array to
pointer transformation is part of our expression evaluation.  And in
most cases this is exactly what we want.  It's not clear to me how
we'd (easily) tell GDB that we didn't want this reduction in _some_
cases.  But I'm sure this is solvable if we really wanted to.

3. $_as_string is a gdb.Function sub-class, and as such is passed
gdb.Value objects.  There's no super convenient way to pass formatting
options to $_as_string.  By this I mean that the new %V feature
supports print formatting options.  Ideally, we might want to add this
feature to $_as_string, we might imagine it working something like:

  (gdb) printf "%s\n", $_as_string(a1,
                                   elements = 3,
                                   array_indexes = True)

where the first item is the value to print, while the remaining
options are the print formatting options.  However, this relies on
Python calling syntax, which isn't something that convenience
functions handle.  We could possibly rely on strictly positional
arguments, like:

  (gdb) printf "%s\n", $_as_string(a1, 3, 1)

But that's clearly terrible as there's far more print formatting
options, and if you needed to set the 9th option you'd need to fill in
all the previous options.

And right now, the only way to pass these options to a gdb.Function is
to have GDB first convert them all into gdb.Value objects, which is
really overkill for what we want.

The new %V format solves all these problems: the string is computed
and printed entirely on the GDB side, we are able to print arrays as
actual arrays rather than pointers, and we can pass named format
arguments.

Finally, the $_as_string is sold in the manual as allowing users to
print the string representation of flag enums, so given:

  enum flags
    {
      FLAG_A = (1 << 0),
      FLAG_B = (1 << 1),
      FLAG_C = (1 << 1)
    };

  enum flags ff = FLAG_B;

We can:

  (gdb) printf "%s\n", $_as_string(ff)
  FLAG_B

This works just fine with %V too:

  (gdb) printf "%V\n", ff
  FLAG_B

So all functionality of $_as_string is replaced by %V.  I'm not
proposing to remove $_as_string, there might be users currently
depending on it, but I am proposing that we don't push $_as_string in
the documentation.

As %V is a feature of printf, GDB's dprintf breakpoints naturally gain
access to this feature too.  dprintf breakpoints can be operated in
three different styles 'gdb' (use GDB's printf), 'call' (call a
function in the inferior), or 'agent' (perform the dprintf on the
remote).

The use of '%V' will work just fine when dprintf-style is 'gdb'.

When dprintf-style is 'call' the format string and arguments are
passed to an inferior function (printf by default).  In this case GDB
doesn't prevent use of '%V', but the documentation makes it clear that
support for '%V' will depend on the inferior function being called.

I chose this approach because the current implementation doesn't place
any restrictions on the format string when operating in 'call' style.
That is, the user might already be calling a function that supports
custom print format specifiers (maybe including '%V') so, I claim, it
would be wrong to block use of '%V' in this case.  The documentation
does make it clear that users shouldn't expect this to "just work"
though.

When dprintf-style is 'agent' then GDB does no support the use of
'%V' (right now).  This is handled at the point when GDB tries to
process the format string and send the dprintf command to the remote,
here's an example:

  Reading symbols from /tmp/hello.x...
  (gdb) dprintf call_me, "%V", a1
  Dprintf 1 at 0x401152: file /tmp/hello.c, line 8.
  (gdb) set sysroot /
  (gdb) target remote | gdbserver --once - /tmp/hello.x
  Remote debugging using | gdbserver --once - /tmp/hello.x
  stdin/stdout redirected
  Process /tmp/hello.x created; pid = 3088822
  Remote debugging using stdio
  Reading symbols from /lib64/ld-linux-x86-64.so.2...
  (No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
  0x00007ffff7fd3110 in _start () from /lib64/ld-linux-x86-64.so.2
  (gdb) set dprintf-style agent
  (gdb) c
  Continuing.
  Unrecognized format specifier 'V' in printf
  Command aborted.
  (gdb)

This is exactly how GDB would handle any other invalid format
specifier, for example:

  Reading symbols from /tmp/hello.x...
  (gdb) dprintf call_me, "%Q", a1
  Dprintf 1 at 0x401152: file /tmp/hello.c, line 8.
  (gdb) set sysroot /
  (gdb) target remote | gdbserver --once - /tmp/hello.x
  Remote debugging using | gdbserver --once - /tmp/hello.x
  stdin/stdout redirected
  Process /tmp/hello.x created; pid = 3089193
  Remote debugging using stdio
  Reading symbols from /lib64/ld-linux-x86-64.so.2...
  (No debugging symbols found in /lib64/ld-linux-x86-64.so.2)
  0x00007ffff7fd3110 in _start () from /lib64/ld-linux-x86-64.so.2
  (gdb) set dprintf-style agent
  (gdb) c
  Continuing.
  Unrecognized format specifier 'Q' in printf
  Command aborted.
  (gdb)

The error message isn't the greatest, but improving that can be put
off for another day I hope.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Acked-By: Simon Marchi <simon.marchi@efficios.com>
17 months agogdb: add interp::on_memory_changed method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_memory_changed method

Same idea as previous patches, but for memory_changed.

Change-Id: Ic19f20c24d8a6431d4a89c5625e8ef4898f76e82

17 months agogdb: add interp::on_param_changed method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_param_changed method

Same idea as previous patches, but for command_param_changed.

Change-Id: I7c2196343423360da05f016f8ffa871c064092bb

17 months agogdb: add interp::on_breakpoint_modified method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_breakpoint_modified method

Same idea as previous patches, but for breakpoint_modified.

Change-Id: I4f0a9edea912de431e32451d74224b2022a7c328

17 months agogdb: add interp::on_breakpoint_deleted method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_breakpoint_deleted method

Same idea as previous patches, but for breakpoint_deleted.

Change-Id: I59c231ce963491bb1eee1432ee1090138f09e19c

17 months agogdb: add interp::on_breakpoint_created method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_breakpoint_created method

Same idea as previous patches, but for breakpoint_created.

Change-Id: I614113c924edc243590018b8fb3bf69cb62215ef

17 months agogdb: add interp::on_tsv_modified method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_tsv_modified method

Same idea as previous patches, but for tsv_modified.

Change-Id: I55454a2386d5450040b3a353909b26f389a43682

17 months agogdb: add interp::on_tsv_deleted method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_tsv_deleted method

Same idea as previous patches, but for tsv_deleted.

Change-Id: I71b0502b493da7b6e293bee02aeca98de83d4b75

17 months agogdb: add interp::on_tsv_created method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_tsv_created method

Same idea as previous patches, but for tsv_created.

Change-Id: I9c30ecfdbd78ca015d613f43a0c0aef6c7eb32b5

17 months agogdb: add interp::on_traceframe_changed method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_traceframe_changed method

Same idea as previous patches, but for traceframe_changed.

Change-Id: Ia473f07d70d57b30aca0094d0e0585d7e0d95637

17 months agogdb: add interp::on_about_to_proceed method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_about_to_proceed method

Same idea as previous patches, but for about_to_proceed.  We only need
(and want, as far as the mi_interp implementation is concerned) to
notify the interpreter that caused the proceed.

Change-Id: Id259bca10dbc3d43d46607ff7b95243a9cbe2f89

17 months agogdb: add interp::on_solib_unloaded method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_solib_unloaded method

Same idea as previous patches, but for solib_unloaded.

Change-Id: Iad847de93f0b38b5c90679a173d3beeaed7af6c5

17 months agogdb: add interp::on_solib_loaded method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_solib_loaded method

Same idea as previous patches, but for solib_loaded

Change-Id: I85edb0a4b377f4b2c39ffccf31cb75f38bae0f55

17 months agogdb: add interp::on_target_resumed method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_target_resumed method

Same idea as previous patches, but for target_resumed.

Change-Id: I66fa28d1d41a1f3c4fb0d6a470137d493eac3c8c

17 months agogdb: add interp::on_record_changed method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_record_changed method

Same idea as previous patches, but for record_changed

Change-Id: I5eeeacd703af8401c315060514c94e8e6439cc40

17 months agogdb: add interp::on_inferior_removed method
Simon Marchi [Tue, 2 May 2023 15:35:36 +0000 (11:35 -0400)]
gdb: add interp::on_inferior_removed method

Same idea as previous patches, but for inferior_removed.

Change-Id: I7971840bbbdcfabf77e2ded7584830c9dfdd10d0

17 months agogdb: add interp::on_inferior_disappeared method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_inferior_disappeared method

Same idea as previous patches, but for inferior_disappeared.

For symmetry with on_inferior_appeared, I named this one
on_inferior_disappeared, despite the observer being called
inferior_exit.  This is called when detaching an inferior, so I think
that calling it "disappeared" is a bit less misleading (the observer
should probably be renamed later).

Change-Id: I372101586bc9454997953c1e540a2a6685f53ef6

17 months agogdb: add interp::on_inferior_appeared method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_inferior_appeared method

Same idea as previous patches, but for inferior_appeared.

Change-Id: Ibe4feba34274549a886b1dfb5b3f8d59ae79e1b5

17 months agogdb: add interp::on_inferior_added method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_inferior_added method

Same idea as previous patches, but for inferior_added.

mi_interp::init avoided using mi_inferior_added, since, as the comment
used to say, it would notify all MI interpreters.  Now, it's easy to
only notify the new interpreter, so it's possible to just call the
on_inferior_added method in mi_interp::init.

Change-Id: I0eddbd5367217d1c982516982089913019ef309f

17 months agogdb: add interp::on_thread_exited method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_thread_exited method

Same idea as previous patches, but for thread_exited.

Change-Id: I4be974cbe58cf635453fef503c2d77c82522cbd9

17 months agogdb: add interp::on_new_thread method
Simon Marchi [Fri, 21 Apr 2023 13:45:30 +0000 (09:45 -0400)]
gdb: add interp::on_new_thread method

Same idea as previous patches, but for new_thread.

Change-Id: Ib70ae3421b736fd69d86c4e7c708bec349aa256c

17 months agogdb: add interp::on_user_selected_context_changed method
Simon Marchi [Thu, 20 Apr 2023 20:07:12 +0000 (16:07 -0400)]
gdb: add interp::on_user_selected_context_changed method

Same as previous patches, but for user_selected_context_changed.

Change-Id: I40de15be897671227d4bcf3e747f0fd595f0d5be

17 months agogdb: add interp::on_command_error method
Simon Marchi [Fri, 28 Apr 2023 18:55:18 +0000 (14:55 -0400)]
gdb: add interp::on_command_error method

Same idea as the previous patches, but for command_error.

Change-Id: If6098225dd72fad8be13b3023b35bc8bc48efb9d

17 months agogdb: add interp::on_sync_execution_done method
Simon Marchi [Thu, 20 Apr 2023 19:47:59 +0000 (15:47 -0400)]
gdb: add interp::on_sync_execution_done method

Same as previous patches, but for sync_execution_done.  Except that
here, we only want to notify the interpreter that is executing the
command, not all interpreters.

Change-Id: I729c719447b5c5f29af65dbf6fed9132e2cd308b

17 months agogdb: add interp::on_no_history method
Simon Marchi [Thu, 20 Apr 2023 19:35:18 +0000 (15:35 -0400)]
gdb: add interp::on_no_history method

Same as previous patches, but for no_history.

Change-Id: I06930fe7cb4082138c6c5496c5118fe4951c10da

17 months agogdb: add interp::on_exited method
Simon Marchi [Thu, 20 Apr 2023 18:46:58 +0000 (14:46 -0400)]
gdb: add interp::on_exited method

Same as previous patch, but for exited.  Remove the exited observable,
since nothing uses it anymore, and we don't have anything coming that
will use it.

Change-Id: I358cbea0159af56752dfee7510d6a86191e722bb

17 months agogdb: add interp::on_signal_exited method
Simon Marchi [Thu, 20 Apr 2023 18:02:28 +0000 (14:02 -0400)]
gdb: add interp::on_signal_exited method

Same as previous patch, but for signal_exited.  Remove the signal_exited
observable, since nothing uses it anymore, and we don't have anything
coming that will use it.

Change-Id: I0dca1eab76338bf27be755786e3dad3241698b10

17 months agogdb: add interp::on_normal_stop method
Simon Marchi [Thu, 2 Mar 2023 01:38:35 +0000 (20:38 -0500)]
gdb: add interp::on_normal_stop method

Same idea as the previous patch, but for the normal_stop event.

Change-Id: I4fc8ca8a51c63829dea390a2b6ce30b77f9fb863

17 months agogdb: add interp::on_signal_received method
Simon Marchi [Wed, 1 Mar 2023 21:48:36 +0000 (16:48 -0500)]
gdb: add interp::on_signal_received method

Instead of having the interpreter code registering observers for the
signal_received observable, add a "signal_received" virtual method to
struct interp.  Add a interps_notify_signal_received function that loops
over all UIs and calls the signal_received method on the interpreter.
Finally, add a notify_signal_received function that calls
interps_notify_signal_received and then notifies the observers.  Replace
all existing notifications to the signal_received observers with calls
to notify_signal_received.

Before this patch, the CLI and MI code both register a signal_received
observer.  These observer go over all UIs, and, for those that have a
interpreter of the right kind, print the stop notifiation.

After this patch, we have just one "loop over all UIs", inside
interps_notify_signal_received.  Since the interp::on_signal_received
method gets called once for each interpreter, the implementations only
need to deal with the current interpreter (the "this" pointer).

The motivation for this patch comes from a future patch, that makes the
amdgpu code register an observer to print a warning after the CLI's
signal stop message.  Since the amdgpu and the CLI code both use
observers, the order of the two messages is not stable, unless we define
the priority using the observer dependency system.  However, the
approach of using virtual methods on the interpreters seems like a good
change anyway, I think it's more straightforward and simple to
understand than the current solution that uses observers.  We are sure
that the amdgpu message gets printed after the CLI message, since
observers are notified after interpreters.

Keep the signal_received, even if nothing uses if, because we will be
using it in the upcoming amdgpu patch implementing the warning described
above.

Change-Id: I4d8614bb8f6e0717f4bfc2a59abded3702f23ac4

17 months ago[gdb] Mention --with/without-system-readline for --configuration
Tom de Vries [Tue, 30 May 2023 15:49:31 +0000 (17:49 +0200)]
[gdb] Mention --with/without-system-readline for --configuration

Simon reported that the new test-case gdb.tui/pr30056.exp fails with system
readline.

This is because the test-case requires a fix in readline that's present in our
in-repo copy of readline, but most likely not in any system readline yet.

Fix this by:
- mentioning --with-system-readline or --without-system-readline in the
  configuration string.
- adding a new proc with_system_readline that makes this information available
  in the testsuite.
- using this in test-case gdb.tui/pr30056.exp to declare it unsupported for
  --with-system-readline.

Tested on x86_64-linux.

Reported-By: Simon Marchi <simon.marchi@efficios.com>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
17 months agoSlight wording improvement for the -Ur documentation
Nick Clifton [Tue, 30 May 2023 15:12:18 +0000 (16:12 +0100)]
Slight wording improvement for the -Ur documentation

17 months agoImprove header information displayed with objdump -P for PE binaries.
Nick Clifton [Tue, 30 May 2023 14:43:24 +0000 (15:43 +0100)]
Improve header information displayed with objdump -P for PE binaries.

  * od-pe.c (targ_info): New array.
  (get_target_specific_info): New function.
  (decode_machine_number): Retire.  Use get_target_specific_info instead.
  (is_pe_object_magic): Likewise.
  (dump_pe_file_header): Display more information.
  Rework layout to be similar to that from 'objdump -p'.
  Add code to handle larger than normnal AOUT headers.

17 months agoLoongArch: ld: Add support for linker relaxation.
mengqinggang [Thu, 1 Dec 2022 09:17:09 +0000 (17:17 +0800)]
LoongArch: ld: Add support for linker relaxation.

Add ld relax support and testsuits.

ld/ChangeLog:

* emultempl/loongarchelf.em: Regenerated.
* testsuite/ld-elf/compressed1d.d: Xfail loongarch*-*.
* testsuite/ld-elf/pr26936.d: Likewise.
* testsuite/ld-loongarch-elf/disas-jirl.d: Regenerated.
* testsuite/ld-loongarch-elf/disas-jirl-32.d: Regenerated.
* testsuite/ld-loongarch-elf/jmp_op.d: Likewise.
* testsuite/ld-loongarch-elf/macro_op.d: Likewise.
* testsuite/ld-loongarch-elf/macro_op_32.d: Likewise.
* testsuite/ld-loongarch-elf/relax-align.dd: New test.
* testsuite/ld-loongarch-elf/relax-align.s: New test.
* testsuite/ld-loongarch-elf/relax.exp: New test.
* testsuite/ld-loongarch-elf/relax.s: New test.
* testsuite/ld-loongarch-elf/uleb128.dd: New test.
* testsuite/ld-loongarch-elf/uleb128.s: New test.

17 months agoLoongArch: gas: Add support for linker relaxation.
mengqinggang [Thu, 1 Dec 2022 08:17:46 +0000 (16:17 +0800)]
LoongArch: gas: Add support for linker relaxation.

Add gas -mrelax and -mno-relax option.
Add R_LARCH_RELAX reloc for instrction if it can be relaxed.
ADD R_LARCH_ALIGN reloc for align pseudo instruction because relax.
Add ADD/SUB reloc pair for debug and exception data to calculate symbol
substraction because relax.

gas/ChangeLog:

* config/tc-loongarch.c:
(struct loongarch_cl_insn): New macro_id member.
(enum options): New OPTION_RELAX and OPTION_NO_RELAX.
(struct option): New mrelax and mno-relax.
(md_parse_option): Likewise.
(get_internal_label):
(loongarch_args_parser_can_match_arg_helper): Generate relax reloc.
(move_insn): Set fx_frag and fx_where if exist.
(append_fixp_and_insn): Call frag_wane and frag_new for linker relax
relocs.
(loongarch_assemble_INSNs): New loongarch_cl_insn pointer parameter.
(md_assemble): Fix function call.
(fix_reloc_insn): Likewise.
(md_apply_fix): Generate ADD/SUB reloc pair for debug and exception
data.
(loongarch_fix_adjustable): Delete.
(md_convert_frag): Generate new fix.
(loongarch_pre_output_hook): New function.
(loongarch_make_nops): Likewise.
(loongarch_frag_align_code): Likewise.
(loongarch_insert_uleb128_fixes): Likewise.
(loongarch_md_finish): Likewise.
* config/tc-loongarch.h
(md_allow_local_subtract): New macro define.
(loongarch_frag_align_code): New declare.
(md_do_align): Likewise.
(loongarch_fix_adjustable): Delete.
(tc_fix_adjustable): New macro define.
(TC_FORCE_RELOCATION_SUB_SAME): Likewise.
(TC_LINKRELAX_FIXUP): Likewise.
(TC_FORCE_RELOCATION_LOCAL): Likewise.
(DWARF2_USE_FIXED_ADVANCE_PC): Likewise.
(MD_APPLY_SYM_VALUE): Likewise.
(tc_symbol_new_hook): New extern.
(NOP_OPCODE): Delete.
(loongarch_pre_output_hook): New macro define.
(md_pre_output_hook): Likewise.
(md_finish): Likewise.
(loongarch_md_finish): New extern.
* testsuite/gas/all/align.d: Mark as unsupported on LoongArch.
* testsuite/gas/all/gas.exp: Xfail loongarch*-*.
* testsuite/gas/all/relax.d: Likewise.
* testsuite/gas/elf/dwarf-5-irp.d: Likewise.
* testsuite/gas/elf/dwarf-5-loc0.d: Likewise.
* testsuite/gas/elf/dwarf-5-macro-include.d: Likewise.
* testsuite/gas/elf/dwarf-5-macro.d: Likewise.
* testsuite/gas/elf/dwarf2-11.d: Likewise.
* testsuite/gas/elf/dwarf2-15.d: Likewise.
* testsuite/gas/elf/dwarf2-16.d: Likewise.
* testsuite/gas/elf/dwarf2-17.d: Likewise.
* testsuite/gas/elf/dwarf2-18.d: Likewise.
* testsuite/gas/elf/dwarf2-19.d: Likewise.
* testsuite/gas/elf/dwarf2-5.d: Likewise.
* testsuite/gas/elf/ehopt0.d: Likewise.
* testsuite/gas/elf/elf.exp: Likewise.
* testsuite/gas/elf/section11.d: Likewise.
* testsuite/gas/lns/lns.exp: Likewise.
* testsuite/gas/loongarch/jmp_op.d: Regenerated.
* testsuite/gas/loongarch/li.d: Likewise.
* testsuite/gas/loongarch/macro_op.d: Likewise.
* testsuite/gas/loongarch/macro_op_32.d: Likewise.
* testsuite/gas/loongarch/macro_op_large_abs.d: Likewise.
* testsuite/gas/loongarch/macro_op_large_pc.d: Likewise.
* testsuite/gas/loongarch/relax_align.d: New test.
* testsuite/gas/loongarch/relax_align.s: New test.
* testsuite/gas/loongarch/uleb128.d: New test.
* testsuite/gas/loongarch/uleb128.s: New test.

17 months agoLoongArch: binutils: Add support for linker relaxation.
mengqinggang [Thu, 1 Dec 2022 08:06:42 +0000 (16:06 +0800)]
LoongArch: binutils: Add support for linker relaxation.

Add support for relocs related to relax to readelf.

binutils/ChangeLog:

* readelf.c (target_specific_reloc_handling): Handle ULEB128 reloc.
(is_32bit_inplace_add_reloc): Handle new reloc.
(is_32bit_inplace_sub_reloc): Likewise.
(is_64bit_inplace_add_reloc): Likewise.
(is_64bit_inplace_sub_reloc): Likewise.
(is_16bit_inplace_add_reloc): Likewise.
(is_16bit_inplace_sub_reloc): Likewise.
(is_8bit_inplace_add_reloc): Likewise.
(is_8bit_inplace_sub_reloc): Likewise.
(is_6bit_inplace_sub_reloc): Likewise.
(is_6bit_inplace_add_reloc): New function.
(apply_relocations): Handle new reloc.
* testsuite/binutils-all/readelf.exp: Add -mno-relax option
for LoongArch.

17 months agoLoongArch: opcodes: Add support for linker relaxation.
mengqinggang [Thu, 1 Dec 2022 08:01:27 +0000 (16:01 +0800)]
LoongArch: opcodes: Add support for linker relaxation.

Set gas default to enable relax.

opcodes/ChangeLog:

* loongarch-opc.c (struct loongarch_ASEs_option): New member relax
with the default value 1.

17 months agoLoongArch: bfd: Add support for linker relaxation.
mengqinggang [Thu, 1 Dec 2022 07:03:42 +0000 (15:03 +0800)]
LoongArch: bfd: Add support for linker relaxation.

Add relax support and related relocs in bfd.

bfd/ChangeLog:

* bfd-in2.h: Add relocs related to relax.
* elfnn-loongarch.c (struct loongarch_elf_link_hash_table): New integer
pointer (data_segment_phase) to monitor the data segment phase.
(loongarch_elf_check_relocs): Swap B21/B26 reloc sequence.
(loongarch_elf_adjust_dynamic_symbol): Fix code format.
(loongarch_reloc_rewrite_imm_insn): Fix function call.
(perform_relocation): Handle new relocs related to relax.
(RELOCATE_CALC_PC32_HI20): Fix code format.
(RELOCATE_CALC_PC64_HI32): Likewise.
(loongarch_elf_relocate_section): Handle new relocs related to relax.
(loongarch_relax_delete_bytes): New function.
(loongarch_relax_pcala_addi): Likewise.
(loongarch_relax_pcala_ld): Likewise.
(bfd_elfNN_loongarch_set_data_segment_info): Likewise.
(loongarch_relax_align): Likewise.
(loongarch_elf_relax_section): Likewise.
(bfd_elfNN_bfd_relax_section): New macro define.
* elfxx-loongarch.c (reloc_bits): New bfd point parameter.
(reloc_bits_b16): Likewise.
(reloc_bits_b21): Likewise.
(reloc_bits_b26): Likewise.
(loongarch_adjust_reloc_bitsfield): Likewise.
(reloc_bits_pcrel20_s2): New function.
(loongarch_elf_add_sub_reloc): Likewise.
(loongarch_elf_add_sub_reloc_uleb128): Likewise.
(loongarch_write_unsigned_leb128): New function.
* elfxx-loongarch.h (loongarch_adjust_reloc_bitsfield): New bfd point
parameter.
(bfd_elf32_loongarch_set_data_segment_info): New declare.
(bfd_elf64_loongarch_set_data_segment_info): Likewise.
(loongarch_write_unsigned_leb128): Likewise.
* libbfd.h: Add relocs related to relax.
* reloc.c: Add relocs related to relax.

17 months agoLoongArch: include: Add support for linker relaxation.
mengqinggang [Thu, 1 Dec 2022 06:34:10 +0000 (14:34 +0800)]
LoongArch: include: Add support for linker relaxation.

Add relocs and gas LARCH_opts.relax option.

include/ChangeLog:

* elf/loongarch.h: Add relocs.
* opcode/loongarch.h: Add LARCH_opts.relax and macro LARCH_NOP.

17 months agoAdd support for an ARMMAGIC value of 0xa00 to the PE dumper.
Nick Clifton [Tue, 30 May 2023 10:42:16 +0000 (11:42 +0100)]
Add support for an ARMMAGIC value of 0xa00 to the PE dumper.

17 months agoarm-pe objdump -P
Alan Modra [Tue, 30 May 2023 03:29:55 +0000 (12:59 +0930)]
arm-pe objdump -P

arm-pe looks to be a very old PE implementation, incompatible with
current arm-wince-pe.  arm-pe has different relocations and uses
ARMMAGIC which has this comment: "I just made this up".  Well, OK, I
don't know the history but it was probably before Microsoft "just made
up" their constants for ARM windows CE.

This patch supports objdump -P for arm-pe, and another magic constant
that may appear in object files.  (I don't think binutils generates
files using ARMV7PEMAGIC aka IMAGE_FILE_MACHINE_ARMNT.)

* od-pe.c (is_pe_object_magic): Handle IMAGE_FILE_MACHINE_ARMNT
and ARMMAGIC.

17 months agoDefine IMAGE_FILE_MACHINE_ARMNT
Alan Modra [Tue, 30 May 2023 03:21:57 +0000 (12:51 +0930)]
Define IMAGE_FILE_MACHINE_ARMNT

Same value as ARMV7PEMAGIC.
https://learn.microsoft.com/en-us/windows/win32/sysinfo/image-file-machine-constants

* coff/pe.h (IMAGE_FILE_MACHINE_ARMNT): Define.

17 months agoDon't define COFF_MAGIC
Alan Modra [Tue, 30 May 2023 03:21:39 +0000 (12:51 +0930)]
Don't define COFF_MAGIC

This macro was unused apart from aout/encap.h, which has been deleted.

* config/tc-arm.h (COFF_MAGIC): Don't define.
* config/tc-sh.h (COFF_MAGIC): Don't define.
* config/tc-z80.h (COFF_MAGIC): Don't define.
* config/tc-z8k.h (COFF_MAGIC): Don't define.

17 months agoDelete include/aout/encap.h
Alan Modra [Tue, 30 May 2023 03:21:22 +0000 (12:51 +0930)]
Delete include/aout/encap.h

This file is unused and as the header comment says, obsolete.

17 months agoRegen binutils POTFILES.in
Alan Modra [Tue, 30 May 2023 03:21:07 +0000 (12:51 +0930)]
Regen binutils POTFILES.in

for od-pe.c

17 months agoAutomatic date update in version.in
GDB Administrator [Tue, 30 May 2023 00:00:40 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months ago[gdb/testsuite] Fix linefeed scrolling in tuiterm
Tom de Vries [Mon, 29 May 2023 20:11:05 +0000 (22:11 +0200)]
[gdb/testsuite] Fix linefeed scrolling in tuiterm

I came across a bug in the implementation of line feed in tuiterm, and added a
unit test that exposes it.

Before sending the line feed we have:
...
Screen Dump (size 8 columns x 4 rows, cursor at column 0, row 3):
    0 abcdefgh
    1 ijklmnop
    2 qrstuvwx
    3 yz01234
...
and after it we have:
...
Screen Dump (size 8 columns x 4 rows, cursor at column 0, row 1):
    0 ijklmnop
    1 qrstuvwx
    2 yz01234
    3 yz01234
...

Note how the cursor started at row 3 and after the line feed ended up at
row 1, while it should have stayed in row 3.

Fix this by moving "incr _cur_row -1" one level up in the loop nest in
proc _ctl_0x0a.

Tested on x86_64-linux.

17 months agogdb/mi: fix ^running record with multiple MI interpreters
Simon Marchi [Fri, 21 Apr 2023 16:08:42 +0000 (12:08 -0400)]
gdb/mi: fix ^running record with multiple MI interpreters

I stumbled on the mi_proceeded and running_result_record_printed
globals, which are shared by all MI interpreter instances (it's unlikely
that people use multiple MI interpreter instances, but it's possible).
After poking at it, I found this bug:

1. Start GDB in MI mode
2. Add a second MI interpreter with the new-ui command
3. Use -exec-run on the second interpreter

This is the output I get on the first interpreter:

    =thread-group-added,id="i1"
    ~"Reading symbols from a.out...\n"
    ~"New UI allocated\n"
    (gdb)
    =thread-group-started,id="i1",pid="94718"
    =thread-created,id="1",group-id="i1"
    ^running
    *running,thread-id="all"

And this is the output I get on the second intepreter:

    =thread-group-added,id="i1"
    (gdb)
    -exec-run
    =thread-group-started,id="i1",pid="94718"
    =thread-created,id="1",group-id="i1"
    *running,thread-id="all"

The problem here is that the `^running` reply to the -exec-run command
is printed on the wrong UI.  It is printed on the first one, it should
be printed on the second (the one on which we sent the -exec-run).

What happens under the hood is that captured_mi_execute_command, while
executing a command for the second intepreter, clears the
running_result_record_printed and mi_proceeded globals.
mi_about_to_proceed then sets mi_proceeded.  Then, mi_on_resume_1 gets
called for the first intepreter first.  Since the

    !running_result_record_printed && mi_proceeded

condition is true, it prints a ^running, and sets
running_result_record_printed.  When mi_on_resume_1 gets called for the
second interpreter, running_result_record_printed is already set, so
^running is not printed there.

It took me a while to understand the relationship between these two
variables.  I think that in the end, this is what we want to track:

 1. When executing an MI command, take note if that command causes a
    "proceed".  This is done in mi_about_to_proceed.
 2. In mi_on_resume_1, if the command indeed caused a "proceed", we want
    to output a ^running record.  And we want to remember that we did,
    because...
 3. Back in captured_mi_execute_command, if we did not output a
    ^running, we want to output a ^done.

Moving those two variables to the mi_interp struture appears to fix it.
Only for the interpreter doing the -exec-run command does the
running_result_record_printed flag get cleared, and therefore only or
that one does the ^running record get printed.

Add a new test for this, that does pretty much what the reproducer above
shows.  Without the fix, the test fails because
mi_send_resuming_command_raw never sees the ^running record.

Change-Id: I63ea30e6cb61a8e1dd5ef03377e6003381a9209b
Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
17 months agoAutomatic date update in version.in
GDB Administrator [Mon, 29 May 2023 00:00:47 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months ago[readline] Fix double free in _rl_scxt_dispose
Tom de Vries [Sun, 28 May 2023 08:17:57 +0000 (10:17 +0200)]
[readline] Fix double free in _rl_scxt_dispose

Consider the following scenario.  We start gdb in TUI mode:
...
$ gdb -q -tui
...
and type ^R which gives us the reverse-isearch prompt in the cmd window:
...
(reverse-i-search)`':
...
and then type "foo", right-arrow-key, and ^C.

In TUI mode, gdb uses a custom rl_getc_function tui_getc.

When pressing the right-arrow-key, tui_getc:
- attempts to scroll the TUI src window, without any effect, and
- returns 0.

The intention of returning 0 is mentioned here in tui_dispatch_ctrl_char:
...
  /* We intercepted the control character, so return 0 (which readline
     will interpret as a no-op).  */
  return 0;
...

However, after this 0 is returned by the rl_read_key () call in
_rl_search_getchar, _rl_read_mbstring is called, which incorrectly interprets
0 as the first part of an utf-8 multibyte char, and tries to read the next
char.

In this state, the ^C takes effect and we run into a double free because
_rl_isearch_cleanup is called twice.

Both these issues need fixing independently, though after fixing the first we
no longer trigger the second.

The first issue is caused by the subtle difference between:
- a char array containing 0 chars, which is zero-terminated, and
- a char array containing 1 char, which is zero.

In mbrtowc terms, this is the difference between:
...
  mbrtowc (&wc, "", 0, &ps);
...
which returns -2, and:
...
  mbrtowc (&wc, "", 1, &ps);
...
which returns 0.

Note that _rl_read_mbstring calls _rl_get_char_len without passing it an
explicit length parameter, and consequently it cannot distinguish between the
two, and defaults to the "0 chars" choice.

Note that the same problem doesn't exist in _rl_read_mbchar.

Fix this by defaulting to the "1 char" choice in _rl_get_char_len:
...
-  if (_rl_utf8locale && l > 0 && UTF8_SINGLEBYTE(*src))
+  if (_rl_utf8locale && l >= 0 && UTF8_SINGLEBYTE(*src))
...

The second problem happens when the call to _rl_search_getchar in
_rl_isearch_callback returns.  At that point _rl_isearch_cleanup has already
been called from the signal handler, but we proceed regardless, using a cxt
pointer that has been freed.

Fix this by checking for "RL_ISSTATE (RL_STATE_ISEARCH)" after the call to
_rl_search_getchar:
...
   c = _rl_search_getchar (cxt);
+  if (!RL_ISSTATE (RL_STATE_ISEARCH))
+    return 1;
...

Tested on x86_64-linux.

Approved-By: Chet Ramey <chet.ramey@case.edu>
PR tui/30056
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30056

17 months agoAutomatic date update in version.in
GDB Administrator [Sun, 28 May 2023 00:00:41 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months ago[PR ld/22263][PR ld/25694] RISC-V: Avoid dynamic TLS relocs in PIE.
Nelson Chu [Thu, 4 May 2023 09:08:50 +0000 (17:08 +0800)]
[PR ld/22263][PR ld/25694] RISC-V: Avoid dynamic TLS relocs in PIE.

Lots of targets already fixed the TEXTREL problem for TLS in PIE.

* For PR ld/25694,
In the check_reloc, refer to spare and loongarch, they don't need to reserve
any local dynamic reloc for TLS LE in pie/pde, and similar to other targets.
So it seems like riscv was too conservative to estimate the TLS LE before.
Just break and don't goto static_reloc for TLS LE in pie/pde can fix the
TEXTREL problem.

* For PR ld/22263,
The risc-v code for TLS GD/IE in the relocate_section seems same as MIPS port.
So similar to MIPS, pr22570, commits 9143e72c6d4d and 1cb83cac9a89, it seems
also the right way to do the same thing for risc-v.

On risc-v, fixes
FAIL: Build pr22263-1

RISC-V haven't supported the TLS transitions, so will need the same fix (use
bfd_link_dll) in the future.

bfd/
PR ld/22263
PR ld/25694
* elfnn-riscv.c (riscv_elf_check_relocs): Replace bfd_link_pic with
bfd_link_dll for TLS IE.  Don't need to reserve the local dynamic
relocation for TLS LE in pie/pde, and report error in pic just like
before.
(riscv_elf_relocate_section): For TLS GD/IE, use bfd_link_dll rather
than !bfd_link_pic in determining the dynamic symbol index.  Avoid
the index of -1.

17 months agoAutomatic date update in version.in
GDB Administrator [Sat, 27 May 2023 00:00:37 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months agoEnhance objdump's --private option so that it can display the contents of PE format...
Nick Clifton [Fri, 26 May 2023 14:41:20 +0000 (15:41 +0100)]
Enhance objdump's --private option so that it can display the contents of PE format files.

  * od-pe.c: New file: Dumps fields in PE format headers.
  * configure.ac (od_vectors): Add objdump_private_desc_pe for PE format targets. (od_files): Add od-pe for PE format targets.
  * configure: Regenerate.
  * Makefile.am (CFILES): Add od-pe.c (EXTRA_objdump_SOURCE): Likewise.
  * Makefile.in: Generate.
  * NEWS: Mention the new feature.
  * doc/binutils.texi: Document the new support.
  * objdump.c (wide_output): Change from local to global.
  * objdump.h (wide_output): Prototype. (objdump_private_desc_pe): Prototype.
  * testsuite/binutils-all/objdump.exp: Add a test of the new feature.

17 months agoRemove duplicate definition
Andreas Schwab [Thu, 25 May 2023 17:43:37 +0000 (19:43 +0200)]
Remove duplicate definition

* coff/pe.h (IMAGE_FILE_MACHINE_AMD64): Remove duplicate
definition.  Alphabetize.

17 months agox86: fix disassembler build after 1a3b4f90bc5f
Jan Beulich [Fri, 26 May 2023 10:44:52 +0000 (12:44 +0200)]
x86: fix disassembler build after 1a3b4f90bc5f

In commit 1a3b4f90bc5f ("x86: convert two pointers to (indexing)
integers") I neglected the fact that compilers may warn about comparing
ptrdiff_t (signed long) with size_t (unsigned long) values. Since just
before we've checked that the value is positive, simply add a cast
(despite my dislike for casts).

17 months ago[gdb/testsuite] Add test-case gdb.tui/color-prompt.exp
Tom de Vries [Fri, 26 May 2023 10:30:24 +0000 (12:30 +0200)]
[gdb/testsuite] Add test-case gdb.tui/color-prompt.exp

Add a test-case that sets a prompt with color in TUI.

The line containing the prompt is shown by get_line_with_attrs as follows:
...
<fg:31>(gdb) <fg:default>
...

The 31 means red, but only for foreground colors, for background colors 41
means red.

Make this more readable by using color names for both foreground and
background, such that we have instead:
....
<fg:red>(gdb) <fg:default>
...

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Add invisible and blinking attributes in tuiterm
Tom de Vries [Fri, 26 May 2023 10:30:24 +0000 (12:30 +0200)]
[gdb/testsuite] Add invisible and blinking attributes in tuiterm

I noticed curses using the invisible and blinking attributes.

Add these in tuiterm.

Tested on x86_64-linux.

17 months ago[gdb/testsuite] Fix reverse attribute in tuiterm
Tom de Vries [Fri, 26 May 2023 10:30:24 +0000 (12:30 +0200)]
[gdb/testsuite] Fix reverse attribute in tuiterm

I noticed in proc Term::_csi_m arguments that while parameters 7 and 27 are
supposed to set the reverse attribute to 1 and 0, in fact it's set to 1 in
both cases:
...
      7 {
set _attrs(reverse) 1
    }
  ...
    27 {
set _attrs(reverse) 1
      }
...

Fix this and add a regression test in gdb.tui/tuiterm.exp.

Tested on x86_64-linux.

17 months agoiamcu: suppress tests which can't possibly work
Jan Beulich [Fri, 26 May 2023 08:14:34 +0000 (10:14 +0200)]
iamcu: suppress tests which can't possibly work

With neither --32 nor --64 passed to gas, advanced features like AVX
aren't available without explicitly enabling them.

17 months agox86-64: improve gas diagnostic when no 32-bit target is configured
Jan Beulich [Fri, 26 May 2023 08:14:13 +0000 (10:14 +0200)]
x86-64: improve gas diagnostic when no 32-bit target is configured

Make this similar to --64 and --x32: Check whether a suitable target
exists.

17 months agox86-64: conditionalize tests using --32
Jan Beulich [Fri, 26 May 2023 08:13:53 +0000 (10:13 +0200)]
x86-64: conditionalize tests using --32

Using this option doesn't really work when no support for any 32-bit
target was configured in (as is the case for at least cloudabi and
rdos).

17 months agox86: split gas testsuite .exp file
Jan Beulich [Fri, 26 May 2023 08:13:29 +0000 (10:13 +0200)]
x86: split gas testsuite .exp file

The set of 32-bit-only and 64-bit-only tests has grown quite large. In
particular when one's after only the results for the 64-bit set, having
them live in a separate .exp file is easier / faster.

17 months agox86: convert two pointers to (indexing) integers
Jan Beulich [Fri, 26 May 2023 07:53:51 +0000 (09:53 +0200)]
x86: convert two pointers to (indexing) integers

This in particular reduces the number of pointers to non-const that we
have (and that could potentially be used for undue modification of
state). As a result, fetch_code()'s 2nd parameter can then also become
pointer-to-const.

17 months agox86: disassembling over-long insns
Jan Beulich [Fri, 26 May 2023 07:53:25 +0000 (09:53 +0200)]
x86: disassembling over-long insns

The present way of dealing with them - misusing MAX_MNEM_SIZE, which has
nothing to do with insn length - leads to inconsistent results. Since we
allow for up to MAX_CODE_LENGTH - 1 prefix bytes (which then could be
followed by another MAX_CODE_LENGTH "normal" insn bytes until we're done
decoding), size the_buffer[] accordingly.

Move struct dis_private down to be able to use MAX_CODE_LENGTH without
moving its #define. While doing this also alter the order to have the
potentially large array last.

17 months agox86: use fixed-width type for codep and friends
Jan Beulich [Fri, 26 May 2023 07:53:01 +0000 (09:53 +0200)]
x86: use fixed-width type for codep and friends

This first of all removes a dependency on bfd_byte and unsigned char
being the same types. It further eliminates the need to mask by 0xff
when fetching values (which wasn't done fully consistently anyway),
improving code legibility.

While there, where possible add const.

17 months agox86: figure braces aren't really part of mnemonics
Jan Beulich [Fri, 26 May 2023 07:42:03 +0000 (09:42 +0200)]
x86: figure braces aren't really part of mnemonics

Instead they're separators for pseudo-prefixes. Don't insert them in
mnemonic_chars[], handling them explicitly in parse_insn() instead. Note
that this eliminates the need for another separator after a pseudo-
prefix. While maybe not overly interesting for a following real
mnemonic, I view this as quite desirable between multiple successive
pseudo-prefixes (bringing things in line with the other use of figure
braces in AVX512's zeroing-masking).

Drop the unused is_mnemonic_char() at this occasion.

17 months agox86: de-duplicate operand_special_chars[] wrt extra_symbol_chars[]
Jan Beulich [Fri, 26 May 2023 07:41:41 +0000 (09:41 +0200)]
x86: de-duplicate operand_special_chars[] wrt extra_symbol_chars[]

Having to add characters to both arrays can easily lead to oversights.
Consuming extra_symbol_chars[] when populating operand_chars[] also
allows to drop two special cases in md_begin().

Constify operand_special_chars[] at this occasion.

17 months agosframe/doc: minor improvements for readability
Indu Bhagat [Fri, 26 May 2023 06:44:15 +0000 (23:44 -0700)]
sframe/doc: minor improvements for readability

libsframe/
* sframe-spec.texi: Cosmetic fixes.

17 months agolibsframe: revisit sframe_find_fre API
Indu Bhagat [Fri, 26 May 2023 06:44:09 +0000 (23:44 -0700)]
libsframe: revisit sframe_find_fre API

Inspite of implementing a rather simple functionality, this function was
relatively difficult to follow, and maintain.  Some changes are done now
to address that - refactor the function and use better names to make it
more readable.

The changes to the implementation do not cause any change in the
contract of the API.

libsframe/
        * sframe.c (sframe_fre_get_end_ip_offset): to here...
        (sframe_find_fre): Refactor some bits from...

17 months agolibsframe: use const char * consistently for immutable FRE buffers
Indu Bhagat [Fri, 26 May 2023 06:44:02 +0000 (23:44 -0700)]
libsframe: use const char * consistently for immutable FRE buffers

libsframe/
        * sframe.c (sframe_decode_fre): Use const char * datatype when
handling buffer containing the FREs.
(sframe_fre_get_end_ip_offset): Likewise.
(sframe_find_fre): Likewise.
(sframe_decoder_get_fre): Likewise.

17 months agolibsframe: use uint8_t data type for FRE info related stubs
Indu Bhagat [Fri, 26 May 2023 06:43:45 +0000 (23:43 -0700)]
libsframe: use uint8_t data type for FRE info related stubs

libsframe/
* sframe.c: Use uint8_t for FRE offset count and FRE offset
size.  Use uint8_t for FRE info word as well.

17 months agoPR22263 ld test
Alan Modra [Fri, 26 May 2023 02:21:57 +0000 (11:51 +0930)]
PR22263 ld test

A number of targets that I test regularly fail the "Build pr22263-1"
test for various reasons.

arm-linux-gnueabi: "undefined reference to `__aeabi_read_tp'"
ia64-linux-gnu: "Explicit stops are ignored in auto mode"
m68k-linux-gnu: "undefined reference to `__m68k_read_tp'"
microblaze-linux-gnu: "undefined reference to `__tls_get_addr'"
nios2-linux-gnu, s390-linux-gnu and sh4-linux-gnu have a tprel reloc in .got
riscv64-linux-gnu has a dynamic relocation in text

So only riscv really fails the pr.  The rest fail due to test issues
or lack of a linker optimisation.  Lack of an optimisation isn't
really a fail, but it's worth keeping the test to ensure those
optimisations don't regress.  The xfail targets may not be an
exhaustive list.  This just tidies test results for those for which I
have cross compilers installed.

PR 22263
* testsuite/ld-elf/tls.exp: Split pr22263 test into two parts,
one to check for -z text errors, the other to check tprel
linker optimisation.  Supply needed symbols and assembler flags.
xfail the linker optimisation on targets known to fail.

17 months agoMake MI commands const-correct
Tom Tromey [Fri, 10 May 2019 22:09:35 +0000 (16:09 -0600)]
Make MI commands const-correct

I've had this patch for a while now and figured I'd update it and send
it.  It changes MI commands to use a "const char * const" for their
argv parameter.

Regression tested on x86-64 Fedora 36.

Acked-By: Simon Marchi <simon.marchi@efficios.com>
17 months agoAutomatic date update in version.in
GDB Administrator [Fri, 26 May 2023 00:00:41 +0000 (00:00 +0000)]
Automatic date update in version.in

17 months agoFix scoped_value_mark not working with empty value chain
Ciaran Woodward [Thu, 25 May 2023 11:14:15 +0000 (11:14 +0000)]
Fix scoped_value_mark not working with empty value chain

The scoped_value_mark helper class was setting its internal
mark value to NULL to indicate that the value chain had already
been freed to mark.

However, value_mark() also returns NULL if the value chain is
empty at the time of call.

This lead to the situation that if the value chain was empty
at the time the scoped_value_mark was created, the class
would not correctly clean up the state when it was destroyed,
because it believed it had already been freed.

I noticed this because I was setting a watchpoint very early
in my debug session, and it was becoming a software watchpoint
rather than hardware. Running any command that called evaluate()
beforehand (such as 'x 0') would mean that a hardware watchpoint
was correctly used. After some careful examination of the
differences in execution, I noticed that values were being freed
later in the 'bad case', which lead me to notice the issue with
scoped_value_mark.

17 months agogdb: remove breakpoint_pointer_iterator
Simon Marchi [Tue, 9 May 2023 14:08:51 +0000 (10:08 -0400)]
gdb: remove breakpoint_pointer_iterator

Remove the breakpoint_pointer_iterator layer.  Adjust all users of
all_breakpoints and all_tracepoints to use references instead of
pointers.

Change-Id: I376826f812117cee1e6b199c384a10376973af5d
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
17 months agogdbsupport: make filtered_iterator::operator* return the same thing as underlying...
Simon Marchi [Mon, 8 May 2023 18:49:33 +0000 (14:49 -0400)]
gdbsupport: make filtered_iterator::operator* return the same thing as underlying iterator

This is the same idea as the previous patch, but for filtered_iterator.
Without this patch, I would see this when applying the patch that
removes reference_to_pointer_iterator from breakpoint_range:

      CXX    breakpoint.o
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c: In function ‘void download_tracepoint_locations()’:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:11007:41: error: cannot allocate an object of abstract type ‘breakpoint’
    11007 |   for (breakpoint &b : all_tracepoints ())
          |                                         ^
    In file included from /home/smarchi/src/binutils-gdb/gdb/gdbthread.h:26,
                     from /home/smarchi/src/binutils-gdb/gdb/infrun.h:21,
                     from /home/smarchi/src/binutils-gdb/gdb/gdbarch.h:28,
                     from /home/smarchi/src/binutils-gdb/gdb/arch-utils.h:23,
                     from /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:21:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.h:619:8: note:   because the following virtual functions are pure within ‘breakpoint’:
      619 | struct breakpoint : public intrusive_list_node<breakpoint>
          |        ^~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:250:1: note:     ‘virtual breakpoint::~breakpoint()’
      250 | breakpoint::~breakpoint ()
          | ^~~~~~~~~~

Change-Id: I05285ff27d21cb0ab80cba392ec4e959167e3cd7
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
17 months agogdbsupport: make basic_safe_iterator::operator* return the same thing as underlying...
Simon Marchi [Mon, 8 May 2023 18:49:33 +0000 (14:49 -0400)]
gdbsupport: make basic_safe_iterator::operator* return the same thing as underlying iterator

Using the following patch that removes the reference_to_pointer_iterator
from breakpoint_range, I would get:

      CXX    breakpoint.o
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c: In function ‘void breakpoint_program_space_exit(program_space*)’:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:3030:46: error: cannot allocate an object of abstract type ‘breakpoint’
     3030 |   for (breakpoint &b : all_breakpoints_safe ())
          |                                              ^
    In file included from /home/smarchi/src/binutils-gdb/gdb/gdbthread.h:26,
                     from /home/smarchi/src/binutils-gdb/gdb/infrun.h:21,
                     from /home/smarchi/src/binutils-gdb/gdb/gdbarch.h:28,
                     from /home/smarchi/src/binutils-gdb/gdb/arch-utils.h:23,
                     from /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:21:
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.h:619:8: note:   because the following virtual functions are pure within ‘breakpoint’:
      619 | struct breakpoint : public intrusive_list_node<breakpoint>
          |        ^~~~~~~~~~
    /home/smarchi/src/binutils-gdb/gdb/breakpoint.c:250:1: note:     ‘virtual breakpoint::~breakpoint()’
      250 | breakpoint::~breakpoint ()
          | ^~~~~~~~~~

This is because the operator* method of the basic_safe_iterator iterator
wrapper returns a value_type.  So, even if the method of the underlying
iterator (breakpoint_iterator, an intrusive_list iterator) returns a
`breakpoint &`, the method of the wrapper returns a `breakpoint`.

I think it would make sense for iterator wrappers such as
basic_safe_iterator to return the exact same thing as the iterator they
wrap.  At least, it fixes my problem.

Change-Id: Ibbcd390ac03d2fb6ae4854923750c8d7c3c04e8a
Reviewed-By: Andrew Burgess <aburgess@redhat.com>
17 months agogdb: link breakpoints with intrusive_list
Simon Marchi [Tue, 9 May 2023 14:04:23 +0000 (10:04 -0400)]
gdb: link breakpoints with intrusive_list

Change-Id: I043d8d6f3dd864d80d5088f6ffc2c098337249ea
Reviewed-By: Andrew Burgess <aburgess@redhat.com>