simple tracing of bad free's using Dtrace

#pragma D option quiet

inline int stack_size = 3; inline int error_stack_size = 10;

pid$target:libc:malloc:entry { self->alloc_size = arg0; ustack(stack_size); } pid$target:libc:malloc:return /self->alloc_size && arg1 != 0/ { printf("alloc of size [%d] on addr 0x%p\n",self->alloc_size,arg1); allocations[arg1] = 1; } pid$target:libc:malloc:return /self->alloc_size && arg1 == 0/ { printf("alloc of size [%d] failed\n",self->alloc_size); } pid$target:libc:free:entry /arg0 != 0 && allocations[arg0]/ { printf("free of addr 0x%p\n",arg0); } pid$target:libc:free:entry /arg0 != 0 && !allocations[arg0]/ { printf("free of unallocated addr 0x%p\n",arg0); ustack(error_stack_size); } pid$target:libc:free:entry /arg0 == 0/ { printf("free of NULL addr !!\n"); ustack(error_stack_size); }

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Emmanuel Jannetti blog

Search

Archives
« avril 2014
lun.mar.mer.jeu.ven.sam.dim.
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today