In a plain terminal, I can run gdb, connect to gdb server via 'target remote :nnnn` and then use the 'monitor' command to send commands to the remote app, and the results from running those commands on the remote app are displayed at the gdb command line.

Under gud/gdb, if I type the same 'monitor xxx' command, the results of the command, if the command has output, do not get echoed on the gud comint command line. The monitor interface does work -- I can send output-less monitor commands and observe that they are followed. The issue is that if the remote command has output, it does not make its way all the way back to the gud command line.

I can create a rudimentary workaround, printing each line to the Messages buffer, with code such as:

(defun gts-gud-gdb-mon (mon-command)
  "send command as monitor command, collect output"
  (interactive "MMonitor command: ")
  (let* ((gdb-command (format "monitor %s" mon-command))
     (out-lines (gud-gdb-run-command-fetch-lines gdb-command gud-comint-buffer)))
    (dolist (l out-lines)
      (message (format "monitor output line: %s." l)))))

But I would like to either (1) be able to type 'monitor xxxx' and see multiple lines of output at the gud command line, or (2) have a new window, "monitor", that echos the result of any monitor commands.

How can I see the output of 'monitor' commands within gud?

1 Answer 1


It looks like the default behavior for gdb-mi is to simply ignore the target-stream output from gdb. This is data returned by the MI interface prefixed with @. The key function is gdbmi-bnf-target-stream-output in gdb-mi.el. I used the advice-add feature to override this function in my .emacs file:

(defun my-gdbmi-bnf-target-stream-output (c-string)
  "Change behavior for GDB/MI targe the target-stream-output so that it is displayed to the console."
  (gdb-console c-string))

(advice-add 'gdbmi-bnf-target-stream-output :override 'my-gdbmi-bnf-target-stream-output)

With this, I'm now able to see monitor command output, e.g. results from running monitor get_vbits <addr> <size> when debugging interactively with valgrind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.