You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add a commands argument to pdb.set_trace so the user can feed commands from source code #120254
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.
importpdbdeff():
x=1# should print 1 and continuepdb.set_trace(commands=['p x', 'c'])
f()
There are many use cases
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.
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.
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.
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
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[/+]on Jul 14, 2024
Activity
[-]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[/+]gh-120254: Add a `commands` argument to `pdb.set_trace` (#120255)