Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'n' in pdb moves me inside of the pdb.set_trace() method

I'm trying to learn pdb using this tutorial referenced from another stackoverflow question, and I'm on the 3rd step of the Getting Started section.

In [12]: %paste
# epdb1.py -- experiment with the Python debugger, pdb
import pdb
a = "aaa"
pdb.set_trace()
b = "bbb"
c = "ccc"
final = a + b + c
print final
## -- End pasted text --
--Return--
> <ipython-input-12-48afa1c7ad72>(4)<module>()->None
-> pdb.set_trace()


(Pdb) l
  1     # epdb1.py -- experiment with the Python debugger, pdb
  2     import pdb
  3     a = "aaa"
  4  -> pdb.set_trace()
  5     b = "bbb"
  6     c = "ccc"
  7     final = a + b + c
  8     print final
[EOF]


(Pdb) n
> /Users/jg/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py(3038)run_code()
-> sys.excepthook = old_excepthook
(Pdb) l
3033                    self.hooks.pre_run_code_hook()
3034                    #rprint('Running code', repr(code_obj)) # dbg
3035                    exec(code_obj, self.user_global_ns, self.user_ns)
3036                finally:
3037                    # Reset our crash handler in place
3038 ->                 sys.excepthook = old_excepthook
3039            except SystemExit as e:
3040                if result is not None:
3041                    result.error_in_exec = e
3042                self.showtraceback(exception_only=True)
3043                warn("To exit: use 'exit', 'quit', or Ctrl-D.", level=1)

It looks like n(ext) should move me to the next line in the current frame:

(Pdb) help next
n(ext)
Continue execution until the next line in the current function
is reached or it returns.

And seems to do that successfully in the tutorial's example. But in my ipython it appears to be moving me to the next line within the pdb.set_trace() code.

How do I simply navigate to the 'b = "bbb"' line?

like image 355
user1956609 Avatar asked Sep 11 '15 18:09

user1956609


People also ask

How do you get out of a loop in pdb?

Once you get you pdb prompt . Just hit n (next) 10 times to exit the loop.

How do you go to the next line in pdb?

The difference between n (next) and s (step) is where pdb stops. Use n (next) to continue execution until the next line and stay within the current function, i.e. not stop in a foreign function if one is called.

How do you remove a breakpoint in pdb?

To remove all commands from a breakpoint, type commands and follow it immediately with end ; that is, give no commands. Specifying any command resuming execution (currently continue , step , next , return , jump , skip , and quit ) terminates the command list as if that command was immediately followed by end .

How do you set a breakpoint in Python pdb?

It's easy to set a breakpoint in Python code to i.e. inspect the contents of variables at a given line. Add import pdb; pdb. set_trace() at the corresponding line in the Python code and execute it. The execution will stop at the breakpoint.


1 Answers

Try this in your ipython:

import pdb
def test_pdb_example():
    a = "aaa"
    pdb.set_trace() # use 'n' for navigate to next line
    b = "bbb"
    c = "ccc"
    final = a + b + c
    return final

test_pdb_example()
like image 134
Tevin Joseph K O Avatar answered Oct 21 '22 06:10

Tevin Joseph K O