>From 5010df825853b0d393f74388371d2bb0e3d5c723 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sun, 6 Oct 2019 14:10:14 -0400 Subject: [PATCH] Add register filters to gdb-mi Add filtering feature to register buffer of gdb-mi. User can add or remove registers they want to see. * lisp/progmodes/gdb-mi.el (gdb-display-these-registers, (gdb-registers-add-to-display, gdb-registers-remove-from-display): new (gdb-registers-handler-custom): add condition check before adding register to display (gdb-registers-mode-map): add "+" and "-" keybinding (gdb-registers-header): add "[-|+]" button --- lisp/progmodes/gdb-mi.el | 111 ++++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 12 deletions(-) diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 60852e4ad6..6b9f448dbe 100644 --- a/lisp/progmodes/gdb-mi.el +++ b/lisp/progmodes/gdb-mi.el @@ -200,6 +200,13 @@ gdb-error (defvar gdb-macro-info nil "Non-nil if GDB knows that the inferior includes preprocessor macro info.") (defvar gdb-register-names nil "List of register names.") +(defvar-local gdb-display-these-registers t + "Registers that are displayed in register buffer. +Can be a list, a function or t/nil. +If a list, registers which names can be found in the list are displayed. +If a function, it is passed with a register name and should +return t to display and nil to not display. +If t/nil, display all registers / none of the registers.") (defvar gdb-changed-registers nil "List of changed register numbers (strings).") (defvar gdb-buffer-fringe-width nil) @@ -4238,6 +4245,62 @@ gdb-frame-locals-buffer 'gdb-registers-mode 'gdb-invalidate-registers) +(defun gdb-registers-add-to-display (event) + "Add register to display in register buffer. + +Register is a string representing the name of the register. +By default the register buffer displays all the registers. +register can also be 'all, which configures gdb to display all registers. +Also see `gdb-registers-remove-from-display'. + +This function is intended to be used from clicking header line +of register buffer, hence the EVENT." + (interactive "e") + (save-selected-window + ;; make sure we are in the right buffer + (select-window (posn-window (event-start event))) + (let ((register (completing-read "Register: " + (append gdb-register-names + '("all"))))) + ;; if `gdb-display-these-registers' is a function, + ;; just override it with list + (if (equal register "all") + (setq gdb-display-these-registers t) + (if (listp gdb-display-these-registers) + (add-to-list 'gdb-display-these-registers register) + (setq gdb-display-these-registers (list register)))) + ;; update register buffer + (gdb-invalidate-registers 'update)))) + +(defun gdb-registers-remove-from-display (event) + "Remove register from display in register buffer. + +Register is a string representing the name of the register. +By default the register buffer displays all the registers. +REGISTER can also be 'all, which configures gdb to hide all registers. +also see `gdb-registers-add-to-display'. + +This function is intended to be used from clicking header line +of register buffer, hence the EVENT." + (interactive "e") + (save-selected-window + ;; make sure we are in the right buffer + (select-window (posn-window (event-start event))) + (let ((register (completing-read "Register: " + (append gdb-register-names + '("all"))))) + (if (equal register "all") + (setq gdb-display-these-registers nil) + (cond ((listp gdb-display-these-registers) + (setq gdb-display-these-registers + (remove register gdb-display-these-registers))) + ((eq gdb-display-these-registers t) + (setq gdb-display-these-registers + (remove register gdb-register-names))) + (t (user-error "`gdb-display-these-registers' is not a list, can’t remove anything from it")))) + ;; update register buffer + (gdb-invalidate-registers 'update)))) + (defun gdb-registers-handler-custom () (when gdb-register-names (let ((register-values @@ -4248,17 +4311,22 @@ gdb-registers-handler-custom (value (bindat-get-field register 'value)) (register-name (nth (string-to-number register-number) gdb-register-names))) - (gdb-table-add-row - table - (list - (propertize register-name - 'font-lock-face font-lock-variable-name-face) - (if (member register-number gdb-changed-registers) - (propertize value 'font-lock-face font-lock-warning-face) - value)) - `(mouse-face highlight - help-echo "mouse-2: edit value" - gdb-register-name ,register-name)))) + (when (cond ((listp gdb-display-these-registers) ; consider nil as empty list + (member register-name gdb-display-these-registers)) + ((functionp gdb-display-these-registers) + (funcall gdb-display-these-registers register-name)) + (t gdb-display-these-registers)) + (gdb-table-add-row + table + (list + (propertize register-name + 'font-lock-face font-lock-variable-name-face) + (if (member register-number gdb-changed-registers) + (propertize value 'font-lock-face font-lock-warning-face) + value)) + `(mouse-face highlight + help-echo "mouse-2: edit value" + gdb-register-name ,register-name))))) (insert (gdb-table-string table " "))) (setq mode-name (gdb-current-context-mode-name "Registers")))) @@ -4287,6 +4355,8 @@ gdb-registers-mode-map (gdb-get-buffer-create 'gdb-locals-buffer gdb-thread-number) t))) + (define-key map "+" #'gdb-registers-add-to-display) + (define-key map "-" #'gdb-registers-remove-from-display) map)) (defvar gdb-registers-header @@ -4296,7 +4366,24 @@ gdb-registers-header mode-line-inactive) " " (gdb-propertize-header "Registers" gdb-registers-buffer - nil nil mode-line))) + nil nil mode-line) + " [" + (propertize "-" + 'face font-lock-warning-face + 'help-echo "mouse-1: remove register from display filter" + 'mouse-face 'mode-line-highlight + 'local-map (gdb-make-header-line-mouse-map + 'mouse-1 + #'gdb-registers-remove-from-display)) + "|" + (propertize "+" + 'face font-lock-warning-face + 'help-echo "mouse-1: add register to display filter" + 'mouse-face 'mode-line-highlight + 'local-map (gdb-make-header-line-mouse-map + 'mouse-1 + #'gdb-registers-add-to-display)) + "]")) (define-derived-mode gdb-registers-mode gdb-parent-mode "Registers" "Major mode for gdb registers." -- 2.23.0