Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a commands argument to pdb.set_trace so the user can feed commands from source code #120254

Closed
gaogaotiantian opened this issue Jun 8, 2024 · 0 comments
Labels
type-feature A feature request or enhancement

Comments

@gaogaotiantian
Copy link
Member

gaogaotiantian commented Jun 8, 2024

Feature or enhancement

Proposal:

I propose to add a commands argument to pdb.set_trace and pdb.Pdb.set_trace. The commands fed should be a list of pdb commands that will be executed the first time the debugger is brought up - it's very similar to .pdbrc.

import pdb
def f():
    x = 1
    # should print 1 and continue
    pdb.set_trace(commands=['p x', 'c'])
f()

There are many use cases

  1. Some users use .pdbrc as debugging scripts, and sometimes it's not the best way because that would be the same for the whole directory. Being able to feed pdb commands can save user a lot of time re-typing all the commands after they try some fix.
  2. It would be much easier to serve a repro regarding pdb on a silver platter. When user reports bugs about pdb, they had to give both the source code, and the commands they use to trigger the bug. With this command, the user can provide a simple one-piece script for the minimal repro.
  3. For cases where stdin is not available, or not super convenient, this could help. For example, in testing. Also, I talked with pyodide maintainer about supporting pdb on webbrowser, and one of the issue was the lack of stdin. They successfully made it work with some workaround, but this could help the case.
  4. It's useful for remote help. It's not uncommon that a more senior developer needs to help a newbee remotely. They could send a fully ready piece of code that contains the command and ask the person to simply put it in and get the result.

This feature is also trivial to implement and easy to maintain - all the pieces are already there.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@gaogaotiantian gaogaotiantian added the type-feature A feature request or enhancement label Jun 8, 2024
@gaogaotiantian gaogaotiantian changed the title Add a commands argument to pdb.Pdb so the user can feed commands from source code Add a commands argument to pdb.set_trace so the user can feed commands from source code Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant