Page MenuHomeFreeBSD

Use ptrace(2) LWP events to track threads reliably in truss.
ClosedPublic

Authored by jhb on Mar 5 2016, 9:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 18 2024, 9:08 PM
Unknown Object (File)
Oct 15 2024, 1:06 AM
Unknown Object (File)
Oct 3 2024, 3:25 PM
Unknown Object (File)
Oct 1 2024, 4:29 AM
Unknown Object (File)
Sep 17 2024, 4:44 PM
Unknown Object (File)
Sep 14 2024, 10:16 PM
Unknown Object (File)
Sep 8 2024, 12:12 PM
Unknown Object (File)
Sep 8 2024, 7:47 AM
Subscribers

Details

Summary

Use ptrace(2) LWP events to track threads reliably in truss.

  • truss can now log the system call invoked by a thread during a voluntary process exit. No return value is logged, but the value passed to exit() is included in the trace output. Arguments passed to thread exit system calls such as thr_exit() are not logged as voluntary thread exits cannot be distinguished from involuntary thread exits during a system call.
  • New events are now reported for thread births and exits similar to the recently added events for new child processes when following forks.

I had originally included this with the truss -H changes, so you've seen
this before (modulo a few comment cleanups and dropping support for trying
to log thr_exit()).

Test Plan
  • Run truss against a test program that creates several threads that exit normally.
  • Run truss against a test program that creates a child thread and then calls exec to ensure the involuntary thread exit is logged.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 2791
Build 2812: arc lint + arc unit

Event Timeline

jhb retitled this revision from to Use ptrace(2) LWP events to track threads reliably in truss..
jhb updated this object.
jhb edited the test plan for this revision. (Show Details)
jhb added a reviewer: kib.
usr.bin/truss/setup.c
655

Style: Spaces around '|'.

660

Is this and other 'else' linkage of 'if's desirable ? I may imagine some syscalls creating sleeping threads, appearing executing syscalls. E.g. you might report aio thread attachment this way.

My only intent is to note this possibility, I do not think that this must be changed to series of independent ifs.

usr.bin/truss/syscalls.c
2058

Why is this needed ? To handle pthread_exit(2) ?

usr.bin/truss/setup.c
660

Well, thread creation is reported in tandem with system call exit now (since it is "returning" from thr_new() or the like). However, we can't really report that as a system call exit. In this case the system call exit would be ignored since there would not be the saved state from system call entry. This would be true in general (e.g. even if AIO created threads, the syscall that triggered the creation would be reported by the original thread, but the new thread would just "appear"). PL_FLAG_EXITED is similarly somewhat interesting. I think PL_FLAG_SCE can be set as well (and in fact it might always be set since we leave TDB_SCE set for the duration of system call execution), but we don't really want to try to parse it as a syscall entry (in fact, we might already have pending system call entry since we have a "real" SCE stop before the system call begins that should be pending in the threadinfo structure when a thread exit is reported).

usr.bin/truss/syscalls.c
2058

Actually exit(). If I could reliably detect a thread exit from thr_exit() it would use it as well. This is used by the newly added thread_exit_syscall().

kib edited edge metadata.
This revision is now accepted and ready to land.Mar 7 2016, 9:20 PM
This revision was automatically updated to reflect the committed changes.