From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id pDnlECU16GrjoDMAWB0awg (envelope-from ) for ; Mon, 02 Nov 2026 02:00:53 -0500 Received: by simark.ca (Postfix, from userid 112) id 2E270378003; Mon, 02 Nov 2026 02:00:53 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2BD3B378002 for ; Mon, 02 Nov 2026 02:00:51 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B11C64B99F6B for ; Mon, 2 Nov 2026 07:00:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B11C64B99F6B Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by sourceware.org (Postfix) with ESMTPS id 099CB4BA2E1F; Mon, 2 Nov 2026 07:00:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 099CB4BA2E1F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kylinos.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 099CB4BA2E1F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793602824; cv=none; b=XJSCRkjiSIL3uZrEf+mQcVqyKr5Fou2Z3CRptqonraRKvY2/IkqhrlkUo4NWnF2Di/q6hc908fXQXaTvGmkvWvUB3OU1G32Hjb3S29B819wcQiU819N1yEW5SBLslmrfjzrHgjENmJofe+KwWe7c5v20xzu0oOiOgNOP8gg1FHE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793602824; c=relaxed/simple; bh=D6CK5zB29Bheq9auumdkY64juVXf3caAr4j7LvpG6+s=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=CTqtS3L4IsJ8RkDVA1080F1mtKHi/f05yI3KUYRkDH6KG8GS9dke9bpmix0TjColHiP0dct34cHSZjASDMLNBpoR9jv1eVljr/IaUuDJz59O0Z3m2+YwV9i08lsDiR/QyFIiPWyXz7xRc9+jYHjZayiYk5VThS+XPc92mvwlCAs= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 099CB4BA2E1F X-UUID: 0e437b9cd68b11f19a56ed5b684f684d-20261102 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19, REQID:1a090e35-73ab-4286-bcf5-165a980ddf88, IP:0, U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:7db8b62, CLOUDID:1482397be44e3fede066011e3646d8ed, BulkI D:nil,BulkQuantity:0,SF:102|865|898,TC:nil,Content:0|15|50|99,EDM:-3,IP:ni l,URL:99|1,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0, LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULS X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 0e437b9cd68b11f19a56ed5b684f684d-20261102 X-User: yupeng@kylinos.cn Received: from send-mail.1lzd9r [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1001878193; Mon, 02 Nov 2026 15:00:15 +0800 From: YuPeng 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 Message-ID: <1793602812842387278.27500@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 --- 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