0

From The Python Library Reference:

b(reak) [[filename:]lineno | function[, condition]]

With a lineno argument, set a break there in the current file. With a function argument, set a break at the first executable statement within that function. The line number may be prefixed with a filename and a colon, to specify a breakpoint in another file (probably one that hasn’t been loaded yet). The file is searched on sys.path. Note that each breakpoint is assigned a number to which all the other breakpoint commands refer.

If a second argument is present, it is an expression which must evaluate to true before the breakpoint is honored.

Without argument, list all breaks, including for each breakpoint, the number of times that breakpoint has been hit, the current ignore count, and the associated condition if any.

condition bpnumber [condition]

Condition is an expression which must evaluate to true before the breakpoint is honored. If condition is absent, any existing condition is removed; i.e., the breakpoint is made unconditional.

What is the difference between a break point with second argument for condition (the first part in the quote), and a condition break point (the second part in the quote)? They look the same to me from the quote.

Community
  • 1
  • 1

1 Answers1

0

The b command defines a breakpoint. You can specify a condition, but you needn't do so.

The condition commands needs a breakpoint that is already defined (i.e. needs a b command before) and changes the condition of it.

The following two debugger commands can be considered equal:

b debugme:3,x==100

and

b debugme:3
condition 1 x==100

Let's go practical:

Create the following Python script and name it debugme.py:

def myfunction():
    for x in range(0,200):
        print x

if __name__ == "__main__":
    myfunction()

Walkthrough of syntax 1 (b with condition):

C:\tmp\py>C:\Python27\python.exe
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb
>>> import debugme
>>> pdb.run('debugme.myfunction()')
> <string>(1)<module>()
(Pdb) b debugme:3,x==100                               <---- note this line
Breakpoint 1 at c:\tmp\py\debugme.py:3
(Pdb) c
0
1
2
3
...
97
98
99
> c:\tmp\py\debugme.py(3)myfunction()
-> print x
(Pdb) p x
100
(Pdb) q
>>> exit()

Walkthrough of syntax 2 (b without condition plus condition):

C:\tmp\py>C:\Python27\python.exe
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pdb
>>> import debugme
>>> pdb.run('debugme.myfunction()')
> <string>(1)<module>()
(Pdb) b debugme:3                                     <---- note this line
Breakpoint 1 at c:\tmp\py\debugme.py:3
(Pdb) b
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at c:\tmp\py\debugme.py:3
(Pdb) condition 1 x==100                              <---- and this one
(Pdb) b
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at c:\tmp\py\debugme.py:3
        stop only if x==100
(Pdb) c
0
1
2
3
...
97
98
99
> c:\tmp\py\debugme.py(3)myfunction()
-> print x
(Pdb) p x
100
(Pdb) q
>>> exit()
Thomas Weller
  • 55,411
  • 20
  • 125
  • 222