File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66"""
77
88import os
9+ import queue
910from pathlib import Path
1011from typing import Any , List , Optional , Tuple
1112
@@ -571,7 +572,26 @@ def handle_exec(
571572 }
572573
573574 try :
574- output = gdb .execute (command , to_string = True )
575+
576+ # The command must run in the main thread, not in the thread that
577+ # receives from the socket. Create a function which will execute
578+ # the command and pass the output through a queue. This definition
579+ # uses lexical scoping for the command and the queue.
580+ result_queue = queue .Queue ()
581+
582+ def run_command ():
583+ try :
584+ output = gdb .execute (command , to_string = True )
585+ result_queue .put (("ok" , output ))
586+ except Exception as e :
587+ result_queue .put (("error" , str (e )))
588+
589+ # Pass the function through post_event() to the main thread,
590+ # where it will run, and this thread waits to receive the output
591+ # from the queue.
592+ gdb .post_event (run_command )
593+ output_status , output = result_queue .get (timeout = 30.0 )
594+
575595 return {
576596 "command" : command ,
577597 "output" : output or "(no output)"
You can’t perform that action at this time.
0 commit comments