diff options
author | Irit Katriel <iritkatriel@yahoo.com> | 2021-04-02 16:15:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 16:15:21 (GMT) |
commit | ad442a674ca443feec43a88a2d3671784712e550 (patch) | |
tree | fcefb60f52bfade464216d47c7ccb74ca698038b /Lib/bdb.py | |
parent | afd12650580725ac598b2845384771c14c4f952e (diff) | |
download | cpython-ad442a674ca443feec43a88a2d3671784712e550.zip cpython-ad442a674ca443feec43a88a2d3671784712e550.tar.gz cpython-ad442a674ca443feec43a88a2d3671784712e550.tar.bz2 |
bpo-24160: Fix breakpoints persistence across multiple pdb sessions (GH-21989)
Diffstat (limited to 'Lib/bdb.py')
-rw-r--r-- | Lib/bdb.py | 29 |
1 files changed, 26 insertions, 3 deletions
@@ -34,6 +34,8 @@ class Bdb: self.fncache = {} self.frame_returning = None + self._load_breaks() + def canonic(self, filename): """Return canonical form of filename. @@ -365,6 +367,12 @@ class Bdb: # Call self.get_*break*() to see the breakpoints or better # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint(). + def _add_to_breaks(self, filename, lineno): + """Add breakpoint to breaks, if not already there.""" + bp_linenos = self.breaks.setdefault(filename, []) + if lineno not in bp_linenos: + bp_linenos.append(lineno) + def set_break(self, filename, lineno, temporary=False, cond=None, funcname=None): """Set a new breakpoint for filename:lineno. @@ -377,12 +385,21 @@ class Bdb: line = linecache.getline(filename, lineno) if not line: return 'Line %s:%d does not exist' % (filename, lineno) - list = self.breaks.setdefault(filename, []) - if lineno not in list: - list.append(lineno) + self._add_to_breaks(filename, lineno) bp = Breakpoint(filename, lineno, temporary, cond, funcname) return None + def _load_breaks(self): + """Apply all breakpoints (set in other instances) to this one. + + Populates this instance's breaks list from the Breakpoint class's + list, which can have breakpoints set by another Bdb instance. This + is necessary for interactive sessions to keep the breakpoints + active across multiple calls to run(). + """ + for (filename, lineno) in Breakpoint.bplist.keys(): + self._add_to_breaks(filename, lineno) + def _prune_breaks(self, filename, lineno): """Prune breakpoints for filename:lineno. @@ -681,6 +698,12 @@ class Breakpoint: else: self.bplist[file, line] = [self] + @staticmethod + def clearBreakpoints(): + Breakpoint.next = 1 + Breakpoint.bplist = {} + Breakpoint.bpbynumber = [None] + def deleteMe(self): """Delete the breakpoint from the list associated to a file:line. |