Skip to content

Commit 7270bef

Browse files
committed
Populate mapping from code to breakpoints
1 parent 3bd9c0a commit 7270bef

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

trepan/lib/breakpoint.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import os.path as osp
2323
from collections import defaultdict
2424
from types import CodeType, ModuleType
25-
from typing import Optional
25+
from typing import DefaultDict, Optional
2626
from types import FrameType
2727
from pyficache import (
2828
code_position_cache,
@@ -215,7 +215,12 @@ def __init__(self):
215215

216216
self.bpbynumber: list = [None]
217217
self.bplist = defaultdict(list)
218-
self.code_list = defaultdict(list)
218+
219+
# Keep a mapping from code object to breakpoints that are currently
220+
# active in that code. By keeping this mapping, we avoid
221+
# tracing frames that do not have breakpoints in their
222+
# corresponding code objects.
223+
self.code_list: DefaultDict[CodeType, list] = defaultdict(list)
219224
return
220225

221226
def bpnumbers(self):
@@ -341,10 +346,18 @@ def delete_breakpoint(self, bp: Breakpoint) -> bool:
341346
index = (bp.filename, bp.line_number)
342347
if index not in self.bplist:
343348
return False
349+
350+
brkpts = self.code_list[bp.code]
351+
assert brkpts, f"Should have a list of breakpoints set in {bp.code}"
352+
if bp in brkpts:
353+
brkpts.remove(bp)
354+
344355
self.bplist[index].remove(bp)
345356
if not self.bplist[index]:
346357
# No more breakpoints for this file:line combo
347358
del self.bplist[index]
359+
360+
348361
return True
349362

350363
def delete_breakpoint_by_number(self, bpnum: int) -> tuple:

0 commit comments

Comments
 (0)