http://blog.sina.com.cn/s/blog_538040b70100eecn.html
如下程序用于跟踪,在分配和回收都会触发探针
#!/usr/sbin/dtrace -s
pid$target:libc:malloc:entry
{
self->trace = 1;
self->size = arg0;
}
pid$target:libc:malloc:return
/self->trace == 1/
{
printf("Ptr=0x%p Size=%d", arg1, self->size);
ustack();
self->trace = 0;
self->size = 0;
}
pid$target:libc:realloc:entry
{
self->trace = 1;
self->size = arg1;
self->oldptr = arg0;
}
pid$target:libc:realloc:return
/self->trace == 1/
{
printf("Ptr=0x%p Oldptr=0x%p Size=%d", arg1, self->oldptr, self->size);
ustack();
self->trace = 0;
self->size = 0;
}
pid$target:libc:calloc:entry
{
self->trace = 1;
self->size = arg1;
}
pid$target:libc:calloc:return
/self->trace == 1/
{
printf("Ptr=0x%p Size=%d", arg1, self->size);
ustack();
self->trace = 0;
self->size = 0;
}
pid$target:libc:free:entry
{
printf("Ptr=0x%p ", arg0);
}
然后用perl程序将正常分配回收的去掉,剩下的就是有问题的调用了。