classification
Title: pdb go stack up/down
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: Markus.Pröller, eric.araujo, georg.brandl, meador.inge
Priority: normal Keywords: patch

Created on 2010-08-18 12:17 by Markus.Pröller, last changed 2010-09-02 03:10 by meador.inge.

Files
File name Uploaded Description Edit
issue9633.patch meador.inge, 2010-09-02 03:10 py3k patch review
Messages (4)
msg114213 - (view) Author: Markus Pröller (Markus.Pröller) Date: 2010-08-18 12:17
Hello,

with python 2.7 I encounter the following problem:
I have created the following sample script:

import pdb

def function_1(number):
    stack_1 = number
    function_2(stack_1)
    
def function_2(number):
    stack_2 = number + 1
    function_3(stack_2)
    
def function_3(number):
    stack_3 = number + 1
    pdb.set_trace()
    print stack_3
    
function_1(1)

This is what I have done in the pdb session:
> c:\tst_pdb.py(14)function_3()
-> print stack_3
(Pdb) l
  9         function_3(stack_2)
 10
 11     def function_3(number):
 12         stack_3 = number + 1
 13         pdb.set_trace()
 14  ->     print stack_3
 15
 16     function_1(1) [EOF]
(Pdb) stack_3
3
(Pdb) !stack_3 = 177
(Pdb) !print stack_3
177
(Pdb) u
> c:\tst_pdb.py(9)function_2()
-> function_3(stack_2)
(Pdb) l
  4         stack_1 = number
  5         function_2(stack_1)
  6
  7     def function_2(number):
  8         stack_2 = number + 1
  9  ->     function_3(stack_2)
 10
 11     def function_3(number):
 12         stack_3 = number + 1
 13         pdb.set_trace()
 14         print stack_3
(Pdb) !print stack_2
2
(Pdb) !stack_2 = 144
(Pdb) !print stack_2
144
(Pdb) d
> c:\tst_pdb.py(14)function_3()
-> print stack_3
(Pdb) l
  9         function_3(stack_2)
 10
 11     def function_3(number):
 12         stack_3 = number + 1
 13         pdb.set_trace()
 14  ->     print stack_3
 15
 16     function_1(1) [EOF]
(Pdb) stack_3
3
(Pdb) u
> c:\tst_pdb.py(9)function_2()
-> function_3(stack_2)
(Pdb) !print stack_2
2
(Pdb)

I walked through the stack and changed the values of the variables stack_x but the values weren't saved when I moved one frame up/down
msg114218 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-18 13:48
Thank you for the report. I don’t know pdb much, but I assume you have checked the doc to make sure this is indeed a bug. Can you test it with 3.1 and 3.2 too?

Bug tracker tip: You can find if a core developer is interested in a module in Misc/maintainers.rst and make them nosy (or assign to them, if there is a star near their name, like in Georg’s case).
msg114231 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-18 15:19
The problem here is that changes in the locals are only saved back to the frame when leaving the trace function, and up/down don't do that.

This could be fixed by making Pdb.curframe_locals a dictionary for all visited frames while interaction is running.  I'll look into it for 3.2.
msg115358 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2010-09-02 03:10
I believe this is slightly tricky because 'bdb.format_stack_entry' makes references to '.f_locals' and 'bdb.format_stack_entry' is invoked in several places in 'pdb'.  One option would be to add a extra parameter to 'bdb.format_stack_entry' to accept a dictionary of locals to operate with.

I implemented this approach and added a doctest to verify.  See attached patch.  I didn't update the 'bdb' documentation to note the new parameter, but will if this approach seems reasonable.
History
Date User Action Args
2010-09-02 03:10:33meador.ingesetkeywords: + patch
files: + issue9633.patch
messages: + msg115358
2010-08-30 13:44:42meador.ingesetnosy: + meador.inge
2010-08-18 15:19:45georg.brandlsetmessages: + msg114231
versions: + Python 3.2, - Python 2.7
2010-08-18 13:48:19eric.araujosetassignee: georg.brandl

messages: + msg114218
nosy: + georg.brandl, eric.araujo
2010-08-18 12:17:16Markus.Pröllercreate