How to loop in python extension while accepting mi-commands?

Simon Sobisch via Gdb <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
I've created an auto-step command (something like that in-built would be 
quite nice), both the "easy" and "nearly full" implementation can be 
found with some explanation at https://stackoverflow.com/a/67470615/5027456


At its core the command does:
         # recognize the kind of stop via stop_handler_auto_step
         global last_stop_was_simple
         last_stop_was_simple = True

         # actual auto-stepping
         try:
             while last_stop_was_simple:
                 gdb.execute("step")
                 time.sleep(sleep_time)
         # we just quit the loop as requested
         # pass keyboard and user errors unchanged
         except (KeyboardInterrupt, gdb.GdbError):
             raise

with a handler of

def stop_handler_auto_step(event):
     # check the type of stop, the following is the common one after
     # step/next, a more complex one would be a subclass (for example
     # breakpoint or signal)
     global last_stop_was_simple
     if not type(event) is gdb.StopEvent:
         last_stop_was_simple = False



This works in general on the console, steps with a pause as setup and 
you can follow the code execution.


It stops on breakpoints and other "events" and when issuing CTRL-C the 
code receives the KeyboardInterrupt and is stopped, too.


The problem with this code: while an application can send 
-exec-interrupt 10 times GDB seems to queue that because the 
user-command is still active.

After the loop is ended, for example by a breakpoint, the MI-side 
receives 10 times a "done" response - so there's more than guessing that 
GDB seems to queue the commands.


I've tried to move the loop into a python thread via 
"thread.start_new_thread(loop_func(sleep_time)" and while the stepping 
worked the -exec-interrupt was still not received.


Side note:
gdb (in this case 9.2 but similar was seen in newer versions) was 
started with "-iex set pagination off -iex set mi-async on".



Questions:
* Is there a way to accept mi-commands while running in Python extension 
in general?
* Is there a better approach for the auto-step than a loop like the one 
above, ending depending on KeyboardInterrupt or a gdb event happens?
* Is there any chance that a command like can be added into GDB? If yes: 
would it be helpful to send the "full" python extension script to 
gdb-patches?


Thanks for any comments,
Simon
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.