From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id U/MzG8ZNYWo+TCcAWB0awg (envelope-from ) for ; Wed, 22 Jul 2026 19:09:58 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=pbwmMICX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 517211E033; Wed, 22 Jul 2026 19:09:58 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 480C51E033 for ; Wed, 22 Jul 2026 19:09:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A0574BA2E2B for ; Wed, 22 Jul 2026 23:09:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A0574BA2E2B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=pbwmMICX Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id D88504BA543C for ; Wed, 22 Jul 2026 23:09:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D88504BA543C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D88504BA543C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784761770; cv=none; b=Hn84JzKFieHPziUFg8OjMsjudVlAsc45/StSkhwIKjGMktmlHXYxkJhYth9l0aKIWwkZXOeNgPCUWjahO9S9zKMvBdOPMlBipwLybLgHVmdX0s84QSdN98Beaw1Yr82BzD3ID9FlAhi+KQBRA5tKFFhDJ/eZMvCpJlaAy23md+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784761770; c=relaxed/simple; bh=2Lvzh1PPrj+YPl35cyzZm+2qDI7irouMYuRUyhLvIik=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=OhhMun4iSqFkv9nHTJMQArvXbB4hvoTY6rFlcj8F7GsVwBRyf+hnlZgLaIUUK+hXVVNU3jXXk6S2I697mwvpkZcUAFkZDRVVrZbvU4cB3XbOzup41UDfRT2dh9dwLDgOwpUCtpLshAevvJspz0xIkbXxGXkumlTia2KJJnWzBn8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=pbwmMICX DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D88504BA543C Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-47de0093c42so7781333f8f.3 for ; Wed, 22 Jul 2026 16:09:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784761768; x=1785366568; darn=sourceware.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RD0AWTget72ab2R0OpJ2Zikd750AZ0j2nv/Fvs0hRhA=; b=pbwmMICX5RCDhMYr3AMzXTXL/945uKeeM+73FWGdIbyeTNeTgs5lB3/wio6vVnXbmp ncjonceay44fE0QcEPElXDXuqDZ2KMX6pRmaOcQXOfdDKlkbFxpN50L8KVsyru4JZhC6 Zl1QujQo/4tvv1Eo+lXqQR6Snr3+h39U7dXjBRffaGME6n4+iXTTrfwiS1dlDAr2mOmF WNrn0cUZwoxcb85eSU6wgD7c7KYKMY6fm0xLVzLeL5TJV0JWfo5vGqhbgVxpscJ8OoQr 0NRGTSddya0NlZYtckTYs710YNb7YTNsVjn5t5OB1eL6IkQSl5/l0PDB2PzM3Ndrluhd 0h5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784761768; x=1785366568; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RD0AWTget72ab2R0OpJ2Zikd750AZ0j2nv/Fvs0hRhA=; b=B0U7KEH8XApyzWeEZ0EskxAHBxT5vdLEu0bsHUNjdq9ivRPQfWmgZUHomJG4E8H6FD iAoKPJh70Kke49hpvsnBHYSyU9KdHbbW//pqQdvCVbLQ0ZY4ZGjNqUp7kdJQvNBy8arN 6ks5DJpnTN7nBUNCxvna1ebr6NFPDVDqIU4YHnR0B40+uPqkoRJtm2z71ucO1f7HwX1P MsJjtgRLuahbV6rimaBV7TlWEYKVw9nCAFMMkKy6uD/y/d+TUIebHEA+Md/1fY6MWC6S 4cT2URNKwkfNiPxQZmfIgt1CSAOJHwTLd5mnKqtnA8QOvkAzotWzwji8OokC/TmM8W5d c0GQ== X-Forwarded-Encrypted: i=1; AHgh+RqNfthFVisH0IErBSASCuOAcz9gTJDJJBV5xBCsBK/QzB1VQ4sB7HbSAvPuwdY2jGYKKtomX6H2/I2L/Q==@sourceware.org X-Gm-Message-State: AOJu0Yypbf0VV41UmpIUOiGMFMpNldyn79bQmj2YeB+ESMpOe0RsGZVs fiB8Xc8jlCYPSUXDwhWItlQV/bZrD02wOimjMJmak0NeCLVW4VaRbiRX X-Gm-Gg: AR+sD120s6gNw5ypaNc+6yQQS12aQH18F5DZbhjinbcguIATH6fR2bqjdm4a3d1WEIE 4+NE3zbdvj9eDeZrHtTgKLvoIUFL7xmwyrYM4KkrjiI9dtdqcrD0FbyUhho+RhMBMnK7EczqSmO 5svrIjPZWAgXteM1WXIraU7wIVRG0oVWtOa6o+SW91vGCvmCItI37qfK6gfOUmfTBPU042T5sld 9FNNFeQoem4kwnVCOwqSf8YkHG8g66pubM6dvcGGwS9w07Nn2myIRZ9lxc7y7j8KmrZrVCUjb0A zsF31WxpaMFNn0Hon1/zJD5LxhruFLtoIlxKBUAwtTsXnEX872SFkONQHnPXUPIt/aBIYViGptB QJ+tE9R8Fx4ezPpfuYn4EItHB7Myjckq5mj0LyQsEkxkiWMt7wK2gFTB9aScISn/wE8xhGDOwtS 3s75vNAwx0C0YE5y4= X-Received: by 2002:a05:6000:230a:b0:47f:8aba:8a9a with SMTP id ffacd0b85a97d-47f8d71c7eamr885842f8f.18.1784761768357; Wed, 22 Jul 2026 16:09:28 -0700 (PDT) Received: from [192.168.0.38] ([86.12.216.189]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85b9a5c4sm9526322f8f.8.2026.07.22.16.09.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jul 2026 16:09:27 -0700 (PDT) Message-ID: <82f5d130-cfa5-46e1-b640-f575f6ab00b9@gmail.com> Date: Thu, 23 Jul 2026 00:09:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] gdb: align siginfo_t with the Linux kernel definition To: Matthieu Longo , gdb-patches@sourceware.org Cc: Thiago Jung Bauermann , Luis Machado , Tom Tromey , Andrew Burgess , Srinath Parvathaneni References: <20260702165231.331169-1-matthieu.longo@arm.com> Content-Language: en-US From: Luis In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed 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 Hi Matthieu, On 22/07/2026 16:00, Matthieu Longo wrote: > On 21/07/2026 22:09, Luis wrote: >> On 02/07/2026 17:52, Matthieu Longo wrote: >>> GDB's current definition of siginfo_t is missing many fields present in >>> the Linux kernel definition [1]. >>> >>> These fields are useful for providing detailed, user-friendly diagnostics >>> when a fault occurs. Some new AArch64 extensions, such as Permission >>> Overlay Enhancement used to implement Protection Keys [2], require the >>> debugger to inspect 'si_pkey' alongside 'si_addr' to help the user identify >>> the problematic key. >>> >>> This patch aligns GDB's definition of the __sifields._sigfault member of >>> siginfo_t with the definition from the Linux kernel master branch. >>> >>> [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ >>>       tree/include/uapi/asm-generic/siginfo.h#n69 >>> [2]: https://lore.kernel.org/all/20160212210213.ABC488FA@viggo.jf.intel.com/ >>> >>> Reviewed-by: Thiago Jung Bauermann >>> --- >>>   gdb/linux-tdep.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- >>>   1 file changed, 44 insertions(+), 2 deletions(-) >>> >>> diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c >>> index a7381677498..d5b0e6e7011 100644 >>> --- a/gdb/linux-tdep.c >>> +++ b/gdb/linux-tdep.c >>> @@ -275,7 +275,7 @@ linux_get_siginfo_type (struct gdbarch *gdbarch) >>>     struct type *void_ptr_type; >>>     struct type *uid_type, *pid_type; >>>     struct type *sigval_type, *clock_type; >>> -  struct type *siginfo_type, *sifields_type; >>> +  struct type *siginfo_type, *sifields_type, *sigfault_union_type; >>>     struct type *type; >>>       linux_gdbarch_data = get_linux_gdbarch_data (gdbarch); >>> @@ -285,11 +285,21 @@ linux_get_siginfo_type (struct gdbarch *gdbarch) >>>     type_allocator alloc (gdbarch); >>>       const struct builtin_type *builtin_types = builtin_type (gdbarch); >>> +  struct type *short_type = builtin_types->builtin_short; >>>     struct type *int_type = builtin_types->builtin_int; >>>     struct type *uint_type = builtin_types->builtin_unsigned_int; >>>     struct type *long_type = builtin_types->builtin_long; >>> +  struct type *unsigned_long_type = builtin_types->builtin_unsigned_long; >>> +  struct type *uint32_type = builtin_types->builtin_uint32; >>>       void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void); >> >> Nit: Blank line here for cleanliness. >> > > Fixed. > >>> +  /* Compute padding length, i.e. __ADDR_BND_PKEY_PAD.  */ >>> +  unsigned alignof_void_ptr = type_align (void_ptr_type); >>> +  unsigned padding_size = (alignof_void_ptr < sizeof(short) >> >> Logic: Are we mixing host-side sizeof (short) with target-side type_align (void_ptr_type) here? >> > > Yes, you're right. Sorry, I missed that. The below should be better. > > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -295,8 +295,8 @@ linux_get_siginfo_type (struct gdbarch *gdbarch) > > /* Compute padding length, i.e. __ADDR_BND_PKEY_PAD. */ > unsigned alignof_void_ptr = type_align (void_ptr_type); > - unsigned padding_size = (alignof_void_ptr < sizeof(short) > - ? sizeof(short) > + unsigned padding_size = (alignof_void_ptr < short_type->length () > + ? short_type->length () > : alignof_void_ptr); > struct type *addr_bnd_pkey_padding_type > = init_vector_type (builtin_types->builtin_uint8, padding_size); > >> Formatting: Space between sizeof and parens. Multiple cases of this one. >> >>> +               ? sizeof(short) >>> +               : alignof_void_ptr); >>> +  struct type *addr_bnd_pkey_padding_type >>> +    = init_vector_type (builtin_types->builtin_uint8, padding_size); >>>       /* sival_t */ >>>     sigval_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); >>> @@ -364,9 +374,41 @@ linux_get_siginfo_type (struct gdbarch *gdbarch) >>>     append_composite_type_field (type, "si_stime", clock_type); >>>     append_composite_type_field (sifields_type, "_sigchld", type); >>>   -  /* _sigfault */ >>> +  /* Begin _sigfault's anonymous union.  */ >>> +  sigfault_union_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION); >>> +  /* used on alpha and sparc */ >>> +  append_composite_type_field (sigfault_union_type, "si_trapno", int_type); >>> +  /* used when si_code=BUS_MCEERR_AR or used when si_code=BUS_MCEERR_AO */ >> >> Nit: Odd phrase. Maybe rewrite as... >> >> "used when si_code is BUS_MCEERR_AR or BUS_MCEERR_AO" >> > > Fixed. > >>> +  append_composite_type_field (sigfault_union_type, "si_addr_lsb", short_type); >>> + >>> +  /* used when si_code=SEGV_BNDERR */ >>> +  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); >>> +  append_composite_type_field (type, "_dummy_bnd", addr_bnd_pkey_padding_type); >>> +  append_composite_type_field (type, "si_lower", void_ptr_type); >>> +  append_composite_type_field (type, "si_upper", void_ptr_type); >>> +  append_composite_type_field (sigfault_union_type, "_addr_bnd", type); >>> + >>> +  /* used when si_code=SEGV_PKUERR */ >>> +  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); >>> +  append_composite_type_field (type, "_dummy_pkey", addr_bnd_pkey_padding_type); >>> +  append_composite_type_field (type, "si_pkey", uint32_type); >>> +  append_composite_type_field (sigfault_union_type, "_addr_pkey", type); >>> + >>> +  /* used when si_code=TRAP_PERF */ >>> +  type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); >>> +  append_composite_type_field (type, "si_perf_data", unsigned_long_type); >>> +  append_composite_type_field (type, "si_perf_type", uint32_type); >>> +  append_composite_type_field (type, "si_perf_flags", uint32_type); >>> +  append_composite_type_field (sigfault_union_type, "_perf", type); >>> + >>> +  /* End _sigfault's anonymous union.  */ >>> + >>> +  /* _sigfault is set by SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGEMT */ >>>     type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT); >>>     append_composite_type_field (type, "si_addr", void_ptr_type); >>> +  /* Since there is no possibility to declare an anonymous union, >>> +     using '_' instead.  */ >>> +  append_composite_type_field (type, "_", sigfault_union_type); >> >> Could we name this in a better way? Simply using _ is a bit strange. >> > > What about "_union" ? > Naming is hard. Given it is an anonymous union, should it have something anonymous in the name? If we're going to access this by hand, it might be worth having some easy to use too. >>>     append_composite_type_field (sifields_type, "_sigfault", type); >>>       /* _sigpoll */ >> >> Do we need to add some extra tests to validate that gdb can read these new fields? > > Indeed, I can add some, but I would like to avoid adding a test for all the new fields. > Can we stick with the original purpose of this change, i.e. adding si_pkey ? > Sure. I'm fine with having the proper coverage as a follow up patch. But it would be nice to at least have the coverage for what you plan to use, like si_pkey. > diff --git a/gdb/testsuite/gdb.base/siginfo-obj.c b/gdb/testsuite/gdb.base/siginfo-obj.c > index 43dc979bc50..960e5b8e9cd 100644 > --- a/gdb/testsuite/gdb.base/siginfo-obj.c > +++ b/gdb/testsuite/gdb.base/siginfo-obj.c > @@ -35,6 +35,7 @@ handler (int sig, siginfo_t *info, void *context) > int ssi_signo = info->si_signo; > int ssi_code = info->si_code; > void *ssi_addr = info->si_addr; > + unsigned int ssi_pkey = info->si_pkey; > > _exit (0); /* set breakpoint here */ > } > diff --git a/gdb/testsuite/gdb.base/siginfo-obj.exp b/gdb/testsuite/gdb.base/siginfo-obj.exp > index a94bf0e33ba..6c43d30b7b8 100644 > --- a/gdb/testsuite/gdb.base/siginfo-obj.exp > +++ b/gdb/testsuite/gdb.base/siginfo-obj.exp > @@ -78,6 +78,14 @@ gdb_test_multiple "p \$_siginfo" "$test" { > } > } > > +set test "extract si_pkey" > +gdb_test_multiple "p \$_siginfo" "$test" { > + -re "si_pkey = (\[0-9\]\+).*$gdb_prompt $" { > + set ssi_pkey $expect_out(1,string) > + pass "$test" > + } > +} > + > set bp_location [gdb_get_line_number "set breakpoint here"] > > with_test_prefix "validate siginfo fields" { > @@ -87,6 +95,7 @@ with_test_prefix "validate siginfo fields" { > gdb_test "p ssi_errno" " = $ssi_errno" > gdb_test "p ssi_code" " = $ssi_code" > gdb_test "p ssi_signo" " = $ssi_signo" > + gdb_test "p ssi_pkey" " = $ssi_pkey" > } > > # Again, but this time, patch si_addr and check that the inferior sees > @@ -106,6 +115,7 @@ gdb_test "p \$_siginfo._sifields._sigfault.si_addr = 0x666" " = \\(void \\*\\) 0 > gdb_test "p \$_siginfo.si_errno = 666" " = 666" > gdb_test "p \$_siginfo.si_code = 999" " = 999" > gdb_test "p \$_siginfo.si_signo = 11" " = 11" > +gdb_test "p \$_siginfo._sifields._sigfault._union._addr_pkey.si_pkey = 123" " = 123" > > with_test_prefix "validate modified siginfo fields" { > gdb_test "break $bp_location" > @@ -114,6 +124,7 @@ with_test_prefix "validate modified siginfo fields" { > gdb_test "p ssi_errno" " = 666" > gdb_test "p ssi_code" " = 999" > gdb_test "p ssi_signo" " = 11" > + gdb_test "p ssi_pkey" " = 123" > } > > # Test siginfo preservation in core files. > @@ -132,4 +143,7 @@ if {$gcore_created} { > gdb_test "p \$_siginfo._sifields._sigfault.si_addr" \ > " = \\(void \\*\\) $ssi_addr" \ > "p \$_siginfo._sifields._sigfault.si_addr from core file" > + gdb_test "p \$_siginfo._sifields._sigfault._union._addr_pkey.si_pkey" \ > + " = $ssi_pkey" \ > + "p \$_siginfo._sifields._sigfault._union._addr_pkey.si_pkey from core file" > } > > > Matthieu