Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb] bpf: Set long_bit and ptr_bit
@ 2026-11-02  7:00 YuPeng
  2026-11-05 19:21 ` Tom Tromey
  0 siblings, 1 reply; 4+ messages in thread
From: YuPeng @ 2026-11-02  7:00 UTC (permalink / raw)
  To: gdb-patches; +Cc: tromey, chouryzh, debianyu

bpf_gdbarch_init sets no bit-size hooks, so long_bit and ptr_bit fall
back to their 32-bit defaults.  BPF is a 64-bit ISA: as a consequence,
bpf_register_type returns the 4-byte builtin_data_ptr and
builtin_func_ptr types for r10 and pc, while frame unwinders access
those registers as 8-byte values, and the first raw_read of r10 after
a backtrace trips:

  raw_read: Assertion `dst.size () == m_descr->sizeof_register[regnum]' failed.

Fix this by setting long_bit and ptr_bit to 64.  addr_bit defaults to
ptr_bit, and the short_bit, int_bit and long_long_bit defaults are
already correct for BPF, so no other hooks need to be set.

The mismatch is observable without a BPF target:

  $ gdb -batch -ex "set architecture bpf" -ex "maintenance print registers"

reports Size 4 for r10 and pc before the fix, and Size 8 after it.

The root cause analysis and the original version of this fix are from
the bug report, filed by choury.

Tested on x86_64-linux.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34435
Co-Authored-By: choury <chouryzh@gmail.com>
---

The change was verified on master (commit b3874756), and gdb/bpf-tdep.c
is still identical on current master (commit 19c3a4c4): the patch
applies cleanly with git am, and gdb was rebuilt before and after it.
Before the fix, "set architecture bpf" followed by "maintenance print
registers" reports:

  r10        10   10   80       4     *1
  pc         11   11   84       4     *1

After the fix, r10 and pc report Size 8:

  r10        10   10   80       8     *1
  pc         11   11   88       8     *1

This is a small change (2 lines of code plus comment), so I believe
no FSF copyright assignment is needed.

gdb/bpf-tdep.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gdb/bpf-tdep.c b/gdb/bpf-tdep.c
index 5ae9fc6..d059046 100644
--- a/gdb/bpf-tdep.c
+++ b/gdb/bpf-tdep.c
@@ -323,6 +323,15 @@ bpf_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   gdbarch *gdbarch
     = gdbarch_alloc (&info, gdbarch_tdep_up (new bpf_gdbarch_tdep));
 
+  /* Bit sizes of the fundamental types.  BPF is a 64-bit ISA; with the
+     32-bit defaults, bpf_register_type would return 4-byte pointer
+     types for r10 and pc, while the frame unwinders access them as
+     8-byte registers.  addr_bit defaults to ptr_bit, and the defaults
+     for short_bit, int_bit and long_long_bit (16, 32 and 64) are
+     already correct for BPF, so only these two need to be set.  */
+  set_gdbarch_long_bit (gdbarch, 64);
+  set_gdbarch_ptr_bit (gdbarch, 64);
+
   /* Information about registers, etc.  */
   set_gdbarch_num_regs (gdbarch, BPF_NUM_REGS);
   set_gdbarch_register_name (gdbarch, bpf_register_name);
-- 
2.39.5

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-17 15:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02  7:00 [PATCH] [gdb] bpf: Set long_bit and ptr_bit YuPeng
2026-11-05 19:21 ` Tom Tromey
2026-11-17  8:36   ` YuPeng
2026-11-17 15:16     ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox