]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
18 months agoBail out of "attach" if a thread cannot be traced
Tom Tromey [Fri, 8 Sep 2023 14:25:15 +0000 (08:25 -0600)] 
Bail out of "attach" if a thread cannot be traced

On Linux, threads are treated much like separate processes by the
kernel.  In particular, it's possible to ptrace just a single thread.
If gdb tries to attach to a multi-threaded inferior, where a non-main
thread is already being traced (e.g., by strace), then gdb will get
into an infinite loop attempting to attach.

This patch fixes this problem by having the attach fail if ptrace
fails to attach to any thread of the inferior.

18 months agoUse gdb_dir_up in linux_proc_attach_tgid_threads
Tom Tromey [Thu, 7 Sep 2023 15:04:37 +0000 (09:04 -0600)] 
Use gdb_dir_up in linux_proc_attach_tgid_threads

This changes linux_proc_attach_tgid_threads to use gdb_dir_up.  This
makes it robust against exceptions.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
18 months agoMinor cleanup in linux_proc_attach_tgid_threads
Tom Tromey [Thu, 7 Sep 2023 15:03:43 +0000 (09:03 -0600)] 
Minor cleanup in linux_proc_attach_tgid_threads

linux_proc_attach_tgid_threads computes a file name, and then
re-computes it for a warning.  It is better to reuse the
already-computed name here.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
18 months agogdb: add missing regcache_map_entry array null terminators in aarch64-linux-tdep.c
Simon Marchi [Wed, 29 Nov 2023 16:35:23 +0000 (11:35 -0500)] 
gdb: add missing regcache_map_entry array null terminators in aarch64-linux-tdep.c

Fix two spots in aarch64-linux-tdep.c that build regcache_map_entry
arrays without a null terminator.  The null terminators are needed for
regcache::transfer_regset and regcache_map_entry_size to work properly.

Change-Id: I3224a314e1360b319438f32de8c81e70ab42e105
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Luis Machado <luis.machado@arm.com>
18 months agogdb: return when exceeding buffer size in regcache::transfer_regset
Simon Marchi [Tue, 28 Nov 2023 19:48:57 +0000 (14:48 -0500)] 
gdb: return when exceeding buffer size in regcache::transfer_regset

regcache::transfer_regset iterates over an array of regcache_map_entry,
transferring the registers (between regcache and buffer) described by
those entries.  It stops either when it reaches the end of the
regcache_map_entry array (marked by a null entry) or (it seems like the
intent is) when it reaches the end of the buffer (in which case not all
described registers are transferred).

I said "seems like the intent is", because there appears to be a small
bug.  transfer_regset is made of two loops:

    foreach regcache_map_entry:
      foreach register described by the regcache_map_entry:
        if the register doesn't fit in the remainder of the buffer:
  break

        transfer register

When stopping because we have reached the end of the buffer, the break
only breaks out of the inner loop.

This problem causes some failures when I run tests such as
gdb.arch/aarch64-sme-core-3.exp (on AArch64 Linux, in qemu).  This is
partly due to aarch64_linux_iterate_over_regset_sections failing to add
a null terminator in its regcache_map_entry array, but I think there is
still a problem in transfer_regset.

