cpython: 96cb47f8142e (original) (raw)
Mercurial > cpython
changeset 76676:96cb47f8142e 3.2
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye [#13183]
Senthil Kumaran senthil@uthcode.com | |
---|---|
date | Tue, 01 May 2012 10:07:49 +0800 |
parents | 5c801899cd6d |
children | ab63e874265e eab5120cc208 |
files | Lib/bdb.py Lib/test/test_pdb.py Misc/NEWS |
diffstat | 3 files changed, 68 insertions(+), 1 deletions(-)[+] [-] Lib/bdb.py 15 Lib/test/test_pdb.py 51 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -22,6 +22,7 @@ class Bdb: self.skip = set(skip) if skip else None self.breaks = {} self.fncache = {}
self.frame_returning = None[](#l1.7)
def canonic(self, filename): if filename == "<" + filename[1:-1] + ">": @@ -80,7 +81,11 @@ class Bdb: def dispatch_return(self, frame, arg): if self.stop_here(frame) or frame == self.returnframe:
self.user_return(frame, arg)[](#l1.15)
try:[](#l1.16)
self.frame_returning = frame[](#l1.17)
self.user_return(frame, arg)[](#l1.18)
finally:[](#l1.19)
self.frame_returning = None[](#l1.20) if self.quitting: raise BdbQuit[](#l1.21) return self.trace_dispatch[](#l1.22)
@@ -186,6 +191,14 @@ class Bdb: def set_step(self): """Stop after one line of code."""
# Issue #13183: pdb skips frames after hitting a breakpoint and running[](#l1.28)
# step commands.[](#l1.29)
# Restore the trace function in the caller (that may not have been set[](#l1.30)
# for performance reasons) when returning from the current frame.[](#l1.31)
if self.frame_returning:[](#l1.32)
caller_frame = self.frame_returning.f_back[](#l1.33)
if caller_frame and not caller_frame.f_trace:[](#l1.34)
caller_frame.f_trace = self.trace_dispatch[](#l1.35) self._set_stopinfo(None, None)[](#l1.36)
--- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -5,6 +5,7 @@ import pdb import sys import unittest import subprocess +import textwrap from test import support
This little helper class is essential for testing pdb under doctest.
@@ -595,6 +596,22 @@ def test_pdb_run_with_code_object(): class PdbTestCase(unittest.TestCase):
- def run_pdb(self, script, commands):
"""Run 'script' lines with pdb and the pdb 'commands'."""[](#l2.16)
filename = 'main.py'[](#l2.17)
with open(filename, 'w') as f:[](#l2.18)
f.write(textwrap.dedent(script))[](#l2.19)
cmd = [sys.executable, '-m', 'pdb', filename][](#l2.20)
stdout = stderr = None[](#l2.21)
with subprocess.Popen(cmd, stdout=subprocess.PIPE,[](#l2.22)
stdin=subprocess.PIPE,[](#l2.23)
stderr=subprocess.STDOUT,[](#l2.24)
) as proc:[](#l2.25)
stdout, stderr = proc.communicate(str.encode(commands))[](#l2.26)
stdout = stdout and bytes.decode(stdout)[](#l2.27)
stderr = stderr and bytes.decode(stderr)[](#l2.28)
return stdout, stderr[](#l2.29)
+ def test_issue7964(self): # open the file as binary so we can force \r\n newline with open(support.TESTFN, 'wb') as f: @@ -610,6 +627,40 @@ class PdbTestCase(unittest.TestCase): self.assertNotIn(b'SyntaxError', stdout, "Got a syntax error running test script under PDB")
def foo():[](#l2.42)
bar()[](#l2.43)
def nope():[](#l2.45)
pass[](#l2.46)
def foobar():[](#l2.48)
foo()[](#l2.49)
nope()[](#l2.50)
foobar()[](#l2.52)
"""[](#l2.53)
commands = """[](#l2.54)
from bar import bar[](#l2.55)
break bar[](#l2.56)
continue[](#l2.57)
step[](#l2.58)
step[](#l2.59)
quit[](#l2.60)
"""[](#l2.61)
bar = """[](#l2.62)
def bar():[](#l2.63)
print('1')[](#l2.64)
"""[](#l2.65)
with open('bar.py', 'w') as f:[](#l2.66)
f.write(textwrap.dedent(bar))[](#l2.67)
stdout, stderr = self.run_pdb(script, commands)[](#l2.68)
self.assertIn('main.py(5)foo()->None', stdout.split('\n')[-3],[](#l2.69)
'Fail to step into the caller after a return')[](#l2.70)
+ def tearDown(self): support.unlink(support.TESTFN)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -59,6 +59,9 @@ Core and Builtins Library ------- +- Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running