Skip to content

Instantly share code, notes, and snippets.

@fpotter
Created May 6, 2012 22:06
Show Gist options
  • Save fpotter/2624774 to your computer and use it in GitHub Desktop.
Save fpotter/2624774 to your computer and use it in GitHub Desktop.
DTrace script to observe UNIX socket traffic to/from a RubyMotion app
#!/usr/bin/env dtrace -s
/*
* DTrace script to observe UNIX socket reads/writes for RubyMotion apps running
* in the iOS Simulator.
*
* Usage: sudo dtrace_rubymotion_repl <pid of running RubyMotion iOS app>
*
*/
syscall::sendto:entry
/pid == $1/
{
self->buffer = arg1;
self->length = arg2;
}
syscall::sendto:return
/pid == $1/
{
/* RubyMotion doesn't send null-terminated strings, so we copy it
into our own null-terminated string. */
self->text = (char *)alloca(self->length + 1);
copyinto(self->buffer, self->length, self->text);
self->text[self->length] = '\0';
printf("%s >> SOCKET >> '%s'", execname, stringof(self->text));
}
syscall::recvfrom:entry
/pid == $1/
{
self->buffer = arg1;
}
syscall::recvfrom:return
/pid == $1/
{
/* RubyMotion doesn't send null-terminated strings, so we copy it
into our own null-terminated string. */
self->numBytes = arg0;
self->text = (char *)alloca(self->numBytes + 1);
copyinto(self->buffer, self->numBytes, self->text);
self->text[self->numBytes] = '\0';
printf("%s << SOCKET << '%s'", execname, stringof(self->text));
}
syscall::write:entry
/pid == $1/
{
self->buffer = arg1;
self->fd = arg0;
}
syscall::write:return
/pid == $1 && self->fd == 1/
{
self->text = copyin(self->buffer, arg0);
printf("%s >> STDOUT >> '%s')", execname, stringof(self->text));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment