1

I sometimes run multiple instances of Emacs, each running a GDB session. These GDB sessions are often running different versions of the same program, or the same program with different arguments, so I'd like the frame title to indicate what program is running, with what arguments, and in what directory.

Right now I'm doing it with

(set-frame-name (format "gdb: %s (%s)" command-string default-directory))

where command-string is the command line that GDB runs. But this doesn't change when I use commands such as cd, file or set args in GDB.

How can I keep the frame title automatically updated when I change the debugged file, run it with different arguments, or change to another directory?

For example, suppose I start Emacs telling it to run myprogram foo. The frame title would initially be something like gdb: myprogram foo (/some/path). I run set args bar, I want this to automatically update the frame title to gdb: myprogram bar (/some/path). If I run file myotherprogram then the frame title should change to gdb: myotherprogram (/some/path), and so on.

It's ok to assume that there is exactly one Gdb session in this Emacs instance and that there is a single frame. It's ok to use something other than set-frame-name to set the frame title initially — anything that works.

  • To the extent you are using the built-in gud library, you may wish to consider tapping into something like the variable comint-input-sender that is set by default to comint-simple-send to examine the INPUT -- if the INPUT matches something interesting like cd, file or set args, then you can do something like update the frame name. You may also wish to do the same thing as I did by examining what happens when you press the return key; i.e., comint-send-input which contains the line (funcall comint-input-sender proc input). You may find other interesting places to examine INPUT. – lawlist Jul 18 '18 at 14:38
  • The function gdb in the gdb-mi library binds comint-input-sender to the function gdb-send. Here is a working example of how to examine the INPUT string: (defun gdb-string-monitor (orig-fun &rest args) "Doc-string." (let ((res (apply orig-fun args))) (message "PROC: %S | STRING: %S | RETURNED: %S." (car args) (substring-no-properties (car (cdr args))) res) res)) (advice-add 'gdb-send :around #'gdb-string-monitor) – lawlist Jul 18 '18 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.