Skip to content

Commit

Permalink
[ext_gdb] use a different input for deadlock prevention instead of ne…
Browse files Browse the repository at this point in the history
…w_thread event

As reported in #66 , new_thread event may not be available for some packages of GDB. Remove dependency on it. Use a check on threading.main_thread().is_alive() instead to detect the termination of the interpreter.

Thanks @sn0ot and @agantet for reporting the issue.
  • Loading branch information
bootleg committed Mar 23, 2021
1 parent b1b7be1 commit 98698a5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ext_gdb/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ def run(self):
if self.evt_stop.is_set():
break

self.evt_enabled.wait()
while True:
if self.evt_enabled.wait(2*TIMER_PERIOD):
break
if not self.interpreter_alive():
return

if not self.sync.tunnel:
break
Expand All @@ -331,6 +335,9 @@ def run(self):

time.sleep(TIMER_PERIOD)

def interpreter_alive(self):
return threading.main_thread().is_alive()

def poll(self):
msg = self.sync.tunnel.poll()
if msg:
Expand Down Expand Up @@ -383,11 +390,11 @@ def __init__(self, cfg, commands=[]):
self.offset = None
self.tunnel = None
self.poller = None

gdb.events.exited.connect(self.exit_handler)
gdb.events.cont.connect(self.cont_handler)
gdb.events.stop.connect(self.stop_handler)
gdb.events.new_objfile.connect(self.newobj_handler)
gdb.events.new_thread.connect(self.newthread_handler)

for cmd in commands:
cmd(self)
Expand Down Expand Up @@ -466,9 +473,6 @@ def release_poll_timer(self):
self.poller.stop()
self.poller = None

def newthread_handler(self, event):
self.create_poll_timer()

def newobj_handler(self, event):
# force a new capture
self.maps = None
Expand Down Expand Up @@ -521,10 +525,7 @@ def invoke(self, arg, from_tty):
id = self.identity()
self.tunnel.send("[notice]{\"type\":\"new_dbg\",\"msg\":\"dbg connect - %s\",\"dialect\":\"gdb\"}\n" % id)
rs_log("sync is now enabled with host %s" % str(arg))

# make sure there is an active thread before running the Poller
if gdb.selected_thread():
self.create_poll_timer()
self.create_poll_timer()
else:
print('(update)')

Expand Down

0 comments on commit 98698a5

Please sign in to comment.