Skip to content

Commit

Permalink
Merge pull request #474 from riscv-software-src/pylint
Browse files Browse the repository at this point in the history
debug: New pylint => new warnings => new cleanups
  • Loading branch information
timsifive authored May 26, 2023
2 parents 557762f + af24229 commit 7b52ba3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
29 changes: 16 additions & 13 deletions debug/gdbserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,18 +634,18 @@ def MCONTROL_DMODE(xlen):
def MCONTROL_MASKMAX(xlen):
return 0x3<<((xlen)-11)

MCONTROL_SELECT = (1<<19)
MCONTROL_TIMING = (1<<18)
MCONTROL_ACTION = (0x3f<<12)
MCONTROL_CHAIN = (1<<11)
MCONTROL_MATCH = (0xf<<7)
MCONTROL_M = (1<<6)
MCONTROL_H = (1<<5)
MCONTROL_S = (1<<4)
MCONTROL_U = (1<<3)
MCONTROL_EXECUTE = (1<<2)
MCONTROL_STORE = (1<<1)
MCONTROL_LOAD = (1<<0)
MCONTROL_SELECT = 1<<19
MCONTROL_TIMING = 1<<18
MCONTROL_ACTION = 0x3f<<12
MCONTROL_CHAIN = 1<<11
MCONTROL_MATCH = 0xf<<7
MCONTROL_M = 1<<6
MCONTROL_H = 1<<5
MCONTROL_S = 1<<4
MCONTROL_U = 1<<3
MCONTROL_EXECUTE = 1<<2
MCONTROL_STORE = 1<<1
MCONTROL_LOAD = 1<<0

MCONTROL_TYPE_NONE = 0
MCONTROL_TYPE_MATCH = 2
Expand Down Expand Up @@ -801,6 +801,9 @@ def test(self):
self.gdb.p("i=0")
self.exit()

class GdbServerError(Exception):
pass

class MemorySampleTest(DebugTest):
def early_applicable(self):
return self.target.support_memory_sampling
Expand Down Expand Up @@ -842,7 +845,7 @@ def check_incrementing_samples(raw_samples, check_addr,
samples_per_second = 1000 * end[1] / (end[0] - first_timestamp)
print(f"{samples_per_second} samples/second")
else:
raise Exception("No samples collected.")
raise GdbServerError("No samples collected.")

@staticmethod
def check_samples_equal(raw_samples, check_addr, check_value):
Expand Down
2 changes: 1 addition & 1 deletion debug/pylint.rc
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,4 @@ max-public-methods=20

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
#overgeneral-exceptions=Exception
5 changes: 4 additions & 1 deletion debug/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ def add_target_options(parser):
"the same time. This may make it harder to debug a failure if it "
"does occur.")

class TargetsException(Exception):
pass

def target(parsed):
directory = os.path.dirname(parsed.target)
filename = os.path.basename(parsed.target)
Expand All @@ -278,7 +281,7 @@ def target(parsed):
if h.xlen == 0:
h.xlen = parsed.xlen
elif h.xlen != parsed.xlen:
raise Exception("The target hart specified an XLEN of "
raise TargetsException("The target hart specified an XLEN of "
f"{h.xlen}, but the command line specified an XLEN of "
f"{parsed.xlen}. They must match.")

Expand Down
22 changes: 13 additions & 9 deletions debug/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# Note that gdb comes with its own testsuite. I was unable to figure out how to
# run that testsuite against the spike simulator.

class TestLibError(Exception):
pass

def find_file(path):
for directory in (os.getcwd(), os.path.dirname(__file__)):
fullpath = os.path.join(directory, path)
Expand Down Expand Up @@ -113,7 +116,7 @@ def __init__(self, target, halted=False, timeout=None, with_jtag_gdb=True,
time.sleep(0.11)
if not self.port:
print_log(logname)
raise Exception("Didn't get spike message about bitbang "
raise TestLibError("Didn't get spike message about bitbang "
"connection")

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

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

if (time.time() - start) > timeout:
raise Exception(
raise TestLibError(
"Timed out waiting for VCS to listen for JTAG vpi")

def __del__(self):
Expand Down Expand Up @@ -382,7 +386,7 @@ def start(self, cmd, logfile, extra_env):
line = fd.readline()
if not line:
if not process.poll() is None:
raise Exception("OpenOCD exited early.")
raise TestLibError("OpenOCD exited early.")
time.sleep(0.1)
continue

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

if self.debug_openocd:
Expand Down Expand Up @@ -533,7 +537,7 @@ def tokenize(text):
yield token
break
else:
raise Exception(repr(text[index:]))
raise TestLibError(repr(text[index:]))

def parse_dict(tokens):
assert tokens[0] == "{"
Expand Down Expand Up @@ -579,13 +583,13 @@ def parse_tokens(tokens):
return parse_dict_or_list(tokens)
if isinstance(tokens[0], str):
return tokens.pop(0)
raise Exception(f"Unsupported tokens: {tokens!r}")
raise TestLibError(f"Unsupported tokens: {tokens!r}")

def parse_rhs(text):
tokens = list(tokenize(text))
result = parse_tokens(tokens)
if tokens:
raise Exception(f"Unexpected input: {tokens!r}")
raise TestLibError(f"Unexpected input: {tokens!r}")
return result

class Gdb:
Expand Down

0 comments on commit 7b52ba3

Please sign in to comment.