dtrace 在 macOS 12.2.1 上因 thread_t 的类型不正确而出错

dtrace errors out with incorrect type for thread_t on macOS 12.2.1

以下 dtrace 调用曾经在 MacOS 11.6.2 上运行,但在升级到 MacOS 12.2.1 后停止运行

sudo --non-interactive  dtrace -l -b 16m -x mangled -x disallow_dsym -x strip -x evaltime=preinit -x preallocate=256m  -n 'oneshot$target:a.out::entry { hdr_vm_addr = ((thread_t)curthread)->task->mach_header_vm_address; }' -w -p 4557 

dtrace: invalid probe specifier oneshot$target:a.out::entry { hdr_vm_addr = ((thread_t)curthread)->task->mach_header_vm_address; }: in action list: task is not a member of struct thread

现在如何从 thread_t 获得 task

看起来可能是t_task。以下是查看 built-in 变量类型的方法,例如 curthread:

$ sudo dtrace -n 'BEGIN { print(*curthread); exit(0); }'
dtrace: description 'BEGIN ' matched 1 probe
CPU     ID                    FUNCTION:NAME
  4      1                           :BEGIN struct thread {
    union  {
        queue_chain_t runq_links = {
            struct queue_entry *next = 0
            struct queue_entry *prev = 0
        }
...
    struct task *t_task = 0xffffff8bd07859f0
...
}