GithubHelp home page GithubHelp logo

Changing runtime state about pudb HOT 9 OPEN

inducer avatar inducer commented on August 25, 2024
Changing runtime state

from pudb.

Comments (9)

inducer avatar inducer commented on August 25, 2024

pudb and pdb use literally the same code to implement user commands/variable assignments. It turns out that this is fine (and works in pudb and pdb) within the global scope, where variables are kept in a dict, but it very nearly can't be done inside a function, where variables are kept in the VM stack.

If you know otherwise, please let me know.

from pudb.

orientalperil avatar orientalperil commented on August 25, 2024

I see. It sounds like a hard problem.

from pudb.

kgabor avatar kgabor commented on August 25, 2024

As of Python 3.6.6 this seems to be resolved in pdb, it can change local variables.

from pudb.

inducer avatar inducer commented on August 25, 2024

Interesting. In that case, could you look into what pdb does to make that happen? We should be able to just steal what they do.

from pudb.

asmeurer avatar asmeurer commented on August 25, 2024

I don't see any obvious changes to bdb.py or pdb.py related to this.

from pudb.

inducer avatar inducer commented on August 25, 2024

@kgabor I can't reproduce this. I use this script to test, on Python 3.7.3rc1.

def f():
    i = 0

    while i < 10:
        i = i+1
        print(i)

f()

I use pdb to step into f until I'm in the middle of the loop, then say

(Pdb) s i = 20
> /home/andreas/tmp/zzz.py(5)f()
-> i = i+1
(Pdb) p i
1

which seems to contradict your statement.

from pudb.

Sharpeee avatar Sharpeee commented on August 25, 2024

I think this should be re-opened as it works in pdb.

When I test the code from #26 (comment), I can modify i just fine:

$ python -m pdb zzz.py
> .../zzz.py(1)<module>()
-> def f():
(Pdb) n
> .../zzz.py(8)<module>()
-> f()
(Pdb) s
--Call--
> .../zzz.py(1)f()
-> def f():
(Pdb) n
> .../zzz.py(2)f()
-> i = 0
(Pdb) n
> .../zzz.py(4)f()
-> while i < 10:
(Pdb) n
> .../zzz.py(5)f()
-> i = i+1
(Pdb) n
-> print(i)
(Pdb) i
1
(Pdb) i = 20
(Pdb) i
20
(Pdb) n
20
> .../zzz.py(4)f()
-> while i < 10:

This is on Python 3.10.8.

from pudb.

asmeurer avatar asmeurer commented on August 25, 2024

It looks like pdb achieves this by making a copy of f_locals https://github.com/python/cpython/blob/aa8b58cb33826bd2b1a1de631ebcd6a5353eecb5/Lib/pdb.py#L299. Otherwise, frame.f_locals recomputes the locals every time it is accessed, wiping any changes that were made to it.

from pudb.

asmeurer avatar asmeurer commented on August 25, 2024

I have an in progress PR for a similar change for pudb to #571. It requires more testing, and also some cleaning up for the different shells.

from pudb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.