Skip to content

Commit 7b52ba3

Browse files
authored
Merge pull request #474 from riscv-software-src/pylint
debug: New pylint => new warnings => new cleanups
2 parents 557762f + af24229 commit 7b52ba3

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

debug/gdbserver.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -634,18 +634,18 @@ def MCONTROL_DMODE(xlen):
634634
def MCONTROL_MASKMAX(xlen):
635635
return 0x3<<((xlen)-11)
636636

637-
MCONTROL_SELECT = (1<<19)
638-
MCONTROL_TIMING = (1<<18)
639-
MCONTROL_ACTION = (0x3f<<12)
640-
MCONTROL_CHAIN = (1<<11)
641-
MCONTROL_MATCH = (0xf<<7)
642-
MCONTROL_M = (1<<6)
643-
MCONTROL_H = (1<<5)
644-
MCONTROL_S = (1<<4)
645-
MCONTROL_U = (1<<3)
646-
MCONTROL_EXECUTE = (1<<2)
647-
MCONTROL_STORE = (1<<1)
648-
MCONTROL_LOAD = (1<<0)
637+
MCONTROL_SELECT = 1<<19
638+
MCONTROL_TIMING = 1<<18
639+
MCONTROL_ACTION = 0x3f<<12
640+
MCONTROL_CHAIN = 1<<11
641+
MCONTROL_MATCH = 0xf<<7
642+
MCONTROL_M = 1<<6
643+
MCONTROL_H = 1<<5
644+
MCONTROL_S = 1<<4
645+
MCONTROL_U = 1<<3
646+
MCONTROL_EXECUTE = 1<<2
647+
MCONTROL_STORE = 1<<1
648+
MCONTROL_LOAD = 1<<0
649649

650650
MCONTROL_TYPE_NONE = 0
651651
MCONTROL_TYPE_MATCH = 2
@@ -801,6 +801,9 @@ def test(self):
801801
self.gdb.p("i=0")
802802
self.exit()
803803

804+
class GdbServerError(Exception):
805+
pass
806+
804807
class MemorySampleTest(DebugTest):
805808
def early_applicable(self):
806809
return self.target.support_memory_sampling
@@ -842,7 +845,7 @@ def check_incrementing_samples(raw_samples, check_addr,
842845
samples_per_second = 1000 * end[1] / (end[0] - first_timestamp)
843846
print(f"{samples_per_second} samples/second")
844847
else:
845-
raise Exception("No samples collected.")
848+
raise GdbServerError("No samples collected.")
846849

847850
@staticmethod
848851
def check_samples_equal(raw_samples, check_addr, check_value):

debug/pylint.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,4 @@ max-public-methods=20
286286

287287
# Exceptions that will emit a warning when being caught. Defaults to
288288
# "Exception"
289-
overgeneral-exceptions=Exception
289+
#overgeneral-exceptions=Exception

debug/targets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ def add_target_options(parser):
256256
"the same time. This may make it harder to debug a failure if it "
257257
"does occur.")
258258

259+
class TargetsException(Exception):
260+
pass
261+
259262
def target(parsed):
260263
directory = os.path.dirname(parsed.target)
261264
filename = os.path.basename(parsed.target)
@@ -278,7 +281,7 @@ def target(parsed):
278281
if h.xlen == 0:
279282
h.xlen = parsed.xlen
280283
elif h.xlen != parsed.xlen:
281-
raise Exception("The target hart specified an XLEN of "
284+
raise TargetsException("The target hart specified an XLEN of "
282285
f"{h.xlen}, but the command line specified an XLEN of "
283286
f"{parsed.xlen}. They must match.")
284287

debug/testlib.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# Note that gdb comes with its own testsuite. I was unable to figure out how to
1919
# run that testsuite against the spike simulator.
2020

21+
class TestLibError(Exception):
22+
pass
23+
2124
def find_file(path):
2225
for directory in (os.getcwd(), os.path.dirname(__file__)):
2326
fullpath = os.path.join(directory, path)
@@ -113,7 +116,7 @@ def __init__(self, target, halted=False, timeout=None, with_jtag_gdb=True,
113116
time.sleep(0.11)
114117
if not self.port:
115118
print_log(logname)
116-
raise Exception("Didn't get spike message about bitbang "
119+
raise TestLibError("Didn't get spike message about bitbang "
117120
"connection")
118121

119122
# pylint: disable=too-many-branches
@@ -220,8 +223,9 @@ def __init__(self, spikes):
220223
time.sleep(0.11)
221224
if not self.port:
222225
print_log(self.lognames[-1])
223-
raise Exception("Didn't get daisy chain message about which port "
224-
"it's listening on.")
226+
raise TestLibError(
227+
"Didn't get daisy chain message about which port "
228+
"it's listening on.")
225229

226230
os.environ['REMOTE_BITBANG_HOST'] = 'localhost'
227231
os.environ['REMOTE_BITBANG_PORT'] = str(self.port)
@@ -281,7 +285,7 @@ def __init__(self, sim_cmd=None, debug=False, timeout=300):
281285
os.environ['JTAG_VPI_PORT'] = str(self.port)
282286

283287
if (time.time() - start) > timeout:
284-
raise Exception(
288+
raise TestLibError(
285289
"Timed out waiting for VCS to listen for JTAG vpi")
286290

287291
def __del__(self):
@@ -382,7 +386,7 @@ def start(self, cmd, logfile, extra_env):
382386
line = fd.readline()
383387
if not line:
384388
if not process.poll() is None:
385-
raise Exception("OpenOCD exited early.")
389+
raise TestLibError("OpenOCD exited early.")
386390
time.sleep(0.1)
387391
continue
388392

@@ -398,7 +402,7 @@ def start(self, cmd, logfile, extra_env):
398402
messaged = True
399403
print("Waiting for OpenOCD to start...")
400404
if (time.time() - start) > self.timeout:
401-
raise Exception("Timed out waiting for OpenOCD to "
405+
raise TestLibError("Timed out waiting for OpenOCD to "
402406
"listen for gdb")
403407

404408
if self.debug_openocd:
@@ -533,7 +537,7 @@ def tokenize(text):
533537
yield token
534538
break
535539
else:
536-
raise Exception(repr(text[index:]))
540+
raise TestLibError(repr(text[index:]))
537541

538542
def parse_dict(tokens):
539543
assert tokens[0] == "{"
@@ -579,13 +583,13 @@ def parse_tokens(tokens):
579583
return parse_dict_or_list(tokens)
580584
if isinstance(tokens[0], str):
581585
return tokens.pop(0)
582-
raise Exception(f"Unsupported tokens: {tokens!r}")
586+
raise TestLibError(f"Unsupported tokens: {tokens!r}")
583587

584588
def parse_rhs(text):
585589
tokens = list(tokenize(text))
586590
result = parse_tokens(tokens)
587591
if tokens:
588-
raise Exception(f"Unexpected input: {tokens!r}")
592+
raise TestLibError(f"Unexpected input: {tokens!r}")
589593
return result
590594

591595
class Gdb:

0 commit comments

Comments
 (0)