-
Notifications
You must be signed in to change notification settings - Fork 197
Closed
Labels
good first issueGood for newcomersGood for newcomers
Description
Follow-up to #92. It'd be nice to have a way to get the drgn.Thread object for the main thread of a program. This probably only makes sense for userspace programs. (You could make a case that for the Linux kernel, some special kernel thread, e.g. kthreadd, is the "main thread", but I think asking for the main thread of the kernel should just be an error. This is up for debate.) So, the API is simply something like this:
class Program:
def main_thread(self) -> Thread:
"""
Get the main thread of the program.
:raises ValueError: if the program is the Linux kernel
"""
...- For core dumps, the main thread can be identified by the the
pidfield of thePRPSINFOnote, which will match thepidfield of thePRSTATUSnote for the main thread:
$ eu-readelf -n crashme_multithreaded_core | grep -A 3 PRPSINFO
CORE 136 PRPSINFO
state: 2, sname: D, zomb: 0, nice: 0, flag: 0x0000000040400404
uid: 1000, gid: 985, pid: 39143, ppid: 39053, pgrp: 39143, sid: 39053
fname: crashme_multith, psargs: ./crashme_multithreaded
$ eu-readelf -n crashme_multithreaded_core | grep -A 4 PRSTATUS
CORE 336 PRSTATUS
info.si_signo: 11, info.si_code: 0, info.si_errno: 0, cursig: 11
sigpend: <>
sighold: <>
pid: 39144, ppid: 39053, pgrp: 39143, sid: 39053
--
CORE 336 PRSTATUS
info.si_signo: 11, info.si_code: 0, info.si_errno: 0, cursig: 11
sigpend: <>
sighold: <>
pid: 39143, ppid: 39053, pgrp: 39143, sid: 39053- For live userspace processes, the main thread has a TID equal to the PID of the process (
struct drgn_program::pid). Note that this part is blocked on Live userspace process support for the Threads API #142.
The implementation needs to:
- Add a
struct drgn_thread *drgn_program_main_thread(struct drgn_program *prog)function to libdrgn. - Get the main thread as described above. This could either be cached (e.g., as part of
drgn_program_cache_core_dump_notes()for core dumps and on the first call todrgn_program_main_thread()for live processes) or recreated every time. - Add the
drgn.Program.main_thread()method to the Python bindings.
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers