aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2022-10-07 09:46:28 -0700
committerTim Newsome <tim@sifive.com>2022-10-07 09:58:32 -0700
commita0e34c70e16e219c84bb15723d48a72065a5829e (patch)
tree2a8649caa7c83189705cc2003cdf28e64c1caa78
parent828c5c714ca0b1f44f57764bdc6d728cbd3da028 (diff)
downloadriscv-tests-a0e34c70e16e219c84bb15723d48a72065a5829e.zip
riscv-tests-a0e34c70e16e219c84bb15723d48a72065a5829e.tar.gz
riscv-tests-a0e34c70e16e219c84bb15723d48a72065a5829e.tar.bz2
debug: Add --debug_server arg to open gdb on OpenOCD
Not as useful as I'd like because we don't connect until after examine() has completed, and the test is likely to time out while debugging. But good to have, and maybe I'll expand on it one day.
-rw-r--r--debug/targets.py6
-rw-r--r--debug/testlib.py11
2 files changed, 14 insertions, 3 deletions
diff --git a/debug/targets.py b/debug/targets.py
index 504a550..b2ed01b 100644
--- a/debug/targets.py
+++ b/debug/targets.py
@@ -136,6 +136,7 @@ class Target:
self.directory = os.path.dirname(path)
self.server_cmd = parsed.server_cmd
self.sim_cmd = parsed.sim_cmd
+ self.debug_server = parsed.debug_server
self.temporary_binary = None
self.compiler_supports_v = True
Target.isolate = parsed.isolate
@@ -166,7 +167,8 @@ class Target:
return testlib.Openocd(server_cmd=self.server_cmd,
config=self.openocd_config_path,
timeout=self.server_timeout_sec,
- freertos=test.freertos())
+ freertos=test.freertos(),
+ debug_openocd=self.debug_server)
def do_compile(self, hart, *sources):
binary_name = (
@@ -237,6 +239,8 @@ def add_target_options(parser):
"simulation)", default="spike")
parser.add_argument("--server_cmd",
help="The command to use to start the debug server (e.g. OpenOCD)")
+ parser.add_argument("--debug_server", action="store_true",
+ help="Open gdb in a separate terminal on the debug server")
xlen_group = parser.add_mutually_exclusive_group()
xlen_group.add_argument("--32", action="store_const", const=32,
diff --git a/debug/testlib.py b/debug/testlib.py
index bbca9fe..67f2e5b 100644
--- a/debug/testlib.py
+++ b/debug/testlib.py
@@ -293,8 +293,9 @@ class Openocd:
logname = logfile.name
def __init__(self, server_cmd=None, config=None, debug=False, timeout=60,
- freertos=False):
+ freertos=False, debug_openocd=False):
self.timeout = timeout
+ self.debug_openocd = debug_openocd
if server_cmd:
cmd = shlex.split(server_cmd)
@@ -387,7 +388,7 @@ class Openocd:
self.gdb_ports.append(int(m.group(1)))
if "telnet server disabled" in line:
- return process
+ break
if not messaged and time.time() - start > 1:
messaged = True
@@ -396,6 +397,12 @@ class Openocd:
raise Exception("Timed out waiting for OpenOCD to "
"listen for gdb")
+ if self.debug_openocd:
+ # pylint: disable=consider-using-with
+ self.debugger = subprocess.Popen(["gnome-terminal", "-e",
+ f"gdb --pid={process.pid}"])
+ return process
+
except Exception:
print_log(Openocd.logname)
raise