From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org, monnier@iro.umontreal.ca, juri@linkov.net
Subject: Re: Extend gdb to filter registers
Date: Sat, 26 Oct 2019 17:56:40 -0400 [thread overview]
Message-ID: <m2k18r6uhz.fsf@gmail.com> (raw)
In-Reply-To: <83wod3bx8i.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 507 bytes --]
> If the buffer is narrowed so that point-min as greater than 1, you
> cannot goto position 1; trying that will signal an error.
Thanks, I’ve fixed it.
Here is the latest patch. I added a customizable variable that controls
the default directory in where we store/restore window config file.
By now I’ve collected 3 patches: register, memory and store/retore
window config. They all seem to work pretty well but I haven’t used them
too much since I’ve finished my bomblab...
Yuan
[-- Attachment #2: store-window.patch --]
[-- Type: text/x-patch, Size: 9116 bytes --]
From 1a39dc1cb80a6ea54edcf17c9d59362c2cc40a33 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Thu, 17 Oct 2019 17:35:48 -0400
Subject: [PATCH 1/2] Add with-selected-window-undedicated
* lisp/window.el (with-selected-window-undedicated): new
---
lisp/window.el | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/lisp/window.el b/lisp/window.el
index d93ec0add6..ba48354572 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -278,6 +278,16 @@ with-displayed-buffer-window
(funcall ,vquit-function ,window ,value)
,value)))))
+(defmacro with-selected-window-undedicated (&rest body)
+ "Run BODY in the selected window with window-dedicated temporarily disabled."
+ (let ((window-dedicated-sym (gensym)))
+ `(let ((,window-dedicated-sym (window-dedicated-p)))
+ (when ,window-dedicated-sym
+ (set-window-dedicated-p nil nil))
+ ,@body
+ (when ,window-dedicated-sym
+ (set-window-dedicated-p nil t)))))
+
;; The following two functions are like `window-next-sibling' and
;; `window-prev-sibling' but the WINDOW argument is _not_ optional (so
;; they don't substitute the selected window for nil), and they return
--
2.23.0
From 1036eccc4bf8e585f0b1ecf9f676db0003adf0f1 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Mon, 14 Oct 2019 21:11:43 -0400
Subject: [PATCH 2/2] 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, wrap inside
‘eval-when-compile’
(gdb-store-window-directory, 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 | 130 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 129 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index 60852e4ad6..5d220caa42 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -91,7 +91,8 @@
(require 'gud)
(require 'json)
(require 'bindat)
-(require 'cl-lib)
+(eval-when-compile (require 'cl-lib))
+(eval-when-compile (require 'pcase))
(declare-function speedbar-change-initial-expansion-list
"speedbar" (new-default))
@@ -589,6 +590,13 @@ gdb-show-main
:group 'gdb
:version "22.1")
+(defcustom gdb-store-window-directory user-emacs-directory
+ "The default directory where window configuration files are stored.
+If nil, use `default-directory'."
+ :type 'string
+ :group 'gdb
+ :version "27.1")
+
(defvar gdbmi-debug-mode nil
"When non-nil, print the messages sent/received from GDB/MI in *Messages*.")
@@ -4609,6 +4617,126 @@ 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
+ (derived-mode-p 'gdb-parent-mode 'gdb-inferior-io-mode)))
+
+(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)))
+
+(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 (list (read-file-name
+ "Save window configuration to file: "
+ (or gdb-store-window-directory default-directory))))
+ ;; 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)
+ (dolist (win (window-list nil 'no-minibuffer))
+ (select-window win)
+ (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)))
+ (with-selected-window-undedicated
+ (set-window-buffer nil placeholder)
+ (set-window-prev-buffers (selected-window) nil)
+ (set-window-next-buffers (selected-window) nil))))
+ ;; save the window configuration to FILE
+ (setq window-config (window-state-get nil t))
+ (let ((buffer (find-file file)))
+ (unwind-protect
+ (with-current-buffer buffer
+ (if buffer-read-only
+ (user-error "Error: file read only")
+ (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 (list (read-file-name
+ "Restore window configuration from file: "
+ (or gdb-store-window-directory default-directory))))
+ ;; 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*")))
+ (unwind-protect ; don't leak buffer
+ (let ((window-config (with-current-buffer config-buffer
+ (goto-char (point-min))
+ (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))))
+ (with-selected-window-undedicated
+ (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-26 21:56 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
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 [this message]
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=m2k18r6uhz.fsf@gmail.com \
--to=casouri@gmail.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=juri@linkov.net \
--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).