Reputation: 357
I'm trying to set up a GDB script that sets some breakpoints and makes sure that they are hit in a certain order, and if not throw an error.
It would look something like:
break *0x400de0 # Should be hit first
break *0x40f650 # Should be hit second
break *0x40f662 # Should be hit third
run
# hits breakpoint #
if (??? == "0x400de0")
continue
# hits breakpoint #
if (??? == "0x40f650")
continue
# hits breakpoint #
if (??? == "0x40f662")
print "The correct thing happened!"
# Do some things here....
quit
else
print "ERROR"
quit
else
print "ERROR"
quit
else
print "ERROR"
quit
However, I'm somewhat stuck on getting the address at the breakpoint into a variable. I've looked into using frame
which prints the current address, however I have no idea how to get that into a variable for comparison.
I've looked into using Python-GDB scripts to do this, however, it seems a little complicated for my application. I will use it if it is the only option however.
Upvotes: 1
Views: 314
Reputation: 10271
This can be done using a state machine.
set $state = 0
break *0x400de0
commands
if $state == 0
set $state = 1
else
printf "error, state is %d expected 0\n", $state
end
end
break *0x40f650
commands
if $state == 1
set $state = 2
else
printf "error, state is %d expected 1\n", $state
end
end
break *0x40f662
commands
if $state == 2
printf "done\n"
else
printf "error, state is %d expected 2\n", $state
end
end
run
Upvotes: 2