In emacs 24 branch there is a new hook called gdb-stopped-hook which is called each time that gdb stop after executing some command. This hook can be very useful for implementing a Eclipse feature that is missed in emacs, highlight the current line. Emacs paints a small icon in the fringe in order to indicate the line, but this is not enough for me.
I use the package highline.el that contains the functions highline-highlight-current-line and highline-unhighlight-current-line, allowing light or unlight the current line in a easy way:
I use the package highline.el that contains the functions highline-highlight-current-line and highline-unhighlight-current-line, allowing light or unlight the current line in a easy way:
(defun my-gdb-highline-file-line (file line light)
(with-selected-window gdb-source-window
(find-file file)
(goto-char (point-min))
(forward-line (1- line))
(setq my-gdb-line line)
(setq my-gdb-file file)
(if light
(highline-highlight-current-line)
(highline-unhighlight-current-line))))
This function open file file into gdb-source-window (window where gud show the current line) move to line line and light or unlight the line based in light. So I only need put my code into the hook calling this function:
(add-hook 'gdb-stopped-hooks
'(lambda (arg)
(let*
((frame (cdr (nth 2 arg)))
(line (bindat-get-field frame 'line))
(file (bindat-get-field frame 'fullname)))
(when (and (stringp line) (stringp file))
(when (and my-gdb-file my-gdb-line)
(my-gdb-highline-file-line my-gdb-file my-gdb-line nil))
(my-gdb-highline-file-line file (string-to-number line) t)))))
This hook is called with a parsed MI response, where we can get the actual file and line using bindat-get-field. After this we only need unlight the line when gud is stopped:
(defadvice gdb-reset
(after my-gdb-reset activate)
(my-gdb-highline-file-line my-gdb-file my-gdb-line nil))
And now we have our missed featued ready to test it!

Leave a comment