From 5d6b15402a5402239dee9bad68e3d57d5c1e430e Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Mon, 7 Aug 2017 15:13:09 -0700 Subject: [PATCH] WIP towards multiple gdb instances. --- debug/testlib.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/debug/testlib.py b/debug/testlib.py index d6c7f8a..856b903 100644 --- a/debug/testlib.py +++ b/debug/testlib.py @@ -218,7 +218,13 @@ class Openocd(object): logfile = open(Openocd.logname, "w") logfile.write("+ %s\n" % " ".join(cmd)) logfile.flush() - self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE, + + self.ports = [] + self.port = None + self.process = self.start(cmd, logfile) + + def start(self, cmd, logfile): + process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=logfile, stderr=logfile) try: @@ -233,10 +239,14 @@ class Openocd(object): m = re.search(r"Listening on port (\d+) for gdb connections", log) if m: - self.port = int(m.group(1)) + if not self.ports: + self.port = int(m.group(1)) + self.ports.append(int(m.group(1))) + + if "telnet server disabled" in log: break - if not self.process.poll() is None: + if not process.poll() is None: raise Exception( "OpenOCD exited before completing riscv_examine()") if not messaged and time.time() - start > 1: @@ -245,7 +255,7 @@ class Openocd(object): if (time.time() - start) > timeout: raise Exception("ERROR: Timed out waiting for OpenOCD to " "listen for gdb") - + return process except Exception: header("OpenOCD log") sys.stdout.write(log) -- 2.30.2