1. 6
  1.  

  2. 2

    In dtrace, if you had an executable called foo and wanted to track calls to malloc and see where they happen within the code with the address returned (you could also output the free’s), the script would look like:

    sudo dtrace -n 'pid$target::malloc:return {@[arg1, ustack()] = count()}' -c./foo
    

    And one would get output like:

      34376540248
              libc.so.7`__malloc+0x1492
              foo`main+0xe
              foo`_start+0x16f
              ld-elf.so.1`0x800621000
                1
      34376540256
              libc.so.7`__malloc+0x1492
              foo`main+0x18
              foo`_start+0x16f
              ld-elf.so.1`0x800621000
                1
      34376540264
              libc.so.7`__malloc+0x1492
              foo`bar+0x20
              foo`main+0x18
              foo`_start+0x16f
              ld-elf.so.1`0x800621000
                1