Skip to content

Commit

Permalink
Add fast continue...
Browse files Browse the repository at this point in the history
When we continue and there are no breakpoints, remove trace hook.
  • Loading branch information
rocky committed Sep 21, 2024
1 parent db74d19 commit 2833e5e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions trepan/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def debug(
core.processor.queue_startfile(init_cmdfile)

if not core.is_started():
core.add_ignore(debug, stop)
core.start(start_opts)
pass
if post_mortem:
Expand Down
2 changes: 0 additions & 2 deletions trepan/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ def get_option(key: str) -> Any:

# Has tracer been started?
if not tracer.is_started() or get_option("force"):
# FIXME: should filter out opts not for tracer

tracer_start_opts = START_OPTS.copy()
if opts:
tracer_start_opts.update(opts.get("tracer_start", {}))
Expand Down
20 changes: 17 additions & 3 deletions trepan/processor/cmdproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import pyficache
from pygments.console import colorize
from tracer import EVENT2SHORT
from tracer import EVENT2SHORT, remove_hook

import trepan.exception as Mexcept
import trepan.lib.display as Mdisplay
Expand Down Expand Up @@ -177,7 +177,7 @@ def print_source_location_info(
L -- 2 import sys,os
(trepan3k)
"""
if remapped_file:
if remapped_file and filename != remapped_file:
mess = f"({remapped_file}:{lineno} remapped {filename}"
else:
mess = f"({filename}:{lineno}"
Expand Down Expand Up @@ -408,7 +408,15 @@ def get_option_fn(key):
get_option = get_option_fn
super().__init__(core_obj)

self.continue_running = False # True if we should leave command loop
# "contine_running" is used by step/next/contine to signal breaking out of
# the command evaluation loop.
self.continue_running = False

# "fast_continue" is used if we should try to see if we can
# remove the debugger callback hook altogether. It is used by
# the "continue" command, but not stepping (step, next, finish).
self.fast_continue = False

self.event2short = dict(EVENT2SHORT)
self.event2short["signal"] = "?!"
self.event2short["brkpt"] = "xx"
Expand Down Expand Up @@ -766,6 +774,7 @@ def process_commands(self):

leave_loop = run_hooks(self, self.preloop_hooks)
self.continue_running = False
self.fast_continue = False

while not leave_loop:
try:
Expand Down Expand Up @@ -795,6 +804,11 @@ def process_commands(self):
pass
pass
run_hooks(self, self.postcmd_hooks)
if self.fast_continue and len(self.core.bpmgr.bplist) == 0:
# remove hook
self.debugger.intf[-1].output.writeline("Fast continue...")
remove_hook(self.core.trace_dispatch, True)

return

def process_command(self):
Expand Down
5 changes: 3 additions & 2 deletions trepan/processor/command/condition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009-2010, 2013, 2015, 2020 Rocky Bernstein
# Copyright (C) 2009-2010, 2013, 2015, 2020, 2024 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -53,14 +53,15 @@ def run(self, args):
condition = " ".join(args[2:])
else:
condition = None
self.msg("Breakpoint %d is now unconditional." % bp.number)
self.msg(f"Breakpoint {bp.number} is now unconditional.")
pass
bp.condition = condition
return


if __name__ == "__main__":
import sys

from trepan import debugger as Mdebugger

Mbreak = __import__("trepan.processor.command.break", None, None, ["*"])
Expand Down
10 changes: 7 additions & 3 deletions trepan/processor/command/continue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2009, 2013, 2015, 2017, 2020 Rocky Bernstein
# Copyright (C) 2009, 2013, 2015, 2017, 2020, 2024 Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from trepan.processor.command.base_cmd import DebuggerCommand
from trepan.processor.cmdbreak import parse_break_cmd, set_break
from trepan.processor.command.base_cmd import DebuggerCommand


class ContinueCommand(DebuggerCommand):
Expand Down Expand Up @@ -51,19 +51,23 @@ class ContinueCommand(DebuggerCommand):
def run(self, args):
if len(args) > 1:
# FIXME: DRY this code. Better is to hook into tbreak.
func, filename, lineno, condition, offset = parse_break_cmd(self.proc, args)
func, filename, lineno, condition, _ = parse_break_cmd(self.proc, args)
if not set_break(self, func, filename, lineno, condition, True, args):
return False
self.core.step_events = None # All events
self.core.step_ignore = -1
self.proc.continue_running = True # Break out of command read loop
self.proc.fast_continue = (
True # try to remove debugger hook if no breakpoints are set.
)
return True

pass


if __name__ == "__main__":
import sys

from trepan.debugger import Trepan

d = Trepan()
Expand Down

0 comments on commit 2833e5e

Please sign in to comment.