Skip to content

Commit 6752986

Browse files
committed
Update break API for "continue" and "tbreak" ...
and also modernize. For 3.13, we need to add the "offset" parameter.
1 parent 44535f1 commit 6752986

File tree

5 files changed

+33
-22
lines changed

5 files changed

+33
-22
lines changed

trepan/processor/cmdproc.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2008-2010, 2013-2021, 2023-2024 Rocky Bernstein
3+
# Copyright (C) 2008-2010, 2013-2021, 2023-2025 Rocky Bernstein
44
55
#
66
# This program is free software: you can redistribute it and/or modify
@@ -40,8 +40,8 @@
4040
import trepan.misc as Mmisc
4141
from trepan.interfaces.script import ScriptInterface
4242
from trepan.lib.bytecode import is_class_def, is_def_stmt
43-
from trepan.processor.print import print_location
4443
from trepan.processor.complete_rl import completer
44+
from trepan.processor.print import print_location
4545
from trepan.vprocessor import Processor
4646

4747

@@ -159,9 +159,6 @@ def get_option_fn(key):
159159
super().__init__(core_obj)
160160

161161
self.aliases = {}
162-
# "contine_running" is used by step/next/contine to signal breaking out of
163-
# the command evaluation loop.
164-
self.continue_running = False
165162

166163
# "fast_continue" is used if we should try to see if we can
167164
# remove the debugger callback hook altogether. It is used by
@@ -243,7 +240,9 @@ def get_option_fn(key):
243240

244241
for cmd, cmd_obj in self.commands.items():
245242
if hasattr(cmd_obj, "cmds") and hasattr(cmd_obj.cmds, "cmdlist"):
246-
trepan3k_completer.add_completions(cmd, sorted(cmd_obj.cmds.cmdlist))
243+
trepan3k_completer.add_completions(
244+
cmd, sorted(cmd_obj.cmds.cmdlist)
245+
)
247246
for subcmd_name, subcmd_obj in cmd_obj.cmds.subcmds.items():
248247
subcmd_key = f"{cmd} {subcmd_name}"
249248
if hasattr(subcmd_obj, "completion_choices"):
@@ -269,7 +268,7 @@ def _saferepr(self, str, maxwidth=None):
269268
maxwidth = self.debugger.settings["width"]
270269
return self._repr.repr(str)[:maxwidth]
271270

272-
def add_preloop_hook(self, hook, position=-1, nodups=True):
271+
def add_preloop_hook(self, hook, position=-1, _=True):
273272
if hook in self.preloop_hooks:
274273
return False
275274
self.preloop_hooks.insert(position, hook)
@@ -282,8 +281,10 @@ def add_remap_pat(self, pat, replace, clear_remap=True):
282281
pyficache.file2file_remap = {}
283282

284283
# To be overridden in derived debuggers
285-
def defaultFile(self):
284+
def defaultFile(self) -> Optional[str]:
286285
"""Produce a reasonable default."""
286+
if self.curframe is None:
287+
return None
287288
filename = self.curframe.f_code.co_filename
288289
# Consider using is_exec_stmt(). I just don't understand
289290
# the conditions under which the below test is true.

trepan/processor/command/base_cmd.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2009-2010, 2012-2013, 2015, 2021, 2023-2024
3+
# Copyright (C) 2009-2010, 2012-2013, 2015, 2021, 2023-2025
44
# Rocky Bernstein
55
#
66
# This program is free software: you can redistribute it and/or modify
@@ -59,6 +59,11 @@ def __init__(self, proc):
5959
# the note below on these latter 3 methods.)
6060
#
6161
self.core = proc.core
62+
63+
# "contine_running" is used by step/next/contine to signal breaking out of
64+
# the command evaluation loop.
65+
self.continue_running = False
66+
6267
self.debugger = proc.debugger
6368
self.settings = self.debugger.settings
6469
return

trepan/processor/command/break.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ def run(self, args):
8787
force=force,
8888
offset=offset,
8989
)
90+
else:
91+
self.errmsg(f"Did not find stopping spot for: {' '.join(args[1:])}")
9092
return
9193

9294

trepan/processor/command/continue.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2013, 2015, 2017, 2020, 2024 Rocky Bernstein
2+
# Copyright (C) 2009, 2013, 2015, 2017, 2020, 2024-2025 Rocky Bernstein
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -51,9 +51,13 @@ class ContinueCommand(DebuggerCommand):
5151
def run(self, args):
5252
if len(args) > 1:
5353
# FIXME: DRY this code. Better is to hook into tbreak.
54-
func, filename, lineno, condition, _ = parse_break_cmd(self.proc, args)
55-
if not set_break(self, func, filename, lineno, condition, True, args):
56-
return False
54+
func, filename, lineno, condition, offset = parse_break_cmd(self.proc, args)
55+
if not (func is None and filename is None):
56+
set_break(
57+
self, func, filename, lineno, condition, True, args, offset=offset
58+
)
59+
else:
60+
self.errmsg(f"Did not find stopping spot for: {' '.join(args[1:])}")
5761
self.core.step_events = None # All events
5862
self.core.step_ignore = -1
5963
self.proc.continue_running = True # Break out of command read loop
@@ -83,7 +87,7 @@ def five():
8387
for c in (
8488
["continue", "wrong", "number", "of", "args"],
8589
["c", str(line)],
86-
["c", str(line + 1)], # Invalid
90+
["c", str(line + 1)], # Invalid
8791
["continue", "1"],
8892
["c", "five"],
8993
["c", "five()"],
@@ -92,13 +96,9 @@ def five():
9296
cmd.continue_running = False
9397
cmd.proc.current_command = " ".join(c)
9498
result = cmd.run(c)
95-
print("Run result: %s" % result)
99+
print(f"Run result: {result}")
96100
print(
97-
"step_ignore %d, continue_running: %s"
98-
% (
99-
d.core.step_ignore,
100-
cmd.continue_running,
101-
)
101+
f"step_ignore {d.core.step_ignore}, continue_running: {cmd.continue_running}"
102102
)
103103
pass
104104
pass

trepan/processor/command/tbreak.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2013, 2015, 2017 Rocky Bernstein
2+
# Copyright (C) 2009, 2013, 2015, 2017, 2025 Rocky Bernstein
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -68,7 +68,10 @@ class TempBreakCommand(DebuggerCommand):
6868
def run(self, args):
6969
func, filename, lineno, condition, offset = parse_break_cmd(self.proc, args)
7070
if not (func is None and filename is None):
71-
set_break(self, func, filename, lineno, condition, True, args)
71+
set_break(self, func, filename, lineno, condition, True, args,
72+
offset=offset)
73+
else:
74+
self.errmsg(f"Did not find stopping spot for: {' '.join(args[1:])}")
7275
return
7376

7477

0 commit comments

Comments
 (0)