Randomize gdb port.
authorRichard Xia <rxia@sifive.com>
Tue, 18 Oct 2016 18:31:25 +0000 (11:31 -0700)
committerRichard Xia <rxia@sifive.com>
Tue, 18 Oct 2016 18:31:25 +0000 (11:31 -0700)
debug/testlib.py

index 0da09a1236dc67bb405f479bace13ab168135faa..29fa1703efdd81f339e726a649e700bac4d77bf1 100644 (file)
@@ -129,13 +129,19 @@ class Openocd(object):
             cmd += ["-f", find_file(config)]
         if debug:
             cmd.append("-d")
+
+        # Assign port
+        self.port = unused_port()
+        print "Using port %d for gdb server" % self.port
+        # This command needs to come before any config scripts on the command
+        # line, since they are executed in order.
+        cmd[1:1] = ["--command", "gdb_port %d" % self.port]
+
         logfile = open(Openocd.logname, "w")
         logfile.write("+ %s\n" % " ".join(cmd))
         logfile.flush()
         self.process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                 stdout=logfile, stderr=logfile)
-        # TODO: Pick a random port
-        self.port = 3333
 
         # Wait for OpenOCD to have made it through riscv_examine(). When using
         # OpenOCD to communicate with a simulator this may take a long time,