GDB 中跳转到下一个分支指令

发布于 01-12 09:45 字数 71 浏览 3 评论 0原文

有没有办法继续执行,直到到达 GDB 中的分支指令?很像 WinDbg“ph”命令。如果没有的话,可以用Python编写脚本吗?

Is there a way to continue execution until a branching instruction is reached in GDB? Much like the WinDbg "ph" command. If not, can it be scripted in Python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花心好男孩2025-01-19 09:45:18

我终于遇到了这个问题:

GDB 是否有“step-to-next-call”指令?

我能够修改那里的代码来创建我自己的“ph”命令:

import gdb

mips_branches = ["beq", "beqz", "bne", "bnez", "bgtz", "bltz", "bgez", "blez", "j", "jr", "jal", "jalr"]
arm_branches = ["b", "bl", "blx", "bx", "beq"]

class StepToNextBranch (gdb.Command):
    def __init__ (self):
        super (StepToNextBranch, self).__init__ ("ph", gdb.COMMAND_OBSCURE)

    def invoke (self, arg, from_tty):
        arch = gdb.selected_frame().architecture()

        while True:
            SILENT=True
            gdb.execute("nexti", to_string=SILENT)
            current_pc = int(gdb.selected_frame().read_register("pc"))
            disa = arch.disassemble(current_pc)[0]
            opcode = disa["asm"].split("\t")[0]
            if opcode in mips_branches or opcode in arm_branches:
                break

        gdb.execute("context")

StepToNextBranch()

我不像MIPS那样熟悉ARM,所以我不确定这是否涵盖了所有内容。最终,我将添加 x86 分支指令。

另外, gdb.execute("context") 行在那里,因为我使用 GEF< /a>.

I finally came across this question:

Does GDB have a "step-to-next-call" instruction?

I was able to modify the code there to create my own "ph" command:

import gdb

mips_branches = ["beq", "beqz", "bne", "bnez", "bgtz", "bltz", "bgez", "blez", "j", "jr", "jal", "jalr"]
arm_branches = ["b", "bl", "blx", "bx", "beq"]

class StepToNextBranch (gdb.Command):
    def __init__ (self):
        super (StepToNextBranch, self).__init__ ("ph", gdb.COMMAND_OBSCURE)

    def invoke (self, arg, from_tty):
        arch = gdb.selected_frame().architecture()

        while True:
            SILENT=True
            gdb.execute("nexti", to_string=SILENT)
            current_pc = int(gdb.selected_frame().read_register("pc"))
            disa = arch.disassemble(current_pc)[0]
            opcode = disa["asm"].split("\t")[0]
            if opcode in mips_branches or opcode in arm_branches:
                break

        gdb.execute("context")

StepToNextBranch()

I'm not as familiar with ARM as MIPS so I'm not sure this covers everything. Eventually, I'll add x86 branching instructions.

Also, that gdb.execute("context") line is there because I use GEF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文