Valgrind Core
Valgrind Tool
Program
x86 Binary
UCode Binary
Emulator
Program
Valgrind Core
Host CPU
Intermediate Representation (IR)
ucode
Tools
Machine Code
PRE(sys_SYNOStat)
{
FUSE_COMPATIBLE_MAY_BLOCK();
PRINT("sys_SYNOStat ( %#lx(%s), %ld, %#lx)",ARG1,(char*)ARG1,ARG2,ARG3);
PRE_REG_READ3(long, "SYNOStat", const char *, file_name,
unsigned int, flags, struct SYNOSTAT64 *, statbuf);
PRE_MEM_RASCIIZ( "SYNOStat(file_name)", ARG1 );
if (ARG3 != 0)
PRE_MEM_WRITE( "SYNOStat(statbuf)", ARG3, sizeof(struct vki_SYNOSTAT) );
}
POST(sys_SYNOStat)
{
if (ARG3 != 0)
POST_MEM_WRITE( ARG3, sizeof(struct vki_SYNOSTAT) );
} void invalid_access() {
int *a = malloc(3 * sizeof(int));
a[3] = 3;
free(a);
}
void use_uninitial() {
int i;
printf("%d\n", i);
}
void rw_after_freed() {
char *a = (char *)malloc(2*sizeof(char));
free(a);
a[0] = '1';
}
void leak()
{
malloc(2000);
}
int main(void)
{
invalid_access();
use_uninitial();
rw_after_freed();
leak();
return 0;
}% valgrind --tool=callgrind ./m
% python gprof2dot.py -f callgrind -n10 -s callgrind.out.19576 > valgrind.dot
% dot -Tpng valgrind.dot -o valgrind.pngvoid g(void)
{
malloc(4000);
}
void f(void)
{
for (int i=0; i < 10000; i++) {
malloc(2000);
}
g();
}
int main(void)
{
int i;
int* a[10];
for (i = 0; i < 10; i++) {
a[i] = (int *)malloc(1000);
}
f();
g();
for (i = 0; i < 10; i++) {
free(a[i]);
}
return 0;
}% valgrind --tool=massif ./m
% ms_print massif.out.18981Monitor all access to memory location if accessed by different threads check if two accesses are ordered by happen-before relations.
Means there is some chain of inter-thread synchronisation operations only correctly handle POSIX condition variables. Ex: pthread_conf_wait, pthread_cond_signal ...