continue out of a loop in pdb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    continue out of a loop in pdb

    Hi

    using the debugger, I happen to be on a line inside a loop, after
    looping few times with "n" and wanting to get out of the loop to the
    next line, I set a break point on a line after the loop structure and
    hit c, that does not continue out of the loop and stop at the break
    line, how is it down, I read the ref docs on pdb but could not figure
    it out.

    thanks
  • Paul McGuire

    #2
    Re: continue out of a loop in pdb

    "Gary Wessle" <phddas@yahoo.c om> wrote in message
    news:87mzdkwke3 .fsf@localhost. localdomain...[color=blue]
    > Hi
    >
    > using the debugger, I happen to be on a line inside a loop, after
    > looping few times with "n" and wanting to get out of the loop to the
    > next line, I set a break point on a line after the loop structure and
    > hit c, that does not continue out of the loop and stop at the break
    > line, how is it down, I read the ref docs on pdb but could not figure
    > it out.
    >
    > thanks[/color]

    This is exactly how I do this operation using pdb, and it works for me, so
    you are on the right track. Is it possible that something inside the loop
    is raising an exception, thereby jumping past your breakpoint? Try putting
    the loop inside a try-except.

    -- Paul


    Comment

    • Gary Wessle

      #3
      Re: continue out of a loop in pdb

      "Paul McGuire" <ptmcg@austin.r r._bogus_.com> writes:
      [color=blue]
      > "Gary Wessle" <phddas@yahoo.c om> wrote in message
      > news:87mzdkwke3 .fsf@localhost. localdomain...[color=green]
      > > Hi
      > >
      > > using the debugger, I happen to be on a line inside a loop, after
      > > looping few times with "n" and wanting to get out of the loop to the
      > > next line, I set a break point on a line after the loop structure and
      > > hit c, that does not continue out of the loop and stop at the break
      > > line, how is it down, I read the ref docs on pdb but could not figure
      > > it out.
      > >
      > > thanks[/color]
      >
      > This is exactly how I do this operation using pdb, and it works for me, so
      > you are on the right track. Is it possible that something inside the loop
      > is raising an exception, thereby jumping past your breakpoint? Try putting
      > the loop inside a try-except.
      >
      > -- Paul[/color]

      the code works with no problem, I am playing around with the pdb, i.e

      *************** *
      from pdb import *
      set_trace()

      for i in range(1,500000) :
      print i
      print "tired of this"
      print "I am out"
      *************** *

      fred@debian:~/python/practic$ python practic.py[color=blue]
      > /home/fred/python/practic/practic.py(4)?( )[/color]
      -> for i in range(1,500000) :
      (Pdb) n[color=blue]
      > /home/fred/python/practic/practic.py(5)?( )[/color]
      -> print i
      (Pdb) n
      1[color=blue]
      > /home/fred/python/practic/practic.py(4)?( )[/color]
      -> for i in range(1,500000) :
      (Pdb) b 6
      Breakpoint 1 at /home/fred/python/practic/practic.py:6
      (Pdb) c[color=blue]
      > /home/fred/python/practic/practic.py(5)?( )[/color]
      -> print i <<<< I expected (print "tired of this")
      (Pdb)

      Comment

      • Diez B. Roggisch

        #4
        Re: continue out of a loop in pdb

        > the code works with no problem, I am playing around with the pdb, i.e[color=blue]
        >
        > *************** *
        > from pdb import *
        > set_trace()
        >
        > for i in range(1,500000) :
        > print i
        > print "tired of this"
        > print "I am out"
        > *************** *
        >
        > fred@debian:~/python/practic$ python practic.py[color=green]
        >> /home/fred/python/practic/practic.py(4)?( )[/color]
        > -> for i in range(1,500000) :
        > (Pdb) n[color=green]
        >> /home/fred/python/practic/practic.py(5)?( )[/color]
        > -> print i
        > (Pdb) n
        > 1[color=green]
        >> /home/fred/python/practic/practic.py(4)?( )[/color]
        > -> for i in range(1,500000) :
        > (Pdb) b 6
        > Breakpoint 1 at /home/fred/python/practic/practic.py:6
        > (Pdb) c[color=green]
        >> /home/fred/python/practic/practic.py(5)?( )[/color]
        > -> print i <<<< I expected (print "tired of this")
        > (Pdb)[/color]


        In TFM it says that set_trace() puts a breakpoint to the current frame.
        I admit that I also wouldn't read that as "each and every instruction in
        this very frame", but that is what essentially happens. I think the docs
        could need some enhancement here. Try debugging a called function, there
        things will work as expected.

        Diez

        Comment

        • R. Bernstein

          #5
          Re: continue out of a loop in pdb

          Gary Wessle <phddas@yahoo.c om> writes:
          [color=blue]
          > Hi
          >
          > using the debugger, I happen to be on a line inside a loop, after
          > looping few times with "n" and wanting to get out of the loop to the
          > next line, I set a break point on a line after the loop structure and
          > hit c, that does not continue out of the loop and stop at the break
          > line, how is it down, I read the ref docs on pdb but could not figure
          > it out.[/color]

          The command you are probably looking for is jump.



          It is also documented in the stock python debugger


          Here's an example:

          pdb ~/python/ptest.py[color=blue]
          > /home/rocky/python/ptest.py(2)?()[/color]
          -> for i in range(1,10):
          (Pdb) step[color=blue]
          > /home/rocky/python/ptest.py(3)?()[/color]
          -> print i
          (Pdb) list
          1 #!/bin/python
          2 for i in range(1,10):
          3 -> print i
          4 print "tired of this"
          [EOF]
          (Pdb) jump 4[color=blue]
          > /home/rocky/python/ptest.py(4)?()[/color]
          -> print "tired of this"
          (Pdb)

          Comment

          • R. Bernstein

            #6
            Re: continue out of a loop in pdb

            "Diez B. Roggisch" <deets@nospam.w eb.de> writes:
            [color=blue][color=green]
            > > the code works with no problem, I am playing around with the pdb, i.e
            > > *************** *
            > > from pdb import *
            > > set_trace() for i in range(1,500000) :
            > > print i
            > > print "tired of this"
            > > print "I am out"
            > > *************** *
            > > fred@debian:~/python/practic$ python practic.py[color=darkred]
            > >> /home/fred/python/practic/practic.py(4)?( )[/color]
            > > -> for i in range(1,500000) :
            > > (Pdb) n[color=darkred]
            > >> /home/fred/python/practic/practic.py(5)?( )[/color]
            > > -> print i
            > > (Pdb) n
            > > 1[color=darkred]
            > >> /home/fred/python/practic/practic.py(4)?( )[/color]
            > > -> for i in range(1,500000) :
            > > (Pdb) b 6
            > > Breakpoint 1 at /home/fred/python/practic/practic.py:6
            > > (Pdb) c[color=darkred]
            > >> /home/fred/python/practic/practic.py(5)?( )[/color]
            > > -> print i <<<< I expected (print "tired of this")
            > > (Pdb)[/color]
            >
            >
            > In TFM it says that set_trace() puts a breakpoint to the current
            > frame. I admit that I also wouldn't read that as "each and every
            > instruction in this very frame", but that is what essentially
            > happens. I think the docs could need some enhancement here. Try
            > debugging a called function, there things will work as expected.[/color]

            Let me try to explain my understanding here. set_trace() merely tells
            the Python interpreter to call the debugger dispatcher after the call
            to set_trace() finishes. In effect this is at the next statement of
            your program because the caller frame here is always the "set_trace( )"
            call you put in your program. Okay, so now we've called this "debugger
            dispatcher" thing and what does that do? Well, it accepts commands
            from you, like "next" or "step" or "continue". .

            In the case above, Python was told to make that set-trace call 500000
            times.

            But yes, I agree the wording in in the pdb (and pydb) manuals are
            written too much from view of someone writing a debugger rather than
            someone using it. If you or someone else wantsto make a suggestion as
            to how to make the description of set_trace() more user friendly (and I
            don't think the above explanation succeeds), I'll put it in the next
            release of pydb (http://bashdb.sourceforge.net/pydb) which probably
            will be in the not-too distant future.

            Comment

            • R. Bernstein

              #7
              Re: continue out of a loop in pdb

              Here's the revision I just made for pydb's documentation (in
              CVS). I welcome suggestions for improvement.


              set_trace([cmdfile=None])

              Enter the debugger before the statement which follows (in
              execution) the set_trace() statement. This hard-codes a call to
              the debugger at a given point in a program, even if the code is
              not otherwise being debugged. For example you might want to do
              this when an assertion fails.

              It is useful in a couple of other situations. First, there may be
              some problem in getting the debugger to stop at this particular
              place for whatever reason (like flakiness in the
              debugger). Alternatively, using the debugger and setting a
              breakpoint can slow down a program a bit. But if you use this
              instead, the code will run as though the debugger is not present
              until you reach this point in the program.

              When the debugger is quitting, this causes the program to be
              terminated. If you want the program to continue instead, use the
              debugger function.


              [color=blue]
              > "Diez B. Roggisch" <deets@nospam.w eb.de> writes:
              >[color=green][color=darkred]
              > > > the code works with no problem, I am playing around with the pdb, i.e
              > > > *************** *
              > > > from pdb import *
              > > > set_trace() for i in range(1,500000) :
              > > > print i
              > > > print "tired of this"
              > > > print "I am out"
              > > > *************** *
              > > > fred@debian:~/python/practic$ python practic.py
              > > >> /home/fred/python/practic/practic.py(4)?( )
              > > > -> for i in range(1,500000) :
              > > > (Pdb) n
              > > >> /home/fred/python/practic/practic.py(5)?( )
              > > > -> print i
              > > > (Pdb) n
              > > > 1
              > > >> /home/fred/python/practic/practic.py(4)?( )
              > > > -> for i in range(1,500000) :
              > > > (Pdb) b 6
              > > > Breakpoint 1 at /home/fred/python/practic/practic.py:6
              > > > (Pdb) c
              > > >> /home/fred/python/practic/practic.py(5)?( )
              > > > -> print i <<<< I expected (print "tired of this")
              > > > (Pdb)[/color]
              > >
              > >
              > > In TFM it says that set_trace() puts a breakpoint to the current
              > > frame. I admit that I also wouldn't read that as "each and every
              > > instruction in this very frame", but that is what essentially
              > > happens. I think the docs could need some enhancement here. Try
              > > debugging a called function, there things will work as expected.[/color]
              >
              > Let me try to explain my understanding here. set_trace() merely tells
              > the Python interpreter to call the debugger dispatcher after the call
              > to set_trace() finishes. In effect this is at the next statement of
              > your program because the caller frame here is always the "set_trace( )"
              > call you put in your program. Okay, so now we've called this "debugger
              > dispatcher" thing and what does that do? Well, it accepts commands
              > from you, like "next" or "step" or "continue". .
              >
              > In the case above, Python was told to make that set-trace call 500000
              > times.
              >
              > But yes, I agree the wording in in the pdb (and pydb) manuals are
              > written too much from view of someone writing a debugger rather than
              > someone using it. If you or someone else wantsto make a suggestion as
              > to how to make the description of set_trace() more user friendly (and I
              > don't think the above explanation succeeds), I'll put it in the next
              > release of pydb (http://bashdb.sourceforge.net/pydb) which probably
              > will be in the not-too distant future.[/color]

              Comment

              Working...