I like to set a conditional breakpoint in gdb, so gdb will break into "gdb>" only when the caller malloc () function is not equal to my_mallc ().
In other words, you want to break malloc when it is not called by my_malloc .
One way to do this is to set three breakpoints: one on malloc , one on my_malloc and one on my_malloc return. Then (provided that the breakpoints are 1, 2, and 3, respectively).
(gdb) commands 2 silent
This method only works for single-threaded applications.
source share