The sequence to the crash is:

 - The `regcache_map_entry za_regmap` object built in
   aarch64_linux_iterate_over_regset_sections does not have a null
   terminator.
 - When the target does not have a ZA register,
   aarch64_linux_collect_za_regset calls `regcache->collect_regset` with
   a size of 0 (it's actually pointless, but still it should work).
 - transfer_regset gets called with a buffer size of 0.
 - transfer_regset detects that the register to transfer wouldn't fit in
   0 bytes, so it breaks out of the inner loop.
 - The outer loop tries to go read the next regcache_map_entry, but
   there isn't one, and we start reading garbage.

Obviously, this would get fixed by making
aarch64_linux_iterate_over_regset_sections use a null terminator (which
is what the following patch does).  But I think that when detecting that
there is not enough buffer left for the current register,
transfer_regset should return, not only break out of the inner loop.

This is a kind of contrived scenario, but imagine we have these two
regcache_map_entry objects:

  - 2 registers of 8 bytes
  - 2 registers of 4 bytes

For some reason, the caller passes a buffer of 12 bytes.
transfer_regset will detect that the second 8 byte register does not
fit, and break out of the inner loop.  However, it will then go try the
next regcache_map_entry.  It will see that it can fit one 4 byte
register in the remaining buffer space, and transfer it from/to there.
This is very likely not an expected behavior, we wouldn't expect to
read/write this sequence of registers from/to the buffer.

In this example, whether passing a 12 bytes buffer makes sense or
whether it is a size computation bug in the caller, we don't know, but I
think that exiting as soon as a register doesn't fit is the sane thing
to do.

Change-Id: Ia349627d2e5d281822ade92a8e7a4dea4f839e07
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
Reviewed-By: Luis Machado <luis.machado@arm.com>
18 months agoAdd link to Debugger Adapter Protocol node in documentation
Tom Tromey [Thu, 30 Nov 2023 19:27:04 +0000 (12:27 -0700)] 
Add link to Debugger Adapter Protocol node in documentation

I noticed that the interpreters node in the docs links to the DAP
protocol docs, but I thought the DAP node ought to as well.  This
patch adds a bit of introductory text there.

Approved-By: Eli Zaretskii <eliz@gnu.org>
18 months agoFix right shifts in mcore simulator on 64 bit hosts.
Jeff Law [Fri, 1 Dec 2023 14:19:50 +0000 (07:19 -0700)] 
Fix right shifts in mcore simulator on 64 bit hosts.

If the value to be shifted has the sign bit set, the sign
bit would get copied into bits 32..63 of the temporary.  Those
would then be right shifted into the final value giving an
incorrect final result.

This was observed with upcoming GCC improvements which eliminate
unnecessary extensions.

18 months agogdb/testsuite: fix completion tests when using READ1
Guinevere Larsen [Wed, 26 Jul 2023 08:08:10 +0000 (10:08 +0200)] 
gdb/testsuite: fix completion tests when using READ1

The commit a3da2e7e550c4fe79128b5e532dbb90df4d4f418 has introduced
regressions when testing using the READ1 mechanism. The reason for that
is the new failure path in proc test_gdb_complete_tab_unique, which
looks for GDB suggesting more than what the test inputted, but not the
correct answer, followed by a white space. Consider the following case:

int foo(int bar, int baz);

Sending the command "break foo<tab>" to GDB will return

break foo(int, int)

which easily fits the buffer in normal testing, so everything works, but
when reading one character at a time, the test will find the partial
"break foo(int, " and assume that there was a mistake, so we get a
spurious FAIL.

That change was added because we wanted to avoid forcing a completion
failure to fail through timeout, which it had to do because there is no
way to verify that the output is done, mostly because when I was trying
to solve a different problem I kept getting reading errors and testing
completion was frustrating.

This commit implements a better way to avoid that frustration, by first
testing gdb's complete command and only if that passes we will test tab
completion. The difference is that when testing with the complete
command, we can tell when the output is over when we receive the GDB
prompt again, so we don't need to rely on timeouts. With this, the
change to test_gdb_complete_tab_unique has been removed as that test
will only be run and fail in the very unlikely scenario that tab
completion is different than command completion.

Approved-By: Andrew Burgess <aburgess@redhat.com>
18 months agoRemove unnecessary returns and unused variables in AIX.
Aditya Vidyadhar Kamath [Fri, 1 Dec 2023 07:43:04 +0000 (01:43 -0600)] 
Remove unnecessary returns and unused variables in AIX.

This is a patch to simplify the pd_activate () in aix-thread.c incase of a failure to start a thread session
, since pd_activate () now has return type void.

Also this patch fixes the shadow declarartion warning in sync-threadlists.

18 months agoFix: nm -U short flag erroneously consumes argument
Nick Clifton [Fri, 1 Dec 2023 09:52:11 +0000 (09:52 +0000)] 
Fix: nm -U short flag erroneously consumes argument

  PR 31105
  * nm.c (main): Remove spurious colon after U in the call to getopt_long

18 months agold: fix build with old makeinfo
Jan Beulich [Fri, 1 Dec 2023 09:13:36 +0000 (10:13 +0100)] 
ld: fix build with old makeinfo

Makeinfo 4.12 is unhappy about the new "Special Sections" without that
also having a @chapter line.

18 months agobinutils/Dwarf: avoid "shadowing" of glibc function name
Jan Beulich [Fri, 1 Dec 2023 09:13:17 +0000 (10:13 +0100)] 
binutils/Dwarf: avoid "shadowing" of glibc function name

Yet once again: Old enough glibc has an (unguarded) declaration of
index() in string.h, which triggers a "shadows a global declaration"
warning with at least some gcc versions.

18 months agogas: drop unused fields from struct segment_info_struct
Jan Beulich [Fri, 1 Dec 2023 07:29:33 +0000 (08:29 +0100)] 
gas: drop unused fields from struct segment_info_struct

user_stuff, dot, and lineno_list_{head,tail} have no users (left), while
bfd_section was only ever written.

18 months agox86: adjust NOP generation after potential non-insn
Jan Beulich [Fri, 1 Dec 2023 07:29:11 +0000 (08:29 +0100)] 
x86: adjust NOP generation after potential non-insn

Just like avoiding to do certain transformations potentially affected by
stand-alone prefixes or direct data emission, also avoid emitting
optimized NOPs right afterwards; insert a plain old NOP first in such
cases.

18 months agox86: i386_cons_align() badly affects diagnostics
Jan Beulich [Fri, 1 Dec 2023 07:28:45 +0000 (08:28 +0100)] 
x86: i386_cons_align() badly affects diagnostics

Warning without knowing what's going to follow isn't useful, the more
that appropriate warnings are emitted elsewhere in all cases. Not
updating state (file/line in particular) also isn't helpful, as it's
always the last directive ahead of a construct potentially needing
fiddling with that's "guilty" in that fiddling being suppressed.

18 months agogas: no md_cons_align() for .nop{,s}
Jan Beulich [Fri, 1 Dec 2023 07:28:20 +0000 (08:28 +0100)] 
gas: no md_cons_align() for .nop{,s}

.nop and .nops generate code, not data. Hence them invoking
md_cons_align() is at best inappropriate. In fact it actually gets in
the of x86'es state maintenance involving i386_cons_align().

18 months agox86: suppress optimization after potential non-insn
Jan Beulich [Fri, 1 Dec 2023 07:27:49 +0000 (08:27 +0100)] 
x86: suppress optimization after potential non-insn

Just like avoiding to do other transformations potentially affected by
stand-alone prefixes or direct data emission, also avoid optimization
on the following insn.

18 months agox86: last-insn recording should be per-section
Jan Beulich [Fri, 1 Dec 2023 07:27:22 +0000 (08:27 +0100)] 
x86: last-insn recording should be per-section

Otherwise intermediate section switches result in inconsistent behavior.
Note, however, that intermediate sub-section switches will continue to
result in inconsistent or even inappropriate behavior.

While there also add recording of state to s_insn().

18 months agox86: allow 32-bit reg to be used with U{RD,WR}MSR
Jan Beulich [Fri, 1 Dec 2023 07:26:36 +0000 (08:26 +0100)] 
x86: allow 32-bit reg to be used with U{RD,WR}MSR

... as MSR index specifier: It is unreasonable to demand that people
write less readable / understandable code, just because the present
documentation mentions only Reg64. Whether to also adjust the
disassembler is a separate question, perhaps indeed more tightly tied
to what the spec says.

18 months agogdb: fix warnings about invalid [[fallthrough]] usage
Simon Marchi [Thu, 30 Nov 2023 20:59:16 +0000 (15:59 -0500)] 
gdb: fix warnings about invalid [[fallthrough]] usage

Fix these two warnings, when building on macos:

      CXX    cp-name-parser.o
    /Users/smarchi/src/binutils-gdb/gdb/cp-name-parser.y:1644:7: error: fallthrough annotation does not directly precede switch label
          [[fallthrough]];
          ^

      CXX    dbxread.o
    /Users/smarchi/src/binutils-gdb/gdb/dbxread.c:2809:7: error: fallthrough annotation does not directly precede switch label
          [[fallthrough]];
          ^

In these two cases, we [[fallthrough]], followed by a regular label,
followed by a case label.  Move the [[fallthrough]] below the regular
label.

Change-Id: If4a3145139e050bdb6950c7f239badd5778e6f64
Approved-By: Tom Tromey <tom@tromey.com>
18 months agoRISC-V: Make riscv_is_mapping_symbol stricter
Patrick O'Neill [Fri, 1 Dec 2023 02:47:39 +0000 (18:47 -0800)] 
RISC-V: Make riscv_is_mapping_symbol stricter

riscv_is_mapping_symbol currently accepts any symbol that starts with $x
or $d. This patch makes the check more strict, requiring exactly $x, $d,
or $xrv. It also makes use of this stricter mapping in
riscv_is_valid_mapping_symbol.

ChangeLog:

* bfd/cpu-riscv.c (riscv_elf_is_mapping_symbols): Match only
strings that are exactly $x, $d, or $xrv.
* opcodes/riscv-dis.c (riscv_is_valid_mapping_symbol): Use
riscv_elf_is_mapping_symbols.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
18 months agoRISC-V: Update gas/NEWS for RISC-V vendor extension news.
Nelson Chu [Fri, 1 Dec 2023 01:25:19 +0000 (09:25 +0800)] 
RISC-V: Update gas/NEWS for RISC-V vendor extension news.

gas/
* NEWS: Update RISC-V vendor extension news.

18 months agoRISC-V: Add SiFive custom vector coprocessor interface instructions v1.0
Nelson Chu [Fri, 24 Nov 2023 07:46:56 +0000 (15:46 +0800)] 
RISC-V: Add SiFive custom vector coprocessor interface instructions v1.0

SiFive has define as set of flexible instruction for extending vector
coprocessor, it able to encoding opcode like .insn but with predefined
format.

List of instructions:
  sf.vc.x
  sf.vc.i
  sf.vc.vv
  sf.vc.xv
  sf.vc.iv
  sf.vc.fv
  sf.vc.vvv
  sf.vc.xvv
  sf.vc.ivv
  sf.vc.fvv
  sf.vc.vvw
  sf.vc.xvw
  sf.vc.ivw
  sf.vc.fvw
  sf.vc.v.x
  sf.vc.v.i
  sf.vc.v.vv
  sf.vc.v.xv
  sf.vc.v.iv
  sf.vc.v.fv
  sf.vc.v.vvv
  sf.vc.v.xvv
  sf.vc.v.ivv
  sf.vc.v.fvv
  sf.vc.v.vvw
  sf.vc.v.xvw
  sf.vc.v.ivw
  sf.vc.v.fvw

Spec of Xsfvcp
https://www.sifive.com/document-file/sifive-vector-coprocessor-interface-vcix-software

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Kito Cheng <kito.cheng@sifive.com>
18 months agoRISC-V: Zv*: Add support for Zvkb ISA extension
Christoph Müllner [Thu, 23 Nov 2023 00:04:47 +0000 (01:04 +0100)] 
RISC-V: Zv*: Add support for Zvkb ISA extension

Back then when the support for the RISC-V vector crypto extensions
was merged, the specification was frozen, but not ratified.
A frozen specification is allowed to change within tight bounds
before ratification and this has happend with the vector crypto
extensions.

The following changes were applied:
* A new extension Zvkb was defined, which is a strict subset of Zvbb.
* Zvkn and Zvks include now Zvkb instead of Zvbb.

This patch implements these changes between the frozen and the
ratified specification.

Note, that this technically an incompatible change of Zvkn and Zvks,
but I am not aware of any project that depends on the currently
implemented behaviour of Zvkn and Zvks. So this patch should be fine.

Reported-By: Jerry Shih <jerry.shih@sifive.com>
Reported-By: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
18 months agoAutomatic date update in version.in
GDB Administrator [Fri, 1 Dec 2023 00:00:13 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months ago[gdb/build] Fix adding -DNDEBUG to python flags of release build
Tom de Vries [Thu, 30 Nov 2023 20:31:46 +0000 (21:31 +0100)] 
[gdb/build] Fix adding -DNDEBUG to python flags of release build

In gdb/configure the line:
...
    $development || tentative_python_cflags="$tentative_python_cflags -DNDEBUG"
...
intends to ensure that -DNDEBUG is added to the python flags of a release
build.

However, when building gdb-14-branch we have:
...
configure:22024: checking compiler flags for python code
  ...
configure:22047: result:  -fno-strict-aliasing -fwrapv
...

This is a regression since commit db6878ac553 ("Move sourcing of development.sh
to GDB_AC_COMMON"), which introduced a reference before assignment:
...
    $development || tentative_python_cflags="$tentative_python_cflags -DNDEBUG"
  ...
. $srcdir/../bfd/development.sh
...
and consequently -DNDEBUG is never added.

[ This was not obvious to me, but apparently evaluating an empty or undefined
variable in this context is similar to using ':' or 'true', so the line is
evaluated as:
...
    true || tentative_python_cflags="$tentative_python_cflags -DNDEBUG"
... ]

Fix this by moving GDB_AC_COMMON up in gdb/configure.ac, similar to how that
was done for gdbserver/configure.ac in commit db6878ac553.

[ Unfortunately, the move might introduce issues similar to the one we're
fixing, and I'm not sure how to check for this.  Shellcheck doesn't detect
this type of problem.  FWIW, I did run shellcheck (using arguments -xa, in the
src/gdb directory to make sure ../bfd/development.sh is taken into account)
before and after and observed that the number of lines/words/chars in the
shellcheck output is identical. ]

Build & tested on top of trunk.

Also build on top of gdb-14-branch, and observed this in gdb/config.log:
...
configure:25214: checking compiler flags for python code
  ...
configure:25237: result:  -fno-strict-aliasing -fwrapv -DNDEBUG
...

Approved-By: Tom Tromey <tom@tromey.com>
PR build/31099
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31099

18 months agoMIPS/GAS: Add -march=loongson2f to loongson-2f-3 test
YunQiang Su [Fri, 24 Nov 2023 06:35:12 +0000 (14:35 +0800)] 
MIPS/GAS: Add -march=loongson2f to loongson-2f-3 test

On MIPSr6, the encoding of JR instruction has been chaned.
This patch can fix these failures for r6 default triples:
ST Microelectronics Loongson-2F workarounds of Jump Instruction issue

18 months agoMIPS: Set r6 as default arch if vendor is img
YunQiang Su [Fri, 24 Nov 2023 09:39:55 +0000 (17:39 +0800)] 
MIPS: Set r6 as default arch if vendor is img

This behavior is used by downstream toolchain since 2014,
and has been in GCC since the same year.

We don't support mips64*-img* due to GCC doesn't support it,
and we believe that the multilib should be used for this case.

18 months agoFix procfs.c compilation
Rainer Orth [Thu, 30 Nov 2023 09:46:25 +0000 (10:46 +0100)] 
Fix procfs.c compilation

procfs.c doesn't currently compile on Solaris:

/vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c: In member function ‘virtual int procfs_target::can_use_hw_breakpoint(bptype, int, int)’:
/vol/src/gnu/gdb/hg/master/dist/gdb/procfs.c:3017:9: error: ‘ptr_type’ was not declared in this scope; did you mean ‘var_types’?
 3017 |   type *ptr_type
      |         ^~~~~~~~
      |         var_types

This was caused by this patch:

commit 99d9c3b92ca96a7425cbb6b1bf453ede9477a2ee
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Fri Sep 29 14:24:38 2023 -0400

    gdb: remove target_gdbarch

Partially undoing it restores the build.

Tested on amd64-pc-solaris2.11.

18 months agolibiberty: Disable hwcaps for sha1.o
Rainer Orth [Thu, 30 Nov 2023 09:14:30 +0000 (10:14 +0100)] 
libiberty: Disable hwcaps for sha1.o

This patch

commit bf4f40cc3195eb7b900bf5535cdba1ee51fdbb8e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Nov 28 13:14:05 2023 +0100

    libiberty: Use x86 HW optimized sha1

broke Solaris/x86 bootstrap with the native as:

libtool: compile:  /var/gcc/regression/master/11.4-gcc/build/./gcc/gccgo -B/var/gcc/regression/master/11.4-gcc/build/./gcc/ -B/vol/gcc/i386-pc-solaris2.11/bin/ -B/vol/gcc/i386-pc-solaris2.11/lib/ -isystem /vol/gcc/i386-pc-solaris2.11/include -isystem /vol/gcc/i386-pc-solaris2.11/sys-include -fchecking=1 -minline-all-stringops -O2 -g -I . -c -fgo-pkgpath=internal/goarch /vol/gcc/src/hg/master/local/libgo/go/internal/goarch/goarch.go zgoarch.go
ld.so.1: go1: fatal: /var/gcc/regression/master/11.4-gcc/build/gcc/go1: hardware capability (CA_SUNW_HW_2) unsupported: 0x4000000  [ SHA1 ]
gccgo: fatal error: Killed signal terminated program go1

As is already done in a couple of other similar cases, this patches
disables hwcaps support for libiberty.

Initially, this didn't work because config/hwcaps.m4 uses target_os, but
didn't ensure it is defined.

Tested on i386-pc-solaris2.11 with as and gas.

2023-11-29  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

config:
* hwcaps.m4 (GCC_CHECK_ASSEMBLER_HWCAP): Require
AC_CANONICAL_TARGET.

libiberty:
* configure.ac (GCC_CHECK_ASSEMBLER_HWCAP): Invoke.
* configure, aclocal.m4: Regenerate.
* Makefile.in (COMPILE.c): Add HWCAP_CFLAGS.

18 months agoRISC-V: Avoid updating state until symbol is found
Patrick O'Neill [Thu, 30 Nov 2023 03:55:20 +0000 (19:55 -0800)] 
RISC-V: Avoid updating state until symbol is found

Currently objdump gets and updates the map state once per symbol. Updating the
state (partiularly riscv_parse_subset) is expensive and grows quadratically
since we iterate over all symbols. By deferring this until once we've found the
symbol of interest, we can reduce the time to dump a 4k insn file of .norvc and
.rvc insns from ~47 seconds to ~0.13 seconds.

opcodes/ChangeLog:

* riscv-dis.c (riscv_get_map_state): Remove state updating logic
and rename to riscv_is_valid_mapping_symbol.
(riscv_update_map_state): Add state updating logic to seperate function.
(riscv_search_mapping_symbol): Use new riscv_update_map_state.
(riscv_data_length): Ditto.

Signed-off-by: Patrick O'Neill <patrick@rivosinc.com>
18 months agogas: support double-slash line comments in BPF assembly
Jose E. Marchesi [Thu, 30 Nov 2023 07:34:09 +0000 (08:34 +0100)] 
gas: support double-slash line comments in BPF assembly

This patch makes the BPF assembler to support double-slash line
comments, like the llvm BPF assembler does.  At this point both
assemblers support the same commenting styles:

- Line comments preceded by # or //.
- Non-nestable block comments delimited by /* and */.

This patch also adds a couple of tests to make sure all the comment
styles work in both normal and pseudoc syntax.  The manual is also
updated to mention double-slash line comments.

18 months agoAutomatic date update in version.in
GDB Administrator [Thu, 30 Nov 2023 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agoRemove gdb_static_assert
Tom Tromey [Thu, 19 Oct 2023 02:44:11 +0000 (20:44 -0600)] 
Remove gdb_static_assert

C++17 makes the second parameter to static_assert optional, so we can
remove gdb_static_assert now.

18 months agoUse C++17 void_t
Tom Tromey [Sun, 15 Oct 2023 19:40:03 +0000 (13:40 -0600)] 
Use C++17 void_t

C++17 has void_t and make_void, so gdbsupport/traits.h can be
simplified.

Approved-By: Pedro Alves <pedro@palves.net>
18 months agoRely on copy elision in scope-exit.h
Tom Tromey [Sun, 15 Oct 2023 19:33:45 +0000 (13:33 -0600)] 
Rely on copy elision in scope-exit.h

gdbsupport/scope-exit.h has a couple of comments about being able to
rely on copy elision in C++17.  This patch makes the change.

Approved-By: Pedro Alves <pedro@palves.net>
18 months agoRely on C++17 <new> in new-op.cc
Tom Tromey [Sun, 15 Oct 2023 18:16:12 +0000 (12:16 -0600)] 
Rely on C++17 <new> in new-op.cc

gdbsupport/new-op.cc has a comment about relying on the C++-17 <new>
header.  This patch implements the suggestion.

Approved-By: Pedro Alves <pedro@palves.net>
18 months agoUse try_emplace in index-write.c
Tom Tromey [Sun, 15 Oct 2023 18:15:36 +0000 (12:15 -0600)] 
Use try_emplace in index-write.c

index-write.c has a comment indicating that C++17's try_emplace could
be used.  This patch makes the change.

Approved-By: Pedro Alves <pedro@palves.net>
18 months agoEnable some C++14 code in array-view.h
Tom Tromey [Sun, 15 Oct 2023 17:20:57 +0000 (11:20 -0600)] 
Enable some C++14 code in array-view.h

This changes gdbsupport/array-view.h to enable some code that is
C++14-specific.

Approved-By: Pedro Alves <pedro@palves.net>
18 months agoSwitch to -Wimplicit-fallthrough=5
Tom Tromey [Mon, 16 Oct 2023 19:36:03 +0000 (13:36 -0600)] 
Switch to -Wimplicit-fallthrough=5

This changes the various gdb-related directories to use
-Wimplicit-fallthrough=5, meaning that only the fallthrough attribute
can be used in switches -- special 'fallthrough' comments will no
longer be usable.

Approved-By: Pedro Alves <pedro@palves.net>
18 months agoUse C++17 [[fallthrough]] attribute
Tom Tromey [Sun, 15 Oct 2023 17:09:07 +0000 (11:09 -0600)] 
Use C++17 [[fallthrough]] attribute

This changes gdb to use the C++17 [[fallthrough]] attribute rather
than special comments.

This was mostly done by script, but I neglected a few spellings and so
also fixed it up by hand.

I suspect this fixes the bug mentioned below, by switching to a
standard approach that, presumably, clang supports.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=23159
Approved-By: John Baldwin <jhb@FreeBSD.org>
Approved-By: Luis Machado <luis.machado@arm.com>
Approved-By: Pedro Alves <pedro@palves.net>
18 months agogprofng: support GNU option syntax in gp-display-html, plus various fixes
Vladimir Mezentsev [Tue, 28 Nov 2023 20:05:15 +0000 (12:05 -0800)] 
gprofng: support GNU option syntax in gp-display-html, plus various fixes

This is a major update of gp-display-html.  The option handling has been
modified to support the GNU style long option syntax.  Compatibility with
the previous syntax has been preserved. If still used, a warning is issued.
Through the --nowarnings option, this can be suppressed.
In addition to this, various lay-out changes have been implemented.  In
particular to reduce the number of lines that extend beyond column 79.
Several bugs have been fixed, for example in the handling of directory names.

gprofng/ChangeLog
2023-11-28  Ruud van der Pas  <ruud.vanderpas@oracle.com>

* gp-display-html/gp-display-html.in: Change option syntax plus fixes.

18 months agogprofng: updated man pages and user guide
Vladimir Mezentsev [Mon, 27 Nov 2023 20:32:09 +0000 (12:32 -0800)] 
gprofng: updated man pages and user guide

This is a major update of all the man pages.  Bugs 30679 and 30895 are
addressed.  In addition to fixes for typos, the texts have been expanded
and clarified, and line lengths no longer extend beyond column 79.  In
case of gp-display-html, the new option syntax is documented. The user
guide has a new section on the gprofng GUI.

gprofng/ChangeLog
2023-11-28  Ruud van der Pas  <ruud.vanderpas@oracle.com>

PR 30679
PR 30895
* doc/gp-archive.texi: Expand the description of the options.
* doc/gp-collect-app.texi: Fix various typos and textual improvements.
* doc/gp-display-html.texi: Cover the new GNU long option syntax.
* doc/gp-display-src.texi: Fix various typos and textual improvements.
* doc/gp-display-text.texi: Fix typos fixed and textual improvements.
* doc/gp-macros.texi: Fix a bug in the vspace macro and add new macro.
* doc/gprofng.texi: Cover the GPROFNG_SYSCONFDIR environment variable.
* doc/gprofng_ug.texi: Fix various typos and textual improvements.
* doc/version.texi: Adapt the date and version number.

18 months agoAutomatic date update in version.in
GDB Administrator [Wed, 29 Nov 2023 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agogdb/python: display errors from command completion
Andrew Burgess [Mon, 27 Nov 2023 21:29:53 +0000 (21:29 +0000)] 
gdb/python: display errors from command completion

This commit makes the gdb.Command.complete methods more verbose when
it comes to error handling.

Previous to this commit if any commands implemented in Python
implemented the complete method, and if there were any errors
encountered when calling that complete method, then GDB would silently
hide the error and continue as if there were no completions.

This makes is difficult to debug any errors encountered when writing
completion methods, and encourages the idea that Python extensions can
be broken, and GDB will just silently work around them.

I don't think this is a good idea.  GDB should encourage extensions to
be written correctly, and robustly, and one way in which GDB can (I
think) support this, is by pointing out when an extension goes wrong.

In this commit I've gone through the Python command completion code,
and added calls to gdbpy_print_stack() or gdbpy_print_stack_or_quit()
in places where we were either clearing the Python error, or, in some
cases, just not handling the error at all.

One thing I have not changed is in cmdpy_completer (py-cmd.c) where we
process the list of completions returned from the Command.complete
method; this routine includes a call to gdbpy_is_string to check a
possible completion is a string, if not the completion is ignored.

I was tempted to remove this check, attempt to complete each result to
a string, and display an error if the conversion fails.  After all,
returning anything but a string is surely a mistake by the extension
author.

However, the docs clearly say that only strings within the returned
list will be considered as completions.  Anything else is ignored.  As
such, and to avoid (what I think is pretty unlikely) breakage of
existing code, I've retained the gdbpy_is_string check.

After the gdbpy_is_string check we call python_string_to_host_string,
if this call fails then I do now print the error, where before we
ignored the error.  I think this is OK; if GDB thinks something is a
string, but still can't convert it to a string, then I think it's OK
to display the error in that case.

Another case which I was a little unsure about was in
cmdpy_completer_helper, and the call to PyObject_CallMethodObjArgs,
which is when we actually call Command.complete.  Previously, if this
call resulted in an exception then we would ignore this and just
pretend there were no completions.

Of all the changes, this is possibly the one with the biggest
potential for breaking existing scripts, but also, is, I think, the
most useful change.  If the user code is wrong in some way, such that
an exception is raised, then previously the user would have no obvious
feedback about this breakage.  Now GDB will print the exception for
them, making it, I think, much easier to debug their extension.  But,
if there is user code in the wild that relies on raising an exception
as a means to indicate there are no completions .... well, that code
is going to break after this commit.  I think we can live with this
though, the exceptions means no completions thing was never documented
behaviour.

I also added a new error() call if the PyObject_CallMethodObjArgs call
raises an exception.  This causes the completion mechanism within GDB
to stop.  Within GDB the completion code is called twice, the first
time to compute the work break characters, and then a second time to
compute the actual completions.

If PyObject_CallMethodObjArgs raises an exception when computing the
word break character, and we print it by calling
gdbpy_print_stack_or_quit(), but then carry on as if
PyObject_CallMethodObjArgs had returns no completions, GDB will
call the Python completion code again, which results in another call
to PyObject_CallMethodObjArgs, which might raise the same exception
again.  This results in the Python exception being printed twice.

By throwing a C++ exception after the failed
PyObject_CallMethodObjArgs call, the completion mechanism is aborted,
and no completions are offered.  But importantly, the Python exception
is only printed once.  I think this gives a much better user
experience.

I've added some tests to cover this case, as I think this is the most
likely case that a user will run into.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb/testsuite: improve test regexp in gdb_get_worker_threads
Andrew Burgess [Tue, 28 Nov 2023 18:17:23 +0000 (18:17 +0000)] 
gdb/testsuite: improve test regexp in gdb_get_worker_threads

I spotted I made a small mistake in this commit:

  commit aff250145af6c7a8ea9332bc1306c1219f4a63db
  Date:   Fri Nov 24 12:04:36 2023 +0000

      gdb: generate gdb-index identically regardless of work thread count

In this commit I added a new proc in testsuite/lib/gdb.exp called
gdb_get_worker_threads.  This proc uses gdb_test_multiple with two
possible patterns.  One pattern is anchored with '^', while the other
is missing the '^' which it could use.

This commit adds the missing '^'.

18 months agognulib: mark configure +x
Mike Frysinger [Sun, 15 Oct 2023 16:12:56 +0000 (21:57 +0545)] 
gnulib: mark configure +x

18 months agogdb: fix call to breakpoint_inserted_here_p in darwin-nat.c
Simon Marchi [Tue, 28 Nov 2023 17:25:07 +0000 (12:25 -0500)] 
gdb: fix call to breakpoint_inserted_here_p in darwin-nat.c

Fixes this issue, introduced by f9582a22dba7 ("[gdb] Fix segfault in
for_each_block, part 1"):

       CXX    darwin-nat.o
     /Users/smarchi/src/binutils-gdb/gdb/darwin-nat.c:1169:7: error: no matching function for call to 'breakpoint_inserted_here_p'
       if (breakpoint_inserted_here_p (inf->aspace, pc))
           ^~~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: I3bb6be75b650319f0fa1dbdceb379b18531da96c

18 months agogas: add NEWS entry for change of comment syntax in BPF assembler
Jose E. Marchesi [Tue, 28 Nov 2023 16:51:51 +0000 (17:51 +0100)] 
gas: add NEWS entry for change of comment syntax in BPF assembler

2023-11-28  Jose E. Marchesi  <jose.marchesi@oracle.com>

* NEWS: Add entry about change of comment syntax in the BPF
assembler.

18 months agoEmit DAP "process" event
Tom Tromey [Fri, 6 Oct 2023 20:30:46 +0000 (14:30 -0600)] 
Emit DAP "process" event

DAP specifies a "process" event that is sent when a process is started
or attached to.  gdb was not emitting this (several DAP clients appear
to ignore it entirely), but it looked easy and harmless to implement.

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

18 months ago[gdb/tui] Use const std::string for string literals in tui-stack.c
Tom de Vries [Tue, 28 Nov 2023 15:31:07 +0000 (16:31 +0100)] 
[gdb/tui] Use const std::string for string literals in tui-stack.c

I noticed in gdb/tui/tui-stack.c a source-level micro-optimization where
strlen with a string literal argument:
...
strlen ("bla")
...
is replaced with sizeof:
...
sizeof ("bla") - 1
...

The benefit of this is that the optimization is also done at O0, but the
drawback is that it makes the expression harder to read.

Use const std::string to encapsulate the string literals, and use
std::string::size () instead.

I tried making the string names (PROC_PREFIX, LINE_PREFIX, PC_PREFIX and
SINGLE_KEY) lower-case, but that clashed with a pre-existing pc_prefix, so
I've left them upper-case.

Tested on x86_64-linux.

Tested-By: Alexandra Petlanova Hajkova <ahajkova@redhat.com>
18 months agosim: bpf: do not use semicolon to begin comments
Jose E. Marchesi [Tue, 28 Nov 2023 13:59:38 +0000 (14:59 +0100)] 
sim: bpf: do not use semicolon to begin comments

The BPF assembler has been updated to follow the clang convention in
the interpretation of semicolons: they separate statements and
directives, and do not start line comments.

18 months agogas: change meaning of ; in the BPF assembler
Jose E. Marchesi [Tue, 28 Nov 2023 10:58:58 +0000 (11:58 +0100)] 
gas: change meaning of ; in the BPF assembler

The BPF assembler in clang uses semi-colon (;) to separate statements,
not to be begin line comments.  This patch adapts the GNU assembler
accordingly.

Testsuite and documentation updated accordingly.

2023-11-28  Jose E. Marchesi  <jose.marchesi@oracle.com>

* config/tc-bpf.c: Semicolon does not start a comment, but
separates multiple commands on a single line.
* testsuite/gas/bpf/alu-pseudoc.s: Adapt test accordingly.
* testsuite/gas/bpf/spacing-pseudoc.s: Likewise.
* testsuite/gas/bpf/offset16-overflow.s: Likewise.
* testsuite/gas/bpf/jump-relax-jump.s: Likewise.
* testsuite/gas/bpf/jump-relax-ja.s: Likewise.
* testsuite/gas/bpf/imm32-overflow.s: Likewise.
* testsuite/gas/bpf/disp32-overflow.s: Likewise.
* testsuite/gas/bpf/disp16-overflow-relax.s: Likewise.
* testsuite/gas/bpf/disp16-overflow.s: Likewise.
* doc/c-bpf.texi (BPF Special Characters): Update.

18 months agolibiberty, ld: Use x86 HW optimized sha1
Jakub Jelinek [Tue, 28 Nov 2023 12:29:58 +0000 (13:29 +0100)] 
libiberty, ld: Use x86 HW optimized sha1

The following patch attempts to use x86 SHA ISA if available to speed
up in my testing about 2.5x sha1 build-id processing (in my case on
AMD Ryzen 5 3600) while producing the same result.
I believe AArch64 has similar HW acceleration for SHA1, perhaps it
could be added similarly.

Note, seems lld uses BLAKE3 rather than md5/sha1.  I think it would be
a bad idea to lie to users, if they choose --buildid=sha1, we should
be using SHA1, not some other checksum, but perhaps we could add some other
--buildid= styles and perhaps make one of the new the default.

Tested on x86_64-linux, both on Intel i9-7960X (which doesn't have
sha_ni ISA support) without/with the patch and on AMD Ryzen 5 3600
(which does have it) without/with the patch.

2023-11-28  Jakub Jelinek  <jakub@redhat.com>

include/
* sha1.h (sha1_process_bytes_fn): New typedef.
(sha1_choose_process_bytes): Declare.
libiberty/
* configure.ac (HAVE_X86_SHA1_HW_SUPPORT): New check.
* sha1.c: If HAVE_X86_SHA1_HW_SUPPORT is defined, include x86intrin.h
and cpuid.h.
(sha1_hw_process_bytes, sha1_hw_process_block,
sha1_choose_process_bytes): New functions.
* config.in: Regenerated.
* configure: Regenerated.
ld/
* ldbuildid.c (generate_build_id): Use sha1_choose_process_bytes ()
instead of &sha1_process_bytes.

18 months agogdb/testsuite: add a new check-all-boards target
Andrew Burgess [Thu, 26 Oct 2023 11:05:06 +0000 (12:05 +0100)] 
gdb/testsuite: add a new check-all-boards target

The make-check-all.sh script (gdb/testsuite/make-check-all.sh) is
great, it makes it super easy to run some test(s) using all the
available board files.

This commit aims to make this script even easier to access by adding a
check-all-boards target to the GDB Makefile.  This new target checks
for (and requires) a number of environment variables, so the target
should be used like this:

  make check-all-boards GDB_TARGET_USERNAME=remote-target \
                        GDB_HOST_USERNAME=remote-host \
TESTS="gdb.base/break.exp"

Where GDB_TARGET_USERNAME and GDB_HOST_USERNAME are the user names
that should be passed to the make-check-all.sh --target-user and
--host-user command line options respectively.

My personal intention is to set these variables in my environment, so
all I'll need to do is:

  make check-all-boards TESTS="gdb.base/break.exp"

The make rule always passes --keep-results to the make-check-all.sh
script, as I find that the most useful.  It's super frustrating to run
the tests and realise you forgot that option and the results have been
discarded.

18 months agogdb/testsuite: log 'make check' command in make-check-all.sh
Andrew Burgess [Tue, 7 Nov 2023 18:11:13 +0000 (18:11 +0000)] 
gdb/testsuite: log 'make check' command in make-check-all.sh

I have been making more use of the make-check-all.sh script to run
tests against all boards.

But one thing is pretty annoying.  When a test fails on some random
board, I have to run make-check-all.sh with --verbose and --dry-run in
order to see what RUNTESTFLAGS I should be using.

I always run with --keep-results on, so, in this commit, I propose
that, when --keep-results is on the 'make check' command will be
written out to a file within the stored results directory, like:

  check-all/BOARD_NAME/make-check.sh

then, if I want to rerun a test, I can just:

  sh check-all/BOARD_NAME/make-check.sh

and the test will be re-run for me.

18 months agogdb: generate dwarf-5 index identically as worker-thread count changes
Andrew Burgess [Mon, 27 Nov 2023 13:19:39 +0000 (13:19 +0000)] 
gdb: generate dwarf-5 index identically as worker-thread count changes

Similar to the previous commit, this commit ensures that the dwarf-5
index files are generated identically as the number of worker-threads
changes.

Building the dwarf-5 index makes use of a closed hash table, the
bucket_hash local within debug_names::build().  Entries are added to
bucket_hash from m_name_to_value_set, which, in turn, is populated
by calls to debug_names::insert() in write_debug_names.  The insert
calls are ordered based on the entries within the cooked_index, and
the ordering within cooked_index depends on the number of worker
threads that GDB is using.

My proposal is to sort each chain within the bucket_hash closed hash
table prior to using this to build the dwarf-5 index.

The buckets within bucket_hash will always have the same ordering (for
a given GDB build with a given executable), and by sorting the chains
within each bucket, we can be sure that GDB will see each entry in a
deterministic order.

I've extended the index creation test to cover this case.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: generate gdb-index identically regardless of work thread count
Andrew Burgess [Fri, 24 Nov 2023 12:04:36 +0000 (12:04 +0000)] 
gdb: generate gdb-index identically regardless of work thread count

It was observed that changing the number of worker threads that GDB
uses (maintenance set worker-threads NUM) would have an impact on the
layout of the generated gdb-index.

The cause seems to be how the CU are distributed between threads, and
then symbols that appear in multiple CU can be encountered earlier or
later depending on whether a particular CU moves between threads.

I certainly found this behaviour was reproducible when generating an
index for GDB itself, like:

  gdb -q -nx -nh -batch \
      -eiex 'maint set worker-threads NUM' \
      -ex 'save gdb-index /tmp/'

And then setting different values for NUM will change the generated
index.

Now, the question is: does this matter?

I would like to suggest that yes, this does matter.  At Red Hat we
generate a gdb-index as part of the build process, and we would
ideally like to have reproducible builds: for the same source,
compiled with the same tool-chain, we should get the exact same output
binary.  And we do .... except for the index.

Now we could simply force GDB to only use a single worker thread when
we build the index, but, I don't think the idea of reproducible builds
is that strange, so I think we should ensure that our generated
indexes are always reproducible.

To achieve this, I propose that we add an extra step when building the
gdb-index file.  After constructing the initial symbol hash table
contents, we will pull all the symbols out of the hash, sort them,
then re-insert them in sorted order.  This will ensure that the
structure of the generated hash will remain consistent (given the same
set of symbols).

I've extended the existing index-file test to check that the generated
index doesn't change if we adjust the number of worker threads used.
Given that this test is already rather slow, I've only made one change
to the worker-thread count.  Maybe this test should be changed to use
a smaller binary, which is quicker to load, and for which we could
then try many different worker thread counts.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: C++-ify mapped_symtab from dwarf2/index-write.c
Andrew Burgess [Sat, 25 Nov 2023 10:35:37 +0000 (10:35 +0000)] 
gdb: C++-ify mapped_symtab from dwarf2/index-write.c

Make static the functions add_index_entry, find_slot, and hash_expand,
member functions of the mapped_symtab class.

Fold an additional snippet of code from write_gdbindex into
mapped_symtab::minimize, this code relates to minimisation, so this
seems like a good home for it.

Make the n_elements, data, and m_string_obstack member variables of
mapped_symtab private.  Provide a new obstack() member function to
provide access to the obstack when needed, and also add member
functions begin(), end(), cbegin(), and cend() so that the
mapped_symtab class can be treated like a contained and iterated
over.

I've also taken this opportunity to split out the logic for whether
the hash table (m_data) needs expanding, this is the new function
hash_needs_expanding.  This will be useful in a later commit.

There should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: reduce size of generated gdb-index file
Andrew Burgess [Fri, 24 Nov 2023 11:50:35 +0000 (11:50 +0000)] 
gdb: reduce size of generated gdb-index file

I noticed in passing that out algorithm for generating the gdb-index
file is incorrect.  When building the hash table in add_index_entry we
count every incoming entry rehash when the number of entries gets too
large.  However, some of the incoming entries will be duplicates,
which don't actually result in new items being added to the hash
table.

As a result, we grow the gdb-index hash table far too often.

With an unmodified GDB, generating a gdb-index for GDB, I see a file
size of 90M, with a hash usage (in the generated index file) of just
2.6%.

With a patched GDB, generating a gdb-index for the _same_ GDB binary,
I now see a gdb-index file size of 30M, with a hash usage of 41.9%.

This is a 67% reduction in gdb-index file size.

Obviously, not every gdb-index file is going to see such big savings,
however, the larger a program, and the more symbols that are
duplicated between compilation units, the more GDB would over count,
and so, over-grow the index.

The gdb-index hash table we create has a minimum size of 1024, and
then we grow the hash when it is 75% full, doubling the hash table at
that time.  Given this, then we expect that either:

  a. The hash table is size 1024, and less than 75% full, or
  b. The hash table is between 37.5% and 75% full.

I've include a test that checks some of these constraints -- I've not
bothered to check the upper limit, and over full hash table isn't
really a problem here, but if the fill percentage is less than 37.5%
then this indicates that we've done something wrong (obviously, I also
check for the 1024 minimum size).

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb/testsuite: small refactor in selftest-support.exp
Andrew Burgess [Fri, 24 Nov 2023 11:10:08 +0000 (11:10 +0000)] 
gdb/testsuite: small refactor in selftest-support.exp

Split out the code that makes a copy of the GDB executable ready for
self testing into a new proc.  A later commit in this series wants to
load the GDB executable into GDB (for creating an on-disk debug
index), but doesn't need to make use of the full do_self_tests proc.

There should be no changes in what is tested after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: option completion for 'save gdb-index' command
Andrew Burgess [Mon, 27 Nov 2023 14:34:57 +0000 (14:34 +0000)] 
gdb: option completion for 'save gdb-index' command

Add proper support for option completion to the 'save gdb-index'
command.  Update save_gdb_index_command function to make use of the
new option_def data structures for parsing the '-dwarf-5' option.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agogdb: allow use of ~ in 'save gdb-index' command
Andrew Burgess [Mon, 27 Nov 2023 13:33:17 +0000 (13:33 +0000)] 
gdb: allow use of ~ in 'save gdb-index' command

Add a call to gdb_tilde_expand in the save_gdb_index_command function,
this means that we can now do:

  (gdb) save gdb-index ~/blah/

Previous this wouldn't work.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoNew Romanian translation for ld
Nick Clifton [Tue, 28 Nov 2023 10:16:05 +0000 (10:16 +0000)] 
New Romanian translation for ld

18 months ago[gdb] Fix segfault in for_each_block, part 2
Tom de Vries [Tue, 28 Nov 2023 09:31:25 +0000 (10:31 +0100)] 
[gdb] Fix segfault in for_each_block, part 2

The previous commit describes PR gdb/30547, a segfault when running test-case
gdb.base/vfork-follow-parent.exp on powerpc64 (likewise on s390x).

The root cause for the segmentation fault is that linux_is_uclinux gives an
incorrect result: it returns true instead of false.

So, why does linux_is_uclinux:
...
int
linux_is_uclinux (void)
{
  CORE_ADDR dummy;

  return (target_auxv_search (AT_NULL, &dummy) > 0
  && target_auxv_search (AT_PAGESZ, &dummy) == 0);
...
return true?

This is because ppc_linux_target_wordsize returns 4 instead of 8, causing
ppc_linux_nat_target::auxv_parse to misinterpret the auxv vector.

So, why does ppc_linux_target_wordsize:
...
int
ppc_linux_target_wordsize (int tid)
{
  int wordsize = 4;

  /* Check for 64-bit inferior process.  This is the case when the host is
     64-bit, and in addition the top bit of the MSR register is set.  */
  long msr;

  errno = 0;
  msr = (long) ptrace (PTRACE_PEEKUSER, tid, PT_MSR * 8, 0);
  if (errno == 0 && ppc64_64bit_inferior_p (msr))
    wordsize = 8;

  return wordsize;
}
...
return 4?

Specifically, we get this result because because tid == 0, so we get
errno == ESRCH.

The tid == 0 is caused by the switch_to_no_thread in
handle_vfork_child_exec_or_exit:
...
  /* Switch to no-thread while running clone_program_space, so
     that clone_program_space doesn't want to read the
     selected frame of a dead process.  */
  scoped_restore_current_thread restore_thread;
  switch_to_no_thread ();

  inf->pspace = new program_space (maybe_new_address_space ());
...
but moving the maybe_new_address_space call to before that gives us the
same result.  The tid is no longer 0, but we still get ESRCH because the
thread has exited.

Fix this in handle_vfork_child_exec_or_exit by doing the
maybe_new_address_space call in the context of the vfork parent.

Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.

Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
PR gdb/30547
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547

18 months ago[gdb] Fix segfault in for_each_block, part 1
Tom de Vries [Tue, 28 Nov 2023 09:31:25 +0000 (10:31 +0100)] 
[gdb] Fix segfault in for_each_block, part 1

When running test-case gdb.base/vfork-follow-parent.exp on powerpc64 (likewise
on s390x), I run into:
...
(gdb) PASS: gdb.base/vfork-follow-parent.exp: \
  exec_file=vfork-follow-parent-exit: target-non-stop=on: non-stop=off: \
  resolution_method=schedule-multiple: print unblock_parent = 1
continue^M
Continuing.^M
Reading symbols from vfork-follow-parent-exit...^M
^M
^M
Fatal signal: Segmentation fault^M
----- Backtrace -----^M
0x1027d3e7 gdb_internal_backtrace_1^M
        src/gdb/bt-utils.c:122^M
0x1027d54f _Z22gdb_internal_backtracev^M
        src/gdb/bt-utils.c:168^M
0x1057643f handle_fatal_signal^M
        src/gdb/event-top.c:889^M
0x10576677 handle_sigsegv^M
        src/gdb/event-top.c:962^M
0x3fffa7610477 ???^M
0x103f2144 for_each_block^M
        src/gdb/dcache.c:199^M
0x103f235b _Z17dcache_invalidateP13dcache_struct^M
        src/gdb/dcache.c:251^M
0x10bde8c7 _Z24target_dcache_invalidatev^M
        src/gdb/target-dcache.c:50^M
...
or similar.

The root cause for the segmentation fault is that linux_is_uclinux gives an
incorrect result: it should always return false, given that we're running on a
regular linux system, but instead it returns first true, then false.

In more detail, the segmentation fault happens as follows:
- a program space with an address space is created
- a second program space is about to be created. maybe_new_address_space
  is called, and because linux_is_uclinux returns true, maybe_new_address_space
  returns false, and no new address space is created
- a second program space with the same address space is created
- a program space is deleted. Because linux_is_uclinux now returns false,
  gdbarch_has_shared_address_space (current_inferior ()->arch ()) returns
  false, and the address space is deleted
- when gdb uses the address space of the remaining program space, we run into
  the segfault, because the address space is deleted.

Hardcoding linux_is_uclinux to false makes the test-case pass.

We leave addressing the root cause for the following commit in this series.

For now, prevent the segmentation fault by making the address space a refcounted
object.

This was already suggested here [1]:
...
A better solution might be to have the address spaces be reference counted
...

Tested on top of trunk on x86_64-linux and ppc64le-linux.
Tested on top of gdb-14-branch on ppc64-linux.

Co-Authored-By: Simon Marchi <simon.marchi@polymtl.ca>
PR gdb/30547
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30547

[1] https://sourceware.org/pipermail/gdb-patches/2023-October/202928.html

18 months agotestsuite: Clean up .allow_index_reg in i386 tests
Haochen Jiang [Tue, 28 Nov 2023 05:29:01 +0000 (13:29 +0800)] 
testsuite: Clean up .allow_index_reg in i386 tests

gas/ChangeLog:

* testsuite/gas/i386/adx.s: Remove .allow_index_reg.
* testsuite/gas/i386/amx-complex-inval.l: Ditto.
* testsuite/gas/i386/amx-complex-inval.s: Ditto.
* testsuite/gas/i386/avx-ifma.s: Ditto.
* testsuite/gas/i386/avx-ne-convert.s: Ditto.
* testsuite/gas/i386/avx-scalar-2.s: Ditto.
* testsuite/gas/i386/avx-vnni-int8.s: Ditto.
* testsuite/gas/i386/avx-vnni.s: Ditto.
* testsuite/gas/i386/avx-wig.s: Ditto.
* testsuite/gas/i386/avx2-wig.s: Ditto.
* testsuite/gas/i386/avx2.s: Ditto.
* testsuite/gas/i386/avx256int.s: Ditto.
* testsuite/gas/i386/avx512_4fmaps.s: Ditto.
* testsuite/gas/i386/avx512_4vnniw.s: Ditto.
* testsuite/gas/i386/avx512_bf16.s: Ditto.
* testsuite/gas/i386/avx512_bf16_vl-inval.l: Ditto.
* testsuite/gas/i386/avx512_bf16_vl-inval.s: Ditto.
* testsuite/gas/i386/avx512_bf16_vl.s: Ditto.
* testsuite/gas/i386/avx512_fp16-inval-bcast.l: Ditto.
* testsuite/gas/i386/avx512_fp16-inval-bcast.s: Ditto.
* testsuite/gas/i386/avx512_fp16.s: Ditto.
* testsuite/gas/i386/avx512_fp16_pseudo_ops.s: Ditto.
* testsuite/gas/i386/avx512_fp16_vl.s: Ditto.
* testsuite/gas/i386/avx512_vpopcntdq.s: Ditto.
* testsuite/gas/i386/avx512bitalg.s: Ditto.
* testsuite/gas/i386/avx512bitalg_vl.s: Ditto.
* testsuite/gas/i386/avx512bw-opts.s: Ditto.
* testsuite/gas/i386/avx512bw-wig.s: Ditto.
* testsuite/gas/i386/avx512bw.s: Ditto.
* testsuite/gas/i386/avx512bw_vl-opts.s: Ditto.
* testsuite/gas/i386/avx512bw_vl-wig.s: Ditto.
* testsuite/gas/i386/avx512bw_vl.s: Ditto.
* testsuite/gas/i386/avx512cd.s: Ditto.
* testsuite/gas/i386/avx512cd_vl.s: Ditto.
* testsuite/gas/i386/avx512dq-rcig.s: Ditto.
* testsuite/gas/i386/avx512dq.s: Ditto.
* testsuite/gas/i386/avx512dq_vl.s: Ditto.
* testsuite/gas/i386/avx512er-rcig.s: Ditto.
* testsuite/gas/i386/avx512er.s: Ditto.
* testsuite/gas/i386/avx512f-opts.s: Ditto.
* testsuite/gas/i386/avx512f-rcig.s: Ditto.
* testsuite/gas/i386/avx512f.s: Ditto.
* testsuite/gas/i386/avx512f_gfni.s: Ditto.
* testsuite/gas/i386/avx512f_vaes.s: Ditto.
* testsuite/gas/i386/avx512f_vl-opts.s: Ditto.
* testsuite/gas/i386/avx512f_vl-wig.s: Ditto.
* testsuite/gas/i386/avx512f_vl.s: Ditto.
* testsuite/gas/i386/avx512f_vpclmulqdq.s: Ditto.
* testsuite/gas/i386/avx512ifma.s: Ditto.
* testsuite/gas/i386/avx512ifma_vl.s: Ditto.
* testsuite/gas/i386/avx512pf.s: Ditto.
* testsuite/gas/i386/avx512vbmi.s: Ditto.
* testsuite/gas/i386/avx512vbmi2.s: Ditto.
* testsuite/gas/i386/avx512vbmi2_vl.s: Ditto.
* testsuite/gas/i386/avx512vbmi_vl.s: Ditto.
* testsuite/gas/i386/avx512vl_gfni.s: Ditto.
* testsuite/gas/i386/avx512vl_vaes.s: Ditto.
* testsuite/gas/i386/avx512vl_vpclmulqdq.s: Ditto.
* testsuite/gas/i386/avx512vnni.s: Ditto.
* testsuite/gas/i386/avx512vnni_vl.s: Ditto.
* testsuite/gas/i386/bmi.s: Ditto.
* testsuite/gas/i386/bmi2.s: Ditto.
* testsuite/gas/i386/cldemote.s: Ditto.
* testsuite/gas/i386/clflushopt.s: Ditto.
* testsuite/gas/i386/clwb.s: Ditto.
* testsuite/gas/i386/cmpccxadd-inval.l: Ditto.
* testsuite/gas/i386/cmpccxadd-inval.s: Ditto.
* testsuite/gas/i386/enqcmd-inval.l: Ditto.
* testsuite/gas/i386/enqcmd-inval.s: Ditto.
* testsuite/gas/i386/enqcmd.s: Ditto.
* testsuite/gas/i386/evex-lig-2.s: Ditto.
* testsuite/gas/i386/evex-lig.s: Ditto.
* testsuite/gas/i386/evex-wig.s: Ditto.
* testsuite/gas/i386/evex.s: Ditto.
* testsuite/gas/i386/fma-scalar.s: Ditto.
* testsuite/gas/i386/fma.s: Ditto.
* testsuite/gas/i386/fma4.s: Ditto.
* testsuite/gas/i386/gfni.s: Ditto.
* testsuite/gas/i386/hle.s: Ditto.
* testsuite/gas/i386/ilp32/enqcmd.s: Ditto.
* testsuite/gas/i386/ilp32/movdir.s: Ditto.
* testsuite/gas/i386/lwp.s: Ditto.
* testsuite/gas/i386/movdir.s: Ditto.
* testsuite/gas/i386/movdir64b-reg.l: Ditto.
* testsuite/gas/i386/movdir64b-reg.s: Ditto.
* testsuite/gas/i386/mpx-inval-1.l: Ditto.
* testsuite/gas/i386/mpx-inval-1.s: Ditto.
* testsuite/gas/i386/mpx.s: Ditto.
* testsuite/gas/i386/msrlist-inval.l: Ditto.
* testsuite/gas/i386/msrlist-inval.s: Ditto.
* testsuite/gas/i386/notrack.s: Ditto.
* testsuite/gas/i386/notrackbad.l: Ditto.
* testsuite/gas/i386/notrackbad.s: Ditto.
* testsuite/gas/i386/optimize-1.s: Ditto.
* testsuite/gas/i386/optimize-2.s: Ditto.
* testsuite/gas/i386/optimize-3.s: Ditto.
* testsuite/gas/i386/optimize-6.s: Ditto.
* testsuite/gas/i386/optimize-6a.l: Ditto.
* testsuite/gas/i386/optimize-7.l: Ditto.
* testsuite/gas/i386/optimize-7.s: Ditto.
* testsuite/gas/i386/opts.s: Ditto.
* testsuite/gas/i386/prefetchwt1.s: Ditto.
* testsuite/gas/i386/raoint.s: Ditto.
* testsuite/gas/i386/sha.s: Ditto.
* testsuite/gas/i386/sse2avx.s: Ditto.
* testsuite/gas/i386/tbm.s: Ditto.
* testsuite/gas/i386/vaes.s: Ditto.
* testsuite/gas/i386/vex-lig-2.s: Ditto.
* testsuite/gas/i386/vp2intersect-inval-bcast.l: Ditto.
* testsuite/gas/i386/vp2intersect-inval-bcast.s: Ditto.
* testsuite/gas/i386/vpclmulqdq.s: Ditto.
* testsuite/gas/i386/x86-64-adx.s: Ditto.
* testsuite/gas/i386/x86-64-amx-complex.s: Ditto.
* testsuite/gas/i386/x86-64-amx-fp16.s: Ditto.
* testsuite/gas/i386/x86-64-avx-ifma.s: Ditto.
* testsuite/gas/i386/x86-64-avx-ne-convert.s: Ditto.
* testsuite/gas/i386/x86-64-avx-scalar-2.s: Ditto.
* testsuite/gas/i386/x86-64-avx-swap.s: Ditto.
* testsuite/gas/i386/x86-64-avx-vnni-int8.s: Ditto.
* testsuite/gas/i386/x86-64-avx-vnni.s: Ditto.
* testsuite/gas/i386/x86-64-avx-wig.s: Ditto.
* testsuite/gas/i386/x86-64-avx2-wig.s: Ditto.
* testsuite/gas/i386/x86-64-avx2.s: Ditto.
* testsuite/gas/i386/x86-64-avx256int.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_4fmaps.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_4vnniw.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_bf16.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_bf16_vl-inval.l: Ditto.
* testsuite/gas/i386/x86-64-avx512_bf16_vl-inval.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_bf16_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16-inval-bcast.l: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16-inval-bcast.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16-inval-register.l: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16-inval-register.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16_pseudo_ops.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512_vpopcntdq.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bitalg.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bitalg_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bw-opts.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bw-wig.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bw.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl-opts.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl-wig.s: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512cd.s: Ditto.
* testsuite/gas/i386/x86-64-avx512cd_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512dq-rcig.s: Ditto.
* testsuite/gas/i386/x86-64-avx512dq.s: Ditto.
* testsuite/gas/i386/x86-64-avx512dq_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512er-rcig.s: Ditto.
* testsuite/gas/i386/x86-64-avx512er.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f-opts.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f-rcig.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f_gfni.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vaes.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl-opts.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl-wig.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vpclmulqdq.s: Ditto.
* testsuite/gas/i386/x86-64-avx512ifma.s: Ditto.
* testsuite/gas/i386/x86-64-avx512ifma_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512pf.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi2.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi2_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_gfni.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_vaes.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_vpclmulqdq.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vnni.s: Ditto.
* testsuite/gas/i386/x86-64-avx512vnni_vl.s: Ditto.
* testsuite/gas/i386/x86-64-avx_gfni.s: Ditto.
* testsuite/gas/i386/x86-64-bmi.s: Ditto.
* testsuite/gas/i386/x86-64-bmi2.s: Ditto.
* testsuite/gas/i386/x86-64-cldemote.s: Ditto.
* testsuite/gas/i386/x86-64-clflushopt.s: Ditto.
* testsuite/gas/i386/x86-64-clwb.s: Ditto.
* testsuite/gas/i386/x86-64-cmpccxadd.s: Ditto.
* testsuite/gas/i386/x86-64-enqcmd-inval.l: Ditto.
* testsuite/gas/i386/x86-64-enqcmd-inval.s: Ditto.
* testsuite/gas/i386/x86-64-enqcmd.s: Ditto.
* testsuite/gas/i386/x86-64-evex-lig-2.s: Ditto.
* testsuite/gas/i386/x86-64-evex-lig.s: Ditto.
* testsuite/gas/i386/x86-64-evex-wig.s: Ditto.
* testsuite/gas/i386/x86-64-evex-wig2.s: Ditto.
* testsuite/gas/i386/x86-64-fma-scalar.s: Ditto.
* testsuite/gas/i386/x86-64-fma.s: Ditto.
* testsuite/gas/i386/x86-64-fma4.s: Ditto.
* testsuite/gas/i386/x86-64-fred.s: Ditto.
* testsuite/gas/i386/x86-64-gfni.s: Ditto.
* testsuite/gas/i386/x86-64-hle.s: Ditto.
* testsuite/gas/i386/x86-64-lkgs.s: Ditto.
* testsuite/gas/i386/x86-64-lwp.s: Ditto.
* testsuite/gas/i386/x86-64-movdir.s: Ditto.
* testsuite/gas/i386/x86-64-movdir64b-reg.l: Ditto.
* testsuite/gas/i386/x86-64-movdir64b-reg.s: Ditto.
* testsuite/gas/i386/x86-64-mpx-inval-1.l: Ditto.
* testsuite/gas/i386/x86-64-mpx-inval-1.s: Ditto.
* testsuite/gas/i386/x86-64-mpx-inval-2.l: Ditto.
* testsuite/gas/i386/x86-64-mpx-inval-2.s: Ditto.
* testsuite/gas/i386/x86-64-mpx.s: Ditto.
* testsuite/gas/i386/x86-64-notrack.s: Ditto.
* testsuite/gas/i386/x86-64-notrackbad.l: Ditto.
* testsuite/gas/i386/x86-64-notrackbad.s: Ditto.
* testsuite/gas/i386/x86-64-optimize-1.s: Ditto.
* testsuite/gas/i386/x86-64-optimize-2.s: Ditto.
* testsuite/gas/i386/x86-64-optimize-3.s: Ditto.
* testsuite/gas/i386/x86-64-optimize-4.s: Ditto.
* testsuite/gas/i386/x86-64-optimize-7.s: Ditto.
* testsuite/gas/i386/x86-64-optimize-7a.l: Ditto.
* testsuite/gas/i386/x86-64-optimize-8.l: Ditto.
* testsuite/gas/i386/x86-64-optimize-8.s: Ditto.
* testsuite/gas/i386/x86-64-opts.s: Ditto.
* testsuite/gas/i386/x86-64-prefetchi-warn.s: Ditto.
* testsuite/gas/i386/x86-64-prefetchi.s: Ditto.
* testsuite/gas/i386/x86-64-prefetchwt1.s: Ditto.
* testsuite/gas/i386/x86-64-raoint.s: Ditto.
* testsuite/gas/i386/x86-64-sha.s: Ditto.
* testsuite/gas/i386/x86-64-sse2avx.s: Ditto.
* testsuite/gas/i386/x86-64-tbm.s: Ditto.
* testsuite/gas/i386/x86-64-vaes.s: Ditto.
* testsuite/gas/i386/x86-64-vex-lig-2.s: Ditto.
* testsuite/gas/i386/x86-64-vp2intersect-inval-bcast.l: Ditto.
* testsuite/gas/i386/x86-64-vp2intersect-inval-bcast.s: Ditto.
* testsuite/gas/i386/x86-64-vpclmulqdq.s: Ditto.
* testsuite/gas/i386/x86-64-xop.s: Ditto.
* testsuite/gas/i386/x86-64-xsavec.s: Ditto.
* testsuite/gas/i386/x86-64-xsaves.s: Ditto.
* testsuite/gas/i386/xop.s: Ditto.
* testsuite/gas/i386/xsavec.s: Ditto.
* testsuite/gas/i386/xsaves.s: Ditto.

18 months agotestsuite: Clean up #as in dump file for i386 tests
Haochen Jiang [Tue, 28 Nov 2023 05:28:45 +0000 (13:28 +0800)] 
testsuite: Clean up #as in dump file for i386 tests

gas/ChangeLog:

* testsuite/gas/i386/avx-gather-intel.d: Remove unused #as.
* testsuite/gas/i386/avx-gather.d: Ditto.
* testsuite/gas/i386/avx-ifma-intel.d: Ditto.
* testsuite/gas/i386/avx-ifma.d: Ditto.
* testsuite/gas/i386/avx-ne-convert-intel.d: Ditto.
* testsuite/gas/i386/avx-ne-convert.d: Ditto.
* testsuite/gas/i386/avx-vnni-int8-intel.d: Ditto.
* testsuite/gas/i386/avx-vnni-int8.d: Ditto.
* testsuite/gas/i386/avx512_bf16.d: Ditto.
* testsuite/gas/i386/avx512_bf16_vl.d: Ditto.
* testsuite/gas/i386/avx512_fp16-intel.d: Ditto.
* testsuite/gas/i386/avx512_fp16.d: Ditto.
* testsuite/gas/i386/avx512_fp16_pseudo_ops.d: Ditto.
* testsuite/gas/i386/avx512_fp16_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512_fp16_vl.d: Ditto.
* testsuite/gas/i386/avx512_vpopcntdq-intel.d: Ditto.
* testsuite/gas/i386/avx512_vpopcntdq.d: Ditto.
* testsuite/gas/i386/avx512bitalg-intel.d: Ditto.
* testsuite/gas/i386/avx512bitalg.d: Ditto.
* testsuite/gas/i386/avx512bitalg_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512bitalg_vl.d: Ditto.
* testsuite/gas/i386/avx512bw-opts-intel.d: Ditto.
* testsuite/gas/i386/avx512bw-opts.d: Ditto.
* testsuite/gas/i386/avx512bw_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512bw_vl-opts-intel.d: Ditto.
* testsuite/gas/i386/avx512bw_vl-opts.d: Ditto.
* testsuite/gas/i386/avx512bw_vl.d: Ditto.
* testsuite/gas/i386/avx512cd-intel.d: Ditto.
* testsuite/gas/i386/avx512cd.d: Ditto.
* testsuite/gas/i386/avx512cd_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512cd_vl.d: Ditto.
* testsuite/gas/i386/avx512dq-intel.d: Ditto.
* testsuite/gas/i386/avx512dq.d: Ditto.
* testsuite/gas/i386/avx512dq_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512dq_vl.d: Ditto.
* testsuite/gas/i386/avx512er-intel.d: Ditto.
* testsuite/gas/i386/avx512er.d: Ditto.
* testsuite/gas/i386/avx512f-nondef.d: Ditto.
* testsuite/gas/i386/avx512f-opts-intel.d: Ditto.
* testsuite/gas/i386/avx512f-opts.d: Ditto.
* testsuite/gas/i386/avx512f_gfni-intel.d: Ditto.
* testsuite/gas/i386/avx512f_gfni.d: Ditto.
* testsuite/gas/i386/avx512f_vaes-intel.d: Ditto.
* testsuite/gas/i386/avx512f_vaes.d: Ditto.
* testsuite/gas/i386/avx512f_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512f_vl-opts-intel.d: Ditto.
* testsuite/gas/i386/avx512f_vl-opts.d: Ditto.
* testsuite/gas/i386/avx512f_vl.d: Ditto.
* testsuite/gas/i386/avx512f_vpclmulqdq-intel.d: Ditto.
* testsuite/gas/i386/avx512f_vpclmulqdq.d: Ditto.
* testsuite/gas/i386/avx512ifma-intel.d: Ditto.
* testsuite/gas/i386/avx512ifma.d: Ditto.
* testsuite/gas/i386/avx512ifma_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512ifma_vl.d: Ditto.
* testsuite/gas/i386/avx512pf-intel.d: Ditto.
* testsuite/gas/i386/avx512pf.d: Ditto.
* testsuite/gas/i386/avx512vbmi-intel.d: Ditto.
* testsuite/gas/i386/avx512vbmi.d: Ditto.
* testsuite/gas/i386/avx512vbmi2-intel.d: Ditto.
* testsuite/gas/i386/avx512vbmi2.d: Ditto.
* testsuite/gas/i386/avx512vbmi2_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512vbmi2_vl.d: Ditto.
* testsuite/gas/i386/avx512vbmi_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512vbmi_vl.d: Ditto.
* testsuite/gas/i386/avx512vl_gfni-intel.d: Ditto.
* testsuite/gas/i386/avx512vl_gfni.d: Ditto.
* testsuite/gas/i386/avx512vl_vaes-intel.d: Ditto.
* testsuite/gas/i386/avx512vl_vaes.d: Ditto.
* testsuite/gas/i386/avx512vl_vpclmulqdq-intel.d: Ditto.
* testsuite/gas/i386/avx512vl_vpclmulqdq.d: Ditto.
* testsuite/gas/i386/avx512vnni-intel.d: Ditto.
* testsuite/gas/i386/avx512vnni.d: Ditto.
* testsuite/gas/i386/avx512vnni_vl-intel.d: Ditto.
* testsuite/gas/i386/avx512vnni_vl.d: Ditto.
* testsuite/gas/i386/bmi-intel.d: Ditto.
* testsuite/gas/i386/bmi.d: Ditto.
* testsuite/gas/i386/bmi2-intel.d: Ditto.
* testsuite/gas/i386/bmi2.d: Ditto.
* testsuite/gas/i386/cldemote-intel.d: Ditto.
* testsuite/gas/i386/cldemote.d: Ditto.
* testsuite/gas/i386/clflushopt-intel.d: Ditto.
* testsuite/gas/i386/clflushopt.d: Ditto.
* testsuite/gas/i386/clwb-intel.d: Ditto.
* testsuite/gas/i386/clwb.d: Ditto.
* testsuite/gas/i386/enqcmd-intel.d: Ditto.
* testsuite/gas/i386/enqcmd.d: Ditto.
* testsuite/gas/i386/gfni-intel.d: Ditto.
* testsuite/gas/i386/gfni.d: Ditto.
* testsuite/gas/i386/hreset.d: Ditto.
* testsuite/gas/i386/invpcid-intel.d: Ditto.
* testsuite/gas/i386/invpcid.d: Ditto.
* testsuite/gas/i386/keylocker-intel.d: Ditto.
* testsuite/gas/i386/keylocker.d: Ditto.
* testsuite/gas/i386/movdir-intel.d: Ditto.
* testsuite/gas/i386/movdir.d: Ditto.
* testsuite/gas/i386/pr27198.d: Ditto.
* testsuite/gas/i386/pr30248.d: Ditto.
* testsuite/gas/i386/prefetchwt1-intel.d: Ditto.
* testsuite/gas/i386/prefetchwt1.d: Ditto.
* testsuite/gas/i386/ptwrite-intel.d: Ditto.
* testsuite/gas/i386/ptwrite.d: Ditto.
* testsuite/gas/i386/raoint-intel.d: Ditto.
* testsuite/gas/i386/raoint.d: Ditto.
* testsuite/gas/i386/serialize.d: Ditto.
* testsuite/gas/i386/tbm-intel.d: Ditto.
* testsuite/gas/i386/tdx.d: Ditto.
* testsuite/gas/i386/tsxldtrk.d: Ditto.
* testsuite/gas/i386/vp2intersect-intel.d: Ditto.
* testsuite/gas/i386/vp2intersect.d: Ditto.
* testsuite/gas/i386/vpclmulqdq-intel.d: Ditto.
* testsuite/gas/i386/vpclmulqdq.d: Ditto.
* testsuite/gas/i386/waitpkg-intel.d: Ditto.
* testsuite/gas/i386/waitpkg.d: Ditto.
* testsuite/gas/i386/wrmsrns-intel.d: Ditto.
* testsuite/gas/i386/wrmsrns.d: Ditto.
* testsuite/gas/i386/x86-64-amx-bad.d: Ditto.
* testsuite/gas/i386/x86-64-amx-complex-bad.d: Ditto.
* testsuite/gas/i386/x86-64-amx-complex-intel.d: Ditto.
* testsuite/gas/i386/x86-64-amx-complex.d: Ditto.
* testsuite/gas/i386/x86-64-amx-fp16-bad.d: Ditto.
* testsuite/gas/i386/x86-64-amx-fp16-intel.d: Ditto.
* testsuite/gas/i386/x86-64-amx-fp16.d: Ditto.
* testsuite/gas/i386/x86-64-amx-intel.d: Ditto.
* testsuite/gas/i386/x86-64-amx.d: Ditto.
* testsuite/gas/i386/x86-64-avx-gather-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx-gather.d: Ditto.
* testsuite/gas/i386/x86-64-avx-ifma-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx-ifma.d: Ditto.
* testsuite/gas/i386/x86-64-avx-ne-convert-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx-ne-convert.d: Ditto.
* testsuite/gas/i386/x86-64-avx-vnni-int8-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx-vnni-int8.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_bf16.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_bf16_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16-bad.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16_pseudo_ops.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_fp16_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_vpopcntdq-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512_vpopcntdq.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bitalg-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bitalg.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bitalg_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bitalg_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw-opts-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw-opts.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl-opts-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl-opts.d: Ditto.
* testsuite/gas/i386/x86-64-avx512bw_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512cd-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512cd.d: Ditto.
* testsuite/gas/i386/x86-64-avx512cd_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512cd_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512dq-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512dq.d: Ditto.
* testsuite/gas/i386/x86-64-avx512dq_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512dq_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512er-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512er.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f-nondef.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f-opts-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f-opts.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_gfni-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_gfni.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vaes-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vaes.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl-opts-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl-opts.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vpclmulqdq-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512f_vpclmulqdq.d: Ditto.
* testsuite/gas/i386/x86-64-avx512ifma-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512ifma.d: Ditto.
* testsuite/gas/i386/x86-64-avx512ifma_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512ifma_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512pf-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512pf.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi2-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi2.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi2_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi2_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vbmi_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_gfni-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_gfni.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_vaes-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_vaes.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_vpclmulqdq-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vl_vpclmulqdq.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vnni-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vnni.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vnni_vl-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx512vnni_vl.d: Ditto.
* testsuite/gas/i386/x86-64-avx_gfni-intel.d: Ditto.
* testsuite/gas/i386/x86-64-avx_gfni.d: Ditto.
* testsuite/gas/i386/x86-64-bmi-intel.d: Ditto.
* testsuite/gas/i386/x86-64-bmi.d: Ditto.
* testsuite/gas/i386/x86-64-bmi2-intel.d: Ditto.
* testsuite/gas/i386/x86-64-bmi2.d: Ditto.
* testsuite/gas/i386/x86-64-cldemote-intel.d: Ditto.
* testsuite/gas/i386/x86-64-cldemote.d: Ditto.
* testsuite/gas/i386/x86-64-clflushopt-intel.d: Ditto.
* testsuite/gas/i386/x86-64-clflushopt.d: Ditto.
* testsuite/gas/i386/x86-64-clwb-intel.d: Ditto.
* testsuite/gas/i386/x86-64-clwb.d: Ditto.
* testsuite/gas/i386/x86-64-cmpccxadd-intel.d: Ditto.
* testsuite/gas/i386/x86-64-cmpccxadd.d: Ditto.
* testsuite/gas/i386/x86-64-fred-intel.d: Ditto.
* testsuite/gas/i386/x86-64-fred.d: Ditto.
* testsuite/gas/i386/x86-64-gfni-intel.d: Ditto.
* testsuite/gas/i386/x86-64-gfni.d: Ditto.
* testsuite/gas/i386/x86-64-hreset.d: Ditto.
* testsuite/gas/i386/x86-64-invpcid-intel.d: Ditto.
* testsuite/gas/i386/x86-64-invpcid.d: Ditto.
* testsuite/gas/i386/x86-64-keylocker-intel.d: Ditto.
* testsuite/gas/i386/x86-64-keylocker.d: Ditto.
* testsuite/gas/i386/x86-64-lkgs-intel.d: Ditto.
* testsuite/gas/i386/x86-64-lkgs.d: Ditto.
* testsuite/gas/i386/x86-64-movsxd-intel.d: Ditto.
* testsuite/gas/i386/x86-64-movsxd.d: Ditto.
* testsuite/gas/i386/x86-64-msrlist-intel.d: Ditto.
* testsuite/gas/i386/x86-64-msrlist.d: Ditto.
* testsuite/gas/i386/x86-64-prefetchi-intel.d: Ditto.
* testsuite/gas/i386/x86-64-prefetchi.d: Ditto.
* testsuite/gas/i386/x86-64-prefetchwt1-intel.d: Ditto.
* testsuite/gas/i386/x86-64-prefetchwt1.d: Ditto.
* testsuite/gas/i386/x86-64-ptwrite-intel.d: Ditto.
* testsuite/gas/i386/x86-64-ptwrite.d: Ditto.
* testsuite/gas/i386/x86-64-raoint-intel.d: Ditto.
* testsuite/gas/i386/x86-64-raoint.d: Ditto.
* testsuite/gas/i386/x86-64-serialize.d: Ditto.
* testsuite/gas/i386/x86-64-sysenter.d: Ditto.
* testsuite/gas/i386/x86-64-tbm-intel.d: Ditto.
* testsuite/gas/i386/x86-64-tdx.d: Ditto.
* testsuite/gas/i386/x86-64-tsxldtrk.d: Ditto.
* testsuite/gas/i386/x86-64-uintr.d: Ditto.
* testsuite/gas/i386/x86-64-vp2intersect-intel.d: Ditto.
* testsuite/gas/i386/x86-64-vp2intersect.d: Ditto.
* testsuite/gas/i386/x86-64-vpclmulqdq-intel.d: Ditto.
* testsuite/gas/i386/x86-64-vpclmulqdq.d: Ditto.
* testsuite/gas/i386/x86-64-waitpkg-intel.d: Ditto.
* testsuite/gas/i386/x86-64-waitpkg.d: Ditto.
* testsuite/gas/i386/x86-64-wrmsrns-intel.d: Ditto.
* testsuite/gas/i386/x86-64-wrmsrns.d: Ditto.
* testsuite/gas/i386/x86-64-xsavec-intel.d: Ditto.
* testsuite/gas/i386/x86-64-xsavec.d: Ditto.
* testsuite/gas/i386/x86-64-xsaves-intel.d: Ditto.
* testsuite/gas/i386/x86-64-xsaves.d: Ditto.
* testsuite/gas/i386/xsavec-intel.d: Ditto.
* testsuite/gas/i386/xsavec.d: Ditto.
* testsuite/gas/i386/xsaves-intel.d: Ditto.
* testsuite/gas/i386/xsaves.d: Ditto.

18 months agoAutomatic date update in version.in
GDB Administrator [Tue, 28 Nov 2023 00:00:24 +0000 (00:00 +0000)] 
Automatic date update in version.in

18 months agoi386: Use a fallback XSAVE layout for remote targets
John Baldwin [Mon, 27 Nov 2023 21:53:22 +0000 (13:53 -0800)] 
i386: Use a fallback XSAVE layout for remote targets

If a target provides a target description including registers from the
XSAVE extended region, but does not provide an XSAVE layout, use a
fallback XSAVE layout based on the included registers.  This fallback
layout matches GDB's behavior in earlier releases which assumes the
layout from Intel CPUs.

This fallback layout is currently only used for remote targets since
native targets which support XSAVE provide an explicit layout derived
from CPUID.

PR gdb/30912
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30912
Approved-By: Simon Marchi <simon.marchi@efficios.com>
18 months ago[gdb/testsuite] Add boards/cc-with-index-cache.exp
Tom de Vries [Mon, 27 Nov 2023 20:15:26 +0000 (21:15 +0100)] 
[gdb/testsuite] Add boards/cc-with-index-cache.exp

We have a target board cc-with-gdb-index that uses the gdb-add-index script to
add a .gdb_index index to an exec.

There is however an alternative way of adding a .gdb_index: the index-cache.

Add a new target board cc-with-index-cache.

This is not superfluous for two reasons:
- there is functionality that gdb-add-index doesn't support, but the
  index-cache does: the index-cache can add an index to an exec with a
  .gnu_debugaltlink (note that when using the cc-with-gdb-index board this
  case is quietly ignored), and
- using the index-cache is excercised in only a few test-cases, and having
  this target board extends the test coverage to the entire test suite.  This
  is for instance relevant because the index-cache is written by a worker
  thread in the background, so we can check more thoroughly for data races
  (see PR symtab/30837).

Tested on x86_64-linux.

Shell script changes checked with shellcheck.

Approved-By: Tom Tromey <tom@tromey.com>
18 months agoChange serial_readchar to throw
Tom Tromey [Tue, 29 Aug 2023 14:22:09 +0000 (08:22 -0600)] 
Change serial_readchar to throw

This changes serial_readchar to throw an exception rather than trying
to set and preserve errno.

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

18 months agoChange serial_send_break and serial_write to throw
Tom Tromey [Wed, 6 Sep 2023 14:33:46 +0000 (08:33 -0600)] 
Change serial_send_break and serial_write to throw

This changes serial_send_break and serial_write to throw exceptions
rather than attempt to set errno and return an error indicator.  This
lets us correctly report failures on Windows.

Both functions had to be converted in a single patch because one
implementation of send_break works via write.

This also introduces remote_serial_send_break to handle error checking
when attempting to send a break.  This was previously ignored.

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

18 months agoChange serial "open" functions to throw exception
Tom Tromey [Fri, 1 Sep 2023 18:11:37 +0000 (12:11 -0600)] 
Change serial "open" functions to throw exception

remote.c assumes that a failure to open the serial connection will set
errno.  This is somewhat true, because the Windows code tries to set
errno appropriately -- but only somewhat, because it isn't clear that
the "pex" code sets it, and the tcp code seems to do the wrong thing.
It seems better to simply have the serial open functions throw on
error.

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

18 months agoChange serial_setbaudrate to throw exception
Tom Tromey [Tue, 29 Aug 2023 13:20:22 +0000 (07:20 -0600)] 
Change serial_setbaudrate to throw exception

remote.c has this code:

      if (serial_setbaudrate (rs->remote_desc, baud_rate))
{
  /* The requested speed could not be set.  Error out to
     top level after closing remote_desc.  Take care to
     set remote_desc to NULL to avoid closing remote_desc
     more than once.  */
  serial_close (rs->remote_desc);
  rs->remote_desc = NULL;
  perror_with_name (name);

The perror here cannot be correct, because if serial_setbaudrate did
set errno, it may be obscured by serial_close.

This patch changes serial_setbaudrate to throw an exception instead.

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

18 months agoIntroduce throw_winerror_with_name
Tom Tromey [Fri, 1 Sep 2023 17:01:33 +0000 (11:01 -0600)] 
Introduce throw_winerror_with_name

This introduces throw_winerror_with_name, a Windows analog of
perror_with_name, and changes various places in gdb to call it.

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

18 months agoFix latent bug in ser_windows_send_break
Tom Tromey [Fri, 1 Sep 2023 17:04:58 +0000 (11:04 -0600)] 
Fix latent bug in ser_windows_send_break

The ClearCommBreak documentation says:

    If the function fails, the return value is zero.

ser_windows_send_break inverts this check.  This has never been
noticed because the caller doesn't check the result.

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

19 months agoFix bug in DAP handling of 'pause' requests
Tom Tromey [Fri, 17 Nov 2023 17:08:50 +0000 (10:08 -0700)] 
Fix bug in DAP handling of 'pause' requests

While working on cancellation, I noticed that a DAP 'pause' request
would set the "do not emit the continue" flag.  This meant that a
subsequent request that should provoke a 'continue' event would
instead suppress the event.

I then tried writing a more obvious test case for this, involving an
inferior call -- and discovered that gdb.events.cont does not fire for
an inferior call.

This patch installs a new event listener for gdb.events.inferior_call
and arranges for this to emit continue and stop events when
appropriate.  It also fixes the original bug, by adding a check to
exec_and_expect_stop.

19 months agogdb: make catch_syscall_enabled return bool
Simon Marchi [Mon, 27 Nov 2023 15:45:51 +0000 (15:45 +0000)] 
gdb: make catch_syscall_enabled return bool

Make it return a bool and adjust a few comparisons where it's used.

Change-Id: Ic77d23b0dcfcfc9195dfe65e4c7ff9cf3229f6fb

19 months agogdb/python: handle completion returning a non-sequence
Andrew Burgess [Thu, 16 Nov 2023 14:42:56 +0000 (14:42 +0000)] 
gdb/python: handle completion returning a non-sequence

GDB's Python API documentation for gdb.Command.complete() says:

  The 'complete' method can return several values:
     * If the return value is a sequence, the contents of the
       sequence are used as the completions.  It is up to 'complete'
       to ensure that the contents actually do complete the word.  A
       zero-length sequence is allowed, it means that there were no
       completions available.  Only string elements of the sequence
       are used; other elements in the sequence are ignored.

     * If the return value is one of the 'COMPLETE_' constants
       defined below, then the corresponding GDB-internal completion
       function is invoked, and its result is used.

     * All other results are treated as though there were no
       available completions.

So, returning a non-sequence, and non-integer from a complete method
should be fine; it should just be treated as though there are no
completions.

However, if I write a complete method that returns None, I see this
behaviour:

  (gdb) complete completefilenone x
  Python Exception <class 'TypeError'>: 'NoneType' object is not iterable
  warning: internal error: Unhandled Python exception
  (gdb)

Which is caused because we currently assume that anything that is not
an integer must be iterable, and we call PyObject_GetIter on it.  When
this call fails a Python exception is set, but instead of
clearing (and therefore ignoring) this exception as we do everywhere
else in the Python completion code, we instead just return with the
exception set.

In this commit I add a PySequence_Check call.  If this call returns
false (and we've already checked the integer case) then we can assume
there are no completion results.

I've added a test which checks returning a non-sequence.

Approved-By: Tom Tromey <tom@tromey.com>
19 months agoas: Add new estimated reciprocal instructions in LoongArch v1.1
Jiajie Chen [Thu, 26 Oct 2023 09:35:14 +0000 (17:35 +0800)] 
as: Add new estimated reciprocal instructions in LoongArch v1.1

New estimated reciprocal instructions in LoongArch v1.1:

- frecipe.s/d
- frsqrte.s/d
- vfrecipe.s/d
- vfrsqrte.s/d
- xvfrecipe.s/d
- xvfrsqrte.s/d

Signed-off-by: Jiajie Chen <c@jia.je>
19 months agoas: Add new atomic instructions in LoongArch v1.1
Jiajie Chen [Thu, 26 Oct 2023 09:35:13 +0000 (17:35 +0800)] 
as: Add new atomic instructions in LoongArch v1.1

LoongArch V1.1 release is out at
https://github.com/loongson/LoongArch-Documentation.

New atomic instructions in LoongArch v1.1:

- sc.q
- llacq.w/d
- screl.w/d
- amcas{_db}.b/h/w/d
- amswap{_db}.b/h
- amadd{_db}.b/h

Signed-off-by: Jiajie Chen <c@jia.je>
19 months agoAutomatic date update in version.in
GDB Administrator [Mon, 27 Nov 2023 00:00:15 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agoAutomatic date update in version.in
GDB Administrator [Sun, 26 Nov 2023 00:00:12 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agoAutomatic date update in version.in
GDB Administrator [Sat, 25 Nov 2023 00:00:11 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months ago[gdb/testsuite] Use more %progbits for arm
Tom de Vries [Fri, 24 Nov 2023 14:41:22 +0000 (15:41 +0100)] 
[gdb/testsuite] Use more %progbits for arm

On pinebook I ran into:
...
Running gdb.tui/tui-layout-asm-short-prog.exp ...
gdb compile failed, gdb.tui/tui-layout-asm-short-prog.S: Assembler messages:
gdb.tui/tui-layout-asm-short-prog.S:23: Error: \
  junk at end of line, first unrecognized character is `,'
...

Fix this by using %progbits instead of @progbits for arm.

Approved-by: Luis Machado <luis.machado@arm.com>
Tested on x86_64-linux and pinebook.

19 months ago[gdb/testsuite] Two fixes in gdb.python/tui-window-disabled.exp
Tom de Vries [Fri, 24 Nov 2023 14:38:17 +0000 (15:38 +0100)] 
[gdb/testsuite] Two fixes in gdb.python/tui-window-disabled.exp

I ran test-case gdb.python/tui-window-disabled.exp on a configuration without
python support, and ran into:
...
PASS: $exp: cleanup_properly=True: initial restart: set pagination off
UNSUPPORTED: $exp: cleanup_properly=True: couldn't restart GDB
PASS: $exp: cleanup_properly=False: initial restart: set pagination off
UNSUPPORTED: $exp: cleanup_properly=False: couldn't restart GDB
...

After looking into the test-case, I realized that this is a consequence of
!allow_python_tests.

Handle this instead by requiring allow_python_tests, such that we get the usual
and more clear:
...
UNSUPPORTED: $exp: require failed: allow_python_tests
...

Also fix a return without value in clean_restart_and_setup, which if triggered
would cause:
...
ERROR: expected boolean value but got ""
...

Tested on x86_64-linux.

19 months agogdb: Fix "target file /proc/.../cmdline contained unexpected null characters"
Ilya Leoshkevich [Wed, 19 Jul 2023 11:27:45 +0000 (13:27 +0200)] 
gdb: Fix "target file /proc/.../cmdline contained unexpected null characters"

When using the gcore command, GDB prints the following warning:

    (gdb) gcore
    warning: target file /proc/.../cmdline contained unexpected null characters

The reason is that cmdline is read with target_fileio_read_stralloc(),
which warns on seeing null characters. However, it's perfectly valid
for cmdline to contain \0s, so switch to target_fileio_read_alloc().

Approved-By: Tom Tromey <tom@tromey.com>
19 months agoRISC-V: drop leftover match_never() references
Jan Beulich [Fri, 24 Nov 2023 09:15:59 +0000 (10:15 +0100)] 
RISC-V: drop leftover match_never() references

Commit 27b33966b18e "RISC-V: disallow x0 with certain macro-insns"
wasn't properly re-based over recent opcode table additions.

19 months agox86: shrink opcode sets table
Jan Beulich [Fri, 24 Nov 2023 08:55:51 +0000 (09:55 +0100)] 
x86: shrink opcode sets table

Have i386-gen produce merely the offsets into i386_optab[]. Besides
allowing to shrink the table even on 32-bit builds, this results in
removing a level of indirection from the frequently accessed
current_templates, in return for adding a level of indirection when
looking up mnemonics (commonly happening just once per insn). Plus for
PIE builds of gas it also reduces the number of relocations by about two
thousand. Finally a somewhat ugly static variable can also be eliminated
from i386_displacement().

19 months agox86: also prefer VEX encoding over EVEX one for VCVTNEPS2BF16 when possible
Jan Beulich [Fri, 24 Nov 2023 08:55:29 +0000 (09:55 +0100)] 
x86: also prefer VEX encoding over EVEX one for VCVTNEPS2BF16 when possible

Deal with what 58bceb182740 ("x86: prefer VEX encodings over EVEX ones
when possible") left out, for being slightly less straightforward.

19 months agoRISC-V: reduce redundancy in sign/zero extension macro insn handling
Jan Beulich [Fri, 24 Nov 2023 08:53:55 +0000 (09:53 +0100)] 
RISC-V: reduce redundancy in sign/zero extension macro insn handling

Fold M_{S,Z}EXTH, deriving signed-ness from the incoming mnemonic. Fold
riscv_ext()'s calls md_assemblef(), the first of which were entirely
identical, while the other pair differed in just a single character.

Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
19 months agoRISC-V: disallow x0 with certain macro-insns
Jan Beulich [Fri, 24 Nov 2023 08:53:15 +0000 (09:53 +0100)] 
RISC-V: disallow x0 with certain macro-insns

While for some of the macro insns using x0 is kind of okay, as they
would merely resolve to a sequence of hint insns (and hence not cause
misbehavior at runtime), several of them have the degenerate AUIPC
followed by a load, store, or branch using other than the designated
symbol as address and hence causing runtime issues. Refuse to assemble
those, leveraging that the matching function so far wasn't really used
for macro insns: NULL is now allowed, indicating a match (which imo is
preferable over converting match_never() to match_always()), while
other matching functions now (also) used for macro insns need to avoid
calling match_opcode().

Note that for LA the restriction is slightly too strict: In non-PIC mode
using x0 would be okay-ish as per above (as it's just LLA there). Yet
libopcodes doesn't know what mode gas is presently assembling for, so we
want to err on the safe side.

Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
19 months agoFix building for the s390 target with clang
Nick Clifton [Fri, 24 Nov 2023 08:10:12 +0000 (08:10 +0000)] 
Fix building for the s390 target with clang

19 months agoRISC-V: Update 'Zfa' extension version
zengxiao [Tue, 21 Nov 2023 06:11:21 +0000 (14:11 +0800)] 
RISC-V: Update 'Zfa' extension version

Because the 'Zfa' extension has a version number of 1.0
(not 0.1). This commit updates the number.

bfd/ChangeLog:

            * elfxx-riscv.c (riscv_supported_std_z_ext): Update the version
            number of the 'Zfa' extension since it's ratified.

19 months agoAutomatic date update in version.in
GDB Administrator [Fri, 24 Nov 2023 00:00:10 +0000 (00:00 +0000)] 
Automatic date update in version.in

19 months agos390: Correct prno instruction name
Jens Remus [Thu, 23 Nov 2023 14:48:59 +0000 (15:48 +0100)] 
s390: Correct prno instruction name

IBM z13 (arch11) introduced ppno (Perform Pseudorandom Number Operation).
IBM z14 (arch12) introduced prno (Perform Random Number Operation) and
deprecated ppno.

opcodes/
* s390-opc.txt: Correct prno instruction name.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
19 months agos390: Add missing extended mnemonics
Jens Remus [Thu, 23 Nov 2023 14:48:15 +0000 (15:48 +0100)] 
s390: Add missing extended mnemonics

Add extended mnemonics specified in the z/Architecture Principles of
Operation [1] and z/Architecture Reference Summary [2], that were
previously missing from the opcode table.

The following added extended mnemonics are synonyms to a base mnemonic
and therefore disassemble into their base mnemonic:
jc, jcth, lfi, llgfi, llghi

The following added extended mnemonics are more specific than their base
mnemonic and therefore disassemble into the added extended mnemonic:
risbhgz, risblgz, rnsbgt, rosbgt, rxsbgt

The following added extended mnemonics are more specific than their base
mnemonic, but disassemble into their base mnemonic due to design
constraints:
notr, notgr

The missing extended mnemonic jl* conditional jump long flavors cannot
be added, as they would clash with the existing non-standard extended
mnemonic j* conditional jump flavors jle and jlh. The missing extended
mnemonic jlc jump long conditional is not added, as the related jl*
flavors cannot be added.
Note that these missing jl* conditional jump long flavors are already
defined as non-standard jg* flavors instead. While the related missing
extended mnemonic jlc could be added as non-standard jgc instead it is
forgone in favor of not adding further non-standard mnemonics.

The missing extended mnemonics sllhh, sllhl, slllh, srlhh, srlhl, and
srllh cannot be implemented using the current design, as they require
computed operands. For that reason the following missing extended
mnemonics are not added as well, as they fall into the same category of
instructions that operate on high and low words of registers. They
should better be added together, not to confuse the user, which of those
instructions are currently implemented or not.
lhhr, lhlr, llhfr, llchhr, llchlr, llclhr, llhhhr, llhhlr, llhlhr,
nhhr, nhlr, nlhr, ohhr, ohlr, olhr, xhhr, xhlr, xlhr

[1] IBM z/Architecture Principles of Operation, SA22-7832-13, IBM z16,
    https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf
[2] IBM z/Architecture Reference Summary, SA22-7871-11,
    https://www.ibm.com/support/pages/sites/default/files/2022-09/SA22-7871-11.pdf

opcodes/
* s390-opc.c: Define operand formats R_CP16_28, U6_18, and
  U5_27. Define instruction formats RIE_RRUUU3, RIE_RRUUU4,
  and RRF_R0RR4.
* s390-opc.txt: Add extended mnemonics jc, jcth, lfi, llgfi,
  llghi, notgr, notr, risbhgz, risblgz, rnsbgt, rosbgt, and
  rxsbgt.

gas/
* config/tc-s390.c: Add support to insert operand for format
  R_CP16_28, reusing existing logic for format V_CP16_12.
* testsuite/gas/s390/esa-g5.s: Add test for extended mnemonic
  jc.
* testsuite/gas/s390/esa-g5.d: Likewise.
* testsuite/gas/s390/zarch-z900.s: Add test for extended
  mnemonic llghi.
* testsuite/gas/s390/zarch-z900.d: Likewise.
* testsuite/gas/s390/zarch-z9-109.s: Add tests for extended
  mnemonics lfi and llgfi.
* testsuite/gas/s390/zarch-z9-109.d: Likewise.
* testsuite/gas/s390/zarch-z10.s: Add tests for extended
  mnemonics rnsbgt, rosbgt, and rxsbgt.
* testsuite/gas/s390/zarch-z10.d: Likewise.
* testsuite/gas/s390/zarch-z196.s: Add tests for extended
  mnemonics jcth, risbhgz, and risblgz.
* testsuite/gas/s390/zarch-z196.d: Likewise.
* testsuite/gas/s390/zarch-arch13.s: Add tests for extended
  mnemonics notr and notgr.
* testsuite/gas/s390/zarch-arch13.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
19 months agos390: Align optional operand definition to specs
Jens Remus [Thu, 23 Nov 2023 14:46:46 +0000 (15:46 +0100)] 
s390: Align optional operand definition to specs

The IBM z/Architecture Principle of Operation [1] specifies the last
operand(s) of some (extended) mnemonics to be optional. Align the
mnemonic definitions in the opcode table according to specification.

This changes the last operand of the following (extended) mnemonics to
be optional:
risbg, risbgz, risbgn, risbgnz, risbhg, risblg, rnsbg, rosbg, rxsbg

Note that efpc and sfpc actually have only one operand, but had
erroneously been defined to have two. For backwards compatibility the
wrong RR register format must be retained. Since the superfluous second
operand is defined as optional the instruction can still be coded as
specified.

[1]: IBM z/Architecture Principles of Operation, SA22-7832-13, IBM z16,
     https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf

opcodes/
* s390-opc.txt: Align optional operand definition to
specification.

testsuite/
* zarch-z10.s: Add test cases for risbg, risbgz, rnsbg, rosbg,
  and rxsbg.
* zarch-z10.d: Likewise.
* zarch-z196.s: Add test cases for risbhg and risblg.
* zarch-z196.d: Likewise.
* zarch-zEC12.s: Add test cases for risbgn and risbgnz.
* zarch-zEC12.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
19 months agos390: Make operand table indices relative to each other
Jens Remus [Thu, 23 Nov 2023 14:45:42 +0000 (15:45 +0100)] 
s390: Make operand table indices relative to each other

This is a purely mechanical change. It allows subsequent insertions into
the operands table without having to renumber all operand indices.

The only differences in the resulting ELF object are in the .debug_info
section. This has been confirmed by diffing the following xxd and readelf
output:

xxd s390-opc.o
readelf -aW -x .text -x .data -x .bss -x .rodata -x .debug_info \
  -x .symtab -x .strtab -x .shstrtab --debug-dump s390-opc.o

opcodes/
* s390-opc.c: Make operand table indices relative to each other.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>