Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f94089

Browse files
committed
#5294: Fix the behavior of pdb "continue" command when called in the top-level debugged frame.
1 parent d72e043 commit 3f94089

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

Lib/bdb.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def stop_here(self, frame):
109109
self.is_skipped_module(frame.f_globals.get('__name__')):
110110
return False
111111
if frame is self.stopframe:
112+
if self.stoplineno == -1:
113+
return False
112114
return frame.f_lineno >= self.stoplineno
113115
while frame is not None and frame is not self.stopframe:
114116
if frame is self.botframe:
@@ -165,10 +167,12 @@ def user_exception(self, frame, exc_info):
165167
but only if we are to stop at or just below this level."""
166168
pass
167169

168-
def _set_stopinfo(self, stopframe, returnframe, stoplineno=-1):
170+
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0):
169171
self.stopframe = stopframe
170172
self.returnframe = returnframe
171173
self.quitting = 0
174+
# stoplineno >= 0 means: stop at line >= the stoplineno
175+
# stoplineno -1 means: don't stop at all
172176
self.stoplineno = stoplineno
173177

174178
# Derived classes and clients can call the following methods
@@ -184,7 +188,7 @@ def set_until(self, frame, lineno=None):
184188

185189
def set_step(self):
186190
"""Stop after one line of code."""
187-
self._set_stopinfo(None,None)
191+
self._set_stopinfo(None, None)
188192

189193
def set_next(self, frame):
190194
"""Stop on the next line in or below the given frame."""
@@ -211,7 +215,7 @@ def set_trace(self, frame=None):
211215

212216
def set_continue(self):
213217
# Don't stop except at breakpoints or when finished
214-
self._set_stopinfo(self.botframe, None)
218+
self._set_stopinfo(self.botframe, None, -1)
215219
if not self.breaks:
216220
# no breakpoints; run without debugger overhead
217221
sys.settrace(None)

Lib/test/test_pdb.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,48 @@ def test_pdb_skip_modules_with_callback():
122122
"""
123123

124124

125+
def test_pdb_continue_in_bottomframe():
126+
"""Test that "continue" and "next" work properly in bottom frame (issue #5294).
127+
128+
>>> def test_function():
129+
... import pdb, sys; inst = pdb.Pdb()
130+
... inst.set_trace()
131+
... inst.botframe = sys._getframe() # hackery to get the right botframe
132+
... print(1)
133+
... print(2)
134+
... print(3)
135+
... print(4)
136+
137+
>>> with PdbTestInput([
138+
... 'next',
139+
... 'break 7',
140+
... 'continue',
141+
... 'next',
142+
... 'continue',
143+
... 'continue',
144+
... ]):
145+
... test_function()
146+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(4)test_function()
147+
-> inst.botframe = sys._getframe() # hackery to get the right botframe
148+
(Pdb) next
149+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(5)test_function()
150+
-> print(1)
151+
(Pdb) break 7
152+
Breakpoint 1 at <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>:7
153+
(Pdb) continue
154+
1
155+
2
156+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(7)test_function()
157+
-> print(3)
158+
(Pdb) next
159+
3
160+
> <doctest test.test_pdb.test_pdb_continue_in_bottomframe[0]>(8)test_function()
161+
-> print(4)
162+
(Pdb) continue
163+
4
164+
"""
165+
166+
125167
def pdb_invoke(method, arg):
126168
"""Run pdb.method(arg)."""
127169
import pdb; getattr(pdb, method)(arg)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ C-API
475475
Library
476476
-------
477477

478+
- Issue #5294: Fix the behavior of pdb's "continue" command when called
479+
in the top-level debugged frame.
480+
478481
- Issue #5727: Restore the ability to use readline when calling into pdb
479482
in doctests.
480483

0 commit comments

Comments
 (0)