[hellogcc] 关于GDB hook-stop命令的问题

  • From: "Amker.Cheng" <amker.cheng@xxxxxxxxx>
  • To: hellogcc@xxxxxxxxxxxxx
  • Date: Thu, 21 Jul 2011 11:11:58 +0800

Hi,
GDB文档里面描述的hook-stop命令可用来在被调试程序停下运行时执行一定的操作.
现在我的程序里面有若干硬编码的breakpoint指令(bkpt on arm cortex-m processors),
想通过定义hook-stop命令来跳过这些指令继续执行:
define skip_bkpt
  printf "skip_bkpt"
  set $pc += 2
  c
end
define hook-stop
  set $insn = *(unsigned short*)$pc
  if ($insn == 0xbeab)  ### 0xbeab 是我想skip的bkpt指令的编码
    skip_bkpt
  end
end

在我执行target program时, hook-stop在第一条bkpt指令处被执行并正确的skip掉bkpt执行并continue,
但是再遇到一条bkpt指令后gdb仍然会停下来, 似乎hook-stop并没有被调用, 输出大概如下:

(gdb) c
Continuing.

Program received signal SIGTRAP, Trace/breakpoint trap.
skip_bkpt

Program received signal SIGTRAP, Trace/breakpoint trap.
0x000022ac in initialise_monitor_handles ()
0x000022ac in initialise_monitor_handles ()

上面0x000022ac处其实也是一条bkpt(0xbeab)指令, 但hook-stop并没有能skip并continue.

之前没用过hook, 不知道什么地方弄错了, Any help?

Thanks very much.
-- 
Best Regards.

Other related posts:

  • » [hellogcc] 关于GDB hook-stop命令的问题 - Amker.Cheng