From: Yuan Fu <casouri@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Extend gdb to filter registers
Date: Mon, 14 Oct 2019 23:05:22 -0400 [thread overview]
Message-ID: <m2wod67lot.fsf@gmail.com> (raw)
In-Reply-To: <m2wodek2fr.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 148 bytes --]
Here is another patch that allows a user to save and restore window
configurations. It seems to work for me and I welcome you to try it out.
Yuan
[-- Attachment #2: 0001-Add-window-configuration-save-restore-feature-for-gd.patch --]
[-- Type: text/x-patch, Size: 7264 bytes --]
From a88ede26b81a1372a74696314fe6c7ed288f730e Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Mon, 14 Oct 2019 21:11:43 -0400
Subject: [PATCH] Add window configuration save/restore feature for gdb-mi
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Now you can save a gdb window configuration to a file with
‘gdb-store-window-configuration’ and restore it from a file
with ‘gdb-restore-window-configuration’.
* lisp/progmodes/gdb-mi.el (require): add pcase
(gdb-buffer-p, gdb-function-buffer-p, gdb--buffer-type,
gdb--inhibit-window-dedicated, gdb-store-window-configuration,
gdb-restore-window-configuration): new
---
lisp/progmodes/gdb-mi.el | 126 +++++++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 60852e4ad6..4cb09da181 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -92,6 +92,7 @@
(require 'json)
(require 'bindat)
(require 'cl-lib)
+(require 'pcase)
(declare-function speedbar-change-initial-expansion-list
"speedbar" (new-default))
@@ -4609,6 +4610,131 @@ gdb-setup-windows
nil win5))
(select-window win0)))
+(defun gdb-buffer-p (buffer)
+ "Return t if BUFFER is gdb-related."
+ (with-current-buffer buffer
+ (eq gud-minor-mode 'gdbmi)))
+
+(defun gdb-function-buffer-p (buffer)
+ "Return t if BUFFER is a gdb function buffer.
+
+E.g., locals buffer, registers buffer, but don't include the main
+command buffer (the one in where you type gdb commands) or source
+buffers."
+ (with-current-buffer buffer
+ (when (or (derived-mode-p 'gdb-parent-mode)
+ (derived-mode-p 'gdb-inferior-io-mode)) t)))
+
+(defun gdb--buffer-type (buffer)
+ "Return the buffer type of BUFFER or nil.
+
+Buffer type is like `gdb-registers-type', `gdb-stack-buffer'.
+This symbol can be passed to `gdb-get-buffer-create'.
+
+Return nil if BUFFER isn't a gdb function buffer."
+ (with-current-buffer buffer
+ (cl-loop for rule in gdb-buffer-rules
+ for mode-name = (gdb-rules-buffer-mode rule)
+ for type = (car rule)
+ if (eq mode-name major-mode)
+ return type
+ finally return nil)))
+
+(defmacro gdb--inhibit-window-dedicated (&rest body)
+ "Run BODY with window-dedicated temporarily disabled."
+ ;; switch-to-buffer-in-dedicated-window
+ ;; doesn't work in non-interactive case
+ `(let ((window-dedicated (window-dedicated-p)))
+ (when window-dedicated
+ (set-window-dedicated-p nil nil))
+ ,@body
+ (when window-dedicated
+ (set-window-dedicated-p nil t))))
+
+(defun gdb-store-window-configuration (file)
+ "Save current window configuration to FILE.
+
+You can later restore this configuration from that file by
+`gdb-restore-window-configuration'."
+ (interactive "F Save window configuration to file: ")
+ ;; we replace the buffer in each window with a placeholder, set
+ ;; window parameter as the buffer type (register, breakpoint, etc),
+ ;; and store window configuration
+ (save-window-excursion
+ (let ((placeholder (get-buffer-create " *gdb-placeholder*"))
+ (window-persistent-parameters
+ (cons '(gdb-buffer-type . writable) window-persistent-parameters))
+ window-config
+ old-window-dedidated-value)
+ (dolist (win (window-list nil 'no-minibuffer))
+ (select-window win)
+ (setq old-window-dedidated-value (window-dedicated-p))
+ (when (gdb-buffer-p (current-buffer))
+ (set-window-parameter
+ nil 'gdb-buffer-type
+ (cond ((gdb-function-buffer-p (current-buffer))
+ ;; we save this gdb-buffer-type symbol so
+ ;; we can later pass it to `gdb-get-buffer-create'
+ ;; one example: `gdb-registers-buffer'
+ (or (gdb--buffer-type (current-buffer))
+ (error "Unrecognized gdb buffer mode: %s" major-mode)))
+ ;; command buffer
+ ((derived-mode-p 'gud-mode) 'command)
+ ((member (selected-window) gdb-source-window) 'source)))
+ (gdb--inhibit-window-dedicated
+ (set-window-buffer nil placeholder))))
+ ;; save the window configuration to FILE
+ (setq window-config (window-state-get nil t))
+ (let ((buffer (find-file file)))
+ (with-current-buffer buffer
+ (erase-buffer)
+ (prin1 window-config (current-buffer))
+ (save-buffer))
+ (kill-buffer buffer))
+ (kill-buffer placeholder))))
+
+(defun gdb-restore-window-configuration (file)
+ "Restore window configuration from FILE.
+
+FILE is saved by `gdb-store-window-configuration'."
+ (interactive "F Restore window configuration from file: ")
+ ;; basically we restore window configuration and go through each
+ ;; window and restore the function buffers
+ (let* ((config-buffer (find-file-noselect file))
+ (placeholder (get-buffer-create " *gdb-placeholder*")))
+ (progn ; don't leak buffer
+ (let ((window-config (with-current-buffer config-buffer
+ (goto-char 1)
+ (read (current-buffer))))
+ ;; a list of existing gdb buffers
+ (existing-gdb-buffer-list (cl-remove-if-not
+ #'gdb-function-buffer-p
+ (buffer-list)))
+ buffer-type
+ (source-buffer (when gdb-source-window
+ (window-buffer gdb-source-window))))
+ (window-state-put window-config (frame-root-window))
+ (dolist (window (window-list nil 'no-minibuffer))
+ (select-window window)
+ (setq buffer-type (window-parameter nil 'gdb-buffer-type))
+ (pcase buffer-type
+ ('source (when source-buffer
+ (set-window-buffer nil source-buffer)
+ (setq gdb-source-window (selected-window))))
+ ('command (switch-to-buffer gud-comint-buffer))
+ ;; locally shadow `buffer-list', it should be safe
+ (_ (let ((buffer (cl-labels ((buffer-list () existing-gdb-buffer-list))
+ (gdb-get-buffer-create buffer-type))))
+ (gdb--inhibit-window-dedicated
+ (set-window-buffer nil buffer))
+ ;; each time when we display a gdb function buffer in a window
+ ;; we remove that buffer from `existing-gdb-buffer-list'
+ ;; this way we avoid displaying the same buffer in two windows
+ (setq existing-gdb-buffer-list
+ (remove buffer existing-gdb-buffer-list)))))))
+ (kill-buffer config-buffer)
+ (kill-buffer placeholder))))
+
(define-minor-mode gdb-many-windows
"If nil just pop up the GUD buffer unless `gdb-show-main' is t.
In this case it starts with two windows: one displaying the GUD
--
2.23.0
next prev parent reply other threads:[~2019-10-15 3:05 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-03 16:40 Extend gdb to filter registers Yuan Fu
2019-10-04 16:13 ` Fu Yuan
2019-10-04 19:32 ` Eli Zaretskii
2019-10-04 19:49 ` Stefan Monnier
2019-10-04 21:55 ` Yuan Fu
2019-10-05 3:15 ` Yuan Fu
2019-10-05 7:08 ` Eli Zaretskii
2019-10-05 13:15 ` Yuan Fu
2019-10-05 13:53 ` Eli Zaretskii
2019-10-05 17:51 ` Yuan Fu
2019-10-05 19:01 ` Eli Zaretskii
2019-10-06 4:24 ` Yuan Fu
2019-10-06 17:36 ` Eli Zaretskii
2019-10-08 2:23 ` Yuan Fu
2019-10-06 4:43 ` Michael Welsh Duggan
2019-10-07 15:50 ` Yuan Fu
2019-10-07 16:19 ` Michael Welsh Duggan
2019-10-08 0:19 ` Yuan Fu
2019-10-08 17:26 ` Stefan Monnier
2019-10-09 3:44 ` Yuan Fu
2019-10-09 3:51 ` Yuan Fu
2019-10-15 3:05 ` Yuan Fu [this message]
2019-10-15 9:48 ` martin rudalics
2019-10-17 3:14 ` Yuan Fu
2019-10-17 3:27 ` Yuan Fu
2019-10-17 8:26 ` martin rudalics
2019-10-15 18:10 ` Juri Linkov
2019-10-15 20:51 ` Stefan Monnier
2019-10-17 3:08 ` Yuan Fu
2019-10-17 8:19 ` Eli Zaretskii
2019-10-26 21:56 ` Yuan Fu
2019-10-27 7:47 ` martin rudalics
2019-10-27 17:38 ` Yuan Fu
2020-01-16 4:25 ` Yuan Fu
2020-01-16 14:51 ` Eli Zaretskii
2020-01-16 15:04 ` Yuan Fu
[not found] ` <CAO0xp5w8PwAiy=JNVmCK652rCs_06cMAO5_+1ppHwppQ2js4VQ@mail.gmail.com>
2020-01-17 23:31 ` Yuan Fu
2020-01-18 11:15 ` Eli Zaretskii
2020-01-18 13:32 ` Yuan Fu
2020-01-18 15:21 ` Eli Zaretskii
2020-01-18 15:41 ` Yuan Fu
2020-01-18 16:50 ` Eli Zaretskii
2020-01-18 16:20 ` John Yates
2020-01-18 16:53 ` Eli Zaretskii
2020-01-18 17:53 ` Yuan Fu
2020-01-18 17:56 ` Eli Zaretskii
2020-01-18 18:21 ` martin rudalics
2020-01-18 18:33 ` Eli Zaretskii
2020-01-18 18:36 ` Yuan Fu
2020-01-18 18:48 ` Eli Zaretskii
2020-01-18 20:10 ` Yuan Fu
2020-01-18 18:41 ` martin rudalics
2020-01-18 19:18 ` Eli Zaretskii
2020-01-18 21:43 ` martin rudalics
2020-01-19 15:40 ` Eli Zaretskii
2020-01-19 17:33 ` Yuan Fu
2020-01-19 17:42 ` Eli Zaretskii
2020-01-19 17:57 ` Yuan Fu
2020-01-19 18:43 ` Eli Zaretskii
2020-01-19 19:35 ` Yuan Fu
2020-01-19 20:07 ` Eli Zaretskii
2020-01-20 1:22 ` Yuan Fu
2020-01-20 18:03 ` Eli Zaretskii
2020-01-22 1:50 ` Yuan Fu
2020-01-24 7:16 ` Eli Zaretskii
2020-01-24 20:12 ` Yuan Fu
2020-01-24 22:37 ` John Yates
2020-01-25 7:45 ` Eli Zaretskii
2020-01-25 14:33 ` John Yates
2020-01-25 17:10 ` Eli Zaretskii
2020-01-25 8:43 ` martin rudalics
2020-01-25 14:56 ` John Yates
2020-01-25 17:14 ` martin rudalics
2020-01-25 20:17 ` John Yates
2020-01-26 8:41 ` martin rudalics
2020-01-26 4:18 ` Richard Stallman
2020-01-26 5:09 ` Drew Adams
2020-01-26 5:31 ` Yuan Fu
2020-01-26 17:12 ` Eli Zaretskii
2020-01-25 8:24 ` Eli Zaretskii
2020-01-25 8:58 ` martin rudalics
2020-01-25 10:25 ` Eli Zaretskii
2020-01-25 10:30 ` Eli Zaretskii
2020-01-25 22:34 ` Yuan Fu
2020-01-26 8:42 ` martin rudalics
2020-01-26 16:12 ` Yuan Fu
2020-01-26 16:57 ` martin rudalics
2020-01-27 15:56 ` Yuan Fu
2020-01-27 19:18 ` martin rudalics
2020-01-27 19:53 ` Yuan Fu
2020-01-28 9:49 ` martin rudalics
2020-01-28 20:01 ` Yuan Fu
2020-01-28 20:33 ` John Yates
2020-01-31 13:58 ` Eli Zaretskii
2020-01-31 15:25 ` Yuan Fu
2020-01-31 15:35 ` Eli Zaretskii
2020-01-25 8:43 ` martin rudalics
2020-01-25 10:21 ` Eli Zaretskii
2020-01-25 12:11 ` martin rudalics
2020-01-25 13:35 ` Eli Zaretskii
2020-01-25 8:42 ` martin rudalics
2020-01-19 18:30 ` martin rudalics
2020-01-19 18:47 ` Eli Zaretskii
2020-01-19 18:05 ` martin rudalics
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2wod67lot.fsf@gmail.com \
--to=casouri@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).