15

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?

3
  • 3
    IF you have access to the source, I usually drop a import pdb; pdb.set_trace() where I want rather than step through with the debugger. Commented Jun 30, 2011 at 17:45
  • @Noufal: Now that I'm a bit more experienced, I've realized the value of your suggestion, thanks. Commented Jul 30, 2011 at 5:04
  • You're welcome. I learned this trick from a bunch of Python pros at PyCon two years ago. :) Commented Jul 30, 2011 at 6:00

1 Answer 1

28

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

(Pdb) from jam2dot import JamParser
(Pdb) b JamParser.parse
Sign up to request clarification or add additional context in comments.

5 Comments

Wow. What an awful, misleading error message. If a program can't find something, it should say so, rather than implying that it found it but it wasn't the right sort of thing.
Yes, it's rather poor, isn't it? The trouble is that the b command takes either a filename, or a function, so the error message has to respect this ambiguity (after all, maybe you wanted a breakpoint in the file named JamParser.py and mis-typed the extension). But I agree that it could do a lot better than this. I suggest you submit a bug report!
this may be a quite old post, but why the pdb module does not automatically import members of a file that is actually being debugged?
This should be included as an example in the pdb documentation.
@IainSamuelMcLeanElder Ten years later, my advice is the same: submit a bug report and a patch!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.