Skip to content

gh-74614: bdb and pdb: Add watchpoint function - #1756

Closed
mlouielu wants to merge 8 commits into
python:mainfrom
mlouielu:bpo-30429
Closed

mlouielu wants to merge 8 commits into
python:mainfrom
mlouielu:bpo-30429

Conversation

@mlouielu

@mlouielu mlouielu commented May 23, 2017 •

Copy link
Copy Markdown
Contributor

watch and awatch will detect value change and breakout, rwatch using dis module to get the file bytecode, with the lineno it can detect current line is load (read) or not.

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Dec 8, 2018

@auvipy auvipy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 19, 2022
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 28, 2022
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 28, 2022
@arhadthedev arhadthedev changed the title bpo-30429: bdb and pdb: Add watchpoint function gh-74614: bdb and pdb: Add watchpoint function Apr 15, 2023
@arhadthedev arhadthedev added the stdlib Standard Library Python modules in the Lib/ directory label Apr 15, 2023
@arhadthedev

Copy link
Copy Markdown
Member

The test.test_pdb.test_rwatch_command doctest fails:

Failed example:
    with PdbTestInput(['next',
                       'rwatch foo',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue',
                       'continue']):
        test_function()
Expected:
    > <doctest test.test_pdb.test_rwatch_command[0]>(3)test_function()
    -> foo = 10
    (Pdb) next
    > <doctest test.test_pdb.test_rwatch_command[0]>(4)test_function()
    -> type(foo)
    (Pdb) rwatch foo
    (Pdb) continue
    <BLANKLINE>
    read watchpoint 10:foo
[...]
Got:
    > <doctest test.test_pdb.test_rwatch_command[0]>(3)test_function()
    -> foo = 10
    (Pdb) next
    > <doctest test.test_pdb.test_rwatch_command[0]>(4)test_function()
    -> type(foo)
    (Pdb) rwatch foo
    (Pdb) continue
    <BLANKLINE>
    read watchpoint 4:foo
[...]

read watchpoint 4:foo comes from the freshly added functions:

self._do_watch(arg, 'read watchpoint')

cpython/Lib/pdb.py

Lines 673 to 683 in e1daed0

def _do_watch(self, arg, type):
if not arg:
# Print out all breakpoint
self.do_break(None)
return None
try:
eval(arg, self.curframe.f_locals)
except NameError:
self.error('No symbol "%s" in current context' % arg)
return None
self.set_watch(arg, self.curframe, type)

cpython/Lib/bdb.py

Lines 543 to 553 in e1daed0

def set_watch(self, var_name, var_frame, bptype):
try:
var_value = copy.copy(eval(var_name, var_frame.f_locals))
except NameError:
return 'Variable %s does not exist' % var_name
list = self.breaks.setdefault(bptype, [])
if var_name not in list:
list.append(var_name)
Breakpoint(None, None, var_name=var_name, var_value=var_value,
var_frame=var_frame, bptype=bptype)
return None

I cannot recognize what the problem is though.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Apr 16, 2023
@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 17, 2023
@ambv
ambv requested a review from gaogaotiantian as a code owner October 22, 2026 21:21
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35337485 | 📁 Comparing c47f63a against main (4be1d35)

  🔍 Preview build  

4 files changed
± library/bdb.html
± library/dis.html
± library/pdb.html
± whatsnew/changelog.html

@gaogaotiantian

Copy link
Copy Markdown
Member

The approach itself is very fagile, and it won't work for all the cases. Also it will slow down the execution quite a bit. I agree that it's nice to have watchpoints in pdb. Mark and I had a discussion today about implementing one with the dict watcher. I'll draft something. I don't believe we can get a good enough result from this direction. I'll close the PR for now, but if anyone is super interested in working on this, feel free to reach out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time. stdlib Standard Library Python modules in the Lib/ directory type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants