How to step through code line-by-line with python and examine the stack

StackOverflow https://stackoverflow.com/questions/21372157

  •  03-10-2022
  •  | 
  •  

Вопрос

I am trying to set up a python script in gdb that steps through a program one line at a time and records the stack pointer at each step. I have been searching all over for some good online references for gdb-python scripting and have not been able to find any that are worthwhile.

A script example or a link to a good online reference for gdb-python scripting would be appreciated.

Это было полезно?

Решение

You can do this even from the gdb command line:

while 1
  step
  # Do something with $sp
end

The Python version would look similar, something like:

while True:
  gdb.execute("step")
  sp = gdb.parse_and_eval("$sp")
  # Do something with sp.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top