From: Claudio Jeker Subject: Re: extend ptrace(2) PT_GET_THREAD_* to include thread names To: kurt@intricatesoftware.com Cc: jca@wxcvbn.org, mark.kettenis@xs4all.nl, pascal@stumpf.co, ports@openbsd.org, tech@openbsd.org Date: Wed, 10 Dec 2025 20:03:24 +0100 On Wed, Dec 10, 2025 at 04:41:27PM +0000, kurt@intricatesoftware.com wrote: > Instead of gdb using sysctl(2) to get thread names let's extend > ptrace(2) PT_GET_THREAD_* to include thread names. This allows > gdb to use ptrace for both thread names and thread is alive > detection. > > I'm using a new define larger then _MAXCOMLEN to avoid that > define and header from propagating in to ptrace.h as well. > > The diff for gdb to use this and remove sysctl use follows > below as well. This would be committed a few days after the > pthread change is committed. > > okay for both? One comment for the kernel bits. Instead of the comment in ptrace.h I would add a CTASSERT() to sys_process.c, either CTASSERT(PT_PTS_NAMELEN >= _MAXCOMLEN); or CTASSERT(PT_PTS_NAMELEN >= sizeof(p->p_name); With that the kernel bits are OK claudio@ > Index: sys/sys/ptrace.h > =================================================================== > RCS file: /cvs/src/sys/sys/ptrace.h,v > diff -u -p -u -r1.16 ptrace.h > --- sys/sys/ptrace.h 16 Mar 2020 11:58:46 -0000 1.16 > +++ sys/sys/ptrace.h 10 Dec 2025 15:56:13 -0000 > @@ -82,8 +82,11 @@ typedef struct ptrace_state { > #define PT_GET_THREAD_FIRST 15 > #define PT_GET_THREAD_NEXT 16 > > +#define PT_PTS_NAMELEN 32 /* must be >= sizeof(p_name) in struct proc */ > + > struct ptrace_thread_state { > pid_t pts_tid; > + char pts_name[PT_PTS_NAMELEN]; > }; > > #define PT_FIRSTMACH 32 /* for machine-specific requests */ > Index: sys/kern/sys_process.c > =================================================================== > RCS file: /cvs/src/sys/kern/sys_process.c,v > diff -u -p -u -r1.106 sys_process.c > --- sys/kern/sys_process.c 17 Feb 2025 15:45:55 -0000 1.106 > +++ sys/kern/sys_process.c 10 Dec 2025 15:56:13 -0000 > @@ -605,8 +605,10 @@ ptrace_kstate(struct proc *p, int req, p > > if (t == NULL) > pts->pts_tid = -1; > - else > + else { > pts->pts_tid = t->p_tid + THREAD_PID_OFFSET; > + strlcpy(pts->pts_name, t->p_name, sizeof(pts->pts_name)); > + } > return 0; > } > } -- :wq Claudio