Skip to content

Commit 9cb2079

Browse files
committed
Add warn class. Warn suspicious jump command
1 parent 425b178 commit 9cb2079

10 files changed

Lines changed: 55 additions & 5 deletions

File tree

test/functional/test_skip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def test_skip():
3131
out = [
3232
"-- x = 3",
3333
"-- x = 4",
34-
"-- y = 5"
34+
"-- y = 5",
35+
"-- y = 7 # NOQA"
3536
]
3637
compare_output(out, d)
3738
assert x == 3, "should have skipped x=4"
@@ -51,6 +52,7 @@ def test_skip():
5152
"-- x = 7",
5253
"-- x = 8",
5354
"-- y = 10 # NOQA",
55+
'-- d.core.stop(options={"remove": True})',
5456
] # x = 8 is shown in prompt, but not run.
5557
compare_output(out, d)
5658
assert x == 7, "x = 8..9 should have been skipped"

trepan/bwprocessor/command/base_cmd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ def run(self, args):
8989
"""
9090
raise NotImplementedError(NotImplementedMessage)
9191

92+
def warnmsg(self, msg, opts={}):
93+
"""Convenience short-hand for self.debugger.intf.warnmsg"""
94+
try:
95+
return self.debugger.intf[-1].warnmsg(msg)
96+
except EOFError:
97+
# FIXME: what do we do here?
98+
pass
99+
return None
100+
92101
pass
93102

94103

trepan/bwprocessor/command/mock.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def msg_nocr(self, msg):
5757
sys.stdout.write(msg)
5858
return
5959

60+
def warnsg(self, msg):
61+
print("** %s" % msg)
62+
return
63+
6064
pass
6165

6266

trepan/interfaces/user.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ def readline(self, prompt=""):
169169
pass
170170
return self.input.readline(prompt=prompt)
171171

172+
def warnmsg(self, msg, prefix="* "):
173+
"""Common routine for reporting debugger warning messages."""
174+
return self.msg("%s%s" % (prefix, msg))
175+
172176
pass
173177

174178

trepan/processor/command/base_cmd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ def run(self, args):
125125
"""
126126
raise NotImplementedError(NotImplementedMessage)
127127

128+
def warnmsg(self, msg, opts={}):
129+
"""Convenience short-hand for self.debugger.intf[-1].warnmsg"""
130+
try:
131+
return self.debugger.intf[-1].warnmsg(msg, prefix="*Warning*: ")
132+
except EOFError:
133+
# FIXME: what do we do here?
134+
pass
135+
return None
136+
128137
pass
129138

130139
def section(self, message, opts={}):

trepan/processor/command/base_subcmd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ def section(self, message, opts={}):
138138

139139
pass
140140

141+
def warnmsg(self, msg):
142+
"""Convenience short-hand for self.debugger.intf[-1].warnmsg"""
143+
return self.debugger.intf[-1].warnmsg(msg, prefix="*Warning*: ")
144+
141145

142146
class DebuggerSetBoolSubcommand(DebuggerSubcommand):
143147
max_args = 1

trepan/processor/command/jump.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
import inspect
1818
import os
19+
from dis import findlinestarts
1920

20-
from trepan.processor import cmdproc as Mcmdproc
21+
from trepan.processor.cmdproc import print_location
2122

2223
# Our local modules
2324
from trepan.processor.command.base_cmd import DebuggerCommand
@@ -81,6 +82,11 @@ def run(self, args):
8182

8283
if lineno is None:
8384
return False
85+
86+
linestarts = dict(findlinestarts(self.proc.curframe.f_code))
87+
if lineno not in linestarts.values():
88+
self.warnmsg(f"code for line {lineno} not found. Results may be unpredictable.")
89+
8490
try:
8591
# Set to change position, update our copy of the stack,
8692
# and display the new position
@@ -89,24 +95,25 @@ def run(self, args):
8995
self.proc.stack[self.proc.curindex][0],
9096
lineno,
9197
)
92-
Mcmdproc.print_location(self.proc)
98+
print_location(self.proc)
9399
except ValueError as e:
94-
self.errmsg("jump failed: %s" % e)
100+
self.errmsg(f"jump failed: {e}")
95101
return False
96102

97103
pass
98104

99105

100106
if __name__ == "__main__":
101107
from trepan.processor.command import mock
108+
from trepan.processor.cmdproc import get_stack
102109

103110
d, cp = mock.dbg_setup()
104111
command = JumpCommand(cp)
105112
print("jump when not running: ", command.run(["jump", "1"]))
106113
command.core.execution_status = "Running"
107114
cp.curframe = inspect.currentframe()
108115
cp.curindex = 0
109-
cp.stack = Mcmdproc.get_stack(cp.curframe, None, None)
116+
cp.stack = get_stack(cp.curframe, None, None)
110117
command.run(["jump", "1"])
111118
cp.curindex = len(cp.stack) - 1
112119
command.run(["jump", "1"])

trepan/processor/command/mock.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def msg_nocr(self, msg):
6868
sys.stdout.write(msg)
6969
return
7070

71+
def warnmsg(self, msg):
72+
print("* %s" % msg)
73+
return
74+
7175
pass
7276

7377

trepan/processor/command/skip.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def run(self, args):
7474
lineno,
7575
)
7676
print_location(self.proc)
77+
self.proc.continue_running = True # Break out of command read loop
7778
except ValueError as e:
7879
self.errmsg(f"skip failed: {e}")
7980
return False

trepan/vprocessor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,10 @@ def section(self, message, opts={}):
8181
def settings(self, setting):
8282
return self.core.debugger.settings.get(setting)
8383

84+
def warnrmsg(self, message, opts={}):
85+
"""Convenience short-hand for self.intf[-1].warnmsg"""
86+
if "plain" != self.debugger.settings["highlight"]:
87+
message = colorize("standout", message)
88+
pass
89+
return self.intf[-1].warnmsg(message)
8490
pass

0 commit comments

Comments
 (0)