Skip to content

Instantly share code, notes, and snippets.

@clayallsopp
Forked from fpotter/dtrace_rubymotion_repl
Created May 9, 2012 21:30

Revisions

  1. @fpotter fpotter revised this gist May 6, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions dtrace_rubymotion_repl
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ syscall::sendto:entry
    syscall::sendto:return
    /pid == $1/
    {
    /* RubyMotion doesn't send null-terminate strings, so we copy it
    /* 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);
    @@ -35,7 +35,7 @@ syscall::recvfrom:entry
    syscall::recvfrom:return
    /pid == $1/
    {
    /* RubyMotion doesn't send null-terminate strings, so we copy it
    /* 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);
  2. @fpotter fpotter revised this gist May 6, 2012. No changes.
  3. @fpotter fpotter created this gist May 6, 2012.
    60 changes: 60 additions & 0 deletions dtrace_rubymotion_repl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    #!/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-terminate 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-terminate 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));
    }