Gdb 如何检查断点是否按特定顺序命中?

Gdb 如何检查断点是否按特定顺序命中?,gdb,Gdb,我正在尝试设置一个GDB脚本,该脚本设置一些断点,并确保按特定顺序命中它们,如果不命中,则抛出一个错误 它看起来像: break *0x400de0 # Should be hit first break *0x40f650 # Should be hit second break *0x40f662 # Should be hit third run # hits breakpoint # if (??? == "0x400de0") continue # hit

我正在尝试设置一个GDB脚本,该脚本设置一些断点,并确保按特定顺序命中它们,如果不命中,则抛出一个错误

它看起来像:

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
但是,我在将断点处的地址放入变量时遇到了一些困难。我研究过如何使用打印当前地址的
frame
,但是我不知道如何将其放入变量中进行比较


我已经研究过使用Python GDB脚本来实现这一点,但是,对于我的应用程序来说,这似乎有点复杂。如果它是唯一的选择,我会使用它

这可以使用状态机来完成

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

啊,当然是国家机器!这正是我需要的,谢谢!