How to execute finish and then another command from inside commands?

前端 未结 5 1434
长情又很酷
长情又很酷 2020-12-16 15:01

This is a reduced example of the structure of my code:

void increment(int j);

int main()
{
  int i = 0;

  while(1) {
    i = increment(i);
  }

  return 0;         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 15:48

    Alternatively to @Matt answer, and if you use GDB 7.4, you can use FinishBreakpoints, with something like (untested -- I'm not sure that comments are accepted here):

    (gdb) python #first defined the class
    class MyFinishBreakpoint (gdb.FinishBreakpoint):
        def stop (self):
            print "%s" % gdb.parse_and_eval("i")
            return False # don't want to stop
    end
    (gdb) break doSomething
    (gdb) commands
    # then set the FinishBreakpoint silently
    silent
    py MyFinishBreakpoint()
    continue
    

    (and a link to the documentation)

提交回复
热议问题