[Bug dap/34435] New: BPF target crashes on `info registers` after `backtrace`
chouryzh at gmail dot com via Gdb-prs <[email protected]>
| Newsgroups | gmane.comp.gdb.bugs.discuss |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://sourceware.org/bugzilla/show_bug.cgi?id=34435
Bug ID: 34435
Summary: BPF target crashes on `info registers` after
`backtrace`
Product: gdb
Version: HEAD
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: dap
Assignee: unassigned at sourceware dot org
Reporter: chouryzh at gmail dot com
Target Milestone: ---
## Summary
`bpf_gdbarch_init` never sets `ptr_bit`/`long_bit`/`int_bit`. With `ptr_bit`
defaulting to 32, `bpf_register_type` returns
`builtin_data_ptr`/`builtin_func_ptr`
(4 bytes) for r10/pc, but frame unwinders read SP/PC with an 8-byte buffer. The
first `raw_read(r10)` after a `backtrace` then trips:
```
regcache.c: raw_read: Assertion `dst.size () ==
m_descr->sizeof_register[regnum]' failed.
```
BPF is a 64-bit ISA (r0..r10 are all 64-bit); these settings appear to be
simply
missing — every other target sets them.
## Reproduction
No target needed — the size mismatch is visible directly:
```
$ gdb -batch -ex "set architecture bpf" -ex "maintenance print registers"
Name Nr Rel Offset Size Type
r0 0 0 0 8 int64_t
...
r9 9 9 72 8 int64_t
r10 10 10 80 4 *1 <- SP, should be 8
pc 11 11 84 4 *1 <- 64-bit address, should be 8
```
End-to-end against any BPF remote target: `break`/`continue`/`backtrace`/`info
registers`
crashes. (`info registers` alone doesn't — `bt` first reads SP as 8-byte,
priming the inconsistency.)
`Target-supplied registers are not supported by the current architecture`, so a
target description cannot paper over this; the fix must be in `bpf-tdep.c`.
## Root cause
`gdb/bpf-tdep.c`:
```c
bpf_register_type (...) {
if (reg == BPF_R10_REGNUM) return builtin_data_ptr; /* len = ptr_bit/8 */
if (reg == BPF_PC_REGNUM) return builtin_func_ptr; /* len = ptr_bit/8 */
return builtin_int64;
}
```
`bpf_gdbarch_init` sets `num_regs`/`register_name`/`register_type`/... but not
the bit-size hooks, so `sizeof_register[r10/pc] = 4` while unwinders use 8.
## Fix
```c
gdbarch *gdbarch = gdbarch_alloc (&info, gdbarch_tdep_up (new
bpf_gdbarch_tdep));
+ set_gdbarch_short_bit (gdbarch, 16);
+ set_gdbarch_int_bit (gdbarch, 32);
+ set_gdbarch_long_bit (gdbarch, 64);
+ set_gdbarch_long_long_bit (gdbarch, 64);
+ set_gdbarch_ptr_bit (gdbarch, 64);
+ set_gdbarch_addr_bit (gdbarch, 64);
+
set_gdbarch_num_regs (gdbarch, BPF_NUM_REGS);
```
Verified on HEAD (1fba9bb3) and 16.3: `maintenance print registers` reports
r10/pc as Size=8; `bt` then `info registers` no longer crashes against a BPF
remote target. (gdbserver must then send a 96-byte `g` packet = 12 × 8,
matching
the corrected layout.)
--
You are receiving this mail because:
You are on the CC list for the bug.