Skip to content

Instantly share code, notes, and snippets.

@jclulow
Created July 17, 2013 17:30
Show Gist options
  • Select an option

  • Save jclulow/6022658 to your computer and use it in GitHub Desktop.

Select an option

Save jclulow/6022658 to your computer and use it in GitHub Desktop.

So, int $3 debugging is alive and well in DTrace. Add USDT probes to your application:

var d = require('dtrace-provider');
var dtp = d.createDTraceProvider('int3-debug');
var p1 = dtp.addProbe('firing', 'char *');
dtp.enable();

setInterval(function () {
  p1.fire(function (p) {
    return ([new Date()]);
  });
}, 100);

Then, run it:

$ node sampler.js

While running, we'll attach a debugger and disassemble the probe site (which I found via terrible, nefarious means beyond the scope of this gist):

$ pgrep -fl node
11402 node sampler.js

$ mdb -p 11402
Loading modules: [ ld.so.1 libumem.so.1 libc.so.1 ]
> 0x89a3010::dis
0x89a3010:                      nop
0x89a3011:                      addl   $0x20,%esp
0x89a3014:                      leave
0x89a3015:                      ret
> $q

$

So, it's a nop right now... Let's start DTrace and listen for the probe:

$ pfexec dtrace -q -n 'int3-debug*:::firing { printf("%s\n", copyinstr(arg0)); }'
Wed Jul 17 2013 18:23:15 GMT+0100 (PST)
Wed Jul 17 2013 18:23:15 GMT+0100 (PST)
Wed Jul 17 2013 18:23:15 GMT+0100 (PST)
Wed Jul 17 2013 18:23:16 GMT+0100 (PST)
Wed Jul 17 2013 18:23:16 GMT+0100 (PST)
...

and disassemble again:

$ mdb -p 11402
Loading modules: [ ld.so.1 libumem.so.1 libc.so.1 ]
> 0x89a3010::dis
0x89a3010:                      int    $0x3
0x89a3011:                      addl   $0x20,%esp
0x89a3014:                      leave
0x89a3015:                      ret

An int $3! DTrace has injected the instruction in the program text and runs the probe action from our D script when handling the int $3, and then returns control to the program.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment