【发布时间】:2020-01-11 23:06:42
【问题描述】:
我正在尝试使用 GDB 命令文件实现单步执行。我想在遇到任何断点时停止执行命令文件。
有没有办法检测断点被命中?以及之后如何停止执行命令文件。
我检查了文档,似乎我只能对某些断点使用中断命令。但不适用于随机断点。
我有这样的事情:
printf "single stepping\n"
set $steps_count = 0
while ($steps_count < 5)
set $steps_count = $steps_count + 1
printf "program counter 0x%x\n", $pc
printf "next #%d\n", $steps_count
next
end
这就是我想要实现的目标:
printf "single stepping\n"
set $steps_count = 0
while (# breakpoint is not hit)
set $steps_count = $steps_count + 1
printf "program counter 0x%x\n", $pc
printf "next #%d\n", $steps_count
next
end
# end the execution of the command file.
更新: 我尝试使用以下方法:
# set the end breakpoint
break *0x199e
commands
stop 1
quit
end
break *0x1980
# set a certain once we encounter the first breakpoint
commands
set $count = 0
while $count < 5
printf "#PC: 0x%x", $pc
set $count = $count + 1
stepi
end
end
一旦命中第一个断点,这应该开始记录程序计数器。但我不知道为什么这个 break 命令不起作用。一旦断点被击中,程序就会停止并且不会进入while循环!
更新: 根据 gdb 文档:
命令列表中的任何其他命令,在恢复执行的命令之后,都将被忽略。这是因为任何时候你恢复执行(即使是简单的下一步或步骤),你都可能遇到另一个断点——它可能有自己的命令列表,导致执行哪个列表的歧义。
所以我认为在中断命令中放置一个具有 step 或 next 的循环不是一个好主意。
【问题讨论】:
-
对于更新,您能否分享您获得的 gdb 输出(可能还有版本)?
-
@ChristianB 我用我在文档中找到的内容更新了这个问题。谢谢
-
似乎中断命令没有在我的命令文件中执行。我已经在另一个问题中问过这个问题。 stackoverflow.com/questions/57988776/…