Public bug reported:

Ubuntu release: 24.04 LTS (noble), arm64
Package: gdbserver 15.1-1ubuntu1~24.04.1 (noble-updates). 
15.0.50.20240403-0ubuntu1 (noble release) has the same bug.
Seen on: NVIDIA Jetson AGX Thor Developer Kit

== What happens ==

On an arm64 system that has SVE with a 128-bit vector length, gdbserver
aborts on the first "continue" (or "step" / "next") sent by a remote
gdb:

 ../../gdbserver/regcache.cc:534: A problem internal to GDBserver has been 
detected.
 raw_compare: Assertion 'offset < regbuf.size ()' failed.
 Aborted (core dumped)

The gdb client reports "Remote connection closed". It happens every
time, with any program, so remote debugging with gdbserver does not work
on these systems.

It does not happen on arm64 without SVE, on SVE systems with a larger
vector length, or on amd64. Native gdb on the same system works.

Expected: the program runs to the breakpoint and the debug session
continues.

== Steps to reproduce ==

 $ cat /proc/sys/abi/sve_default_vector_length
 16

 $ printf 'int main(void){return 0;}\n' > t.c && gcc -g -O0 -o t t.c
 $ gdbserver --once :1234 ./t &
 $ gdb -q -batch -ex 'target remote localhost:1234' -ex 'break main' -ex 
'continue' ./t

No special hardware is needed. A QEMU guest started with "-cpu
max,sve128=on" reproduces it. So does any SVE system after "echo 16 >
/proc/sys/abi/sve_default_vector_length". A plain "-cpu max" guest has a
512-bit default vector length and does not reproduce it.

== Cause ==

When gdbserver writes registers back before resuming the program, the
SVE code compares the part of each Z register above the first 128 bits
against zero. With a 128-bit vector length that part is empty, so the
compare starts at an offset equal to the register size. gdbserver's
raw_compare asserts "offset < size" and rejects this valid zero-length
compare. gdb's own copy of the same function uses "<=", which is why
native gdb works.

The strict assert came in during GDB 15 development (upstream commit
51e6b8cfd649), so it is in every 15.x and in 16.1 and 16.2.

== Fix ==

Fixed upstream in GDB 16.3 by one commit:

 1137625d46f3 "Fix gdbserver crashes on SVE/SME-enabled systems"
 
https://gnu.googlesource.com/binutils-gdb/+/1137625d46f3840dd7cb7f8519ec9dcba0acd53e

The functional change is one line in gdbserver/regcache.cc:

 -  gdb_assert (offset < regbuf.size ());
 +  gdb_assert (offset <= regbuf.size ());

Upstream did not backport it to the 15 branch, so no 15.x release has
it. Every Ubuntu series after noble has 16.3 or newer.

== Upstream ==

 - Upstream bug, PR gdb/32775: 
https://sourceware.org/bugzilla/show_bug.cgi?id=32775
 - The same commit on the 16 branch: 
https://gnu.googlesource.com/binutils-gdb/+/5c89e5539aef2992a2417be55307c9071ffbe89c
 - The upstream commit also adds a selftest in gdbserver/server.cc. Only the 
one-line regcache.cc change is needed for the fix.

** Affects: gdb (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: noble

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2174807

Title:
  gdbserver aborts on "continue" on arm64 SVE systems with a 128-bit
  vector length (raw_compare assertion)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/2174807/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to