I have a program which SIGABRT after >5hrs of execution. It is most likely cause by memory leak after checking by valgrind, but I have problem trace down onto which variable actually causes this issue based on valgrind report (which simply contains addresses and ???).
I try to use valgrind and gdb to step through. However since it takes 5hrs to reach the leak (after looping for 428 rounds), I would like to set a breakpoint, let say, when loop=428, and step into the codes. How can I do that?
Based on a simple program below, may I know,
a) how to trace change of value in variable 'a'?
b) how to set a breakpoint when loop = 428?
typedef struct data_attr {
int a[2500];
}stdata;
typedef struct pcfg{
stdata *data;
}stConfig;
int funcA(stConfig* pt){
int loop = 0;
while (loop < NUM_NODE){
pt->data->a[0] = 1000;
pt->data->a[0] = 1001;
loop++;
}
return 0;
}
int main(){
stConfig *p;
p = (stConfig*) malloc(sizeof(stConfig));
p->data = (stdata*) malloc (sizeof(stdata));
funcA(p);
free(p->data);
free (p);
return 0;
}
I am using valgrind 3.7 on ubuntu 10.04
@ valgrind terminal,
valgrind -v --vgdb=yes --vgdb-error=0 --tool=memcheck --leak-check=full --leak-resolution=high --num-callers=40 --track-origins=yes --log-file=mr3m1n2500_valgrind_0717_1155.txt ./pt m >& mr3m1n2500_logcheck_0717_1155.txt
@ gdb terminal I tried to get address of 'p' but it returns void, why?
> gdb ./pt
(gdb) target remote | vgdb
Remote debugging using | vgdb
relaying data between gdb and process 12857
Reading symbols from /lib/ld-linux.so.2...Reading symbols from /usr/lib/debug/lib/ld-2.11.1.so...done.
done.
Loaded symbols for /lib/ld-linux.so.2
[Switching to Thread 12857]
0x04000850 in _start () from /lib/ld-linux.so.2
(gdb) p $p
$1 = void
(gdb) bt 10
#0 0x04000850 in _start () from /lib/ld-linux.so.2