How to get output of -interpreter-exec in GDB/MI?
Question: I'm writing a wrapper for GDB/MI, however, I miss some commands in the MI
interface. For example, the 'info variables' command. I can execute it with
"-interpreter-exec console", but getting the output of it is tricky since it
writes everything to console records and not to the result record. So I
decided to just take every console record between prompt ("(gdb) " line) and
"^done" record, concatenate them, and return as a result. My question is — is
this safe? It seems that this approach is error-prone, but I don't have any
other idea. Ideas?

**UPDATE:** Also, it might be useful to use python like this `-interpreter-
exec console "python\nprint(gdb.execute('info variables', False, True))\n"`
and the results will appear in one line which is nice, but still how do I get
exactly this line safely? Maybe I should prepend it with some token... Anyway,
it seems that the third argument of `gdb.execute` is not commonly supported,
so relying on it may not be a good idea.


Answer: Well, in fact `gdb.execute` with the third argument is actually supported in
gdb 7.3 which is dated 2011, so I guess using it is fine. So I decided to go
with this command

    
    
    import gdb
    import sys
    
    
    class ConcatCommand(gdb.Command):
        """Executes a command and print concatenated results with a prefix."""
    
    def __init__(self):
        super(ConcatCommand, self).__init__("concat", gdb.COMMAND_USER)
    
    def invoke(self, arg, from_tty):
        pair = arg.partition(' ')
        sys.stdout.write(pair[0] + gdb.execute(pair[2], False, True))
        sys.stdout.flush()
    
    ConcatCommand()
    

Execute it like `-interpreter-exec console "concat token info variables"`.
Then I just take the contents of console record that starts with a token.

