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

前端 未结 5 1449
长情又很酷
长情又很酷 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:45

    The problem is that finish seems to stop abort the commands set for the first breakpoint after it.

    This is expected behavior: any command that resumes the inferior (being debugged) process (as finish does) also stops the execution of canned command sequence.

    Update:

    See also this GDB bug report.

    Is there a way to tell GDB to print i right after any increment call?

    Yes:

    1. Diassemble increment routine using disas command. Find ret instruction at the end of it (there will only be one).
    2. Set a breakpoint on that instruction, using break *0xNNNNN syntax.
    3. Attach a command to that breakpoint:

      command N
       print $rax    # or $eax if you are on 32-bit x86 platform
       continue
      end
      

    Voila: you should get values being returned from increment() printed (just before being returned).

提交回复
热议问题