Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is pdb displaying "*** Blank or comment" when I try to set a Break?

Tags:

python

django

pdb

I'm working with my Django app. For some reason an element of a list is being assigned incorrectly.

I'm trying to set a break where I think the error is occurring. ( line 20 )

I'm invoking pdb with this line of code:

import pdb; pdb.set_trace()

However, inside the code, I can't seem to set a Break.

(Pdb) b 20  
*** Blank or comment  
(Pdb) break 20  
*** Blank or comment  `

What am I doing wrong?

like image 270
BryanWheelock Avatar asked Dec 05 '09 15:12

BryanWheelock


People also ask

How do you set a breakpoint in pdb?

Optionally, you can also tell pdb to break only when a certain condition is true. Use the command b (break) to set a breakpoint. You can specify a line number or a function name where execution is stopped. If filename: is not specified before the line number lineno , then the current source file is used.

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 .

What are these pdb commands used for?

The module pdb defines an interactive source code debugger for Python programs. It supports setting (conditional) breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame.

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.


1 Answers

pdb is telling you that line 20 of the file you're in doesn't contain code; it's either blank or just contains a comment. Such a line will never actually be executed, so a breakpoint can't be set on it.

Use the 'list' command to see the code of the file you're currently in ('help list' for details on this command), and then set breakpoints on lines which include executable code.

You can also use the 'where' command to see the stack frame, since you might not be in the right file because you're not looking at the level of the stack frame where you think you are. Use 'up' and 'down' to go to the level of the stack where you want to debug.

like image 147
taleinat Avatar answered Sep 19 '22 01:09

taleinat