@@ -361,10 +361,14 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
361361 self ._chained_exceptions = tuple ()
362362 self ._chained_exception_index = 0
363363
364- def set_trace (self , frame = None ):
364+ def set_trace (self , frame = None , * , commands = None ):
365365 Pdb ._last_pdb_instance = self
366366 if frame is None :
367367 frame = sys ._getframe ().f_back
368+
369+ if commands is not None :
370+ self .rcLines .extend (commands )
371+
368372 super ().set_trace (frame )
369373
370374 def sigint_handler (self , signum , frame ):
@@ -2350,21 +2354,22 @@ def runcall(*args, **kwds):
23502354 """
23512355 return Pdb ().runcall (* args , ** kwds )
23522356
2353- def set_trace (* , header = None ):
2357+ def set_trace (* , header = None , commands = None ):
23542358 """Enter the debugger at the calling stack frame.
23552359
23562360 This is useful to hard-code a breakpoint at a given point in a
23572361 program, even if the code is not otherwise being debugged (e.g. when
23582362 an assertion fails). If given, *header* is printed to the console
2359- just before debugging begins.
2363+ just before debugging begins. *commands* is an optional list of
2364+ pdb commands to run when the debugger starts.
23602365 """
23612366 if Pdb ._last_pdb_instance is not None :
23622367 pdb = Pdb ._last_pdb_instance
23632368 else :
23642369 pdb = Pdb ()
23652370 if header is not None :
23662371 pdb .message (header )
2367- pdb .set_trace (sys ._getframe ().f_back )
2372+ pdb .set_trace (sys ._getframe ().f_back , commands = commands )
23682373
23692374# Post-Mortem interface
23702375
0 commit comments