python / cpython

The Python programming language
https://www.python.org
Other
62.4k stars 29.96k forks source link

Only support restart command in pdb when it's a command line usage #123756

Open gaogaotiantian opened 2 weeks ago

gaogaotiantian commented 2 weeks ago

Feature or enhancement

Proposal:

Now when we have a breakpoint() in the source code and enter pdb, we can do restart and raise a Restart exception - which in most cases will just stop the program with an exception. For other rare cases, it might be even worse.

It simply does not make sense to allow a restart command if pdb is not brought up from command line - that exception is only caught in command line usage. So, we should only allow restart in command line usage and do nothing (except for an error) in other cases.

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

iritkatriel commented 1 week ago

Rather than allow_restart, I'd add an enum for the ways that pdb can be invoked. That could be useful for other things.

gaogaotiantian commented 1 week ago

Do you mean an indicator for whether pdb is invoked through a inline breakpoint or command line?

iritkatriel commented 1 week ago

Do you mean an indicator for whether pdb is invoked through a inline breakpoint or command line?

Yes

gaogaotiantian commented 1 week ago

In that case, do you think we should have an unknown option as the default - just to keep all the old behavior? Or we should be a bit more aggressive, and use inline(or some other word) as default, to keep the default behavior safer for users? In another word, only allow commands like restart when the pdb is invoked with an explicit option.

Besides restart, I'll also work on exit later. Currently when the user exits pdb invoked by an inline breakpoint an error will be raised and it's just weird to show a trackback of an exception when I exit the debugger. I'll make the behavior similar to other debuggers - ask the user whether they want to exit the process, and do a os._exit() to kill everything quietly.

iritkatriel commented 1 week ago

It can be None by default, and for each situation make None behave like it used to.