30

Is there a command to step out of cycles (say, for or while) while debugging on ipdb without having to use breakpoints out of them?

I use the until command to step out of list comprehensions, but don't know how could I do a similar thing, if possible, of entire loop blocks.

Javier Novoa C.
  • 11,257
  • 13
  • 57
  • 75

4 Answers4

28

I believe this is the intent of the until command. It's like a next except that when a jump occurs to a previous line number for the loop, it will continue until exiting the loop.

unt(il)
Continue execution until the line with a number greater than the current
one is reached or until the current frame returns

In general, to "step out" of the current function, use return.

r(eturn)
Continue execution until the current function returns.
John Lehmann
  • 7,975
  • 4
  • 58
  • 71
  • nope, until steps out of list comprehensions for example. It continues execution UNTIL reching a different line number as the current one, just that. If inside some code block (for, while, anything else), there's no way but with breakpoints, as far as I have researched – Javier Novoa C. Aug 01 '15 at 20:14
  • @Javier Navoa What you described for `until` is the behavior of `next`. I believe he is right: `until` is just like `next` except that it always goes down. In that way `until` can effectively be used to go out of loops, but it can take several times (the number of lines remaining in the loop). – Jean Paul Oct 04 '18 at 13:33
  • The trap is that the debugger understands list comprehensions as several lines, but it is the same for `next` and `until`. – Jean Paul Oct 04 '18 at 14:32
23

You can use j <line number> (jump) to go to another line. for example, j 28 to go to line 28.

amstree
  • 537
  • 1
  • 4
  • 12
15

This could sound obvious: jump makes you jump. This means that you don't execute the lines you jump: you should use this to skip code that you don’t want to run.

You probably need tbreak (Temporary breakpoint, which is removed automatically when it is first hit. The arguments are the same as break) as I did when I found this page.

jimifiki
  • 5,377
  • 2
  • 34
  • 60
1

If you are willing to use another debugger, trepan, has more ways you can step. It is more gdb-like. So you can give a count of how many times you want to step. Or you can give a line number in a continue debugger command which in essence sets a temporary breakpoint at the line and then issues "continue". Other things that change stepping are "set different". See also the even suffixes you can put on step.

Note that like ipdb, there is syntax highlighting of the source text.

rocky
  • 7,226
  • 3
  • 33
  • 74