Skip to content

Commit 75655b3

Browse files
committed
bpo-30429: bdb and pdb: Add watchpoint function
1 parent 054e091 commit 75655b3

5 files changed

Lines changed: 722 additions & 23 deletions

File tree

‎Doc/library/bdb.rst‎

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ The following exception is defined:
2020

2121
The :mod:`bdb` module also defines two classes:
2222

23-
.. class:: Breakpoint(self, file, line, temporary=0, cond=None, funcname=None)
23+
.. class:: Breakpoint(self, file, line, temporary=0, cond=None, funcname=None, \
24+
var_name=None, var_value=None, var_frame=None, \
25+
bptype='breakpoint')
2426

25-
This class implements temporary breakpoints, ignore counts, disabling and
26-
(re-)enabling, and conditionals.
27+
This class implements temporary breakpoints, watchpoints, ignore counts,
28+
disabling and (re-)enabling, and conditionals.
2729

2830
Breakpoints are indexed by number through a list called :attr:`bpbynumber`
2931
and by ``(file, line)`` pairs through :attr:`bplist`. The former points to a
@@ -35,6 +37,12 @@ The :mod:`bdb` module also defines two classes:
3537
first line of that function is executed. A conditional breakpoint always
3638
counts a hit.
3739

40+
When creating a watchpoint, *file* and *line* should be ``None``, and *cond*
41+
, *funcname* are not used. *bptype* should be set to corresponding
42+
watchpoiont type: ``watchpoint``, ``read watchpoint`` or
43+
``read/write watchpoint``.
44+
45+
3846
:class:`Breakpoint` instances have the following methods:
3947

4048
.. method:: deleteMe()
@@ -60,6 +68,7 @@ The :mod:`bdb` module also defines two classes:
6068
formatted:
6169

6270
* The breakpoint number.
71+
* The breakpoint type.
6372
* If it is temporary or not.
6473
* Its file,line position.
6574
* The condition that causes a break.
@@ -68,6 +77,9 @@ The :mod:`bdb` module also defines two classes:
6877

6978
.. versionadded:: 3.2
7079

80+
.. versionchanged:: 3.7::
81+
Breakpoint type will now changed by corresponding type.
82+
7183
.. method:: bpprint(out=None)
7284

7385
Print the output of :meth:`bpformat` to the file *out*, or if it is
@@ -182,6 +194,11 @@ The :mod:`bdb` module also defines two classes:
182194
This method checks if there is a breakpoint in the filename of the current
183195
frame.
184196

197+
.. method:: watch_here(frame)
198+
199+
This method checks if there is a watchpoint in the filename and line
200+
belonging to *frame* or, at least, in the current function.
201+
185202
Derived classes should override these methods to gain control over debugger
186203
operation.
187204

@@ -250,15 +267,21 @@ The :mod:`bdb` module also defines two classes:
250267

251268

252269
Derived classes and clients can call the following methods to manipulate
253-
breakpoints. These methods return a string containing an error message if
254-
something went wrong, or ``None`` if all is well.
270+
breakpoints and watchpoints. These methods return a string containing an
271+
error message if something went wrong, or ``None`` if all is well.
255272

256273
.. method:: set_break(filename, lineno, temporary=0, cond, funcname)
257274

258275
Set a new breakpoint. If the *lineno* line doesn't exist for the
259276
*filename* passed as argument, return an error message. The *filename*
260277
should be in canonical form, as described in the :meth:`canonic` method.
261278

279+
.. method:: set_watch(var_name, var_frame, bptype)
280+
281+
Set a new watchpoint. If the *var_name* does not exist in *var_frame*,
282+
return a error message. bptype should be *watchpoint*, *read watchpoint*
283+
or *read/write watchpoint*.
284+
262285
.. method:: clear_break(filename, lineno)
263286

264287
Delete the breakpoints in *filename* and *lineno*. If none were set, an

‎Doc/library/pdb.rst‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,48 @@ by the local file.
271271
If a second argument is present, it is an expression which must evaluate to
272272
true before the breakpoint is honored.
273273

274-
Without argument, list all breaks, including for each breakpoint, the number
275-
of times that breakpoint has been hit, the current ignore count, and the
276-
associated condition if any.
274+
Without argument, list all breaks, including for each breakpoint or
275+
watchpoint, the number of times that breakpoint has been hit, the current
276+
ignore count, and the associated condition if any.
277277

278278
.. pdbcommand:: tbreak [([filename:]lineno | function) [, condition]]
279279

280280
Temporary breakpoint, which is removed automatically when it is first hit.
281281
The arguments are the same as for :pdbcmd:`break`.
282282

283+
.. pdbcommand:: wa(tch) [expr]
284+
285+
Set a watchpoint for an expression. It will break when expression is written
286+
into by program and the values changes.
287+
288+
Without argument, list all breaks, including for each breakpoint or
289+
watchpoint, the number of times that breakpoint has been hit, the current
290+
ignore count, and the associated condition if any.
291+
292+
.. versionadded:: 3.7
293+
294+
.. pdbcommand:: rwa(tch) [expr]
295+
296+
Set a watchpoint for an expression. It will break when expression is
297+
readed by program.
298+
299+
Without argument, list all breaks, including for each breakpoint or
300+
watchpoint, the number of times that breakpoint has been hit, the current
301+
ignore count, and the associated condition if any.
302+
303+
.. versionadded:: 3.7
304+
305+
.. pdbcommand:: aw(atch) [expr]
306+
307+
Set a watchpoint for an expression. It will break when expression is
308+
readed or written into by program.
309+
310+
Without argument, list all breaks, including for each breakpoint or
311+
watchpoint, the number of times that breakpoint has been hit, the current
312+
ignore count, and the associated condition if any.
313+
314+
.. versionadded:: 3.7
315+
283316
.. pdbcommand:: cl(ear) [filename:lineno | bpnumber [bpnumber ...]]
284317

285318
With a *filename:lineno* argument, clear all the breakpoints at this line.

0 commit comments

Comments
 (0)