* [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* Re: [PATCH] [gdb] bpf: Set long_bit and ptr_bit
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
0 siblings, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2026-11-05 19:21 UTC (permalink / raw)
To: YuPeng; +Cc: gdb-patches, tromey, chouryzh, debianyu
>>>>> YuPeng <yupeng@kylinos.cn> writes:
> 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.
Thanks for the patch. FWIW this looks good to me.
Approved-By: Tom Tromey <tom@tromey.com>
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [gdb] bpf: Set long_bit and ptr_bit
2026-11-05 19:21 ` Tom Tromey
@ 2026-11-17 8:36 ` YuPeng
2026-11-17 15:16 ` Tom Tromey
0 siblings, 1 reply; 4+ messages in thread
From: YuPeng @ 2026-11-17 8:36 UTC (permalink / raw)
To: gdb-patches; +Cc: tom, chouryzh, debianyu
Hi Tom,
(My previous reply was posted as a separate HTML message, so I am
resending it in plain text.)
Thanks for the review and the approval.
I don't have write access to the sourceware git repository, so could I
ask you to push this on my behalf? The patch is unchanged since your
review and still applies cleanly on top of the current master
(gdb/bpf-tdep.c is unchanged, base blob 5ae9fc6); it was tested on
x86_64-linux.
Thanks,
YuPeng
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [gdb] bpf: Set long_bit and ptr_bit
2026-11-17 8:36 ` YuPeng
@ 2026-11-17 15:16 ` Tom Tromey
0 siblings, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2026-11-17 15:16 UTC (permalink / raw)
To: YuPeng; +Cc: gdb-patches, tom, chouryzh, debianyu
>>>>> YuPeng <yupeng@kylinos.cn> writes:
> Thanks for the review and the approval.
> I don't have write access to the sourceware git repository, so could I
> ask you to push this on my behalf? The patch is unchanged since your
> review and still applies cleanly on top of the current master
> (gdb/bpf-tdep.c is unchanged, base blob 5ae9fc6); it was tested on
> x86_64-linux.
No problem, I've done it now.
Tom
^ 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