cpython: 5ea23739e9ba (original) (raw)
Mercurial > cpython
changeset 76677:5ea23739e9ba 2.7
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:36:28 +0800 |
parents | 2468b58f7fce |
children | 4c3c4891fd6a |
files | Lib/bdb.py Lib/test/test_pdb.py Misc/NEWS |
diffstat | 3 files changed, 71 insertions(+), 1 deletions(-)[+] [-] Lib/bdb.py 11 Lib/test/test_pdb.py 58 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -24,6 +24,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] + ">": @@ -82,7 +83,9 @@ class Bdb: def dispatch_return(self, frame, arg): if self.stop_here(frame) or frame == self.returnframe:
self.frame_returning = frame[](#l1.15) self.user_return(frame, arg)[](#l1.16)
self.frame_returning = None[](#l1.17) if self.quitting: raise BdbQuit[](#l1.18) return self.trace_dispatch[](#l1.19)
@@ -186,6 +189,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.25)
# step commands.[](#l1.26)
# Restore the trace function in the caller (that may not have been set[](#l1.27)
# for performance reasons) when returning from the current frame.[](#l1.28)
if self.frame_returning:[](#l1.29)
caller_frame = self.frame_returning.f_back[](#l1.30)
if caller_frame and not caller_frame.f_trace:[](#l1.31)
caller_frame.f_trace = self.trace_dispatch[](#l1.32) self._set_stopinfo(None, None)[](#l1.33)
--- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -6,12 +6,66 @@ import sys import os import unittest import subprocess +import textwrap from test import test_support
This little helper class is essential for testing pdb under doctest.
from test_doctest import _FakeInput +class PdbTestCase(unittest.TestCase): +
- def run_pdb(self, script, commands):
"""Run 'script' lines with pdb and the pdb 'commands'."""[](#l2.17)
filename = 'main.py'[](#l2.18)
with open(filename, 'w') as f:[](#l2.19)
f.write(textwrap.dedent(script))[](#l2.20)
cmd = [sys.executable, '-m', 'pdb', filename][](#l2.21)
stdout = stderr = None[](#l2.22)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,[](#l2.23)
stdin=subprocess.PIPE,[](#l2.24)
stderr=subprocess.STDOUT,[](#l2.25)
)[](#l2.26)
stdout, stderr = proc.communicate(commands)[](#l2.27)
proc.stdout.close()[](#l2.28)
proc.stdin.close()[](#l2.29)
return stdout, stderr[](#l2.30)
def foo():[](#l2.36)
bar()[](#l2.37)
def nope():[](#l2.39)
pass[](#l2.40)
def foobar():[](#l2.42)
foo()[](#l2.43)
nope()[](#l2.44)
foobar()[](#l2.46)
"""[](#l2.47)
commands = """[](#l2.48)
from bar import bar[](#l2.49)
break bar[](#l2.50)
continue[](#l2.51)
step[](#l2.52)
step[](#l2.53)
quit[](#l2.54)
"""[](#l2.55)
bar = """[](#l2.56)
def bar():[](#l2.57)
print('1')[](#l2.58)
"""[](#l2.59)
with open('bar.py', 'w') as f:[](#l2.60)
f.write(textwrap.dedent(bar))[](#l2.61)
stdout, stderr = self.run_pdb(script, commands)[](#l2.62)
self.assertIn('main.py(5)foo()->None', stdout.split('\n')[-3],[](#l2.63)
'Fail to step into the caller after a return')[](#l2.64)
+ + class PdbTestInput(object): """Context manager that makes testing Pdb in doctests easier.""" @@ -309,7 +363,9 @@ class ModuleInitTester(unittest.TestCase def test_main(): from test import test_pdb test_support.run_doctest(test_pdb, verbosity=True)
if name == 'main': test_main()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -56,6 +56,9 @@ Core and Builtins Library ------- +- Issue #13183: Fix pdb skipping frames after hitting a breakpoint and running