Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,9 +1449,18 @@ def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
prefix = '> '
else:
prefix = ' '

# Save copy of curframe_locals because format_stack_entry
# causes a .f_locals access
curframe_locals_copy = dict(self.curframe_locals)

self.message(prefix +
self.format_stack_entry(frame_lineno, prompt_prefix))

# Restore from copy
self.curframe_locals.clear()
self.curframe_locals.update(curframe_locals_copy)

# Provide help

def do_help(self, arg):
Expand Down
46 changes: 46 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,52 @@ def test_pdb_issue_20766():
pdb 2: <built-in function default_int_handler>
"""

def test_issue22577():
"""Test that local variable change not lost after jump.

>>> def test_function(x):
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... lineno = 3
... lineno = 4

>>> with PdbTestInput(['x = 123',
... 'jump 4',
... 'x',
... 'continue']):
... test_function(1)
> <doctest test.test_pdb.test_issue22577[0]>(3)test_function()
-> lineno = 3
(Pdb) x = 123
(Pdb) jump 4
> <doctest test.test_pdb.test_issue22577[0]>(4)test_function()
-> lineno = 4
(Pdb) x
123
(Pdb) continue
"""

def test_local_variable_change():
"""Test that local variable change persists after step.

>>> def test_function(x):
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... print(x)

>>> with PdbTestInput(['x = 123',
... 'step',
... 'continue']):
... test_function(1)
> <doctest test.test_pdb.test_local_variable_change[0]>(3)test_function()
-> print(x)
(Pdb) x = 123
(Pdb) step
123
--Return--
> <doctest test.test_pdb.test_local_variable_change[0]>(3)test_function()->None
-> print(x)
(Pdb) continue
"""


class PdbTestCase(unittest.TestCase):
def tearDown(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the loss of changes to local variables after a jump command in a PDB
session. Patch by Henry Chen.