Please consider:
void bar (int* ptr3)
{
printf ("\n*ptr3 =%d\n",*ptr3);
}
void foo (int* ptr2)
{
*ptr2 +=5;
bar (ptr2);
}
int main()
{
int numb = 5;
int *ptr = &numb;
foo (ptr);
printf("\nHello !!!\n");
return 0;
}
Is it possible to track ptr
, in such a way that at some point I can find out the backtrace of the variable, something like:
bar() : ptr3
foo() : *ptr2 +=5;
main(): int *ptr = &numb;
Roughly: Can we开发者_如何学编程 get the pointer history in gdb through some way.
Actually, this can help in fixing Memory Leaks/UMR's reported through Purify.
Thanks.
Your question is very unclear, as in your example ptr3 == ptr2 == ptr == &numb
, so what exactly do you mean by 'pointer history'?
It appears that you are asking to track the changes to the value that ptr
points to (i.e. changes to numb
). You can do that with GDB watchpoints.
精彩评论