我希望GDB在创建条件断点时执行变量替换.例如:
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
Run Code Online (Sandbox Code Playgroud)
这实际上创建了2个相同的断点,当my_param等于$ my_value的当前值时,断点在my_function()中.因此,当运行我的程序时,只有当my_param等于5时才会触发断点.我真正想要的是两个不同的条件断点,对于值1和5.
有没有办法让GDB使用方便变量的当前值而不是变量本身设置这样的条件断点?
我问这个问题,因为我正在尝试创建一个GDB脚本来跟踪内存释放,这将自动设置条件断点,例如
# set breakpoint after malloc() statement of interest
b some_file.c:2238
# define commands to execute when the above breakpoint is hit
commands
# $last is set to the allocated memory address
set variable $last = new_pointer
# set conditional breakpoint in free() to check when allocated pointer is released
b free if ptr …Run Code Online (Sandbox Code Playgroud) gdb ×1