Gdb: conditionally split a function only if the caller's function is not equal to a specific value

In my project, I have my_malloc (), which will call malloc ().

I like to set a conditional breakpoint in gdb so that gdb will break into "gdb>" only when the caller malloc () function is not equal to my_mallc ().

Is it possible?

The goal is to identify all the code that calls malloc () directly, and did not go through my_malloc ().

+6
source share
1 answer

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 # don't announce hitting breakpoint #2 disable 1 # don't stop when malloc is called within my_malloc continue # continue execution when BP#2 is hit end (gdb) commands 3 silent enable 1 # re-enable malloc breakpoint continue end 

This method only works for single-threaded applications.

+4
source

Source: https://habr.com/ru/post/978304/


All Articles