Skip to content

Pdb bug when using names that collide w/ aliases of breakpoints operations #111352

Description

@JosephSBoyle

Bug report

Bug description:

Using specific values as variable names in breakpoints leads to incorrect behaviour.
This seems to be because certain chars are used as aliases in pdb, i.e c is continue, p is print etc.
It is triggered when the following char is non-alpha-numeric, afaict.

MRE:

Python 3.9.5 (default, Sep 14 2021, 12:04:19) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> breakpoint()
--Return--
> <stdin>(1)<module>()->None
(Pdb) c = None
>>> c
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'c' is not defined
>>> 
# I expect to still be in a breakpoint here, and for `c` to be `None`,  but pdb has 'continued' execution instead.

The same is true for other aliases, like q and p, which raise errors relating to their respective functions. (I have not tried all aliases).

CPython versions tested on:

3.9

Operating systems tested on:

Linux

Activity

  1. AlexWaygood commented on Oct 26, 2023

    @AlexWaygood
    Member

    I can reproduce your results on Python 3.12, but the output is pretty different on main (likely because of some changes @gaogaotiantian has been making to improve pdb):

    Running Debug|x64 interpreter...
    Python 3.13.0a1+ (heads/main:232465204e, Oct 17 2023, 15:23:17) [MSC v.1932 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> breakpoint()
    --Return--
    > <python-input-0>(1)<module>()->None
    -> breakpoint()
    (Pdb) c = None
    *** Invalid argument: = None
          Usage: c(ont(inue))
    (Pdb)
  2. gaogaotiantian commented on Oct 26, 2023

    @gaogaotiantian
    Member

    Right, the fix just missed 3.12 because core devs were super busy before release :) We did not consider it as a "bug fix" so no backport was done. The PR is #103465.

    The core issue is pdb parses c = None as a c, or continue command + = None args, which is what cmd.Cmd (pdb is a subclass of it) does. In the old pdb, there's no argument checking - extra arguments will just be ignored. So c = None is strictly equivalent to c.

    We can backport the PR if we want, otherwise this should be marked done. We won't fix 3.9 of course, it does not take bug fixes anymore. The best we can do is to backport the fix to 3.11.

  3. AlexWaygood commented on Oct 26, 2023

    @AlexWaygood
    Member

    Yeah, I think I agree that this is probably a new feature rather than a bugfix. So... wait for Python 3.13, I guess :)

    Sorry we can't do better than that here @JosephSBoyle!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions