2017-02-25 22 views
1

我很好奇gdb如何实现“until”命令。如何gdb命令“直到”能够跳过一个循环?

我的意思是,我可以理解“完成”是如何工作的,我们知道在函数的开始和结束处,有代码例程来操作ebp/esp寄存器,所以gdb可以使用它来执行到功能。

但我的问题是,gdb如何知道循环的结束?如果没有提供调试符号,我们知道该循环可能会嵌入另一个内部循环,所以取决于ecx寄存器不是解决方案。那么它如何知道循环的结束? “while”“do/while”和“for”的汇编代码可能不同,不确定是否有“完成”命令可以查找的模式。

希望看到你的解释。

回答

1

gdb如何知道循环的结束?

它没有。从documentation

until 
    Continue running until a source line past the current line, in the current stack 
    frame, is reached. 

    This command is used to avoid single stepping through a loop more than once. 
    It is like the next command, except that when until encounters a jump, it 
    automatically continues execution until the program counter is greater 
    than the address of the jump. 

它实现为上述最后一条语句描述的非常准确。