Re: [PATCH v5] gdb: align siginfo_t with the Linux kernel definition

Simon Marchi <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
On 8/14/26 6:05 AM, Matthieu Longo wrote:
> So, if I understood you well, you don't want to touch the current definition in
> linux_get_siginfo_type(). Instead, you propose to define a new siginfo type as the data structure
> below. Then, siginfo data should be cast to the new user-facing type before being returned.
> Is this correct ?

I think I was a bit confused about how the siginfo convenience variable
is constructed.  I thought we had code to set the value of individual
fields, but that does not make sense.  How it actually works is that we
read the bytes from the target, and the type constructed by
linux_get_siginfo_type (not only Linux, but all platforms) must overlay
perfectly the actual byte layout from the target.

But in any case, I don't think that anything from nat/ is used during
that process normally.  The type of $_siginfo comes from a struct type
constructed with arch_composite_type & co calls, not from a literal
struct in the GDB source code.

> #define __ARCH_SI_CLOCK_T unsigned long
> #define __ADDR_BND_PKEY_PAD  (__alignof__(void *) < sizeof(short) ? \
> 			      sizeof(short) : __alignof__(void *))
> 
> struct siginfo {
>   int si_signo;
>   int si_errno;
>   int si_code;
> 
>   /* Beginning of __sifields.  */
>   union {
> 
>     /* _kill, signals, _sigchld and _timer are tangled, so should be flattened
>        together.  */
>     struct {
>       union {
>         int si_pid; // _kill, _rt, _sigchld
>         int si_tid; // _timer
>       };
>       union {
>         uint32_t si_uid; // _kill, _rt, _sigchld
>         int si_overrun; // _timer
>       };
>       union {
>         struct {
>           int si_status;
>           __ARCH_SI_CLOCK_T si_utime;
>           __ARCH_SI_CLOCK_T si_stime;
>         }; // _sigchld
> 
>         struct {
>           union {
>             int si_int;
>             void *si_ptr;
>           } si_value; // _rt, _timer
>           int si_sys_private; // _timer
>         };
>       };
>     };
> 
>     /* _sigfault, _sigpoll and _sigsys are not sharing anything, so are
>        flattened on their own.  */
> 
>     struct {
>       void *si_addr;
>       union {
>         int si_trapno;
>         short si_addr_lsb;
>         struct {
>           char _dummy_padding_1[__ADDR_BND_PKEY_PAD];
>           void *si_lower;
>           void *si_upper;
>         }; /* _addr_bnd */
>         struct {
>           char _dummy_padding_2[__ADDR_BND_PKEY_PAD];
>           uint32_t si_pkey;
>         }; /* _addr_pkey */
>         struct {
>           unsigned long si_perf_data;
>           uint32_t si_perf_type;
>           uint32_t si_perf_flags;
>         }; /* _perf */
>       };
>     }; /* _sigfault */
> 
>     struct {
>       long si_band;
>       int si_fd;
>     }; /* _sigpoll */
> 
>     struct {
>       void *si_call_addr;
>       int si_syscall;
>       unsigned int si_arch;
>     }; /* _sigsys */
> 
>   }; /* End of __sifields.  */
> };

This is a bit hard to read, but yeah I guess that having all the struct
and union fields anonymouns would make the si_* fields accessible from
the top-level, and that would be ideal from a UX point of view.  So, we
would like to model a structure like the above, but constructed with
arch_composite_type & co calls.

But we'd need the old names to keep working.

You don't have to worry about this though (unless you want to), it's out
of scope of your original patch.

Simon
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.