unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
@ 2020-01-18 20:51 Yuan Fu
  2020-01-31  9:56 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2020-01-18 20:51 UTC (permalink / raw)
  To: 39179

[-- Attachment #1: Type: text/plain, Size: 198 bytes --]

By default the register buffer of gdb-mi displays all the registers. This patch allows a user to choose what to display: by enabling a filter. More information is included in the commit message.


[-- Attachment #2: register-filter.patch --]
[-- Type: application/octet-stream, Size: 9133 bytes --]

From 1ac2f247617ee21eab5e86dbf6bf2ce0ef1929a0 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Sun, 6 Oct 2019 14:10:14 -0400
Subject: [PATCH] Add register filters to gdb-mi
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Add filtering feature to register buffer of gdb-mi.
User can add or remove registers they want to see.

On startup, there will be a button “[filter off]” on the header line
of the register buffer. Clicking on it enables the register filter,
changes the button to “[filter on]” and adds a “[-|+]” button next to
it. Click “+” to add patterns to the pattern list, click “-” to
remove. Register whose name matches any pattern in the list is
displayed. You can also use key “f” for toggle, “+” to add pattern,
“-” to remove pattern.

* lisp/progmodes/gdb-mi.el (gdb-registers-enable-filter,
gdb-registers-filter-pattern-list, gdb-header-click-event-handler,
gdb-registers-add-to-display, gdb-registers-remove-from-display,
gdb-registers-toggle-filter): new
(gdb-registers-handler-custom): condition check before adding each
register
(gdb-registers-mode-map): add new keys
(gdb-registers-header): add new buttons
---
 lisp/progmodes/gdb-mi.el | 137 +++++++++++++++++++++++++++++++++++----
 1 file changed, 125 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 60852e4ad6..dce6d76d1a 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -535,6 +535,24 @@ gdb-show-threads-by-default
   :group 'gdb-buffers
   :version "23.2")
 
+;; automatically local because we don't want filters persist across gdb sessions
+(defcustom gdb-registers-enable-filter nil
+  "If t, enable register name filter in register buffer."
+  :local t
+  :type 'boolean
+  :group 'gdb-buffers
+  :version "27.1")
+
+(defcustom gdb-registers-filter-pattern-list nil
+  "Registers that are displayed in register buffer.
+
+Should be a list. Registers whose name can match
+any of the regexps in the list is displayed."
+  :local t
+  :type 'list
+  :group 'gdb-buffers
+  :version "27.1")
+
 (defvar gdb-debug-log nil
   "List of commands sent to and replies received from GDB.
 Most recent commands are listed first.  This list stores only the last
@@ -4238,6 +4256,53 @@ gdb-frame-locals-buffer
  'gdb-registers-mode
  'gdb-invalidate-registers)
 
+(defun gdb-header-click-event-handler (function)
+  "Return a function that handles clicking event on gdb header buttons.
+
+This function switches to the window where the header locates and
+executes FUNCTION."
+  (lambda (event)
+    (interactive "e")
+    (save-selected-window
+      ;; make sure we are in the right buffer
+      (select-window (posn-window (event-start event)))
+      (funcall function))))
+
+(defun gdb-registers-add-to-display ()
+  "Add register to display in register buffer.
+
+Prompt for a register pattern.  The pattern should be a regexp
+pattern matching the name of the register(s) you want to
+display."
+  (interactive)
+  (let ((register (completing-read "Register pattern: "
+                                   gdb-register-names)))
+    (cl-pushnew register gdb-registers-filter-pattern-list)
+    ;; update register buffer
+    (gdb-invalidate-registers 'update)))
+
+(defun gdb-registers-remove-from-display ()
+  "Remove register from display in register buffer.
+
+Prompt for a register pattern.  The pattern should be a pattern
+you want to remove from the existing patterns."
+  (interactive)
+  (let ((register (completing-read "Register pattern: "
+                                   gdb-registers-filter-pattern-list
+                                   nil t))) ; require match
+    (setq gdb-registers-filter-pattern-list
+          (remove register gdb-registers-filter-pattern-list))
+    ;; update register buffer
+    (gdb-invalidate-registers 'update)))
+
+(defun gdb-registers-toggle-filter ()
+  "Toggle register filter."
+  (interactive)
+  (setq gdb-registers-enable-filter
+        (not gdb-registers-enable-filter))
+  ;; update register buffer
+  (gdb-invalidate-registers 'update))
+
 (defun gdb-registers-handler-custom ()
   (when gdb-register-names
     (let ((register-values
@@ -4248,17 +4313,24 @@ 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))))
+          ;; add register if `gdb-display-these-registers' is t
+          ;; or any pattern in `gdb-display-these-registers' matches
+          (when (or (not gdb-registers-enable-filter)
+                    (cl-loop for pattern in gdb-registers-filter-pattern-list
+                             if (string-match pattern register-name)
+                             return t
+                             finally return nil))
+            (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 +4359,9 @@ 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)
+    (define-key map "f" #'gdb-registers-toggle-filter)
     map))
 
 (defvar gdb-registers-header
@@ -4296,7 +4371,45 @@ gdb-registers-header
                           mode-line-inactive)
    " "
    (gdb-propertize-header "Registers" gdb-registers-buffer
-			  nil nil mode-line)))
+			  nil nil mode-line)
+
+   '(:eval (if (not gdb-registers-enable-filter)
+               (propertize " [filter off]"
+                           'face 'shadow
+                           'help-echo "mouse-1: toggle filter"
+                           'mouse-face 'mode-line-highlight
+                           'local-map (gdb-make-header-line-mouse-map
+                                       'mouse-1
+                                       (gdb-header-click-event-handler
+                                        #'gdb-registers-toggle-filter)))
+             (concat ; enable filter
+              (propertize " [filter on]"
+                          'face '(:weight bold :inherit success)
+                          'help-echo "mouse-1: toggle filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-toggle-filter)))
+              " ["
+              (propertize "-"
+                          'face 'font-lock-warning-face
+                          'help-echo "mouse-1: remove register pattern from display filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-remove-from-display)))
+              "|"
+              (propertize "+"
+                          'face 'font-lock-warning-face
+                          'help-echo "mouse-1: add register pattern to display filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-add-to-display)))
+              "]")))))
 
 (define-derived-mode gdb-registers-mode gdb-parent-mode "Registers"
   "Major mode for gdb registers."
-- 
2.24.1


[-- Attachment #3: Type: text/plain, Size: 8841 bytes --]



In GNU Emacs 27.0.50 (build 3, x86_64-apple-darwin19.0.0, NS appkit-1894.10 Version 10.15.1 (Build 19B88))
of 2019-11-30 built on missSilver
Repository revision: e2828795d73637577c7726965974a047fe2d7119
Repository branch: master
Windowing system distributor 'Apple', version 10.3.1894
System Description:  Mac OS X 10.15.2

Recent messages:
Mark set
Quit
Auto-saving...
Mark set
Quit
Delete unmerged branch master? (y or n) y
Quit [3 times]
Revert buffer from file /Users/yuan/emacs/lisp/progmodes/gdb-mi.el? (y or n) y
Showing all blocks ... done
Mark set

Configured using:
'configure --with-modules --with-pdumper=yes
--oldincludedir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/libxml2/'

Configured features:
NOTIFY KQUEUE ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS NS MODULES
THREADS PDUMPER LCMS2

Important settings:
  value of $LC_CTYPE: UTF-8
  value of $LANG: en_CN.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Emacs-Lisp

Minor modes in effect:
  magit-todos-mode: t
  bug-reference-prog-mode: t
  desktop-save-mode: t
  ghelp-global-minor-mode: t
  minibuffer-electric-default-mode: t
  flymake-mode: t
  global-magit-file-mode: t
  magit-file-mode: t
  global-git-commit-mode: t
  async-bytecomp-package-mode: t
  shell-dirtrack-mode: t
  flyspell-mode: t
  outshine-mode: t
  ws-butler-global-mode: t
  ws-butler-mode: t
  minions-mode: t
  eyebrowse-mode: t
  savehist-mode: t
  global-hl-todo-mode: t
  hl-todo-mode: t
  global-highlight-parentheses-mode: t
  highlight-parentheses-mode: t
  rainbow-delimiters-mode: t
  global-undo-tree-mode: t
  undo-tree-mode: t
  electric-pair-mode: t
  winner-mode: t
  aggressive-indent-mode: t
  ivy-prescient-mode: t
  prescient-persist-mode: t
  recentf-mode: t
  which-key-mode: t
  general-override-mode: t
  outline-minor-mode: t
  ivy-mode: t
  company-mode: t
  override-global-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-quote-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  transient-mark-mode: t
  hs-minor-mode: t

Load-path shadows:
/Users/yuan/.emacs.d/ranch/winman/windman hides /Users/yuan/.emacs.d/ranch/windman/windman
/Users/yuan/.emacs.d/ranch/nerd-font/test/test-helper hides /Users/yuan/.emacs.d/ranch/doom-themes/test/test-helper
/Users/yuan/.emacs.d/ranch/julia-mode/julia-mode hides /Users/yuan/.emacs.d/package/julia-mode-20190813.1326/julia-mode
/Users/yuan/.emacs.d/ranch/julia-mode/julia-latexsubs hides /Users/yuan/.emacs.d/package/julia-mode-20190813.1326/julia-latexsubs
/Users/yuan/.emacs.d/ranch/matlab-emacs/mlint hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/mlint
/Users/yuan/.emacs.d/ranch/matlab-emacs/company-matlab-shell hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/company-matlab-shell
/Users/yuan/.emacs.d/ranch/matlab-emacs/linemark hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/linemark
/Users/yuan/.emacs.d/ranch/matlab-emacs/semanticdb-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/semanticdb-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/semantic-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/semantic-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/srecode-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/srecode-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/cedet-matlab hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/cedet-matlab
/Users/yuan/.emacs.d/ranch/matlab-emacs/tlc hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/tlc
/Users/yuan/.emacs.d/ranch/matlab-emacs/matlab-publish hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/matlab-publish
/Users/yuan/.emacs.d/ranch/matlab-emacs/matlab-mode-pkg hides /Users/yuan/.emacs.d/package/matlab-mode-20180928.1526/matlab-mode-pkg
/Users/yuan/.emacs.d/package/faceup-20170925.1946/faceup hides /Users/yuan/attic/emacs/lisp/emacs-lisp/faceup

Features:
(magit-todos pcre2el rxt re-builder grep checkdoc lisp-mnt bug-reference
vc-mtn vc-hg ffap tramp tramp-loaddefs trampver tramp-integration
files-x tramp-compat parse-time iso8601 ls-lisp shadow sort mail-extr
emacsbug sendmail vc-git vc-bzr vc-src vc-sccs vc-svn vc-cvs vc-rcs vc
vc-dispatcher magit-bookmark bookmark company-oddmuse company-keywords
company-etags etags fileloop company-gtags company-dabbrev-code
company-dabbrev company-files company-capf company-cmake company-xcode
company-clang company-semantic company-eclim company-template
company-bbdb hideshow desktop frameset trivial-copy ghelp-eglot
ghelp-helpful ghelp-builtin ghelp cus-edit cus-start cus-load
luna-publish utility pause luna-general-config minibuf-eldef eglot array
jsonrpc ert pp ewoc debug flymake-proc flymake warnings url-util
magit-submodule magit-obsolete magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-status
magit magit-repos magit-apply magit-wip magit-log which-func magit-diff
smerge-mode diff-mode magit-core magit-autorevert autorevert filenotify
magit-margin magit-transient magit-process magit-mode transient
git-commit magit-git magit-section magit-utils crm log-edit message rmc
puny rfc822 mml mml-sec epa derived epg epg-config gnus-util rmail
rmail-loaddefs text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr
mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log with-editor
async-bytecomp async shell server flyspell ispell outshine
outshine-org-cmds outorg isolate inline expand-region
text-mode-expansions the-org-mode-expansions er-basic-expansions
thingatpt expand-region-core expand-region-custom ws-butler minions
eyebrowse savehist buffer-move windmove hl-todo highlight-parentheses
rainbow-delimiters doom-cyberpunk-theme undo-tree diff
doom-one-light-theme elec-pair winner doom-themes doom-themes-base
windman aggressive-indent find-char ivy-prescient prescient recentf-ext
recentf tree-widget wid-edit which-key general helpful imenu trace
edebug backtrace info-look f dash-functional help-fns radix-tree
elisp-refs s loop dash org-element avl-tree generator org advice
org-macro org-footnote org-pcomplete pcomplete org-list org-faces
org-entities time-date noutline outline org-version ob-emacs-lisp ob
ob-tangle org-src ob-ref ob-lob ob-table ob-keys ob-exp ob-comint
ob-core ob-eval org-compat org-macs org-loaddefs format-spec find-func
cal-menu calendar cal-loaddefs counsel xdg xref project dired
dired-loaddefs compile comint ansi-color swiper cl-extra help-mode ivy
delsel ring colir color ivy-overlay company edmacro kmacro pcase
use-package use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key easy-mmode use-package-core finder-inf
tex-site info cowboy package easymenu browse-url url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json subr-x map url-vars cl-loaddefs cl-lib lunary
lunary-ui luna-f rx seq byte-opt gv bytecomp byte-compile cconv tooltip
eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
term/ns-win ns-win ucs-normalize mule-util term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote threads kqueue cocoa ns
lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 198126 23690)
(symbols 48 9373 50)
(strings 32 38317 1952)
(string-bytes 1 1116054)
(vectors 16 24583)
(vector-slots 8 288178 27922)
(floats 8 506 310)
(intervals 56 14663 1329)
(buffers 1000 26))

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-01-18 20:51 bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer Yuan Fu
@ 2020-01-31  9:56 ` Eli Zaretskii
  2020-01-31 23:08   ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2020-01-31  9:56 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39179

> From: Yuan Fu <casouri@gmail.com>
> Date: Sat, 18 Jan 2020 15:51:31 -0500
> 
> On startup, there will be a button “[filter off]” on the header line
> of the register buffer. Clicking on it enables the register filter,
> changes the button to “[filter on]” and adds a “[-|+]” button next to
> it. Click “+” to add patterns to the pattern list, click “-” to
> remove. Register whose name matches any pattern in the list is
> displayed. You can also use key “f” for toggle, “+” to add pattern,
> “-” to remove pattern.

I'm not sure it's a good idea to implement this as a button on the
header-line.  Such buttons are for frequent operations, and also have
the disadvantage of being unavailable on TTY frames.  What are the
chances users will need to redefine the register patters frequently
enough to justify the button?  Wouldn't it be much easier to have a
defcustom whose value users could interactively modify as needed?

And please don't use non-ASCII characters in log messages, as these
could cause trouble reading the Git log on less capable terminals.

> * lisp/progmodes/gdb-mi.el (gdb-registers-enable-filter,
> gdb-registers-filter-pattern-list, gdb-header-click-event-handler,
> gdb-registers-add-to-display, gdb-registers-remove-from-display,
> gdb-registers-toggle-filter): new
                                ^^^
"New functions."

> (gdb-registers-handler-custom): condition check before adding each
> register
> (gdb-registers-mode-map): add new keys
> (gdb-registers-header): add new buttons

Please start description of changes with a capitalized word, and end
with a period -- these should be complete English sentences.

> +;; automatically local because we don't want filters persist across gdb sessions

Likewise in comments: complete sentences (here and elsewhere in the
patch).

Thanks.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-01-31  9:56 ` Eli Zaretskii
@ 2020-01-31 23:08   ` Yuan Fu
  2020-02-01  2:22     ` Yuan Fu
  2020-02-01  7:58     ` Eli Zaretskii
  0 siblings, 2 replies; 14+ messages in thread
From: Yuan Fu @ 2020-01-31 23:08 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 39179

[-- Attachment #1: Type: text/plain, Size: 3015 bytes --]



> On Jan 31, 2020, at 4:56 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Sat, 18 Jan 2020 15:51:31 -0500
>> 
>> On startup, there will be a button “[filter off]” on the header line
>> of the register buffer. Clicking on it enables the register filter,
>> changes the button to “[filter on]” and adds a “[-|+]” button next to
>> it. Click “+” to add patterns to the pattern list, click “-” to
>> remove. Register whose name matches any pattern in the list is
>> displayed. You can also use key “f” for toggle, “+” to add pattern,
>> “-” to remove pattern.
> 
> I'm not sure it's a good idea to implement this as a button on the
> header-line.  Such buttons are for frequent operations, and also have
> the disadvantage of being unavailable on TTY frames.  What are the
> chances users will need to redefine the register patters frequently
> enough to justify the button?  Wouldn't it be much easier to have a
> defcustom whose value users could interactively modify as needed?

I mainly use it to display only the registers I care about, say, all the *dx registers (rdx, edx, dx) or all the r** registers (rdx, rsi, etc). And that depends on the program you are working on. The main motivation behind this patch is that, currently the register buffer simply displays all the possible registers (153 on my machine), and tracking on some of them is very hard (scrolling back and forth, very annoying).

So this feather is a session-based quick filtering for interesting registers, I don’t think defcustom makes it better.

As for the buttons, I mimicked the buttons on memory buffer. And you don’r really need to use these buttons, instead of clicking this buttons, I just hit -/+/f key (since register buffer is a special buffer) and it’s convenient:

>> You can also use key “f” for toggle, “+” to add pattern,
>> “-” to remove pattern.


---------------------------------

> And please don't use non-ASCII characters in log messages, as these
> could cause trouble reading the Git log on less capable terminals.
> 
>> * lisp/progmodes/gdb-mi.el (gdb-registers-enable-filter,
>> gdb-registers-filter-pattern-list, gdb-header-click-event-handler,
>> gdb-registers-add-to-display, gdb-registers-remove-from-display,
>> gdb-registers-toggle-filter): new
>                                ^^^
> "New functions."
> 
>> (gdb-registers-handler-custom): condition check before adding each
>> register
>> (gdb-registers-mode-map): add new keys
>> (gdb-registers-header): add new buttons
> 
> Please start description of changes with a capitalized word, and end
> with a period -- these should be complete English sentences.
> 
>> +;; automatically local because we don't want filters persist across gdb sessions
> 
> Likewise in comments: complete sentences (here and elsewhere in the
> patch).
> 
> Thanks.

I’ve fixed these bits, here is the revised patch.

Yuan


[-- Attachment #2: register-fixed.patch --]
[-- Type: application/octet-stream, Size: 9024 bytes --]

From dcd9d640b4fa32560e40ea5e733392c4d19ff130 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
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.

On startup, there will be a button "[filter off]" on the header line
of the register buffer. Clicking on it enables the register filter,
changes the button to "[filter on]" and adds a "[-|+]" button next to
it. Click "+" to add patterns to the pattern list, click "-" to
remove. Register whose name matches any pattern in the list is
displayed. You can also use key "f" for toggle, "+" to add pattern,
"-" to remove pattern.

* lisp/progmodes/gdb-mi.el (gdb-registers-enable-filter,
gdb-registers-filter-pattern-list, gdb-header-click-event-handler,
gdb-registers-add-to-display, gdb-registers-remove-from-display,
gdb-registers-toggle-filter): New functions.
(gdb-registers-handler-custom): Condition check before adding each
register.
(gdb-registers-mode-map): New keys.
(gdb-registers-header): New buttons.
---
 lisp/progmodes/gdb-mi.el | 137 +++++++++++++++++++++++++++++++++++----
 1 file changed, 125 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 60852e4ad6..aafdbad2c9 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -535,6 +535,24 @@ gdb-show-threads-by-default
   :group 'gdb-buffers
   :version "23.2")
 
+;; Automatically local because we don't want filters persist across gdb sessions.
+(defcustom gdb-registers-enable-filter nil
+  "If t, enable register name filter in register buffer."
+  :local t
+  :type 'boolean
+  :group 'gdb-buffers
+  :version "27.1")
+
+(defcustom gdb-registers-filter-pattern-list nil
+  "Registers that are displayed in register buffer.
+
+Should be a list.  Registers whose name can match
+any of the regexps in the list is displayed."
+  :local t
+  :type 'list
+  :group 'gdb-buffers
+  :version "28.1")
+
 (defvar gdb-debug-log nil
   "List of commands sent to and replies received from GDB.
 Most recent commands are listed first.  This list stores only the last
@@ -4238,6 +4256,53 @@ gdb-frame-locals-buffer
  'gdb-registers-mode
  'gdb-invalidate-registers)
 
+(defun gdb-header-click-event-handler (function)
+  "Return a function that handles clicking event on gdb header buttons.
+
+This function switches to the window where the header locates and
+executes FUNCTION."
+  (lambda (event)
+    (interactive "e")
+    (save-selected-window
+      ;; Make sure we are in the right buffer.
+      (select-window (posn-window (event-start event)))
+      (funcall function))))
+
+(defun gdb-registers-add-to-display ()
+  "Add register to display in register buffer.
+
+Prompt for a register pattern.  The pattern should be a regexp
+pattern matching the name of the register(s) you want to
+display."
+  (interactive)
+  (let ((register (completing-read "Register pattern: "
+                                   gdb-register-names)))
+    (cl-pushnew register gdb-registers-filter-pattern-list)
+    ;; Update register buffer.
+    (gdb-invalidate-registers 'update)))
+
+(defun gdb-registers-remove-from-display ()
+  "Remove register from display in register buffer.
+
+Prompt for a register pattern.  The pattern should be a pattern
+you want to remove from the existing patterns."
+  (interactive)
+  (let ((register (completing-read "Register pattern: "
+                                   gdb-registers-filter-pattern-list
+                                   nil t))) ; require match
+    (setq gdb-registers-filter-pattern-list
+          (remove register gdb-registers-filter-pattern-list))
+    ;; Update register buffer.
+    (gdb-invalidate-registers 'update)))
+
+(defun gdb-registers-toggle-filter ()
+  "Toggle register filter."
+  (interactive)
+  (setq gdb-registers-enable-filter
+        (not gdb-registers-enable-filter))
+  ;; Update register buffer.
+  (gdb-invalidate-registers 'update))
+
 (defun gdb-registers-handler-custom ()
   (when gdb-register-names
     (let ((register-values
@@ -4248,17 +4313,24 @@ 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))))
+          ;; Add register if `gdb-display-these-registers' is t;
+          ;; or any pattern that `gdb-display-these-registers' matches.
+          (when (or (not gdb-registers-enable-filter)
+                    (cl-loop for pattern in gdb-registers-filter-pattern-list
+                             if (string-match pattern register-name)
+                             return t
+                             finally return nil))
+            (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 +4359,9 @@ 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)
+    (define-key map "f" #'gdb-registers-toggle-filter)
     map))
 
 (defvar gdb-registers-header
@@ -4296,7 +4371,45 @@ gdb-registers-header
                           mode-line-inactive)
    " "
    (gdb-propertize-header "Registers" gdb-registers-buffer
-			  nil nil mode-line)))
+			  nil nil mode-line)
+
+   '(:eval (if (not gdb-registers-enable-filter)
+               (propertize " [filter off]"
+                           'face 'shadow
+                           'help-echo "mouse-1: toggle filter"
+                           'mouse-face 'mode-line-highlight
+                           'local-map (gdb-make-header-line-mouse-map
+                                       'mouse-1
+                                       (gdb-header-click-event-handler
+                                        #'gdb-registers-toggle-filter)))
+             (concat ; enable filter
+              (propertize " [filter on]"
+                          'face '(:weight bold :inherit success)
+                          'help-echo "mouse-1: toggle filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-toggle-filter)))
+              " ["
+              (propertize "-"
+                          'face 'font-lock-warning-face
+                          'help-echo "mouse-1: remove register pattern from display filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-remove-from-display)))
+              "|"
+              (propertize "+"
+                          'face 'font-lock-warning-face
+                          'help-echo "mouse-1: add register pattern to display filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-add-to-display)))
+              "]")))))
 
 (define-derived-mode gdb-registers-mode gdb-parent-mode "Registers"
   "Major mode for gdb registers."
-- 
2.25.0


[-- Attachment #3: Type: text/plain, Size: 1 bytes --]



^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-01-31 23:08   ` Yuan Fu
@ 2020-02-01  2:22     ` Yuan Fu
  2020-02-01  7:58     ` Eli Zaretskii
  1 sibling, 0 replies; 14+ messages in thread
From: Yuan Fu @ 2020-02-01  2:22 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 39179

[-- Attachment #1: Type: text/plain, Size: 114 bytes --]

Sorry, I forgot to fix the white spaces after period in the commit message. Here is the correct one.

Yuan



[-- Attachment #2: register-fixed.patch --]
[-- Type: application/octet-stream, Size: 9028 bytes --]

From 47bfc24e08b3a07d8a5b9bda8f38cd23421a1ac4 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
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.

On startup, there will be a button "[filter off]" on the header line
of the register buffer.  Clicking on it enables the register filter,
changes the button to "[filter on]" and adds a "[-|+]" button next to
it.  Click "+" to add patterns to the pattern list, click "-" to
remove.  Register whose name matches any pattern in the list is
displayed.  You can also use key "f" for toggle, "+" to add pattern,
"-" to remove pattern.

* lisp/progmodes/gdb-mi.el (gdb-registers-enable-filter,
gdb-registers-filter-pattern-list, gdb-header-click-event-handler,
gdb-registers-add-to-display, gdb-registers-remove-from-display,
gdb-registers-toggle-filter): New functions.
(gdb-registers-handler-custom): Condition check before adding each
register.
(gdb-registers-mode-map): New keys.
(gdb-registers-header): New buttons.
---
 lisp/progmodes/gdb-mi.el | 137 +++++++++++++++++++++++++++++++++++----
 1 file changed, 125 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 60852e4ad6..aafdbad2c9 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -535,6 +535,24 @@ gdb-show-threads-by-default
   :group 'gdb-buffers
   :version "23.2")
 
+;; Automatically local because we don't want filters persist across gdb sessions.
+(defcustom gdb-registers-enable-filter nil
+  "If t, enable register name filter in register buffer."
+  :local t
+  :type 'boolean
+  :group 'gdb-buffers
+  :version "27.1")
+
+(defcustom gdb-registers-filter-pattern-list nil
+  "Registers that are displayed in register buffer.
+
+Should be a list.  Registers whose name can match
+any of the regexps in the list is displayed."
+  :local t
+  :type 'list
+  :group 'gdb-buffers
+  :version "28.1")
+
 (defvar gdb-debug-log nil
   "List of commands sent to and replies received from GDB.
 Most recent commands are listed first.  This list stores only the last
@@ -4238,6 +4256,53 @@ gdb-frame-locals-buffer
  'gdb-registers-mode
  'gdb-invalidate-registers)
 
+(defun gdb-header-click-event-handler (function)
+  "Return a function that handles clicking event on gdb header buttons.
+
+This function switches to the window where the header locates and
+executes FUNCTION."
+  (lambda (event)
+    (interactive "e")
+    (save-selected-window
+      ;; Make sure we are in the right buffer.
+      (select-window (posn-window (event-start event)))
+      (funcall function))))
+
+(defun gdb-registers-add-to-display ()
+  "Add register to display in register buffer.
+
+Prompt for a register pattern.  The pattern should be a regexp
+pattern matching the name of the register(s) you want to
+display."
+  (interactive)
+  (let ((register (completing-read "Register pattern: "
+                                   gdb-register-names)))
+    (cl-pushnew register gdb-registers-filter-pattern-list)
+    ;; Update register buffer.
+    (gdb-invalidate-registers 'update)))
+
+(defun gdb-registers-remove-from-display ()
+  "Remove register from display in register buffer.
+
+Prompt for a register pattern.  The pattern should be a pattern
+you want to remove from the existing patterns."
+  (interactive)
+  (let ((register (completing-read "Register pattern: "
+                                   gdb-registers-filter-pattern-list
+                                   nil t))) ; require match
+    (setq gdb-registers-filter-pattern-list
+          (remove register gdb-registers-filter-pattern-list))
+    ;; Update register buffer.
+    (gdb-invalidate-registers 'update)))
+
+(defun gdb-registers-toggle-filter ()
+  "Toggle register filter."
+  (interactive)
+  (setq gdb-registers-enable-filter
+        (not gdb-registers-enable-filter))
+  ;; Update register buffer.
+  (gdb-invalidate-registers 'update))
+
 (defun gdb-registers-handler-custom ()
   (when gdb-register-names
     (let ((register-values
@@ -4248,17 +4313,24 @@ 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))))
+          ;; Add register if `gdb-display-these-registers' is t;
+          ;; or any pattern that `gdb-display-these-registers' matches.
+          (when (or (not gdb-registers-enable-filter)
+                    (cl-loop for pattern in gdb-registers-filter-pattern-list
+                             if (string-match pattern register-name)
+                             return t
+                             finally return nil))
+            (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 +4359,9 @@ 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)
+    (define-key map "f" #'gdb-registers-toggle-filter)
     map))
 
 (defvar gdb-registers-header
@@ -4296,7 +4371,45 @@ gdb-registers-header
                           mode-line-inactive)
    " "
    (gdb-propertize-header "Registers" gdb-registers-buffer
-			  nil nil mode-line)))
+			  nil nil mode-line)
+
+   '(:eval (if (not gdb-registers-enable-filter)
+               (propertize " [filter off]"
+                           'face 'shadow
+                           'help-echo "mouse-1: toggle filter"
+                           'mouse-face 'mode-line-highlight
+                           'local-map (gdb-make-header-line-mouse-map
+                                       'mouse-1
+                                       (gdb-header-click-event-handler
+                                        #'gdb-registers-toggle-filter)))
+             (concat ; enable filter
+              (propertize " [filter on]"
+                          'face '(:weight bold :inherit success)
+                          'help-echo "mouse-1: toggle filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-toggle-filter)))
+              " ["
+              (propertize "-"
+                          'face 'font-lock-warning-face
+                          'help-echo "mouse-1: remove register pattern from display filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-remove-from-display)))
+              "|"
+              (propertize "+"
+                          'face 'font-lock-warning-face
+                          'help-echo "mouse-1: add register pattern to display filter"
+                          'mouse-face 'mode-line-highlight
+                          'local-map (gdb-make-header-line-mouse-map
+                                      'mouse-1
+                                      (gdb-header-click-event-handler
+                                       #'gdb-registers-add-to-display)))
+              "]")))))
 
 (define-derived-mode gdb-registers-mode gdb-parent-mode "Registers"
   "Major mode for gdb registers."
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-01-31 23:08   ` Yuan Fu
  2020-02-01  2:22     ` Yuan Fu
@ 2020-02-01  7:58     ` Eli Zaretskii
  2020-02-02 14:32       ` Yuan Fu
  1 sibling, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2020-02-01  7:58 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39179

> From: Yuan Fu <casouri@gmail.com>
> Date: Fri, 31 Jan 2020 18:08:18 -0500
> Cc: 39179@debbugs.gnu.org
> 
> > I'm not sure it's a good idea to implement this as a button on the
> > header-line.  Such buttons are for frequent operations, and also have
> > the disadvantage of being unavailable on TTY frames.  What are the
> > chances users will need to redefine the register patters frequently
> > enough to justify the button?  Wouldn't it be much easier to have a
> > defcustom whose value users could interactively modify as needed?
> 
> I mainly use it to display only the registers I care about, say, all
> the *dx registers (rdx, edx, dx) or all the r** registers (rdx, rsi,
> etc).

I understand, but why wouldn't a simple defcustom do this job?  A list
of registers to display is a simple thing, no?

> And that depends on the program you are working on.

Really?  In what way?  I could only understand why you'd like to see
FP registers in some programs, but not in others.  But other than
that, why would you want to see this or that register?  Are you
frequently debugging on the machine language level?

> The main motivation behind this patch is that, currently the register buffer simply displays all the possible registers (153 on my machine), and tracking on some of them is very hard (scrolling back and forth, very annoying).

Then perhaps we should allow reordering the registers instead of
filtering their list, so that registers you want to see are at the
beginning?

> So this feather is a session-based quick filtering for interesting registers, I don’t think defcustom makes it better.

Why don't you think a defcustom will do?

> +(defcustom gdb-registers-enable-filter nil
> +  "If t, enable register name filter in register buffer."
> +  :local t
> +  :type 'boolean
> +  :group 'gdb-buffers
> +  :version "27.1")

This should be "28.1", not "27.1".

> +(defcustom gdb-registers-filter-pattern-list nil
> +  "Registers that are displayed in register buffer.
> +
> +Should be a list.  Registers whose name can match
> +any of the regexps in the list is displayed."
                                  ^^
"are"

> +  :local t
> +  :type 'list
> +  :group 'gdb-buffers
> +  :version "28.1")
> +
>  (defvar gdb-debug-log nil
>    "List of commands sent to and replies received from GDB.
>  Most recent commands are listed first.  This list stores only the last
> @@ -4238,6 +4256,53 @@ gdb-frame-locals-buffer
>   'gdb-registers-mode
>   'gdb-invalidate-registers)
>  
> +(defun gdb-header-click-event-handler (function)
> +  "Return a function that handles clicking event on gdb header buttons.

This doesn't really return a function, it calls it, right?

But before we discuss the particular code, let's please first agree on
the design, OK?





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-02-01  7:58     ` Eli Zaretskii
@ 2020-02-02 14:32       ` Yuan Fu
  2020-02-02 15:52         ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2020-02-02 14:32 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 39179



> On Feb 1, 2020, at 2:58 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Fri, 31 Jan 2020 18:08:18 -0500
>> Cc: 39179@debbugs.gnu.org
>> 
>>> I'm not sure it's a good idea to implement this as a button on the
>>> header-line.  Such buttons are for frequent operations, and also have
>>> the disadvantage of being unavailable on TTY frames.  What are the
>>> chances users will need to redefine the register patters frequently
>>> enough to justify the button?  Wouldn't it be much easier to have a
>>> defcustom whose value users could interactively modify as needed?
>> 
>> I mainly use it to display only the registers I care about, say, all
>> the *dx registers (rdx, edx, dx) or all the r** registers (rdx, rsi,
>> etc).
> 
> I understand, but why wouldn't a simple defcustom do this job?  A list
> of registers to display is a simple thing, no?

My main concern is that defcustom wouldn’t be as convenient as the current one. Right now I only need `f + .*dx` and I’m good to go, whereas defcustom I need to go to customize and configure there, and come back.


>> And that depends on the program you are working on.
> 
> Really?  In what way?  I could only understand why you'd like to see
> FP registers in some programs, but not in others.  But other than
> that, why would you want to see this or that register?  Are you
> frequently debugging on the machine language level?

Honestly I only used this for the bomb lab in my CS course last semester where we need to debug assembly code. So if you think in real life scenarios we don’t really need this _quick_ filtering and customize will cut it. I’m fine with that too. Is your main reason of objection the (unnecessary) complexity of the code?

>> The main motivation behind this patch is that, currently the register buffer simply displays all the possible registers (153 on my machine), and tracking on some of them is very hard (scrolling back and forth, very annoying).
> 
> Then perhaps we should allow reordering the registers instead of
> filtering their list, so that registers you want to see are at the
> beginning?

That would be more complex that just filtering IMO. 

> 
>> So this feather is a session-based quick filtering for interesting registers, I don’t think defcustom makes it better.
> 
> Why don't you think a defcustom will do?

In the “quick” aspect (as I described above).

> 
>> +(defcustom gdb-registers-enable-filter nil
>> +  "If t, enable register name filter in register buffer."
>> +  :local t
>> +  :type 'boolean
>> +  :group 'gdb-buffers
>> +  :version "27.1")
> 
> This should be "28.1", not "27.1".
> 
>> +(defcustom gdb-registers-filter-pattern-list nil
>> +  "Registers that are displayed in register buffer.
>> +
>> +Should be a list.  Registers whose name can match
>> +any of the regexps in the list is displayed."
>                                  ^^
> "are"
> 
>> +  :local t
>> +  :type 'list
>> +  :group 'gdb-buffers
>> +  :version "28.1")
>> +
>> (defvar gdb-debug-log nil
>>   "List of commands sent to and replies received from GDB.
>> Most recent commands are listed first.  This list stores only the last
>> @@ -4238,6 +4256,53 @@ gdb-frame-locals-buffer
>>  'gdb-registers-mode
>>  'gdb-invalidate-registers)
>> 
>> +(defun gdb-header-click-event-handler (function)
>> +  "Return a function that handles clicking event on gdb header buttons.
> 
> This doesn't really return a function, it calls it, right?
> 
> But before we discuss the particular code, let's please first agree on
> the design, OK?

That’s ideal.

Thanks,
Yuan






^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-02-02 14:32       ` Yuan Fu
@ 2020-02-02 15:52         ` Eli Zaretskii
  2020-08-09 11:57           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2020-02-02 15:52 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39179

> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 2 Feb 2020 09:32:45 -0500
> Cc: 39179@debbugs.gnu.org
> 
> >> I mainly use it to display only the registers I care about, say, all
> >> the *dx registers (rdx, edx, dx) or all the r** registers (rdx, rsi,
> >> etc).
> > 
> > I understand, but why wouldn't a simple defcustom do this job?  A list
> > of registers to display is a simple thing, no?
> 
> My main concern is that defcustom wouldn’t be as convenient as the current one. Right now I only need `f + .*dx` and I’m good to go, whereas defcustom I need to go to customize and configure there, and come back.

Sure, but this convenience is only a significant consideration for a
feature that is supposed to be used very frequently.  I don't think
this is so in this case.

> > Really?  In what way?  I could only understand why you'd like to see
> > FP registers in some programs, but not in others.  But other than
> > that, why would you want to see this or that register?  Are you
> > frequently debugging on the machine language level?
> 
> Honestly I only used this for the bomb lab in my CS course last semester where we need to debug assembly code. So if you think in real life scenarios we don’t really need this _quick_ filtering and customize will cut it. I’m fine with that too.

Good, then let's do it via a defcustom.

> Is your main reason of objection the (unnecessary) complexity of the code?

No, my main reason is to avoid unnecessarily cluttering the UI.

> > Then perhaps we should allow reordering the registers instead of
> > filtering their list, so that registers you want to see are at the
> > beginning?
> 
> That would be more complex that just filtering IMO. 

OK.

Thanks.





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-02-02 15:52         ` Eli Zaretskii
@ 2020-08-09 11:57           ` Lars Ingebrigtsen
  2020-08-10 18:20             ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-09 11:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Yuan Fu, 39179

Eli Zaretskii <eliz@gnu.org> writes:

>> Honestly I only used this for the bomb lab in my CS course last
>> semester where we need to debug assembly code. So if you think in
>> real life scenarios we don’t really need this _quick_ filtering and
>> customize will cut it. I’m fine with that too.
>
> Good, then let's do it via a defcustom.

Yuan, this was in February.  Did you find time to redo the patch using a
defcustom instead?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-08-09 11:57           ` Lars Ingebrigtsen
@ 2020-08-10 18:20             ` Yuan Fu
  2021-05-12 15:54               ` Lars Ingebrigtsen
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2020-08-10 18:20 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 39179



> On Aug 9, 2020, at 7:57 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
>>> Honestly I only used this for the bomb lab in my CS course last
>>> semester where we need to debug assembly code. So if you think in
>>> real life scenarios we don’t really need this _quick_ filtering and
>>> customize will cut it. I’m fine with that too.
>> 
>> Good, then let's do it via a defcustom.
> 
> Yuan, this was in February.  Did you find time to redo the patch using a
> defcustom instead?

Ah, I forgot about this, thanks. I promise I’ll do it :-)

Yuan




^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2020-08-10 18:20             ` Yuan Fu
@ 2021-05-12 15:54               ` Lars Ingebrigtsen
  2021-05-19  0:19                 ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-12 15:54 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39179

Yuan Fu <casouri@gmail.com> writes:

> Ah, I forgot about this, thanks. I promise I’ll do it :-)

This was half a year ago.  :-)  Has there been any progress here?
Skimming this thread, it seems like the general consensus was that this
was a good feature to add...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2021-05-12 15:54               ` Lars Ingebrigtsen
@ 2021-05-19  0:19                 ` Yuan Fu
  2021-07-22 12:43                   ` Lars Ingebrigtsen
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2021-05-19  0:19 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 39179


> On May 12, 2021, at 11:54 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> Ah, I forgot about this, thanks. I promise I’ll do it :-)
> 
> This was half a year ago.  :-)  Has there been any progress here?
> Skimming this thread, it seems like the general consensus was that this
> was a good feature to add...
> 
> -- 
> (domestic pets only, the antidote for overdose, milk.)
>   bloggy blog: http://lars.ingebrigtsen.no

Hey Lars,

Thanks for reminding me, and sorry for the delay. I have rebased the patch and modified it, that wasn’t hard. But I had some problem installing a linux to test the patch on it, since gdb couldn’t work on my Mac. It shouldn’t take much longer though.

Yuan




^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2021-05-19  0:19                 ` Yuan Fu
@ 2021-07-22 12:43                   ` Lars Ingebrigtsen
  2021-07-24 17:04                     ` Yuan Fu
  0 siblings, 1 reply; 14+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-22 12:43 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39179

Yuan Fu <casouri@gmail.com> writes:

> Thanks for reminding me, and sorry for the delay. I have rebased the
> patch and modified it, that wasn’t hard. But I had some problem
> installing a linux to test the patch on it, since gdb couldn’t work on
> my Mac. It shouldn’t take much longer though.

This was a couple of months ago -- have you made any further progress
here?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2021-07-22 12:43                   ` Lars Ingebrigtsen
@ 2021-07-24 17:04                     ` Yuan Fu
  2021-07-24 17:11                       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 14+ messages in thread
From: Yuan Fu @ 2021-07-24 17:04 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 39179

[-- Attachment #1: Type: text/plain, Size: 626 bytes --]



> On Jul 22, 2021, at 8:43 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> Yuan Fu <casouri@gmail.com> writes:
> 
>> Thanks for reminding me, and sorry for the delay. I have rebased the
>> patch and modified it, that wasn’t hard. But I had some problem
>> installing a linux to test the patch on it, since gdb couldn’t work on
>> my Mac. It shouldn’t take much longer though.
> 
> This was a couple of months ago -- have you made any further progress
> here?
> 

The 10th 10% isn’t it ;-) Here is the patch. I finally installed a linux VM and compiled Emacs on it and tested the patch. 

Yuan


[-- Attachment #2: filter.patch --]
[-- Type: application/octet-stream, Size: 6499 bytes --]

From 684f0b4e8b913f5cf10a5ee20b869016d391009d Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Thu, 24 Jun 2021 12:38:17 -0400
Subject: [PATCH] Add filter to GDB's register buffer

* lisp/progmodes/gdb-mi.el (gdb-registers-enable-filter,
gdb-registers-filter-pattern-list): New custom options.
(gdb-header-click-event-handler, gdb-registers-toggle-filter): New
functions.
(gdb-header-click-event-handler): Only add a register if it passes the
filter.
(gdb-registers-mode-map): New keybinding for toggling the filter.
(gdb-registers-header): New buttons on the header line for the filter.
---
 lisp/progmodes/gdb-mi.el | 97 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 85 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index aa3365278c..1303ac55f8 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -581,6 +581,23 @@ gdb-show-threads-by-default
   :group 'gdb-buffers
   :version "23.2")
 
+(defcustom gdb-registers-enable-filter nil
+  "If t, enable register name filter in register buffer.
+Use `gdb-registers-filter-pattern-list' to control what register to
+filter."
+  :type 'boolean
+  :group 'gdb-buffers
+  :version "28.1")
+
+(defcustom gdb-registers-filter-pattern-list nil
+  "Patterns for names that are displayed in register buffer.
+Each pattern is a regular expression.  GDB displays registers
+whose name matches any pattern in the list.  Refresh the register
+buffer for the change to take effect."
+  :type 'list
+  :group 'gdb-buffers
+  :version "28.1")
+
 (defvar gdb-debug-log nil
   "List of commands sent to and replies received from GDB.
 Most recent commands are listed first.  This list stores only the last
@@ -4393,6 +4410,26 @@ gdb-frame-locals-buffer
  'gdb-registers-mode
  'gdb-invalidate-registers)
 
+(defun gdb-header-click-event-handler (function)
+  "Return a function that handles clicking event on gdb header buttons.
+
+This function switches to the window where the header locates and
+executes FUNCTION."
+  (lambda (event)
+    (interactive "e")
+    (save-selected-window
+      ;; Make sure we are in the right buffer.
+      (select-window (posn-window (event-start event)))
+      (funcall function))))
+
+(defun gdb-registers-toggle-filter ()
+  "Toggle register filter."
+  (interactive)
+  (setq gdb-registers-enable-filter
+        (not gdb-registers-enable-filter))
+  ;; Update the register buffer.
+  (gdb-invalidate-registers 'update))
+
 (defun gdb-registers-handler-custom ()
   (when gdb-register-names
     (let ((register-values
@@ -4403,17 +4440,27 @@ gdb-registers-handler-custom
                (value (gdb-mi--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))))
+          ;; Add register if `gdb-registers-filter-pattern-list' is nil;
+          ;; or any pattern that `gdb-registers-filter-pattern-list'
+          ;; matches.
+          (when (or (null gdb-registers-enable-filter)
+                    ;; Return t if any register name matches a pattern.
+                    (cl-loop for pattern
+                             in gdb-registers-filter-pattern-list
+                             if (string-match pattern register-name)
+                             return t
+                             finally return nil))
+            (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"))))
@@ -4441,6 +4488,7 @@ gdb-registers-mode-map
                             (gdb-get-buffer-create
                              'gdb-locals-buffer
                              gdb-thread-number) t)))
+    (define-key map "f" #'gdb-registers-toggle-filter)
     map))
 
 (defvar gdb-registers-header
@@ -4450,7 +4498,32 @@ gdb-registers-header
                           mode-line-inactive)
    " "
    (gdb-propertize-header "Registers" gdb-registers-buffer
-			  nil nil mode-line)))
+			  nil nil mode-line)
+   " "
+   '(:eval (format "[filter %s %s]"
+                   (propertize
+                    (if gdb-registers-enable-filter
+                        "[on]" "[off]")
+                    'face (if gdb-registers-enable-filter
+                              '(:weight bold :inherit success)
+                            'shadow)
+                    'help-echo "mouse-1: toggle filter"
+                    'mouse-face 'mode-line-highlight
+                    'local-map
+                    (gdb-make-header-line-mouse-map
+                     'mouse-1
+                     (gdb-header-click-event-handler
+                      #'gdb-registers-toggle-filter)))
+                   (propertize
+                    "[set]"
+                    'face 'mode-line
+                    'help-echo "mouse-1: Customize filter patterns"
+                    'mouse-face 'mode-line-highlight
+                    'local-map
+                    (gdb-make-header-line-mouse-map
+                     'mouse-1 (lambda () (interactive)
+                                (customize-variable-other-window
+                                 'gdb-registers-filter-pattern-list))))))))
 
 (define-derived-mode gdb-registers-mode gdb-parent-mode "Registers"
   "Major mode for gdb registers."
-- 
2.24.3 (Apple Git-128)


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer
  2021-07-24 17:04                     ` Yuan Fu
@ 2021-07-24 17:11                       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 14+ messages in thread
From: Lars Ingebrigtsen @ 2021-07-24 17:11 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 39179

Yuan Fu <casouri@gmail.com> writes:

> The 10th 10% isn’t it ;-) Here is the patch. I finally installed a
> linux VM and compiled Emacs on it and tested the patch.

Great; pushed to Emacs 28 now.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-07-24 17:11 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-18 20:51 bug#39179: 27.0.50; [PATCH] Add filter to gdb-mi register buffer Yuan Fu
2020-01-31  9:56 ` Eli Zaretskii
2020-01-31 23:08   ` Yuan Fu
2020-02-01  2:22     ` Yuan Fu
2020-02-01  7:58     ` Eli Zaretskii
2020-02-02 14:32       ` Yuan Fu
2020-02-02 15:52         ` Eli Zaretskii
2020-08-09 11:57           ` Lars Ingebrigtsen
2020-08-10 18:20             ` Yuan Fu
2021-05-12 15:54               ` Lars Ingebrigtsen
2021-05-19  0:19                 ` Yuan Fu
2021-07-22 12:43                   ` Lars Ingebrigtsen
2021-07-24 17:04                     ` Yuan Fu
2021-07-24 17:11                       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).