I would like GDB to perform variable substitution when I create a conditional breakpoint. For instance:
set variable $my_value = 1
b my_function if my_param == $my_value
set variable $my_value = 5
b my_function if my_param == $my_value
This actually creates 2 identical breakpoints that break in my_function () when my_param is equal to the current value of $ my_value. Therefore, when starting my program, a breakpoint only starts when my_param is 5. What I really wanted was two different conditional breakpoints for values 1 and 5.
Is there a way to make GDB to set conditional breakpoints like this, using the current value of a convenience variable instead of the variable itself?
I ask this question because I am trying to create a GDB script to track memory freeing that automatically sets conditional breakpoints, for example.
b some_file.c:2238
commands
set variable $last = new_pointer
b free if ptr == $last
continue
end
But of course, I believe that this only works for the last pointer value, because all of my automatically generated breakpoints are identical!
I'm going to research the use of Python scripts to see if this can solve my problem, but since I have no experience with Python, I would like to post this question first! I am sure that it should be possible to do what I am trying to achieve, and any help or suggestions would be highly appreciated.
source
share