Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit75c1dc2

Browse files
gaogaotiantianSonicField
authored andcommitted
pythonGH-111744: Make breakpoint() enter the debugger immediately (pythonGH-118579)
1 parent1ee085e commit75c1dc2

File tree

8 files changed

+162
-68
lines changed

8 files changed

+162
-68
lines changed

‎Doc/library/bdb.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ The :mod:`bdb` module also defines two classes:
289289
Start debugging from *frame*. If *frame* is not specified, debugging
290290
starts from caller's frame.
291291

292+
..versionchanged::3.13
293+
:func:`set_trace` will enter the debugger immediately, rather than
294+
on the next line of code to be executed.
295+
292296
..method::set_continue()
293297

294298
Stop only at breakpoints or when finished. If there are no breakpoints,

‎Doc/library/pdb.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ running without the debugger using the :pdbcmd:`continue` command.
6262

6363
The debugger's prompt is ``(Pdb)``, which is the indicator that you are in debug mode::
6464

65-
> ...(3)double()
66-
->return x * 2
65+
> ...(2)double()
66+
->breakpoint()
6767
(Pdb) p x
6868
3
6969
(Pdb) continue
@@ -164,6 +164,9 @@ slightly different way:
164164
..versionchanged::3.7
165165
The keyword-only argument *header*.
166166

167+
..versionchanged::3.13
168+
:func:`set_trace` will enter the debugger immediately, rather than
169+
on the next line of code to be executed.
167170

168171
..function::post_mortem(traceback=None)
169172

‎Doc/whatsnew/3.13.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ pdb
715715
*:mod:`zipapp` is supported as a debugging target.
716716
(Contributed by Tian Gao in:gh:`118501`.)
717717

718+
* ``breakpoint()`` and ``pdb.set_trace()`` now enter the debugger immediately
719+
rather than on the next line of code to be executed. This change prevents the
720+
debugger from breaking outside of the context when ``breakpoint()`` is positioned
721+
at the end of the context.
722+
(Contributed by Tian Gao in:gh:`118579`.)
723+
718724
queue
719725
-----
720726

‎Lib/bdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def set_trace(self, frame=None):
378378
# We need f_trace_lines == True for the debugger to work
379379
frame.f_trace_lines=True
380380
frame=frame.f_back
381-
self.set_step()
381+
self.set_stepinstr()
382382
sys.settrace(self.trace_dispatch)
383383

384384
defset_continue(self):

‎Lib/pdb.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ def user_line(self, frame):
431431
ifself.bp_commands(frame):
432432
self.interaction(frame,None)
433433

434+
user_opcode=user_line
435+
434436
defbp_commands(self,frame):
435437
"""Call every command that was set for the current active breakpoint
436438
(if there is one).

‎Lib/test/test_doctest/test_doctest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,8 +2056,7 @@ def test_pdb_set_trace():
20562056
20572057
>>> try: runner.run(test)
20582058
... finally: sys.stdin = real_stdin
2059-
--Return--
2060-
> <doctest foo-bar@baz[2]>(1)<module>()->None
2059+
> <doctest foo-bar@baz[2]>(1)<module>()
20612060
-> import pdb; pdb.set_trace()
20622061
(Pdb) print(x)
20632062
42
@@ -2087,8 +2086,7 @@ def test_pdb_set_trace():
20872086
... runner.run(test)
20882087
... finally:
20892088
... sys.stdin = real_stdin
2090-
--Return--
2091-
> <doctest test.test_doctest.test_doctest.test_pdb_set_trace[9]>(3)calls_set_trace()->None
2089+
> <doctest test.test_doctest.test_doctest.test_pdb_set_trace[9]>(3)calls_set_trace()
20922090
-> import pdb; pdb.set_trace()
20932091
(Pdb) print(y)
20942092
2
@@ -2114,6 +2112,7 @@ def test_pdb_set_trace():
21142112
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
21152113
>>> real_stdin = sys.stdin
21162114
>>> sys.stdin = FakeInput([
2115+
... 'step', # return event of g
21172116
... 'list', # list source from example 2
21182117
... 'next', # return from g()
21192118
... 'list', # list source from example 1
@@ -2124,6 +2123,9 @@ def test_pdb_set_trace():
21242123
>>> try: runner.run(test)
21252124
... finally: sys.stdin = real_stdin
21262125
... # doctest: +NORMALIZE_WHITESPACE
2126+
> <doctest foo-bar@baz[1]>(3)g()
2127+
-> import pdb; pdb.set_trace()
2128+
(Pdb) step
21272129
--Return--
21282130
> <doctest foo-bar@baz[1]>(3)g()->None
21292131
-> import pdb; pdb.set_trace()
@@ -2188,6 +2190,7 @@ def test_pdb_set_trace_nested():
21882190
>>> test = parser.get_doctest(doc, globals(), "foo-bar@baz", "foo-bar@baz.py", 0)
21892191
>>> real_stdin = sys.stdin
21902192
>>> sys.stdin = FakeInput([
2193+
... 'step',
21912194
... 'print(y)', # print data defined in the function
21922195
... 'step', 'step', 'step', 'step', 'step', 'step', 'print(z)',
21932196
... 'up', 'print(x)',
@@ -2201,6 +2204,9 @@ def test_pdb_set_trace_nested():
22012204
... finally:
22022205
... sys.stdin = real_stdin
22032206
... # doctest: +REPORT_NDIFF
2207+
> <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(4)calls_set_trace()
2208+
-> import pdb; pdb.set_trace()
2209+
(Pdb) step
22042210
> <doctest test.test_doctest.test_doctest.test_pdb_set_trace_nested[0]>(5)calls_set_trace()
22052211
-> self.f1()
22062212
(Pdb) print(y)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp