From: YuPeng <yupeng@kylinos.cn>
To: gdb-patches@sourceware.org
Cc: tromey@sourceware.org,chouryzh@gmail.com,debianyu@163.com
Subject: [PATCH] [gdb] bpf: Set long_bit and ptr_bit
Date: Mon, 02 Nov 2026 15:00:12 +0800 [thread overview]
Message-ID: <1793602812842387278.27500@kylinos.cn> (raw)
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
next reply other threads:[~2026-11-02 7:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 7:00 YuPeng [this message]
2026-11-05 19:21 ` Tom Tromey
2026-11-17 8:36 ` YuPeng
2026-11-17 15:16 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1793602812842387278.27500@kylinos.cn \
--to=yupeng@kylinos.cn \
--cc=chouryzh@gmail.com \
--cc=debianyu@163.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox