diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2024-09-24 19:52:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 19:52:15 (GMT) |
commit | af8403a58dbe45130400a133f756cbf53c5f1d7e (patch) | |
tree | d7155ab818e6df7448daab516b9140255cd3d6dd /Lib/pdb.py | |
parent | fc9e6bf53d1c9ce2b5f802864e0da265a77c111f (diff) | |
download | cpython-af8403a58dbe45130400a133f756cbf53c5f1d7e.zip cpython-af8403a58dbe45130400a133f756cbf53c5f1d7e.tar.gz cpython-af8403a58dbe45130400a133f756cbf53c5f1d7e.tar.bz2 |
gh-120254: Add a `commands` argument to `pdb.set_trace` (#120255)
Diffstat (limited to 'Lib/pdb.py')
-rw-r--r-- | Lib/pdb.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -361,10 +361,14 @@ class Pdb(bdb.Bdb, cmd.Cmd): self._chained_exceptions = tuple() self._chained_exception_index = 0 - def set_trace(self, frame=None): + def set_trace(self, frame=None, *, commands=None): Pdb._last_pdb_instance = self if frame is None: frame = sys._getframe().f_back + + if commands is not None: + self.rcLines.extend(commands) + super().set_trace(frame) def sigint_handler(self, signum, frame): @@ -2350,13 +2354,14 @@ def runcall(*args, **kwds): """ return Pdb().runcall(*args, **kwds) -def set_trace(*, header=None): +def set_trace(*, header=None, commands=None): """Enter the debugger at the calling stack frame. This is useful to hard-code a breakpoint at a given point in a program, even if the code is not otherwise being debugged (e.g. when an assertion fails). If given, *header* is printed to the console - just before debugging begins. + just before debugging begins. *commands* is an optional list of + pdb commands to run when the debugger starts. """ if Pdb._last_pdb_instance is not None: pdb = Pdb._last_pdb_instance @@ -2364,7 +2369,7 @@ def set_trace(*, header=None): pdb = Pdb() if header is not None: pdb.message(header) - pdb.set_trace(sys._getframe().f_back) + pdb.set_trace(sys._getframe().f_back, commands=commands) # Post-Mortem interface |