From 42c61fb1dbb005871c6d0896e6e85f29e0494f6d Mon Sep 17 00:00:00 2001 From: Yuan Fu
Date: Fri, 4 Oct 2019 17:34:28 -0400 Subject: [PATCH] Add filter to regiter display in gdb-mi lisp/progmode/gdb-mi.el (gdb-display-these-registers, gdb-registers-add-to-display, gdb-registers-remove-from-display): new (gdb-registers-handler-custom): add conditional check before adding each registers to table --- lisp/progmodes/gdb-mi.el | 64 +++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el index 60852e4ad6..5b7e3321f3 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 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,35 @@ gdb-frame-locals-buffer 'gdb-registers-mode 'gdb-invalidate-registers) +(defun gdb-registers-add-to-display (register) + "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'. " + (interactive (list (completing-read "Register: " (append gdb-register-names + '("all"))))) + (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))))) + +(defun gdb-registers-remove-from-display (register) + "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'." + (interactive (list (completing-read "Register: " (append gdb-register-names + '("all"))))) + (if (equal register "all") + (setq gdb-display-these-registers nil) + (if (listp gdb-display-these-registers) + (setq gdb-display-these-registers + (remove register gdb-display-these-registers)) + (user-error "gdb-display-these-registers is not a list, can’t remove anything from it")))) + (defun gdb-registers-handler-custom () (when gdb-register-names (let ((register-values @@ -4248,17 +4284,23 @@ 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 ((and (listp gdb-display-these-registers) + gdb-display-these-registers) ; not nil + (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")))) -- 2.23.0