Re: [Python-Dev] Changing a value in a frame (for a debugger)
On 2/7/07, Greg Ewing [EMAIL PROTECTED] wrote: Fabio Zadrozny wrote: frame = findFrame(thread_id, frame_id) exec '%s=%s' % (attr, expression) in frame.f_globals, frame.f_locals The locals of a function are actually stored in an array. When you access them as a dict using locals(), all you get is a dict containing a copy of their current values. Modifying that dict doesn't affect the underlying array. It seems that reading the f_locals of a frame does the same thing. To modify the locals, you would need to poke values into the original array -- but it doesn't seem to be exposed to Python. So it looks like you're out of luck. Would it be ok to add a feature request for that? I initially thought it was completely read-only, but I find it strange that it affects the topmost frame correctly (so, it seems that even though I get a copy, when I alter that copy on the topmost frame it affects it correctly)... anyone has a clue why that happens? It seems to affect pdb too... Consider the code: if __name__ == '__main__': def call1(): v_on_frame1 = 10 print 'v_on_frame1', v_on_frame1 def call0(): import pdb;pdb.set_trace() v_on_frame0 = 10 call1() print 'v_on_frame0', v_on_frame0 call0() #when modifying in the current frame x:\scbr15\source\python\tests_base\empty_test.py(9)call0() - v_on_frame0 = 10 (Pdb) n x:\scbr15\source\python\tests_base\empty_test.py(10)call0() - call1() (Pdb) v_on_frame0 = 40 (Pdb) c v_on_frame1 10 v_on_frame0 40 #when modifying an upper frame it does not work x:\scbr15\source\python\tests_base\empty_test.py(9)call0() - v_on_frame0 = 10 (Pdb) n x:\scbr15\source\python\tests_base\empty_test.py(10)call0() - call1() (Pdb) s --Call-- x:\scbr15\source\python\tests_base\empty_test.py(3)call1() - def call1(): (Pdb) n x:\scbr15\source\python\tests_base\empty_test.py(4)call1() - v_on_frame1 = 10 (Pdb) u x:\scbr15\source\python\tests_base\empty_test.py(10)call0() - call1() (Pdb) v_on_frame0 = 40 (Pdb) d x:\scbr15\source\python\tests_base\empty_test.py(4)call1() - v_on_frame1 = 10 (Pdb) c v_on_frame1 10 v_on_frame0 10 ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Changing a value in a frame (for a debugger)
Fabio Zadrozny schrieb: Would it be ok to add a feature request for that? Nobody can stop you, anyway :-) Seriously, a feature request is likely to sit there forever. If you would come up with an actual patch, that would be a different thing. You'll likely answer your other question in the process of developing a patch, too. Regards, Martin ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Changing a value in a frame (for a debugger)
On 2/7/07, Martin v. Löwis [EMAIL PROTECTED] wrote: Seriously, a feature request is likely to sit there forever. If you would come up with an actual patch, that would be a different thing. You'll likely answer your other question in the process of developing a patch, too. Ok... I've added it as a feature-request in https://sourceforge.net/tracker/index.php?func=detailaid=1654367group_id=5470atid=355470(it explains the problem and proposes a patch), so, if someone could take some time to go through it, it would be nice ;-) Thanks, Fabio ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Changing a value in a frame (for a debugger)
At 08:11 AM 2/7/2007 -0200, Fabio Zadrozny wrote: Would it be ok to add a feature request for that? I initially thought it was completely read-only, but I find it strange that it affects the topmost frame correctly (so, it seems that even though I get a copy, when I alter that copy on the topmost frame it affects it correctly)... anyone has a clue why that happens? The code that calls the debugging hook calls PyFrame_FastToLocals() before invoking the debugger, and then PyFrame_LocalsToFast() afterwards. Thus, the interrupted frame can have its locals modified, but no others can. In order for this to work on other frames, you'd have to explicitly call PyFrame_FastToLocals(frame, 1) -- which you could probably do with ctypes or a C extension. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Changing a value in a frame (for a debugger)
Fabio Zadrozny wrote: Would it be ok to add a feature request for that? It seems a reasonable thing to suggest. Instead of a copy, locals() could return a mapping object that is a view of the underlying array. The only limitation then would be that you couldn't add new keys. I initially thought it was completely read-only, but I find it strange that it affects the topmost frame correctly That's because the topmost frame has a module's dict as its locals, so in that case you are modifying them directly. It's only code compiled as the body of a function that uses an array for locals. -- Greg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Changing a value in a frame (for a debugger)
At 12:06 PM 2/8/2007 +1300, Greg Ewing wrote: That's because the topmost frame has a module's dict as its locals, so in that case you are modifying them directly. It's only code compiled as the body of a function that uses an array for locals. By topmost, he means the frame that was interrupted by the debugger, not the code at the top level of a module. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] Changing a value in a frame (for a debugger)
Fabio Zadrozny wrote: frame = findFrame(thread_id, frame_id) exec '%s=%s' % (attr, expression) in frame.f_globals, frame.f_locals The locals of a function are actually stored in an array. When you access them as a dict using locals(), all you get is a dict containing a copy of their current values. Modifying that dict doesn't affect the underlying array. It seems that reading the f_locals of a frame does the same thing. To modify the locals, you would need to poke values into the original array -- but it doesn't seem to be exposed to Python. So it looks like you're out of luck. -- Greg ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com