Search code examples
c++debuggingrepeatlldb

Repeating Command in LLDB


How can I repeatedly run a command in LLDB for debugging C++ code?

For example, when I set a breakpoint inside a loop and want to continue for 10 iterations before stopping, I am currently typing continue ten times manually to do this. Is there a better way?

As an example, let's say I have this code block:

int i = 0;
while (true) {
  // Increment i
  i++;
}

If I set a breakpoint on the line with the comment, I could keep using the command continue to go through one iteration of the loop and go back to that line. However, if I wanted to skip over 10 iterations (i.e. use the command continue 10 times), how would I do that?


Solution

  • lldb tends to use options where gdb would use a command argument. That makes it easier to have a bunch of different ways to condition a particular command without having to come up with ad hoc mini-syntaxes for each command.

    Anyway, so in lldb you would do:

    (lldb) c -i 10
    

    You can see this in help:

    (lldb) help continue
    Continue execution of all threads in the current process.
    
    Syntax: continue <cmd-options>
    
    Command Options Usage:
      continue [-i <unsigned-integer>]
    
           -i <unsigned-integer> ( --ignore-count <unsigned-integer> )
                Ignore <N> crossings of the breakpoint (if it exists) for the currently selected thread.
    
    'continue' is an abbreviation for 'process continue'
    

    Note also that you can do the same thing just by setting the ignore count in the breakpoint you just hit: break modify -i 10 <BKPTNO>.