Pause auf allen retq der aktuellen Funktion
Dieser Python-Befehl setzt einen Breakpoint auf jede retq
Anweisung der aktuellen Funktion:
class BreakReturn(gdb.Command):
def __init__(self):
super().__init__(
'break-return',
gdb.COMMAND_RUNNING,
gdb.COMPLETE_NONE,
False
)
def invoke(self, arg, from_tty):
frame = gdb.selected_frame()
# TODO make this work if there is no debugging information, where .block() fails.
block = frame.block()
# Find the function block in case we are in an inner block.
while block:
if block.function:
break
block = block.superblock
start = block.start
end = block.end
arch = frame.architecture()
pc = gdb.selected_frame().pc()
instructions = arch.disassemble(start, end - 1)
for instruction in instructions:
if instruction['asm'].startswith('retq '):
gdb.Breakpoint('*{}'.format(instruction['addr']))
BreakReturn()
Quelle mit:
und verwenden Sie den Befehl wie:
break-return
continue
Sie jetzt bei retq
sein sollte.
Schritt bis retq
Just for fun, eine andere Implementierung, wenn stoppt ein retq
(weniger effizient von da keine Hardware-Unterstützung) zu finden ist:
class ContinueReturn(gdb.Command):
def __init__(self):
super().__init__(
'continue-return',
gdb.COMMAND_RUNNING,
gdb.COMPLETE_NONE,
False
)
def invoke(self, arg, from_tty):
thread = gdb.inferiors()[0].threads()[0]
while thread.is_valid():
gdb.execute('ni', to_string=True)
frame = gdb.selected_frame()
arch = frame.architecture()
pc = gdb.selected_frame().pc()
instruction = arch.disassemble(pc)[0]['asm']
if instruction.startswith('retq '):
break
ContinueReturn()
Dies wird Ihre anderen Haltepunkte ignorieren. TODO: Kann vermieden werden?
Nicht sicher, ob es schneller oder langsamer als reverse-step
ist.
Eine Version, die bei zu einem gegebenen Opcode hält zu finden: https://stackoverflow.com/a/31249378/895245
Haben Sie RBR erforscht? – Jack