|
22 | 22 | import os.path as osp |
23 | 23 | from collections import defaultdict |
24 | 24 | from types import CodeType, ModuleType |
25 | | -from typing import Optional |
| 25 | +from typing import DefaultDict, Optional |
26 | 26 | from types import FrameType |
27 | 27 | from pyficache import ( |
28 | 28 | code_position_cache, |
@@ -215,7 +215,12 @@ def __init__(self): |
215 | 215 |
|
216 | 216 | self.bpbynumber: list = [None] |
217 | 217 | 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) |
219 | 224 | return |
220 | 225 |
|
221 | 226 | def bpnumbers(self): |
@@ -341,10 +346,18 @@ def delete_breakpoint(self, bp: Breakpoint) -> bool: |
341 | 346 | index = (bp.filename, bp.line_number) |
342 | 347 | if index not in self.bplist: |
343 | 348 | 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 | + |
344 | 355 | self.bplist[index].remove(bp) |
345 | 356 | if not self.bplist[index]: |
346 | 357 | # No more breakpoints for this file:line combo |
347 | 358 | del self.bplist[index] |
| 359 | + |
| 360 | + |
348 | 361 | return True |
349 | 362 |
|
350 | 363 | def delete_breakpoint_by_number(self, bpnum: int) -> tuple: |
|
0 commit comments