binutils-gdb.git
2 years agosim: callback: expose argv & environ
Mike Frysinger [Tue, 16 Nov 2021 04:04:10 +0000 (23:04 -0500)]
sim: callback: expose argv & environ

Pass the existing strings data to the callbacks so that common
libgloss syscalls can be implemented (which we'll do shortly).

2 years agosim: keep track of program environment strings
Mike Frysinger [Tue, 16 Nov 2021 04:00:04 +0000 (23:00 -0500)]
sim: keep track of program environment strings

We've been passing the environment strings to sim_create_inferior,
but most ports don't do anything with them.  A few will use ad-hoc
logic to stuff the stack for user-mode programs, but that's it.

Let's formalize this across the board by storing the strings in the
normal sim state.  This will allow (in future commits) supporting
more functionality in the run interface, and to unify some of the
libgloss syscalls.

2 years agosim: iq2000: fix some missing prototypes warnings
Mike Frysinger [Tue, 16 Nov 2021 05:44:35 +0000 (00:44 -0500)]
sim: iq2000: fix some missing prototypes warnings

Turns out some of these were hiding real bugs like not passing the
pc variable down.

2 years agoRISC-V: Scalar crypto instruction and entropy source CSR testcases.
jiawei [Mon, 15 Nov 2021 03:03:43 +0000 (11:03 +0800)]
RISC-V: Scalar crypto instruction and entropy source CSR testcases.

Add testcases for Scalar Crypto extension, with total testcase contain all
instructions in k-ext/k-ext-64 and sub-extension testcase for zbk* zk*. Also
add testcase for new CSR name 'seed' which is the Entropy Source in zkr.

In fact these whole testcases can be combined into one file, after we have
supported the .option arch +-= directives.

gas/
* testsuite/gas/riscv/k-ext-64.d: New testcase for crypto instructions.
* testsuite/gas/riscv/k-ext-64.s: Likewise.
* testsuite/gas/riscv/k-ext.d: Likewise.
* testsuite/gas/riscv/k-ext.s: Likewise.
* testsuite/gas/riscv/zbkb-32.d: Likewise.
* testsuite/gas/riscv/zbkb-32.s: Likewise.
* testsuite/gas/riscv/zbkb-64.d: Likewise.
* testsuite/gas/riscv/zbkb-64.s: Likewise.
* testsuite/gas/riscv/zbkc-32.d: Likewise.
* testsuite/gas/riscv/zbkc-64.d: Likewise.
* testsuite/gas/riscv/zbkc.s: Likewise.
* testsuite/gas/riscv/zbkx-32.d: Likewise.
* testsuite/gas/riscv/zbkx-64.d: Likewise.
* testsuite/gas/riscv/zbkx.s: Likewise.
* testsuite/gas/riscv/zknd-32.d: Likewise.
* testsuite/gas/riscv/zknd-32.s: Likewise.
* testsuite/gas/riscv/zknd-64.d: Likewise.
* testsuite/gas/riscv/zknd-64.s: Likewise.
* testsuite/gas/riscv/zkne-32.d: Likewise.
* testsuite/gas/riscv/zkne-32.s: Likewise.
* testsuite/gas/riscv/zkne-64.d: Likewise.
* testsuite/gas/riscv/zkne-64.s: Likewise.
* testsuite/gas/riscv/zknh-32.d: Likewise.
* testsuite/gas/riscv/zknh-32.s: Likewise.
* testsuite/gas/riscv/zknh-64.d: Likewise.
* testsuite/gas/riscv/zknh-64.s: Likewise.
* testsuite/gas/riscv/zksed-32.d: Likewise.
* testsuite/gas/riscv/zksed-64.d: Likewise.
* testsuite/gas/riscv/zksed.s: Likewise.
* testsuite/gas/riscv/zksh-32.d: Likewise.
* testsuite/gas/riscv/zksh-64.d: Likewise.
* testsuite/gas/riscv/zksh.s: Likewise.
* testsuite/gas/riscv/priv-reg-fail-zkr.d: New testcase for zkr
csr check.
* testsuite/gas/riscv/priv-reg-fail-zkr.l: Likewise.
* testsuite/gas/riscv/priv-reg-fail-version-1p10.d: Updated march to
rv32if_zkr.
* testsuite/gas/riscv/priv-reg-fail-version-1p11.d: Likewise.
* testsuite/gas/riscv/priv-reg-fail-version-1p9p1.d: Likewise.
* testsuite/gas/riscv/priv-reg-version-1p10.d: Added Crypto seed csr.
* testsuite/gas/riscv/priv-reg-version-1p11.d: Likewise.
* testsuite/gas/riscv/priv-reg-version-1p9p1.d: Likewise.
* testsuite/gas/riscv/priv-reg.s: Likewise.

2 years agoRISC-V: Scalar crypto instructions and operand set.
jiawei [Mon, 15 Nov 2021 03:03:42 +0000 (11:03 +0800)]
RISC-V: Scalar crypto instructions and operand set.

Add instructions in k-ext, some instruction in zbkb, zbkc is reuse from
zbb,zbc, we just change the class attribute to make them both support.
The 'aes64ks1i' and 'aes64ks2' instructions are present in both the Zknd
and Zkne extensions on rv64.  Add new operand letter 'y' to present 'bs'
symbol and 'Y' to present 'rnum' symbolc  for zkn instructions.  Also add
a new Entropy Source CSR define 'seed' located at address 0x015.

bfd/
* elfxx-riscv.c (riscv_multi_subset_supports): Added support for
crypto extension.
gas/
*config/tc-riscv.c (enum riscv_csr_class): Added CSR_CLASS_ZKR.
(riscv_csr_address): Checked for CSR_CLASS_ZKR.
(validate_riscv_insn): Added y and Y for bs and rnum operands.
(riscv_ip): Handle y and Y operands.
include/
* opcode/riscv-opc.h: Added encodings of crypto instructions.
Also defined new csr seed, which address is 0x15.
* opcode/riscv.h: Defined OP_* and INSN_CLASS_* for crypto.
opcodes/
* riscv-dis.c (print_insn_args): Recognized new y and Y operands.
* riscv-opc.c (riscv_opcodes): Added crypto instructions.

2 years agoRISC-V: Minimal support of scalar crypto extension.
jiawei [Mon, 15 Nov 2021 03:03:41 +0000 (11:03 +0800)]
RISC-V: Minimal support of scalar crypto extension.

Minimal support of scalar crypto extension, add "k" in the
riscv_supported_std_ext, to make the order check right with
"zk" behind "zb".

bfd/
* elfxx-riscv.c (riscv_implicit_subsets): Added implicit
rules for zk* extensions.
(riscv_supported_std_ext): Added entry for k.
(riscv_supported_std_z_ext): Added entries for zk*.

2 years agogdb: rework "set debuginfod" commands
Simon Marchi [Tue, 2 Nov 2021 16:21:31 +0000 (12:21 -0400)]
gdb: rework "set debuginfod" commands

As discussed here [1], do some re-work in the "set debuginfod commands".

First, use "set debuginfod enabled on/off/ask" instead of "set
debuginfod on/off/ask".  This is more MI-friendly, and it gives an
output that makes more sense in "info set", for example.

Then, make the show commands not call "error" when debuginfod support is
not compiled in.  This makes the commands "show" and "show debuginfod"
stop early, breaking gdb.base/default.exp:

    Running /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.base/default.exp ...
    FAIL: gdb.base/default.exp: info set
    FAIL: gdb.base/default.exp: show

 - Make the "debuginfod enabled" setting default to "off" when debuginfod
   support is not compiled in, and "ask" otherwise.
 - Make the setter of "debuginfod enabled" error out when debuginfod
   support is not compiled in, so that "debuginfod enabled" will always
   remain "off" in that case.
 - Make the setter of "debuginfod verbose" work in any case.  I don't
   see the harm in letting the user change that setting, since the user will
   hit an error if they try to enable the use of debuginfod.
 - I would do the same for the "debuginfod urls" setter, but because
   this one needs to see the DEBUGINFOD_URLS_ENV_VAR macro, provided by
   libdebuginfod, I made that one error out as well if debuginfod
   support is not compiled it (otherwise, I would have left it like
   "debuginfod verbose".  Alternatively, we could hard-code
   "DEBUGINFOD_URLS" in the code (in fact, it was prior to this patch,
   but I think it was an oversight, as other spots use
   DEBUGINFOD_URLS_ENV_VAR), or use a dummy string to store the setting,
   but I don't really see the value in that.

Rename debuginfod_enable to debuginfod_enabled, just so it matches the
setting name.

[1] https://sourceware.org/pipermail/gdb-patches/2021-October/182937.html

Change-Id: I45fdb2993f668226a5639228951362b7800f09d5
Co-Authored-By: Aaron Merey <amerey@redhat.com>
2 years agogdb: adjust gdbarch_tdep calls in nat files
Simon Marchi [Mon, 15 Nov 2021 20:22:34 +0000 (15:22 -0500)]
gdb: adjust gdbarch_tdep calls in nat files

Commit 345bd07cce33 ("gdb: fix gdbarch_tdep ODR violation") forgot to
update the gdbarch_tdep calls in the native files other than x86-64
Linux.  This patch updates them all (to the best of my knowledge).
These are the files I was able to build-test:

  aarch64-linux-nat.c
  amd64-bsd-nat.c
  arm-linux-nat.c
  ppc-linux-nat.c
  windows-nat.c
  xtensa-linux-nat.c

And these are the ones I could not build-test:

  aix-thread.c
  arm-netbsd-nat.c
  ppc-fbsd-nat.c
  ppc-netbsd-nat.c
  ia64-tdep.c (the part that needs libunwind)
  ppc-obsd-nat.c
  rs6000-nat.c

If there are still some build problems related to gdbarch_tdep in them,
they should be pretty obvious to fix.

Change-Id: Iaa3d791a850e4432973757598e634e3da6061428

2 years agogdb: remove unused variables in xtensa-linux-nat.c
Simon Marchi [Tue, 16 Nov 2021 02:38:44 +0000 (21:38 -0500)]
gdb: remove unused variables in xtensa-linux-nat.c

While build-testing this file, the compiler complained about these two
unused variables, remove them.

Change-Id: I3c54f779f12c16ef6184af58aca75eaad042ce4e

2 years agogdb: add arc-newlib-tdep.c to ALL_TARGET_OBS
Simon Marchi [Tue, 16 Nov 2021 02:19:30 +0000 (21:19 -0500)]
gdb: add arc-newlib-tdep.c to ALL_TARGET_OBS

This file is currently not compiled in an --enable-targets=all build,
but it should be.  Add it to ALL_TARGET_OBS.

Update the gdbarch_tdep call that commit 345bd07cce33 ("gdb: fix
gdbarch_tdep ODR violation") forgot to update.

Change-Id: I86248a01493eea5e70186e9c46a298ad3994b034

2 years agoUpdate my email address.
Jim Wilson [Tue, 16 Nov 2021 00:51:05 +0000 (16:51 -0800)]
Update my email address.

I've left SiFive and have a new gmail account because it is convenient
to use with git send-email.  I'm planning to use this for my RISC-V
work.  My tuliptree address still works, it just isn't as convenient.

binutils:
* MAINTAINERS (RISC-V): Update my address.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 16 Nov 2021 00:00:06 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years ago[gdb] Don't use gdb_stdlog for inferior-events
Tom de Vries [Mon, 15 Nov 2021 21:55:02 +0000 (22:55 +0100)]
[gdb] Don't use gdb_stdlog for inferior-events

The test-case gdb.base/foll-vfork.exp contains:
...
if [gdb_debug_enabled] {
    untested "debug is enabled"
    return 0
}
...

To understand what it does, I disabled this bit and ran with GDB_DEBUG=infrun,
like so:
...
$ cd $build/gdb/testsuite
$ make check GDB_DEBUG=infrun RUNTESTFLAGS=gdb.base/foll-vfork.exp
...
and ran into:
...
(gdb) PASS: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: set follow-fork parent
next^M
33        if (pid == 0) {^M
(gdb) FAIL: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: step
...

The problem is that the test-case expects:
...
(gdb) PASS: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: set follow-fork parent
next^M
[Detaching after vfork from child process 28169]^M
33        if (pid == 0) {^M
(gdb) PASS: gdb.base/foll-vfork.exp: exec: \
  vfork parent follow, through step: step
...
but the "Detaching" line has been redirected to
$outputs/gdb.base/foll-vfork/gdb.debug.

I looked at the documentation of "set logging debugredirect [on|off]":
...
  By default, GDB debug output will go to both the terminal and the logfile.
  Set debugredirect if you want debug output to go only to the log file.
...
and my interpretation of it was that "debug output" did not match the
"messages" description of inferior-events:
...
The set print inferior-events command allows you to enable or disable printing
of messages when GDB notices that new inferiors have started or that inferiors
have exited or have been detached.
...

Fix the discrepancy by not using gdb_stdlog for inferior-events.

Update the gdb.base/foll-vfork.exp test-case to not require
gdb_debug_enabled == 0.

Tested on x86_64-linux.

Tested test-case gdb.base/foll-vfork.exp with and without GDB_DEBUG=infrun.

2 years agold: Fix testsuite failures under --enable-textrel-check=error
Roland McGrath [Mon, 15 Nov 2021 19:09:17 +0000 (11:09 -0800)]
ld: Fix testsuite failures under --enable-textrel-check=error

ld/
* testsuite/ld-aarch64/dt_textrel.d: Pass explicit -z notext in
case ld was configured with --enable-textrel-check=error.
* testsuite/ld-aarch64/pr22764.d: Likewise.
* testsuite/ld-aarch64/pr20402.d: Likewise.

2 years agoExtend the prologue analyzer to handle the bti instruction
Luis Machado [Thu, 11 Nov 2021 20:22:50 +0000 (17:22 -0300)]
Extend the prologue analyzer to handle the bti instruction

Handle the BTI instruction in the prologue analyzer. The patch handles all
the variations of the BTI instruction.

2 years agogdb: fix gdbarch_tdep ODR violation
Simon Marchi [Mon, 15 Nov 2021 16:29:39 +0000 (11:29 -0500)]
gdb: fix gdbarch_tdep ODR violation

I would like to be able to use non-trivial types in gdbarch_tdep types.
This is not possible at the moment (in theory), because of the one
definition rule.

To allow it, rename all gdbarch_tdep types to <arch>_gdbarch_tdep, and
make them inherit from a gdbarch_tdep base class.  The inheritance is
necessary to be able to pass pointers to all these <arch>_gdbarch_tdep
objects to gdbarch_alloc, which takes a pointer to gdbarch_tdep.

These objects are never deleted through a base class pointer, so I
didn't include a virtual destructor.  In the future, if gdbarch objects
deletable, I could imagine that the gdbarch_tdep objects could become
owned by the gdbarch objects, and then it would become useful to have a
virtual destructor (so that the gdbarch object can delete the owned
gdbarch_tdep object).  But that's not necessary right now.

It turns out that RISC-V already has a gdbarch_tdep that is
non-default-constructible, so that provides a good motivation for this
change.

Most changes are fairly straightforward, mostly needing to add some
casts all over the place.  There is however the xtensa architecture,
doing its own little weird thing to define its gdbarch_tdep.  I did my
best to adapt it, but I can't test those changes.

Change-Id: Ic001903f91ddd106bd6ca09a79dabe8df2d69f3b

2 years agoCOFF: avoid modifications over C_FILE filename aux entries.
Clément Chigot [Mon, 15 Nov 2021 09:37:36 +0000 (10:37 +0100)]
COFF: avoid modifications over C_FILE filename aux entries.

Commit e86fc4a5bc37 ("PR 28447: implement multiple parameters for .file
on XCOFF") introduces C_FILE entries which can store additional
information.
However, some modifications are needed by them but not by the original
C_FILE entries, usually representing the filename.
This patch ensures that filename entries are kept as is, in order to
protect targets not supporting the additional entries.

* coffgen.c (coff_write_symbol): Protect filename entries
(coff_write_symbols): Likewise.
(coff_print_symbol): Likewise.

2 years agoDeal with full path in .file 0 directive
Eric Botcazou [Mon, 15 Nov 2021 11:50:51 +0000 (12:50 +0100)]
Deal with full path in .file 0 directive

Gas uses the directory part, if present, of the .file 0 directive to set
entry 0 of the directory table in DWARF 5, which represents the "current
directory".

Now Gas also uses the file part of the same directive to set entry 0 of the
file table, which represents the "current compilation file".  But the latter
need not be located in the former so GCC will use a full path in the file
part when it is passed a full path:

gcc -c /full/path/test.c -save-temps

yields:

 .file 0 "/current/directory" "/full/path/test.c"

in the assembly file and:

 The Directory Table (offset 0x22, lines 2, columns 1):
  Entry Name
  0     (indirect line string, offset: 0x25): /current/directory
  1     (indirect line string, offset: 0x38): /full/path

 The File Name Table (offset 0x30, lines 2, columns 2):
  Entry Dir     Name
  0     0       (indirect line string, offset: 0x43): /full/path/test.c

in the object file.  Note the full path and the questionable Dir value in
the 0 entry of the file table.

2 years agosim: cris: make error message test a little more flexible
Mike Frysinger [Mon, 15 Nov 2021 08:34:36 +0000 (03:34 -0500)]
sim: cris: make error message test a little more flexible

The point of this test is to just make sure the usage text is shown,
not the exact details of the usage text.  So shorten the output test
to match the beginning.  This fixes breakage when the output changed
slightly to include [--].

2 years agosim: run: fix crash in argc==0 error situation
Mike Frysinger [Mon, 15 Nov 2021 08:32:26 +0000 (03:32 -0500)]
sim: run: fix crash in argc==0 error situation

The new argv processing code assumed that we were always passed a
command line.  If we weren't, make sure we don't crash before we
get a chance to output an error message about incorrect usage.

2 years agosim: cris: touch up rvdummy handling
Mike Frysinger [Mon, 15 Nov 2021 08:00:05 +0000 (03:00 -0500)]
sim: cris: touch up rvdummy handling

Add quiet build support and make sure it's removed with `make clean`.

2 years agosim: cris: replace custom "dest" test field with new --argv0
Mike Frysinger [Mon, 15 Nov 2021 07:44:30 +0000 (02:44 -0500)]
sim: cris: replace custom "dest" test field with new --argv0

The #dest field used in the cris testsuite is a bit of hack to set the
argv[0] for the tests to read out later on.  Now that the sim has an
option to set argv[0] explicitly, we don't need this custom field, so
let's drop it to harmonize the testsuites a little.

2 years agosim: run: add --argv0 option to control argv[0]
Mike Frysinger [Mon, 15 Nov 2021 07:36:29 +0000 (02:36 -0500)]
sim: run: add --argv0 option to control argv[0]

We default argv[0] to the program we run which is a standard *NIX
convention, but sometimes we want to be able to control the argv[0]
setting independently (especially for programs that inspect argv[0]
to change their behavior or output).  Add an option to control it.

2 years agosim: split program path out of argv vector
Mike Frysinger [Mon, 15 Nov 2021 07:32:06 +0000 (02:32 -0500)]
sim: split program path out of argv vector

We use the program argv to both find the program to run (argv[0]) and
to hold the arguments to the program.  Most of the time this is fine,
but if we want to let programs specify argv[0] independently (which is
possible in standard *NIX programs), this double duty doesn't work.

So let's split the path to the program to run out into a separate
field by itself.  This simplifies the various sim_open funcs too.

By itself, this code is more of a logical cleanup than something that
is super useful.  But it will open up customization of argv[0] in a
follow up commit.  Split the changes to make it easier to review.

2 years agosim: bfin: fix mach/xfail usage in tests
Mike Frysinger [Sun, 14 Nov 2021 18:43:46 +0000 (13:43 -0500)]
sim: bfin: fix mach/xfail usage in tests

Set the mach to the right value all the time, and update xfail to
say the test fails on all targets.  WIth multitarget testing, the
idea of target here doesn't make much sense.

2 years ago-Waddress fixes for gold testsuite
Alan Modra [Mon, 15 Nov 2021 02:32:26 +0000 (13:02 +1030)]
-Waddress fixes for gold testsuite

Current mainline gcc.
common_test_1.c: In function 'main':
common_test_1.c:56:14: error: comparison between two arrays [-Werror=array-compare]
   56 |   assert (c5 > c4);
      |              ^
common_test_1.c:56:14: note: use '&c5[0] > &c4[0]' to compare the addresses

* testsuite/common_test_1.c: Avoid -Waddress warnings.
* testsuite/common_test_1_v1.c: Likewise.
* testsuite/common_test_1_v2.c: Likewise.
* testsuite/script_test_2.cc: Likewise.

2 years agoPowerPC64 @notoc in non-power10 code
Alan Modra [Tue, 9 Nov 2021 22:19:05 +0000 (08:49 +1030)]
PowerPC64 @notoc in non-power10 code

R_PPC64_REL24_P9NOTOC is a variant of R_PPC64_REL24_NOTOC for use on
@notoc cals from non-power10 code in the rare case that using such a
construct is useful.  R_PPC64_REL24_P9NOTOC will be emitted by gas
rather than R_PPC64_REL24_NOTOC when @notoc is used in a branch
instruction if power10 instructions are not enabled at that point.
The new relocation tells the linker to not use power10 instructions on
any stub emitted for that branch, unless overridden by
--power10-stubs=yes.

The current linker heuristic of only generating power10 instructions
for stubs if power10-only relocations are detected, continues to be
used.

include/
* elf/ppc64.h (R_PPC64_REL24_P9NOTOC): Define.
bfd/
* reloc.c (BFD_RELOC_PPC64_REL24_P9NOTOC): Define.
* elf64-ppc.c (ppc64_elf_howto_raw): Add entry for new reloc.
(ppc64_elf_reloc_type_lookup): Handle it.
(enum ppc_stub_type): Delete.
(enum ppc_stub_main_type, ppc_stub_sub_type): New.
(struct ppc_stub_type): New.
(struct ppc_stub_hash_entry): Use the above new type.
(struct ppc_link_hash_table): Update stub_count.
(is_branch_reloc, ppc64_elf_check_relocs),
(toc_adjusting_stub_needed): Handle new reloc.
(stub_hash_newfunc, select_alt_stub, ppc_merge_stub),
(ppc_type_of_stub, plt_stub_size, build_plt_stub),
(build_tls_get_addr_head, build_tls_get_addr_tail),
(ppc_build_one_stub, ppc_size_one_stub, ppc64_elf_size_stubs),
(ppc64_elf_build_stubs, ppc64_elf_relocate_section): Handle new
reloc.  Modify stub handling to suit new scheme.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
gas/
* config/tc-ppc.c (ppc_elf_suffix): When power10 is not enabled
return BFD_RELOC_PPC64_REL24_P9NOTOC for @notoc.
(fixup_size, ppc_force_relocation, ppc_fix_adjustable): Handle
BFD_RELOC_PPC64_REL24_P9NOTOC.
ld/
* testsuite/ld-powerpc/callstub-2.s: Add .machine power10.

2 years agoRegenerate a couple of files
Alan Modra [Sun, 14 Nov 2021 23:19:54 +0000 (09:49 +1030)]
Regenerate a couple of files

A couple of files changed on my latest --enable-maintainer-mode
build.  ld/Makefile.in had a missing dependency but better sorting of
the loongson entries.

intl/
* configure: Regenerate.
ld/
* Makefile.am: Sort loongson entries.
* Makefile.in: Regenerate.

2 years agoFix build with current GCC: EL_EXPLICIT(location) always non-NULL
Pedro Alves [Tue, 9 Nov 2021 17:33:41 +0000 (17:33 +0000)]
Fix build with current GCC: EL_EXPLICIT(location) always non-NULL

Compiling GDB with current GCC (1b4a63593b) runs into this:

  src/gdb/location.c: In function 'int event_location_empty_p(const event_location*)':
  src/gdb/location.c:963:38: error: the address of 'event_location::<unnamed union>::explicit_loc' will never be NULL [-Werror=address]
    963 |       return (EL_EXPLICIT (location) == NULL
|                                      ^
  src/gdb/location.c:57:30: note: 'event_location::<unnamed union>::explicit_loc' declared here
     57 |     struct explicit_location explicit_loc;
|                              ^~~~~~~~~~~~

GCC is right, EL_EXPLICIT is defined as returning the address of an
union field:

      /* An explicit location.  */
      struct explicit_location explicit_loc;
  #define EL_EXPLICIT(P) (&((P)->u.explicit_loc))

and thus must always be non-NULL.

Change-Id: Ie74fee7834495a93affcefce03c06e4d83ad8191

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 15 Nov 2021 00:00:22 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years ago[PR gdb/16238] Add completer for the show user command
Lancelot SIX [Mon, 11 Oct 2021 22:42:33 +0000 (23:42 +0100)]
[PR gdb/16238] Add completer for the show user command

The 'show user' command (which shows the definition of non-python/scheme
user defined commands) is currently missing a completer. This is
mentioned in PR 16238.  Having one can improve the user experience.

In this commit I propose an implementation for such completer as well as
the associated tests.

Tested on x86_64 GNU/Linux.

All feedbacks are welcome.

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

2 years agosync libbacktrace from gcc
Alan Modra [Sun, 14 Nov 2021 07:37:50 +0000 (18:07 +1030)]
sync libbacktrace from gcc

2 years agoAutomatic date update in version.in
GDB Administrator [Sun, 14 Nov 2021 00:00:13 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoSync Makefile.tpl with GCC
H.J. Lu [Sat, 13 Nov 2021 16:51:02 +0000 (08:51 -0800)]
Sync Makefile.tpl with GCC

* Makefile.tpl: Sync with GCC.
* Makefile.in: Regenerate.

2 years agosim: sh: fix switch-bool warnings
Mike Frysinger [Fri, 12 Nov 2021 00:36:28 +0000 (19:36 -0500)]
sim: sh: fix switch-bool warnings

This code triggers -Werror=switch-bool warnings with <=gcc-5 versions.
Rework it to use if statements instead as it also simplifies a bit.

2 years agosim: sh: rework carry checks to not rely on integer overflows
Mike Frysinger [Fri, 12 Nov 2021 00:30:41 +0000 (19:30 -0500)]
sim: sh: rework carry checks to not rely on integer overflows

In <=gcc-7 versions, -fstrict-overflow is enabled by default, and that
triggers warnings in this code that relies on integer overflows to test
for carries.  Change the logic to test against the limit directly.

2 years agoAutomatic date update in version.in
GDB Administrator [Sat, 13 Nov 2021 00:00:24 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoFix gdb.base/sigstep.exp test for ppc
Carl Love [Fri, 5 Nov 2021 20:25:28 +0000 (20:25 +0000)]
Fix gdb.base/sigstep.exp test for ppc

The test stops at <signal_handler called> which is the call to the handler
rather than in the handler as intended.  This patch replaces the
gdb_test "$enter_cmd to handler" with a gdb_test_multiple test.  The multiple
test looks for the stop at <signal_handler called>.  If found, the command
is issued again.  The test passes if gdb stops in the handler as expected.

(gdb) PASS: gdb.base/sigstep.exp: stepi to handler, nothing in handler, step
from handler: continue to signal
stepi
<signal handler called>
1: x/i $pc
=> 0x7ffff7f80440 <__kernel_start_sigtramp_rt64>:       bctrl
(gdb) stepi
handler (sig=551) at sigstep.c:32
32      {
1: x/i $pc
=> 0x10000097c <handler>:       addis   r2,r12,2
(gdb) PASS: gdb.base/sigstep.exp: stepi to handler, nothing in handler,
step from handler: stepi to handler

Patch has been tested on x86_64-linux and ppc64le-linux with no test failures.

2 years ago[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp
Tom de Vries [Fri, 12 Nov 2021 16:12:56 +0000 (17:12 +0100)]
[gdb/testsuite] Fix regexp in gdb.base/foll-vfork.exp

On OBS I ran into:
...
(gdb) PASS: gdb.base/foll-vfork.exp: exit: \
  vfork relations in info inferiors: continue to child exit
info inferiors^M
  Num  Description       Connection           Executable        ^M
  1    <null>                                 foll-vfork-exit ^M
* 2    <null>                                 foll-vfork-exit ^M
(gdb) I'm the proud parent of child #5044!^M
FAIL: gdb.base/foll-vfork.exp: exit: vfork relations in info inferiors: \
  vfork relation no longer appears in info inferiors (timeout)
...

Fix this by removing the '$' anchor in the corresponding '$gdb_prompt $'
regexps.

Tested on x86_64-linux.

2 years agoDon't compile some opcodes files when bfd is 32-bit only
Alan Modra [Fri, 12 Nov 2021 08:25:45 +0000 (18:55 +1030)]
Don't compile some opcodes files when bfd is 32-bit only

* Makefile.am (TARGET_LIBOPCODES_CFILES): Split into..
(TARGET64_LIBOPCODES_CFILES): ..this and..
(TARGET32_LIBOPCODES_CFILES): ..this.
(ALL_MACHINES): Likewise split to
(ALL64_MACHINES, ALL32_MACHINES): ..this.
* disassemble.c: Define some ARCH_* when ARCH_all only if BFD64.
* configure.ac (BFD_MACHINES): Defined depending on BFD_ARCH_SIZE.
* Makefile.in: Regenerate.
* configure: Regenerate.

2 years agoImport Makefile.def from gcc
Alan Modra [Fri, 12 Nov 2021 08:08:23 +0000 (18:38 +1030)]
Import Makefile.def from gcc

* Makefile.def: Import from gcc.
* Makefile.in: Regenerate.

2 years agoFix demangle style usage info
Alan Modra [Thu, 11 Nov 2021 09:51:32 +0000 (20:21 +1030)]
Fix demangle style usage info

Extract allowed styles from libiberty, so we don't have to worry about
our help messages getting out of date.  The function probably belongs
in libiberty/cplus-dem.c but it can be here for a while to iron out
bugs.

PR 28581
* demanguse.c: New file.
* demanguse.h: New file.
* nm.c (usage): Break up output.  Use display_demangler_styles.
* objdump.c (usage): Use display_demangler_styles.
* readelf.c (usage): Likewise.
* Makefile.am: Add demanguse.c and demanguse.h.
* Makefile.in: Regenerate.
* po/POTFILESin: Regenerate.

2 years agoAutomatic date update in version.in
GDB Administrator [Fri, 12 Nov 2021 00:00:17 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agogdb: fix "set scheduler-locking" thread exit hang
Simon Marchi [Mon, 8 Nov 2021 21:49:21 +0000 (16:49 -0500)]
gdb: fix "set scheduler-locking" thread exit hang

GDB hangs when doing this:

 - launch inferior with multiple threads
 - multiple threads hit some breakpoint(s)
 - one breakpoint hit is presented as a stop, the rest are saved as
   pending wait statuses
 - "set scheduler-locking on"
 - resume the currently selected thread (because of scheduler-locking,
   it's the only one resumed), let it execute until exit
 - GDB hangs, not showing the prompt, impossible to interrupt with ^C

When the resumed thread exits, we expect the target to return a
TARGET_WAITKIND_NO_RESUMED event, and that's what we see:

    [infrun] fetch_inferior_event: enter
      [infrun] scoped_disable_commit_resumed: reason=handling event
      [infrun] random_pending_event_thread: None found.
    [Thread 0x7ffff7d9c700 (LWP 309357) exited]
      [infrun] print_target_wait_results: target_wait (-1.0.0 [process -1], status) =
      [infrun] print_target_wait_results:   -1.0.0 [process -1],
      [infrun] print_target_wait_results:   status->kind = no-resumed
      [infrun] handle_inferior_event: status->kind = no-resumed
      [infrun] handle_no_resumed: TARGET_WAITKIND_NO_RESUMED (ignoring: found resumed)
      [infrun] prepare_to_wait: prepare_to_wait
      [infrun] reset: reason=handling event
      [infrun] maybe_set_commit_resumed_all_targets: not requesting commit-resumed for target native, no resumed threads
    [infrun] fetch_inferior_event: exit

The problem is in handle_no_resumed: we check if some other thread is
actually resumed, to see if we should ignore that event (see comments in
that function for more info).  If this condition is true:

    (thread->executing () || thread->has_pending_waitstatus ())

... then we ignore the event.  The problem is that there are some non-resumed
threads with a pending event, which makes us ignore the event.  But these
threads are not resumed, so we end up waiting while nothing executes, hence
waiting for ever.

My first fix was to change the condition to:

    (thread->executing ()
     || (thread->resumed () && thread->has_pending_waitstatus ()))

... but then it occured to me that we could simply check for:

    (thread->resumed ())

Since "executing" implies "resumed", checking simply for "resumed"
covers threads that are resumed and executing, as well as threads that
are resumed with a pending status, which is what we want.

Change-Id: Ie796290f8ae7f34c026ca3a8fcef7397414f4780

2 years ago[gdb/build] Fix Wimplicit-exception-spec-mismatch in clang build
Tom de Vries [Thu, 11 Nov 2021 10:22:39 +0000 (11:22 +0100)]
[gdb/build] Fix Wimplicit-exception-spec-mismatch in clang build

When building with clang 13 (and -std=gnu++17 to work around an issue in
string_view-selftests.c), we run into a few Wimplicit-exception-spec-mismatch
warnings:
...
src/gdbsupport/new-op.cc:102:1: error: function previously declared with an \
  explicit exception specification redeclared with an implicit exception \
  specification [-Werror,-Wimplicit-exception-spec-mismatch]
operator delete (void *p)
^
/usr/include/c++/11/new:130:6: note: previous declaration is here
void operator delete(void*) _GLIBCXX_USE_NOEXCEPT
     ^
...

These are due to recent commit 5fff6115fea "Fix
LD_PRELOAD=/usr/lib64/libasan.so.6 gdb".

Fix this by adding the missing noexcept.

Build on x86_64-linux, using gcc 7.5.0 and clang 13.0.0.

2 years ago[gdb/build] Fix build with -std=c++11
Tom de Vries [Thu, 11 Nov 2021 10:22:39 +0000 (11:22 +0100)]
[gdb/build] Fix build with -std=c++11

When building with -std=c++11, we run into two Werror=missing-declarations:
...
new-op.cc: In function 'void operator delete(void*, std::size_t)':
new-op.cc:114:1: error: no previous declaration for \
  'void operator delete(void*, std::size_t)' [-Werror=missing-declarations]
 operator delete (void *p, std::size_t) noexcept
 ^~~~~~~~
new-op.cc: In function 'void operator delete [](void*, std::size_t)':
new-op.cc:132:1: error: no previous declaration for \
  'void operator delete [](void*, std::size_t)' [-Werror=missing-declarations]
 operator delete[] (void *p, std::size_t) noexcept
 ^~~~~~~~
...

These are due to recent commit 5fff6115fea "Fix
LD_PRELOAD=/usr/lib64/libasan.so.6 gdb".

The declarations are provided by <new> (which is included) for c++14 onwards,
but they are missing for c++11.

Fix this by adding the missing declarations.

Tested on x86_64-linux, with gcc 7.5.0, both without (implying -std=gnu++14) and
with -std=c++11.

2 years ago[gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp
Tom de Vries [Thu, 11 Nov 2021 09:48:50 +0000 (10:48 +0100)]
[gdb/testsuite] Add gdb.arch/ppc64-break-on-_exit.exp

Add a regression test-case for commit a50bdb99afe "[gdb/tdep, rs6000] Don't
skip system call in skip_prologue":
- set a breakpoint on a local copy of glibc's _exit, and
- verify that it triggers.

The test-case uses an assembly file by default, but also has the possibility
to use a C source file instead.

Tested on ppc64le-linux.  Verified that the test-case fails without
aforementioned commit, and passes with the commit.  Both with assembly
and C source.

2 years agoRISC-V: Dump objects according to the elf architecture attribute.
Nelson Chu [Mon, 8 Nov 2021 08:35:25 +0000 (16:35 +0800)]
RISC-V: Dump objects according to the elf architecture attribute.

For now we should always generate the elf architecture attribute both for
elf and linux toolchains, so that we could dump the objects correctly
according to the generated architecture string.  This patch resolves the
problem that we probably dump an object with c.nop instructions, but
in fact the c extension isn't allowed.  Consider the following case,

nelson@LAPTOP-QFSGI1F2:~/test$ cat temp.s
.option norvc
.option norelax
.text
add     a0, a0, a0
.byte   0x1
.balign 16
nelson@LAPTOP-QFSGI1F2:~/test$ ~/binutils-dev/build-elf32-upstream/build-install/bin/riscv32-unknown-elf-as temp.s -o temp.o
nelson@LAPTOP-QFSGI1F2:~/test$ ~/binutils-dev/build-elf32-upstream/build-install/bin/riscv32-unknown-elf-objdump -d temp.o

temp.o:     file format elf32-littleriscv

Disassembly of section .text:

00000000 <.text>:
   0:   00a50533                add     a0,a0,a0
   4:   01                      .byte   0x01
   5:   00                      .byte   0x00
   6:   0001                    nop
   8:   00000013                nop
   c:   00000013                nop
nelson@LAPTOP-QFSGI1F2:~/test$ ~/binutils-dev/build-elf32-upstream/build-install/bin/riscv32-unknown-elf-readelf -A temp.o
Attribute Section: riscv
File Attributes
  Tag_RISCV_arch: "rv32i2p0_m2p0_a2p0_f2p0_d2p0"

The c.nop at address 0x6 is generated for alignment, but since the rvc isn't
allowed for this object, dump it as a c.nop instruction looks wrong.  After
applying this patch, I get the following result,

nelson@LAPTOP-QFSGI1F2:~/test$ ~/binutils-dev/build-elf32-upstream/build-install/bin/riscv32-unknown-elf-objdump -d temp.o

temp.o:     file format elf32-littleriscv

Disassembly of section .text:

00000000 <.text>:
   0:   00a50533                add     a0,a0,a0
   4:   01                      .byte   0x01
   5:   00                      .byte   0x00
   6:   0001                    .2byte  0x1
   8:   00000013                nop
   c:   00000013                nop

For the current objdump, we dump data to .byte/.short/.word/.dword, and
dump the unknown or unsupported instructions to .2byte/.4byte/.8byte, which
respectively are 2, 4 and 8 bytes instructions.  Therefore, we shouldn't
dump the 0x0001 as a c.nop instruction in the above case, we should dump
it to .2byte 0x1 as a unknown instruction, since the rvc is disabled.

However, consider that some people may use the new objdump to dump the old
objects, which don't have any elf attributes.  We usually set the default
architecture string to rv64g by bfd/elfxx-riscv.c:riscv_set_default_arch.
But this will cause rvc instructions to be unrecognized.  Therefore, we
set the default architecture string to rv64gc for disassembler, to keep
the previous behavior.

This patch pass the riscv-gnu-toolchain gcc/binutils regressions for
rv32emc-elf, rv32gc-linux, rv32i-elf, rv64gc-elf and rv64gc-linux
toolchains.  Also, tested by --enable-targets=all and can build
riscv-gdb successfully.

bfd/
* elfnn-riscv.c (riscv_merge_arch_attr_info): Tidy the
codes for riscv_parse_subset_t setting.
* elfxx-riscv.c (riscv_get_default_ext_version): Updated.
(riscv_subset_supports): Moved from gas/config/tc-riscv.c.
(riscv_multi_subset_supports): Likewise.
* elfxx-riscv.h: Added extern for riscv_subset_supports and
riscv_multi_subset_supports.
gas/
* config/tc-riscv.c (riscv_subset_supports): Moved to
bfd/elfxx-riscv.c.
(riscv_multi_subset_supports): Likewise.
(riscv_rps_as): Defined for architectrue parser.
(riscv_set_arch): Updated.
(riscv_set_abi_by_arch): Likewise.
(riscv_csr_address): Likewise.
(reg_lookup_internal): Likewise.
(riscv_ip): Likewise.
(s_riscv_option): Updated.
* testsuite/gas/riscv/mapping-04b.d: Updated.
* testsuite/gas/riscv/mapping-norelax-03b.d: Likewise.
* testsuite/gas/riscv/mapping-norelax-04b.d: Likewise.
opcodes/
* riscv-dis.c: Include elfxx-riscv.h since we need the
architecture parser.  Also removed the cpu-riscv.h, it
is already included in elfxx-riscv.h.
(default_isa_spec): Defined since the parser need this
to set the default architecture string.
(xlen): Moved out from riscv_disassemble_insn as a global
variable, it is more convenient to initialize riscv_rps_dis.
(riscv_subsets): Defined to recoed the supported
extensions.
(riscv_rps_dis): Defined for architectrue parser.
(riscv_disassemble_insn): Call riscv_multi_subset_supports
to make sure if the instructions are valid or not.
(print_insn_riscv): Initialize the riscv_subsets by parsing
the elf architectrue attribute.  Otherwise, set the default
architectrue string to rv64gc.

2 years agosim: testsuite: drop sim_compile cover function
Mike Frysinger [Thu, 11 Nov 2021 06:23:10 +0000 (01:23 -0500)]
sim: testsuite: drop sim_compile cover function

Most code isn't using this, and the only call site (in one cris file)
can use target_compile directly.  So switch it over to simplify.

2 years agosim: cris: stop testing a.out explicitly [ld/13900]
Mike Frysinger [Thu, 11 Nov 2021 05:25:16 +0000 (00:25 -0500)]
sim: cris: stop testing a.out explicitly [ld/13900]

Since gcc dropped support for a.out starting with 4.4.0 in 2009, it's
been impossible to verify this code actually still works.  Since it
crashes in ld, and it uses a config option that no other tests uses
and we want to remove, drop the test to avoid all the trouble.

2 years agosim: io: tweak compiler workaround with error output
Mike Frysinger [Thu, 11 Nov 2021 05:14:46 +0000 (00:14 -0500)]
sim: io: tweak compiler workaround with error output

Outputting an extra space broke a cris test.  Change the workaround
to use %s with an empty string to avoid the compiler warning but not
output an extra space.

2 years agosim: testsuite: delete unused arm remote host logic
Mike Frysinger [Thu, 11 Nov 2021 02:58:08 +0000 (21:58 -0500)]
sim: testsuite: delete unused arm remote host logic

There's no need to sync testutils.inc with remote hosts.  The one
we have in the source tree is all we need and only thing we test.
Delete it to simplify.

2 years agosim: synacor: simplify test generation
Mike Frysinger [Wed, 10 Nov 2021 06:10:00 +0000 (01:10 -0500)]
sim: synacor: simplify test generation

Objcopy was used to create a binary file of just the executable code
since the environment requires code to based at address 0.  We can
accomplish the same thing with the -Ttext=0 flag, so switch to that
to get rid of custom logic.

2 years agoAutomatic date update in version.in
GDB Administrator [Thu, 11 Nov 2021 00:00:35 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoHandle PIE in .debug_loclists
Tom Tromey [Wed, 10 Nov 2021 19:15:02 +0000 (12:15 -0700)]
Handle PIE in .debug_loclists

Simon pointed out that my recent patches to .debug_loclists caused
some regressions.  After a brief discussion we realized it was because
his system compiler defaults to PIE.

This patch changes this code to unconditionally apply the text offset
here.  It also changes loclist_describe_location to work more like
dwarf2_find_location_expression.

I tested this by running the gdb.dwarf2 tests both with and without
-pie.

2 years agoarm: enable Cortex-A710 CPU
Przemyslaw Wirkus [Wed, 10 Nov 2021 14:09:05 +0000 (14:09 +0000)]
arm: enable Cortex-A710 CPU

This patch is adding support for Cortex-A710 CPU in Arm.

bfd/

* cpu-arm.c (processors): Add cortex-a710.

gas/

* NEWS: Update docs.
* config/tc-arm.c (arm_cpus): Add cortex-a710 to -mcpu.
* doc/c-arm.texi: Update docs.
* testsuite/gas/arm/cpu-cortex-a710.d: New test.

2 years agogdb: adjust x_file fields on COFF readers
Clément Chigot [Wed, 10 Nov 2021 12:35:07 +0000 (13:35 +0100)]
gdb: adjust x_file fields on COFF readers

Commit e86fc4a5bc37 ("PR 28447: implement multiple parameters for .file
on XCOFF") changes the structure associated to the internal
representation of files in COFF formats.  However, gdb directory update
has been forgotten, leading to compilation errors of this kind:

      CXX    coffread.o
    /home/simark/src/binutils-gdb/gdb/coffread.c: In function 'const char* coff_getfilename(internal_auxent*)':
    /home/simark/src/binutils-gdb/gdb/coffread.c:1343:29: error: 'union internal_auxent::<unnamed struct>::<unnamed>' has no member named 'x_zeroes'
     1343 |   if (aux_entry->x_file.x_n.x_zeroes == 0)
          |                             ^~~~~~~~

Fix it by adjusting the COFF code in GDB.

Change-Id: I703fa134bc722d47515efbd72b88fa5650af6c3c

2 years ago[gdb/testsuite] Add gdb.opt/break-on-_exit.exp
Tom de Vries [Wed, 10 Nov 2021 11:55:55 +0000 (12:55 +0100)]
[gdb/testsuite] Add gdb.opt/break-on-_exit.exp

Add a test-case to excercise the problem scenario reported in PR28527 and
fixed in commit a50bdb99afe "[gdb/tdep, rs6000] Don't skip system call in
skip_prologue":
- set a breakpoint on _exit, and
- verify that it triggers.

Note that this is not a regression test for that commit.  Since the actual
code in _exit may vary across os instances, we cannot guarantee that the
problem will always trigger with this test-case.

Rather, this test-case is a version of the original test-case
(gdb.threads/process-dies-while-detaching.exp) that is minimal while still
reproducing the problem reported in PR28527, in that same setting.

The benefit of this test-case is that it exercise real-life code and may
expose similar problems in other settings.  Also, it provides a much easier
test-case to investigate in case a similar problem occurs.

Tested on x86_64-linux and ppc64le-linux.

2 years agosim: frv: flip trapdump default back to off
Mike Frysinger [Wed, 10 Nov 2021 10:15:33 +0000 (05:15 -0500)]
sim: frv: flip trapdump default back to off

When I refactored this by scoping it to sim-frv-xxx in commit
e7954ef5e5ed90fb7d28c013518f4c2e6bcd20a1 ("sim: frv: scope the
unique configure flag"), I changed the default from off to on.
While the feature is nice for developers, it breaks a bunch of
tests which aren't expecting this extra output.  So flip it back
to off by default.

2 years agoPR28575, readelf.c and strings.c use undefined type uint
Pekka Seppänen [Wed, 10 Nov 2021 09:45:19 +0000 (20:15 +1030)]
PR28575, readelf.c and strings.c use undefined type uint

Since --unicode support (commit b3aa80b45c4) both binutils/readelf.c
and binutils/strings.c use 'uint' in a few locations.  It likely
should be 'unsigned int' since there isn't anything defining 'uint'
within binutils (besides zlib) and AFAIK it isn't a standard type.

* readelf.c (print_symbol): Replace uint with unsigned int.
* strings.c (string_min, display_utf8_char): Likewise.
(print_unicode_stream_body, print_unicode_stream): Likewise.
(print_strings): Likewise.
(get_unicode_byte): Wrap long line.

2 years agold: set correct flags for AIX shared tests
Clément Chigot [Thu, 11 Mar 2021 10:08:17 +0000 (11:08 +0100)]
ld: set correct flags for AIX shared tests

Previous flags were aimed to be run with XLC.
Nowadays, only GCC is being tested with GNU toolchain. Moreover,
recent XLC versions might also accept "-shared".

* testsuite/ld-shared/shared.exp: Adjust shared flags.

2 years agoPR 28447: implement multiple parameters for .file on XCOFF
Clément Chigot [Fri, 15 Oct 2021 14:12:39 +0000 (16:12 +0200)]
PR 28447: implement multiple parameters for .file on XCOFF

On XCOFF, ".file" pseudo-op allows 3 extras parameters to provide
additional information to AIX linker, or its debugger. These are
stored in auxiliary entries of the C_FILE symbol.

bfd/
PR 28447
* coffcode.h (combined_entry_type): Add extrap field.
(coff_bigobj_swap_aux_in): Adjust names of x_file fields.
(coff_bigobj_swap_aux_out): Likewise.
* coffgen.c (coff_write_auxent_fname): New function.
(coff_fix_symbol_name): Write x_file using
 coff_write_auxent_fname.
(coff_write_symbol): Likewise.
(coff_write_symbols): Add C_FILE auxiliary entries to
string table if needed.
(coff_get_normalized_symtab): Adjust names of x_file fields.
Normalize C_FILE auxiliary entries.
(coff_print_symbol): Print C_FILE auxiliary entries.
* coff-rs6000.c (_bfd_xcoff_swap_aux_in): Adjust names of
x_file fields.
(_bfd_xcoff_swap_aux_out): Likewise.
* coff64-rs6000.c (_bfd_xcoff64_swap_aux_in): Likewise.
(_bfd_xcoff64_swap_aux_out): Likewise.
* cofflink.c (_bfd_coff_final_link): Likewise.
(_bfd_coff_link_input_bfd): Likewise.
* coffswap.h (coff_swap_aux_in): Likewise.
* peXXigen.c (_bfd_XXi_swap_aux_in): Likewise.
(_bfd_XXi_swap_aux_out): Likewise.
* xcofflink.c (xcoff_link_input_bfd): Likewise.
* libcoff.h: Regenerate.
gas/
* config/tc-ppc.c (ppc_file): New function.
* config/tc-ppc.h (OBJ_COFF_MAX_AUXENTRIES): Change to 4.
* testsuite/gas/ppc/aix.exp: Add tests.
* testsuite/gas/ppc/xcoff-file-32.d: New test.
* testsuite/gas/ppc/xcoff-file-64.d: New test.
* testsuite/gas/ppc/xcoff-file.s: New test.
include/
* coff/internal.h (union internal_auxent): Change x_file to be a
  struct instead of a union. Add x_ftype field.
* coff/rs6000.h (union external_auxent): Add x_resv field.
* coff/xcoff.h (XFT_FN): New define.
(XFT_CT): Likewise.
(XFT_CV): Likewise.
(XFT_CD): Likewise.

2 years agoTest case for Bug 28308
Kevin Buettner [Sat, 2 Oct 2021 00:14:00 +0000 (17:14 -0700)]
Test case for Bug 28308

The purpose of this test is described in the comments in
dprintf-execution-x-script.exp.

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

The name of this new test was based on that of an existing test,
bp-cmds-execution-x-script.exp.  I started off by copying that test,
adding to it, and then rewriting almost all of it.  It's different
enough that I decided that listing the copyright year as 2021
was sufficient.

2 years agoFix PR 28308 - dprintf breakpoints not working when run from script
Kevin Buettner [Sat, 2 Oct 2021 00:01:17 +0000 (17:01 -0700)]
Fix PR 28308 - dprintf breakpoints not working when run from script

This commit fixes Bug 28308, titled "Strange interactions with
dprintf and break/commands":

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

Since creating that bug report, I've found a somewhat simpler way of
reproducing the problem.  I've encapsulated it into the GDB test case
which I've created along with this bug fix.  The name of the new test
is gdb.base/dprintf-execution-x-script.exp, I'll demonstrate the
problem using this test case, though for brevity, I've placed all
relevant files in the same directory and have renamed the files to all
start with 'dp-bug' instead of 'dprintf-execution-x-script'.

The script file, named dp-bug.gdb, consists of the following commands:

dprintf increment, "dprintf in increment(), vi=%d\n", vi
break inc_vi
commands
  continue
end
run

Note that the final command in this script is 'run'.  When 'run' is
instead issued interactively, the  bug does not occur.  So, let's look
at the interactive case first in order to see the correct/expected
output:

$ gdb -q -x dp-bug.gdb dp-bug
... eliding buggy output which I'll discuss later ...
(gdb) run
Starting program: /mesquite2/sourceware-git/f34-master/bld/gdb/tmp/dp-bug
vi=0
dprintf in increment(), vi=0

Breakpoint 2, inc_vi () at dprintf-execution-x-script.c:26
26 in dprintf-execution-x-script.c
vi=1
dprintf in increment(), vi=1

Breakpoint 2, inc_vi () at dprintf-execution-x-script.c:26
26 in dprintf-execution-x-script.c
vi=2
dprintf in increment(), vi=2

Breakpoint 2, inc_vi () at dprintf-execution-x-script.c:26
26 in dprintf-execution-x-script.c
vi=3
[Inferior 1 (process 1539210) exited normally]

In this run, in which 'run' was issued from the gdb prompt (instead
of at the end of the script), there are three dprintf messages along
with three 'Breakpoint 2' messages.  This is the correct output.

Now let's look at the output that I snipped above; this is the output
when 'run' is issued from the script loaded via GDB's -x switch:

$ gdb -q -x dp-bug.gdb dp-bug
Reading symbols from dp-bug...
Dprintf 1 at 0x40116e: file dprintf-execution-x-script.c, line 38.
Breakpoint 2 at 0x40113a: file dprintf-execution-x-script.c, line 26.
vi=0
dprintf in increment(), vi=0

Breakpoint 2, inc_vi () at dprintf-execution-x-script.c:26
26 dprintf-execution-x-script.c: No such file or directory.
vi=1

Breakpoint 2, inc_vi () at dprintf-execution-x-script.c:26
26 in dprintf-execution-x-script.c
vi=2

Breakpoint 2, inc_vi () at dprintf-execution-x-script.c:26
26 in dprintf-execution-x-script.c
vi=3
[Inferior 1 (process 1539175) exited normally]

In the output shown above, only the first dprintf message is printed.
The 2nd and 3rd dprintf messages are missing!  However, all three
'Breakpoint 2...' messages are still printed.

Why does this happen?

bpstat_do_actions_1() in gdb/breakpoint.c contains the following
comment and code near the start of the function:

  /* Avoid endless recursion if a `source' command is contained
     in bs->commands.  */
  if (executing_breakpoint_commands)
    return 0;

  scoped_restore save_executing
    = make_scoped_restore (&executing_breakpoint_commands, 1);

Also, as described by this comment prior to the 'async' field
in 'struct ui' in top.h, the main UI starts off in sync mode
when processing command line arguments:

  /* True if the UI is in async mode, false if in sync mode.  If in
     sync mode, a synchronous execution command (e.g, "next") does not
     return until the command is finished.  If in async mode, then
     running a synchronous command returns right after resuming the
     target.  Waiting for the command's completion is later done on
     the top event loop.  For the main UI, this starts out disabled,
     until all the explicit command line arguments (e.g., `gdb -ex
     "start" -ex "next"') are processed.  */

This combination of things, the state of the static global
'executing_breakpoint_commands' plus the state of the async
field in the main UI causes this behavior.

This is a backtrace after hitting the dprintf breakpoint for
the second time when doing 'run' from the script file, i.e.
non-interactively:

Thread 1 "gdb" hit Breakpoint 3, bpstat_do_actions_1 (bsp=0x7fffffffc2b8)
    at /ironwood1/sourceware-git/f34-master/bld/../../worktree-master/gdb/breakpoint.c:4431
4431   if (executing_breakpoint_commands)

 #0  bpstat_do_actions_1 (bsp=0x7fffffffc2b8)
     at gdb/breakpoint.c:4431
 #1  0x00000000004d8bc6 in dprintf_after_condition_true (bs=0x1538090)
     at gdb/breakpoint.c:13048
 #2  0x00000000004c5caa in bpstat_stop_status (aspace=0x116dbc0, bp_addr=0x40116e, thread=0x137f450, ws=0x7fffffffc718,
     stop_chain=0x1538090) at gdb/breakpoint.c:5498
 #3  0x0000000000768d98 in handle_signal_stop (ecs=0x7fffffffc6f0)
     at gdb/infrun.c:6172
 #4  0x00000000007678d3 in handle_inferior_event (ecs=0x7fffffffc6f0)
     at gdb/infrun.c:5662
 #5  0x0000000000763cd5 in fetch_inferior_event ()
     at gdb/infrun.c:4060
 #6  0x0000000000746d7d in inferior_event_handler (event_type=INF_REG_EVENT)
     at gdb/inf-loop.c:41
 #7  0x00000000007a702f in handle_target_event (error=0, client_data=0x0)
     at gdb/linux-nat.c:4207
 #8  0x0000000000b8cd6e in gdb_wait_for_event (block=block@entry=0)
     at gdbsupport/event-loop.cc:701
 #9  0x0000000000b8d032 in gdb_wait_for_event (block=0)
     at gdbsupport/event-loop.cc:597
 #10 gdb_do_one_event () at gdbsupport/event-loop.cc:212
 #11 0x00000000009d19b6 in wait_sync_command_done ()
     at gdb/top.c:528
 #12 0x00000000009d1a3f in maybe_wait_sync_command_done (was_sync=0)
     at gdb/top.c:545
 #13 0x00000000009d2033 in execute_command (p=0x7fffffffcb18 "", from_tty=0)
     at gdb/top.c:676
 #14 0x0000000000560d5b in execute_control_command_1 (cmd=0x13b9bb0, from_tty=0)
     at gdb/cli/cli-script.c:547
 #15 0x000000000056134a in execute_control_command (cmd=0x13b9bb0, from_tty=0)
     at gdb/cli/cli-script.c:717
 #16 0x00000000004c3bbe in bpstat_do_actions_1 (bsp=0x137f530)
     at gdb/breakpoint.c:4469
 #17 0x00000000004c3d40 in bpstat_do_actions ()
     at gdb/breakpoint.c:4533
 #18 0x00000000006a473a in command_handler (command=0x1399ad0 "run")
     at gdb/event-top.c:624
 #19 0x00000000009d182e in read_command_file (stream=0x113e540)
     at gdb/top.c:443
 #20 0x0000000000563697 in script_from_file (stream=0x113e540, file=0x13bb0b0 "dp-bug.gdb")
     at gdb/cli/cli-script.c:1642
 #21 0x00000000006abd63 in source_gdb_script (extlang=0xc44e80 <extension_language_gdb>, stream=0x113e540,
     file=0x13bb0b0 "dp-bug.gdb") at gdb/extension.c:188
 #22 0x0000000000544400 in source_script_from_stream (stream=0x113e540, file=0x7fffffffd91a "dp-bug.gdb",
     file_to_open=0x13bb0b0 "dp-bug.gdb")
     at gdb/cli/cli-cmds.c:692
 #23 0x0000000000544557 in source_script_with_search (file=0x7fffffffd91a "dp-bug.gdb", from_tty=1, search_path=0)
     at gdb/cli/cli-cmds.c:750
 #24 0x00000000005445cf in source_script (file=0x7fffffffd91a "dp-bug.gdb", from_tty=1)
     at gdb/cli/cli-cmds.c:759
 #25 0x00000000007cf6d9 in catch_command_errors (command=0x5445aa <source_script(char const*, int)>,
     arg=0x7fffffffd91a "dp-bug.gdb", from_tty=1, do_bp_actions=false)
     at gdb/main.c:523
 #26 0x00000000007cf85d in execute_cmdargs (cmdarg_vec=0x7fffffffd1b0, file_type=CMDARG_FILE, cmd_type=CMDARG_COMMAND,
     ret=0x7fffffffd18c) at gdb/main.c:615
 #27 0x00000000007d0c8e in captured_main_1 (context=0x7fffffffd3f0)
     at gdb/main.c:1322
 #28 0x00000000007d0eba in captured_main (data=0x7fffffffd3f0)
     at gdb/main.c:1343
 #29 0x00000000007d0f25 in gdb_main (args=0x7fffffffd3f0)
     at gdb/main.c:1368
 #30 0x00000000004186dd in main (argc=5, argv=0x7fffffffd508)
     at gdb/gdb.c:32

There are two frames for bpstat_do_actions_1(), one at frame #16 and
the other at frame #0.  The one at frame #16 is processing the actions
for Breakpoint 2, which is a 'continue'.  The one at frame #0 is attempting
to process the dprintf breakpoint action.  However, at this point,
the value of 'executing_breakpoint_commands' is 1, forcing an early
return, i.e. prior to executing the command(s) associated with the dprintf
breakpoint.

For the sake of comparison, this is what the stack looks like when hitting
the dprintf breakpoint for the second time when issuing the 'run'
command from the GDB prompt.

Thread 1 "gdb" hit Breakpoint 3, bpstat_do_actions_1 (bsp=0x7fffffffccd8)
    at /ironwood1/sourceware-git/f34-master/bld/../../worktree-master/gdb/breakpoint.c:4431
4431   if (executing_breakpoint_commands)

 #0  bpstat_do_actions_1 (bsp=0x7fffffffccd8)
     at gdb/breakpoint.c:4431
 #1  0x00000000004d8bc6 in dprintf_after_condition_true (bs=0x16b0290)
     at gdb/breakpoint.c:13048
 #2  0x00000000004c5caa in bpstat_stop_status (aspace=0x116dbc0, bp_addr=0x40116e, thread=0x13f0e60, ws=0x7fffffffd138,
     stop_chain=0x16b0290) at gdb/breakpoint.c:5498
 #3  0x0000000000768d98 in handle_signal_stop (ecs=0x7fffffffd110)
     at gdb/infrun.c:6172
 #4  0x00000000007678d3 in handle_inferior_event (ecs=0x7fffffffd110)
     at gdb/infrun.c:5662
 #5  0x0000000000763cd5 in fetch_inferior_event ()
     at gdb/infrun.c:4060
 #6  0x0000000000746d7d in inferior_event_handler (event_type=INF_REG_EVENT)
     at gdb/inf-loop.c:41
 #7  0x00000000007a702f in handle_target_event (error=0, client_data=0x0)
     at gdb/linux-nat.c:4207
 #8  0x0000000000b8cd6e in gdb_wait_for_event (block=block@entry=0)
     at gdbsupport/event-loop.cc:701
 #9  0x0000000000b8d032 in gdb_wait_for_event (block=0)
     at gdbsupport/event-loop.cc:597
 #10 gdb_do_one_event () at gdbsupport/event-loop.cc:212
 #11 0x00000000007cf512 in start_event_loop ()
     at gdb/main.c:421
 #12 0x00000000007cf631 in captured_command_loop ()
     at gdb/main.c:481
 #13 0x00000000007d0ebf in captured_main (data=0x7fffffffd3f0)
     at gdb/main.c:1353
 #14 0x00000000007d0f25 in gdb_main (args=0x7fffffffd3f0)
     at gdb/main.c:1368
 #15 0x00000000004186dd in main (argc=5, argv=0x7fffffffd508)
     at gdb/gdb.c:32

This relatively short backtrace is due to the current UI's async field
being set to 1.

Yet another thing to be aware of regarding this problem is the
difference in the way that commands associated to dprintf breakpoints
versus regular breakpoints are handled.  While they both use a command
list associated with the breakpoint, regular breakpoints will place
the commands to be run on the bpstat chain constructed in
bp_stop_status().  These commands are run later on.  For dprintf
breakpoints, commands are run via the 'after_condition_true' function
pointer directly from bpstat_stop_status().  (The 'commands' field in
the bpstat is cleared in dprintf_after_condition_true().  This
prevents the dprintf commands from being run again later on when other
commands on the bpstat chain are processed.)

Another thing that I noticed is that dprintf breakpoints are the only
type of breakpoint which use 'after_condition_true'.  This suggests
that one possible way of fixing this problem, that of making dprintf
breakpoints work more like regular breakpoints, probably won't work.
(I must admit, however, that my understanding of this code isn't
complete enough to say why.  I'll trust that whoever implemented it
had a good reason for doing it this way.)

The comment referenced earlier regarding 'executing_breakpoint_commands'
states that the reason for checking this variable is to avoid
potential endless recursion when a 'source' command appears in
bs->commands.  We know that a dprintf command is constrained to either
1) execution of a GDB printf command, 2) an inferior function call of
a printf-like function, or 3) execution of an agent-printf command.
Therefore, infinite recursion due to a 'source' command cannot happen
when executing commands upon hitting a dprintf breakpoint.

I chose to fix this problem by having dprintf_after_condition_true()
directly call execute_control_commands().  This means that it no
longer attempts to go through bpstat_do_actions_1() avoiding the
infinite recursion check for potential 'source' commands on the
command chain.  I think it simplifies this code a little bit too, a
definite bonus.

Summary:

* breakpoint.c (dprintf_after_condition_true): Don't call
bpstat_do_actions_1().  Call execute_control_commands()
instead.

2 years agoRe: Add --unicode option
Alan Modra [Wed, 10 Nov 2021 01:26:46 +0000 (11:56 +1030)]
Re: Add --unicode option

* objdump: Whitespace fixes.
(long_options): Correct "ctf" entry.

2 years agoRe: Add --unicode option
Alan Modra [Tue, 9 Nov 2021 23:56:10 +0000 (10:26 +1030)]
Re: Add --unicode option

At low optimisation levels gcc may warn.

* strings.c (print_unicode_stream_body): Avoid bogus "may be
used unitialised" warning.

2 years agoAutomatic date update in version.in
GDB Administrator [Wed, 10 Nov 2021 00:00:22 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoPR28543, readelf entered an infinite loop
Alan Modra [Mon, 8 Nov 2021 22:32:22 +0000 (09:02 +1030)]
PR28543, readelf entered an infinite loop

This little tweak terminates fuzzed binary readelf output a little
quicker.

PR 28543
* dwarf.c (read_and_display_attr_value): Consume a byte when
form is unrecognized.

2 years agoPR28542, Undefined behaviours in readelf.c
Alan Modra [Mon, 8 Nov 2021 22:32:03 +0000 (09:02 +1030)]
PR28542, Undefined behaviours in readelf.c

PR 28542
* readelf.c (dump_relocations): Check that section headers have
been read before attempting to access section name.
(print_dynamic_symbol): Likewise.
(process_mips_specific): Delete dead code.

2 years agogdb::array_view slicing/container selftest - test std::array too
Pedro Alves [Tue, 9 Nov 2021 17:48:50 +0000 (17:48 +0000)]
gdb::array_view slicing/container selftest - test std::array too

Change-Id: I2141b0b8a09f6521a59908599eb5ba1a19b18dc6

2 years agogdb.debuginfod/fetch_src_and_symbols.exp: fix when GDB is built with AddressSanitizer
Simon Marchi [Tue, 2 Nov 2021 19:05:39 +0000 (15:05 -0400)]
gdb.debuginfod/fetch_src_and_symbols.exp: fix when GDB is built with AddressSanitizer

This test fails for me, showing:

    ERROR: tcl error sourcing /home/smarchi/src/binutils-gdb/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp.
    ERROR: This GDB was configured as follows:
       configure --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
                 --with-auto-load-dir=$debugdir:$datadir/auto-load
                 --with-auto-load-safe-path=$debugdir:$datadir/auto-load
    ... and much more ...

The problem is that TCL's exec throws an error as soon as the exec'ed
process outputs on stderr.  When GDB is built with ASan, it prints some
warnings about pre-existing signal handlers:

    warning: Found custom handler for signal 7 (Bus error) preinstalled.
    warning: Found custom handler for signal 8 (Floating point exception) preinstalled.
    warning: Found custom handler for signal 11 (Segmentation fault) preinstalled.

Pass --quiet to GDB to avoid these warnings.

Change-Id: I3751d89b9b1df646da19149d7cb86775e2d3e80f

2 years agoCorrectly handle DW_LLE_start_end
Tom Tromey [Mon, 8 Nov 2021 17:58:27 +0000 (10:58 -0700)]
Correctly handle DW_LLE_start_end

When the code to handle DW_LLE_start_end was added (as part of some
DWARF 5 work), it was written to add the base address.  However, this
seems incorrect -- the DWARF standard describes this as an address,
not an offset from the base address.

This patch changes a couple of spots in dwarf2/loc.c to fix this
problem.  It then changes decode_debug_loc_addresses to return
DEBUG_LOC_OFFSET_PAIR instead, which preserves the previous semantics.

This only showed up on the RISC-V target internally, due to the
combination of DWARF 5 and a newer version of GCC.  I've updated a
couple of existing loclists test cases to demonstrate the bug.

2 years agoFix build on rhES5
Tom Tromey [Wed, 12 May 2021 18:39:22 +0000 (12:39 -0600)]
Fix build on rhES5

The rhES5 build failed due to an upstream import a while back.  The
bug here is that, while the 'personality' function exists,
ADDR_NO_RANDOMIZE is only defined in <linux/personality.h>, not
<sys/personality.h>.

However, <linux/personality.h> does not declare the 'personality'
function, and <sys/personality.h> and <linux/personality.h> cannot
both be included.

This patch restores one of the removed configure checks and updates
the code to check it.

We had this as a local patch at AdaCore, because it seemed like there
was no interest upstream.  However, now it turns out that this fixes
PR build/28555, so I'm sending it now.

2 years agodoc/ctf-spec.texi: Remove "@validatemenus off"
H.J. Lu [Tue, 9 Nov 2021 13:35:42 +0000 (05:35 -0800)]
doc/ctf-spec.texi: Remove "@validatemenus off"

Remove @validatemenus from ctf-spec.texi, which has been removed from
texinfo by

commit a16dd1a9ece08568a1980b9a65a3a9090717997f
Author: Gavin Smith <gavinsmith0123@gmail.com>
Date:   Mon Oct 12 16:32:37 2020 +0100

    * doc/texinfo.texi
    (Writing a Menu, Customization Variables for @-Commands)
    (Command List),
    * doc/refcard/txirefcard.tex
    Remove @validatemenus.
    * tp/Texinfo/XS/Makefile.am (command_ids.h): Use gawk instead
    of awk.  Avoid discouraged "$p" usage, using "$(p)" instead.
    * tp/Texinfo/XS/configure.ac: Check for gawk.

commit 128acab3889b51809dc3bd3c6c74b61d13f7f5f4
Author: Gavin Smith <gavinsmith0123@gmail.com>
Date:   Thu Jan 3 14:51:53 2019 +0000

    Update refcard.

    * doc/refcard/txirefcard.tex: @setfilename is no longer
    mandatory.  Do not mention @validatemenus or explicitly giving
    @node pointers, as these are not very important features.

PR libctf/28567
* doc/ctf-spec.texi: Remove "@validatemenus off".

2 years agoAdd --unicode option to control how unicode characters are handled by display tools.
Nick Clifton [Tue, 9 Nov 2021 13:25:42 +0000 (13:25 +0000)]
Add --unicode option to control how unicode characters are handled by display tools.

* nm.c: Add --unicode option to control how unicode characters are
handled.
* objdump.c: Likewise.
* readelf.c: Likewise.
* strings.c: Likewise.
* binutils.texi: Document the new feature.
* NEWS: Document the new feature.
* testsuite/binutils-all/unicode.exp: New file.
* testsuite/binutils-all/nm.hex.unicode
* testsuite/binutils-all/strings.escape.unicode
* testsuite/binutils-all/objdump.highlight.unicode
* testsuite/binutils-all/readelf.invalid.unicode

2 years agosim: sh: simplify testsuite a bit
Mike Frysinger [Tue, 9 Nov 2021 06:22:06 +0000 (01:22 -0500)]
sim: sh: simplify testsuite a bit

Switch from the centralized list in the exp file to each test declaring
its own requirements which they're already (mostly) doing.  This will
increase coverage slightly by running more tests in more configurations
since the hardcoded exp list was a little out of date.

We have to mark the psh* tests as shdsp only (to match what the exp
file was doing), mark the fsca & fsrra tests as failing (since they
weren't even being run by the exp file), and to fix the expected
output & status of the fail test.

2 years agosim: cris: clean up missing func prototype warnings
Mike Frysinger [Tue, 9 Nov 2021 03:38:07 +0000 (22:38 -0500)]
sim: cris: clean up missing func prototype warnings

Move some unused funcs under existing #if 0 protection, mark a few
local funcs as static, and add missing prototypes for the rest which
are used from other files.  This fixes all the fatal warnings in the
mloop files so we can turn -Werror on here fully.

2 years agoAutomatic date update in version.in
GDB Administrator [Tue, 9 Nov 2021 00:00:18 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoImprove gdb::array_view ctor from contiguous containers
Lancelot SIX [Tue, 19 Oct 2021 21:51:40 +0000 (21:51 +0000)]
Improve gdb::array_view ctor from contiguous containers

While reading the interface of gdb::array_view, I realized that the
constructor that builds an array_view on top of a contiguous container
(such as std::vector, std::array or even gdb::array_view) can be
missused.

Lets consider the following code sample:

struct Parent
{
  Parent (int a): a { a } {}
  int a;
};

std::ostream &operator<< (std::ostream& os, const Parent & p)
{ os << "Parent {a=" << p.a << "}"; return os; }

struct Child : public Parent
{
  Child (int a, int b): Parent { a }, b { b } {}
  int b;
};

std::ostream &operator<< (std::ostream& os, const Child & p)
{ os << "Child {a=" << p.a << ", b=" << p.b << "}"; return os; }

template <typename T>
void print (const gdb::array_view<const T> &p)
{
  std::for_each (p.begin (), p.end (), [](const T &p) { std::cout << p << '\n'; });
}

Then with the current interface nothinng prevents this usage of
array_view to be done:

const std::array<Child, 3> elts = {
  Child {1, 2},
  Child {3, 4},
  Child {5, 6}
};
print_all<Parent> (elts);

This compiles fine and produces the following output:

Parent {a=1}
Parent {a=2}
Parent {a=3}

which is obviously wrong.  There is nowhere in memory a Parent-like
object for which the A member is 2 and this call to print_all<Parent>
shold not compile at all (calling print_all<Child> is however fine).

This comes down to the fact that a Child* is convertible into a Parent*,
and that an array view is constructed to a pointer to the first element
and a size.  The valid type pointed to that can be used with this
constructor are restricted using SFINAE, which requires that a
pointer to a member into the underlying container can be converted into a
pointer the array_view's data type.

This patch proposes to change the constraints on the gdb::array_view
ctor which accepts a container now requires that the (decayed) type of
the elements in the container match the (decayed) type of the array_view
being constructed.

Applying this change required minimum adjustment in GDB codebase, which
are also included in this patch.

Tested by rebuilding.

2 years agoAdd a const version of gdb_argv:as_array_view
Lancelot SIX [Tue, 19 Oct 2021 21:44:19 +0000 (21:44 +0000)]
Add a const version of gdb_argv:as_array_view

This commits adds const versions for the GET and AS_ARRAX_VIEW methods
of gdb_argv.  Those methods will be required in the following patch of
the series.

2 years agogdb: fix nulltr -> nullptr typo
Simon Marchi [Mon, 8 Nov 2021 21:45:30 +0000 (16:45 -0500)]
gdb: fix nulltr -> nullptr typo

Change-Id: I04403bd85ec3fa75ea14130d68daba675a2a8aeb

2 years agogdb: tweak scoped_disable_commit_resumed uses when resuming all threads in non-stop
Simon Marchi [Mon, 8 Nov 2021 21:42:45 +0000 (16:42 -0500)]
gdb: tweak scoped_disable_commit_resumed uses when resuming all threads in non-stop

When doing "continue -a" in non-stop mode, each thread is individually
resumed while the commit resumed state is enabled.  This forces the
target to commit each resumption immediately, instead of being able to
batch things.

The reason is that there is no scoped_disable_commit_resumed around the
loop over threads in continue_1, when "non_stop && all_threads" is true.
Since the proceed function is called once for each thread, the
scoped_disable_commit_resumed in proceed therefore forces commit-resumed
between each thread resumption.  Add the necessary
scoped_disable_commit_resumed in continue_1 to avoid that.

I looked at the MI side of things, the function exec_continue, and found
that it was correct.  There is a similar iteration over threads, and
there is a scoped_disable_commit_resumed at the function scope.  This is
not wrong, but a bit more than we need.  The branches that just call
continue_1 do not need it, as continue_1 takes care of disabling commit
resumed.  So, move the scoped_disable_commit_resumed to the inner scope
where we iterate on threads and proceed them individually.

Here's an example debugging a multi-threaded program attached by
gdbserver (debug output trimmed for brevity):

    $ ./gdb -nx -q --data-directory=data-directory -ex "set non-stop" -ex "tar rem :1234"
    (gdb) set debug remote
    (gdb) set debug infrun
    (gdb) c -a
    Continuing.
    [infrun] proceed: enter
      [infrun] scoped_disable_commit_resumed: reason=proceeding
      [remote] Sending packet: $vCont;c:p14388.14388#90
      [infrun] reset: reason=proceeding
      [infrun] maybe_set_commit_resumed_all_targets: enabling commit-resumed for target remote
      [infrun] maybe_call_commit_resumed_all_targets: calling commit_resumed for target remote
    [infrun] proceed: exit
    [infrun] proceed: enter
      [infrun] scoped_disable_commit_resumed: reason=proceeding
      [remote] Sending packet: $vCont;c:p14388.1438a#b9
      [infrun] reset: reason=proceeding
      [infrun] maybe_set_commit_resumed_all_targets: enabling commit-resumed for target remote
      [infrun] maybe_call_commit_resumed_all_targets: calling commit_resumed for target remote
    [infrun] proceed: exit
    ... and so on for each thread ...

Notice how we send one vCont;c for each thread.  With the patch applied, we
send a single vCont;c at the end:

    [infrun] scoped_disable_commit_resumed: reason=continue all threads in non-stop
    [infrun] proceed: enter
      [infrun] scoped_disable_commit_resumed: reason=proceeding
      [infrun] reset: reason=proceeding
    [infrun] proceed: exit
    [infrun] clear_proceed_status_thread: Thread 85790.85792
    [infrun] proceed: enter
      [infrun] scoped_disable_commit_resumed: reason=proceeding
      [infrun] reset: reason=proceeding
    [infrun] proceed: exit
    ... proceeding threads individually ...
    [infrun] reset: reason=continue all threads in non-stop
    [infrun] maybe_set_commit_resumed_all_targets: enabling commit-resumed for target remote
    [infrun] maybe_call_commit_resumed_all_targets: calling commit_resumed for target remote
    [remote] Sending packet: $vCont;c#a8

Change-Id: I331dd2473c5aa5114f89854196fed2a8fdd122bb

2 years agogdb: make dwarf2_find_containing_comp_unit take a dwarf2_per_bfd
Simon Marchi [Mon, 8 Nov 2021 21:40:59 +0000 (16:40 -0500)]
gdb: make dwarf2_find_containing_comp_unit take a dwarf2_per_bfd

While reading another patch, I saw that this function didn't need to
take a dwarf2_per_objfile, but could take a dwarf2_per_bfd instead.
It doesn't change the behavior, but doing this shows that this function
is objfile-independent (can work with only the shared per-bfd data).

Change-Id: I58f9c9cef6688902e95226480285da2d0005d77f

2 years agogdb: remove bpstat typedef, rename bpstats to bpstat
Simon Marchi [Fri, 5 Nov 2021 19:29:20 +0000 (15:29 -0400)]
gdb: remove bpstat typedef, rename bpstats to bpstat

I don't find that the bpstat typedef, which hides a pointer, is
particularly useful.  In fact, it confused me many times, and I just see
it as something to remember that adds cognitive load.  Also, with C++,
we might want to be able to pass bpstats objects by const-reference, not
necessarily by pointer.

So, remove the bpstat typedef and rename struct bpstats to bpstat (since
it represents one bpstat, it makes sense that it is singular).

Change-Id: I52e763b6e54ee666a9e045785f686d37b4f5f849

2 years agolibctf: add CTF format specification
Nick Alcock [Mon, 8 Nov 2021 18:31:38 +0000 (18:31 +0000)]
libctf: add CTF format specification

It's been a long time since most of this was written: it's long past
time to put it in the binutils source tree.  It's believed correct and
complete insofar as it goes: it documents format v3 (the current
version) but not the libctf API or any earlier versions.  (The
earlier versions can be read by libctf but not generated by it, and you
are highly unlikely ever to see an example of any of them.)

libctf/ChangeLog
2021-11-08  Nick Alcock  <nick.alcock@oracle.com>

* doc/ctf-spec.texi: New file.
* configure.ac (MAKEINFO): Add.
(BUILD_INFO): Likewise.
(AC_CONFIG_FILES) [doc/Makefile]: Add.
* Makefile.am [BUILD_INFO] (SUBDIRS): Add doc/.
* doc/Makefile.am: New file.
* doc/Makefile.in: Likewise.
* configure: Regenerated.
* Makefile.in: Likewise.

2 years agoAutomatic date update in version.in
GDB Administrator [Mon, 8 Nov 2021 00:00:10 +0000 (00:00 +0000)]
Automatic date update in version.in

2 years agoCorrect ld script wildcard matching description
Alan Modra [Sun, 7 Nov 2021 21:49:34 +0000 (08:19 +1030)]
Correct ld script wildcard matching description

Goes with commit 68bbb9f788d0

* ld.texi (Input Section Wildcards): Delete paragraph incorrectly
saying '*' does not match '/'.

2 years agosim: sh: fix conversion of PC to an integer
Mike Frysinger [Sun, 7 Nov 2021 01:09:08 +0000 (21:09 -0400)]
sim: sh: fix conversion of PC to an integer

On LLP64 targets where sizeof(long) != sizeof(void*), this code fails:
sim/sh/interp.c:704:24: error: cast from pointer to integer of different size  -Werror=pointer-to-int-cast]
  704 |   do { memstalls += ((((long) PC & 3) != 0) ? (n) : ((n) - 1)); } while (0)
      |                        ^

Since this code simply needs to check alignment, cast it using uintptr_t
which is the right type for this.

2 years agosim: sh: clean up time(NULL) call
Mike Frysinger [Sun, 7 Nov 2021 01:06:47 +0000 (21:06 -0400)]
sim: sh: clean up time(NULL) call

Casting 0 to a pointer via (long *) doesn't work on LLP64 targets:
error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

It's also unnecessary here.  We can simply pass NULL like every other
bit of code does.

2 years agosim: sh: break utime logic out of _WIN32 check
Mike Frysinger [Sun, 7 Nov 2021 01:01:41 +0000 (21:01 -0400)]
sim: sh: break utime logic out of _WIN32 check

Some _WIN32 targets provide utime (like mingw), so move the header
include out from _WIN32 and under the specific HAVE_UTIME_H check.

2 years agosim: sh: drop errno extern
Mike Frysinger [Sun, 7 Nov 2021 00:59:17 +0000 (20:59 -0400)]
sim: sh: drop errno extern

This isn't needed on any reasonable target nowadays, and no other
source does this, and breaks with some mingw targets, so punt the
extern entirely.

2 years agosim: sh: fix isnan redefinition with mingw targets
Mike Frysinger [Sun, 7 Nov 2021 00:57:32 +0000 (20:57 -0400)]
sim: sh: fix isnan redefinition with mingw targets

The code assumes that all _WIN32 targets are the same and can
define isnan to _isnan.  For mingw targets, they provide an isnan
define already, so no need for the fallback here.

2 years agosim: arm/bfin/rx: undefine page size from system headers
Mike Frysinger [Sun, 7 Nov 2021 00:40:20 +0000 (20:40 -0400)]
sim: arm/bfin/rx: undefine page size from system headers

Some targets (like cygwin) will export page size defines that clash
with our local usage here.  Undefine the system one to fix building
for these targets.

2 years agosim: ppc: switch to libiberty environ.h
Mike Frysinger [Sun, 7 Nov 2021 00:35:52 +0000 (20:35 -0400)]
sim: ppc: switch to libiberty environ.h

Drop our compat code and assume environ exists to simplify.
We did this for all other targets already, but ppc was missed.

2 years agosim: sh: enable -Werror everywhere
Mike Frysinger [Sat, 6 Nov 2021 17:23:17 +0000 (13:23 -0400)]
sim: sh: enable -Werror everywhere

With most of the warnings fixed in interp.c, we can enable -Werror
here too now.  There are some -Wmaybe-uninitialized warnings still
lurking that look legitimate, but we don't flag those are fatal,
and I don't have the expertise to dive into each opcode to figure
out the right way to clean them up.

2 years agosim: sh: fix uninitialized variable usage with pdmsb
Mike Frysinger [Sat, 6 Nov 2021 17:19:35 +0000 (13:19 -0400)]
sim: sh: fix uninitialized variable usage with pdmsb

This block of code relies on i to control which bits to test and how
many times to run through the loop, but it never actually initialized
it.  There is another chunk of code that handles the pdmsb instruction
that sets i to 16, so use that here too assuming it's correct.  The
programming manual suggests this is the right value too, but I am by
no means a SuperH DSP expert.  The tests are still passing though ...

2 years agosim: sh: constify a few read-only lookup tables
Mike Frysinger [Sat, 6 Nov 2021 17:14:46 +0000 (13:14 -0400)]
sim: sh: constify a few read-only lookup tables

2 years agosim: sh: fix various parentheses warnings
Mike Frysinger [Sat, 6 Nov 2021 17:03:47 +0000 (13:03 -0400)]
sim: sh: fix various parentheses warnings

Add parentheses to a bunch of places where the compiler suggests we
do to avoid confusion to most readers.

2 years agosim: sh: fix unused-value warnings
Mike Frysinger [Sat, 6 Nov 2021 16:52:00 +0000 (12:52 -0400)]
sim: sh: fix unused-value warnings

These macro expansions are deliberate in not using the computed value
so that they trigger side-effects (possible invalid memory accesses)
but while otherwise being noops.  Add a (void) cast so the compiler
knows these are intentional.

2 years agosim: sh: rework register layout with anonymous unions & structs
Mike Frysinger [Sat, 6 Nov 2021 16:44:56 +0000 (12:44 -0400)]
sim: sh: rework register layout with anonymous unions & structs

Now that we require C11, we can leverage anonymous unions & structs
to fix a long standing issue with the SH register layout.  The use
of sregs.i for sh-dsp has generated a lot of compiler warnings about
the access being out of bounds -- it only has 7 elements declared,
but code goes beyond that to reach into the fregs that follow.  But
now that we have anonymous unions, we can reduce the nested names
and have sregs cover all of these registers.