Skip to content

Commit f8c0105

Browse files
committed
Improve "list" error handling
1 parent 43223e1 commit f8c0105

5 files changed

Lines changed: 22 additions & 14 deletions

File tree

trepan/interfaces/user.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"""Interface when communicating with the user in the same process as
1919
the debugged program."""
2020
import atexit
21+
import os.path as osp
22+
import pathlib
2123

2224
from os import environ
2325

@@ -28,6 +30,10 @@
2830

2931
histfile = environ.get("TREPAN3KHISTFILE", default_configfile("history"))
3032

33+
# Create HISTFILE if it doesn't exist already
34+
if not osp.isfile(histfile):
35+
pathlib.Path(histfile).touch()
36+
3137
# is_pypy = '__pypy__' in sys.builtin_module_names
3238

3339
DEFAULT_USER_SETTINGS = {
@@ -45,7 +51,8 @@
4551
write_history_file,
4652
)
4753
except ImportError:
48-
pass
54+
def write_history_file(histfile: str):
55+
return
4956

5057
class UserInterface(TrepanInterface):
5158
"""Interface when communicating with the user in the same
@@ -86,10 +93,7 @@ def __init__(self, inp=None, out=None, opts={}):
8693
return
8794

8895
def user_write_history_file(self):
89-
try:
90-
write_history_file(self.histfile)
91-
except Exception:
92-
pass
96+
write_history_file(self.histfile)
9397

9498
def close(self):
9599
"""Closes both input and output"""

trepan/processor/cmdlist.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from trepan.processor.location import resolve_location
1818
from trepan.processor.parse.parser import LocationError
1919
from trepan.processor.parse.scanner import ScannerError
20-
from trepan.processor.parse.semantics import Location, build_location, build_range
20+
from trepan.processor.parse.semantics import Location, RangeError, build_location, build_range
2121

2222
INVALID_PARSE_LIST = (None, None, None)
2323

@@ -63,6 +63,9 @@ def parse_list_cmd(proc, args, listsize=10):
6363
proc.errmsg(e.text)
6464
proc.errmsg(e.text_cursor)
6565
return INVALID_PARSE_LIST
66+
except RangeError as e:
67+
proc.errmsg(e.errmsg)
68+
return INVALID_PARSE_LIST
6669

6770
if list_range.first is None:
6871
# Last must have been given
@@ -100,6 +103,8 @@ def parse_list_cmd(proc, args, listsize=10):
100103
last = first + int(last[1:])
101104
elif not last:
102105
last = first + listsize
106+
elif first is None:
107+
return INVALID_PARSE_LIST
103108
elif last < first:
104109
# Treat as a count rather than an absolute location
105110
last = first + last

trepan/processor/cmdproc.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,6 @@ def get_option_fn(key):
197197

198198
self._populate_cmd_lists()
199199

200-
# Note: prompt_str's value set below isn't used. It is
201-
# computed dynamically. The value is suggestive of what it
202-
# looks like.
203-
self.prompt_str = "(trepan3k) "
204-
205200
# Stop only if line/file is different from last time
206201
self.different_line = None
207202

@@ -234,6 +229,8 @@ def get_option_fn(key):
234229
initfile_list = get_option("initfile_list")
235230
for init_cmdfile in initfile_list:
236231
self.queue_startfile(init_cmdfile)
232+
233+
self.set_prompt()
237234
return
238235

239236
def _saferepr(self, str, maxwidth=None):

trepan/processor/location.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ def resolve_location(proc, location) -> Optional[Location]:
151151
if lineinfo:
152152
offset = lineinfo[0].offsets[0]
153153
mod_func = lineinfo[0].name
154-
else:
155-
print(f"No offset found for {filename} {lineno}")
156154

157155
elif location.line_number:
156+
if curframe is None:
157+
proc.errmsg("Current frame is not set")
158+
return INVALID_LOCATION
158159
filename = frame2file(proc.core, curframe, canonic=False)
159160
lineno = location.line_number
160161
is_address = location.is_address

trepan/processor/parse/semantics.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ def n_range(self, range_node):
204204
Location(None, last_node.value, False, None, offset=None), None
205205
)
206206
else:
207-
assert last_node == "DIRECTION"
207+
if last_node != "DIRECTION":
208+
raise RangeError("Expecting a range direction at the end")
208209
self.result = ListRange(None, last_node.value)
209210
pass
210211
self.prune()

0 commit comments

Comments
 (0)