Codie CodeMonkey
Codie CodeMonkey

Reputation: 7946

Breaking at a member function in the Python debugger

This should be a trivial question, but my search so far has been fruitless:

I'm using the Python debugger (pdb) for the first time, and was quite pleased to find most of the commands familiar from using gdb.

However, when I went to set a breakpoint in the parse() member of class JamParser with the statement:

(Pdb) b JamParser.parse
*** The specified object 'JamParser.parse' is not a function
or was not found along sys.path.

I tried several several variants, including:

(Pdb) b jam2dot.py:JamParser.parse

I assume that since I invoked the debugger from the command line that it knows the entities in the file. Is that a false assumption?

The documentation says that break can take a function as an argument, but doesn't offer any syntax help. So how do I set a breakpoint for a member function by name?

Upvotes: 14

Views: 9531

Answers (1)

Gareth Rees
Gareth Rees

Reputation: 65854

You need to import names before you can refer to them in the debugger.

(Pdb) from jam2dot import JamParser
(Pdb) b JamParser.parse

Upvotes: 27

Related Questions