I am trying to inspect the contents of a data structure in a core dump. There are many nodes in this. And I need to compare two nodes. I am trying to implement the same compare function that the program used to handle the data structure as a user defined gdb function. A node has multiple parameters and the compare function checks each of them and returns -1, 0 or 1.
I did the following,
define single_compare
if $arg0 > $arg1
set $arg2 = 1
end
if $arg0 < $arg1
set $arg2 = -1
end
if $arg0 == $arg1
set $arg2 = 0
end
end
define compare_nodes
set $obj_inst_a = (nodetype*)$arg0
set $obj_inst_b = (nodetype*)$arg1
set $compr = 0
single_compare $obj_inst_a->a $obj_inst_b->a $compr
if $compr != 0
set $arg2 = $compr
end
single_compare $obj_inst_a->b $obj_inst_b->b $compr
if $compr != 0
set $arg2 = $compr
end
...
The problem here is, if i find the a values in each node is different, I don't need to compare b, just return from there, and use $arg2 to take a decision. Is there a way to do that in gdb script? finish/return will cause the current program functions to return/finish. Not the script.