On 05/11/17 05:13, Gregor Jasny wrote:
> Hello,
>
> One of my applications leaked a file descriptor due to some unbalanced
> socketpair(2) / close(2) calls. I intended to use the dtrace syscall
> provider to print file descriptor numbers and invocations of those two
> syscalls. This happens on macOS 10.12.
>
> However I have problems to print the sockets allocated by socketpair(2).
> The following (and many variations) does not work as expected:
>
> syscall::socketpair:entry
> /pid == $target/
> {
> ps1 = arg3;
> }
>
> syscall::socketpair:return
> /pid == $target/
> {
> s1 = *(int*)copyin(ps1, 4);
> printf("%i", s1);
> }
>
> Could someone please explain how to properly dump the allocated sockets?
The following works for me on Mac OS X:
syscall::socketpair:entry
/pid == $target/
{
self->ps1 = arg3;
}
syscall::socketpair:return
/pid == $target/
{
s1 = *(int *)copyin(self->ps1, 4);
s2 = *(int *)copyin(self->ps1 + 4, 4);
printf("%i %i", s1, s2);
}
The important part is using a thread-local variable ('self') rather than
a plain old local. (While playing with this, I noticed that it also
happens to work with clause-local ['this']. I assume that's because
'entry' and 'return' are treated as two parts of the same clause. But I
wouldn't trust that; thread-local is almost always what you want.)
--
James Carlson 42.703N 71.076W <[email protected]>
-------------------------------------------
dtrace-discuss
Archives: https://www.listbox.com/member/archive/184261/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184261/25769126-e243886f
Modify Your Subscription:
https://www.listbox.com/member/?member_id=25769126&id_secret=25769126-8d47a7b2
Powered by Listbox: http://www.listbox.com