Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion trepan/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,32 @@ def debug(
if post_mortem:
debugger_on_post_mortem()
pass

# Add breakpoint to list of breakpoints if it is not there.
# And if it is there determine whether it has been disabled.
bpmgr = core.bpmgr
code = frame.f_code
filename = code.co_filename
line_number = frame.f_lineno

bp = bpmgr.find_breakpoint(filename, line_number)
if bp is None:
bp = core.bpmgr.add_breakpoint(
filename=filename,
line_number=line_number,
is_code_offset=False,
condition=None,
func_or_code=code)
elif not bp.enabled:
core.step_ignore = -1
return

if 0 == step_ignore:
frame = sys._getframe(1 + level)
core.stop_reason = "at a debug() call"
old_trace_hook_suspend = core.trace_hook_suspend
core.trace_hook_suspend = True
core.processor.event_processor(frame, "line", None)
core.processor.event_processor(frame, "debug", None)
core.trace_hook_suspend = old_trace_hook_suspend
else:
core.step_ignore = step_ignore - 1
Expand Down
18 changes: 17 additions & 1 deletion trepan/lib/breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def delete_breakpoints_by_lineno(self, filename: str, line_number: int):
self.delete_breakpoint(bp)
return bpnums

def find_bp(self, filename: str, line_number: int, frame):
def find_bp(self, filename: str, line_number: int, frame) -> tuple:
"""Determine which breakpoint for this file:line is to be acted upon.

Called only if we know there is a bpt at this
Expand Down Expand Up @@ -466,6 +466,22 @@ def find_bp(self, filename: str, line_number: int, frame):
pass
return (None, None)

def find_breakpoint(self, filename: str, line_number: int) -> Optional[Breakpoint]:
"""Check for a breakpoint() or trepan.api.debug call

Called only if we know there is a breakpoint at this
location. Returns breakpoint that was triggered and a flag
that indicates if it is ok to delete a temporary breakpoint.

"""
possibles = self.bplist[filename, line_number]
if len(possibles) > 0:
# Count every hit when bp is enabled
b = possibles[0]
b.hits += 1
return b
return None

def last(self):
return len(self.bpbynumber) - 1

Expand Down
1 change: 1 addition & 0 deletions trepan/processor/cmdproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def get_option_fn(key):
self.event2short = dict(EVENT2SHORT)
self.event2short["signal"] = "?!"
self.event2short["brkpt"] = "xx"
self.event2short["debug"] = "db" # debug() call

self.optional_modules = ("ipython", "bpy")
self.cmd_instances = self._populate_commands()
Expand Down