diff --git a/tools/ade b/tools/ade index 6c5c6beb1db6972817eb2485bc08b7710d920cd7..47f442815bb75856661e7ea0ce804d718f7e9d8d 100755 --- a/tools/ade +++ b/tools/ade @@ -177,19 +177,39 @@ class TargetTriplet: class DebuggerServerThread(threading.Thread): - def __init__(self, target, port, app, *args): + def __init__(self, cond, target, port, app, *args): super().__init__() self.target = target self.port = port self.app = app self.args = args + self._cond = cond + self._exception = None + self._listening = False + def run(self): - self._data = self.target.start_gdbserver(self.port, self.app, *self.args) + try: + self._data = self.target.start_gdbserver(self.port, self.app, *self.args) + with self._cond: + self._listening = True + self._cond.notify() + while True: + pass + except Exception as e: + with self._cond: + self._exception = e + self._cond.notify() def stop(self): self.target.stop_gdbserver(self._data) + def is_listening(self): + return self._listening + + def get_exception(self): + return self._exception + class DebuggerServer: @@ -201,8 +221,14 @@ class DebuggerServer: self._thread = None def __enter__(self): - self._thread = DebuggerServerThread(self.target, self.port, self.app, *self.args) + cond = threading.Condition() + self._thread = DebuggerServerThread(cond, self.target, self.port, self.app, *self.args) self._thread.start() + with cond: + while not self._thread.is_listening() and not self._thread.get_exception(): + cond.wait() + if self._thread.get_exception(): + raise self._thread.get_exception() return self def __exit__(self, et, ev, tb):