@@ -309,7 +309,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
309309 _last_pdb_instance = None
310310
311311 def __init__ (self , completekey = 'tab' , stdin = None , stdout = None , skip = None ,
312- nosigint = False , readrc = True ):
312+ nosigint = False , readrc = True , mode = None ):
313313 bdb .Bdb .__init__ (self , skip = skip )
314314 cmd .Cmd .__init__ (self , completekey , stdin , stdout )
315315 sys .audit ("pdb.Pdb" )
@@ -321,6 +321,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
321321 self .mainpyfile = ''
322322 self ._wait_for_mainpyfile = False
323323 self .tb_lineno = {}
324+ self .mode = mode
324325 # Try to load readline if it exists
325326 try :
326327 import readline
@@ -1611,6 +1612,11 @@ def do_run(self, arg):
16111612 sys.argv. History, breakpoints, actions and debugger options
16121613 are preserved. "restart" is an alias for "run".
16131614 """
1615+ if self .mode == 'inline' :
1616+ self .error ('run/restart command is disabled when pdb is running in inline mode.\n '
1617+ 'Use the command line interface to enable restarting your program\n '
1618+ 'e.g. "python -m pdb myscript.py"' )
1619+ return
16141620 if arg :
16151621 import shlex
16161622 argv0 = sys .argv [0 :1 ]
@@ -2366,7 +2372,7 @@ def set_trace(*, header=None, commands=None):
23662372 if Pdb ._last_pdb_instance is not None :
23672373 pdb = Pdb ._last_pdb_instance
23682374 else :
2369- pdb = Pdb ()
2375+ pdb = Pdb (mode = 'inline' )
23702376 if header is not None :
23712377 pdb .message (header )
23722378 pdb .set_trace (sys ._getframe ().f_back , commands = commands )
@@ -2481,7 +2487,7 @@ def main():
24812487 # modified by the script being debugged. It's a bad idea when it was
24822488 # changed by the user from the command line. There is a "restart" command
24832489 # which allows explicit specification of command line arguments.
2484- pdb = Pdb ()
2490+ pdb = Pdb (mode = 'cli' )
24852491 pdb .rcLines .extend (opts .commands )
24862492 while True :
24872493 try :
0 commit comments