From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Extend gdb to filter registers Date: Sat, 26 Oct 2019 17:56:40 -0400 Message-ID: References: <878spmuerf.fsf@mail.linkov.net> <83wod3bx8i.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="13730"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org, monnier@iro.umontreal.ca, juri@linkov.net To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 27 00:45:19 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iOUo7-0003Kl-Pb for ged-emacs-devel@m.gmane.org; Sun, 27 Oct 2019 00:45:16 +0200 Original-Received: from localhost ([::1]:43336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOUo6-0001V6-6t for ged-emacs-devel@m.gmane.org; Sat, 26 Oct 2019 18:45:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34620) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iOU3J-0006a3-PH for emacs-devel@gnu.org; Sat, 26 Oct 2019 17:56:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iOU3H-0004iH-0G for emacs-devel@gnu.org; Sat, 26 Oct 2019 17:56:52 -0400 Original-Received: from mail-qt1-x82f.google.com ([2607:f8b0:4864:20::82f]:40969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iOU3E-0004fm-2z; Sat, 26 Oct 2019 17:56:48 -0400 Original-Received: by mail-qt1-x82f.google.com with SMTP id o3so8832235qtj.8; Sat, 26 Oct 2019 14:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=ocGydBKl97iTfKQdAznJLS48lvdeWSD6/nyQREhNrLY=; b=U3Pr2KCNiR42M0yYJ7HFjpa6Rug6xJt4Dwm5zmS6IV5tw+vEsplqAodRy7dE+U3vF7 G/Bc3xE8OAlS+ercZLwX27ccX2cQgbmqV1fypx57VSU+H2hfTXYPMBbCq4dajiX1+Ey4 69kPjZTZKQ89jYUoQ9jouuQSqNjB+yUZrD5ebbQugHZe0ofsSGpNMWUL9SbLeomCVX4Y BYh86dHiQ/+P8YSZ1y+pZjSG1ioSrNIuq8MW44jm8opqUGK4Y+vZpOI62Km7V9Q8vJmE F8gnhzGGQ+/TOE+paI68ZEa24URgcH+87dQyaP+ZJXV7s3SBvH4OR0HhNbmQRzDuNYXX 6uPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=ocGydBKl97iTfKQdAznJLS48lvdeWSD6/nyQREhNrLY=; b=unRQocxSiLwL/JSVWv9FABPdiw9puewwsnldxLJ7I+d2Ppi4OQdtwRrJX+N5J0pca8 sfLKyvQbw37HOXgCsUrw7lAp6KArvCJvhkPfjRaMuNK/ZbzQvTQWSLiVNUgC6Ss7pPSX E80tgr81jF1O1ylK/ERWppgc05E2AKKBTzFwa4fOC3V5S/GEFbwvDXZDyZjmEw6FOzea tKfKMHFumvg8A4Lg6Ww7aVVQZLNHDBBD7usuNrNZ7gW7adjf6LDgpC7ojwJw/uUfjo5B rOvA1H4wVEXwBGVdZRLDiJPFFhQ62rwckIvCzQag9oCZpIgM0vo93RzsTlzevfVcQlhp xuqw== X-Gm-Message-State: APjAAAV6HPoqYfw+ClgcquFeWTabCGGy5VxcUbpRD5eMcecYwv4eb6FC +Kh9ji1hqP5rZrqmfPIISR1VqsAeDVqfkA== X-Google-Smtp-Source: APXvYqzcgGOtKYQkvz3sQ3UesacknULRwa7OX9rmO3gXeNzPskhLXtyyvriHuHZPtl3EjeWXuWWTeA== X-Received: by 2002:ac8:22f1:: with SMTP id g46mr10379808qta.12.1572127005301; Sat, 26 Oct 2019 14:56:45 -0700 (PDT) Original-Received: from missSilver.localdomain (c-71-207-8-160.hsd1.pa.comcast.net. [71.207.8.160]) by smtp.gmail.com with ESMTPSA id i185sm3369104qkc.129.2019.10.26.14.56.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 26 Oct 2019 14:56:44 -0700 (PDT) Original-Received: by missSilver.localdomain (Postfix, from userid 501) id DB1D820298EF65; Sat, 26 Oct 2019 17:56:40 -0400 (EDT) In-Reply-To: <83wod3bx8i.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::82f X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:241488 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > 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=E2=80=99ve 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=E2=80=99ve collected 3 patches: register, memory and store/retore window config. They all seem to work pretty well but I haven=E2=80=99t used= them too much since I=E2=80=99ve finished my bomblab... Yuan --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=store-window.patch Content-Transfer-Encoding: quoted-printable >From 1a39dc1cb80a6ea54edcf17c9d59362c2cc40a33 Mon Sep 17 00:00:00 2001 From: Yuan Fu 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))))) =20 +(defmacro with-selected-window-undedicated (&rest body) + "Run BODY in the selected window with window-dedicated temporarily disab= led." + (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 --=20 2.23.0 >From 1036eccc4bf8e585f0b1ecf9f676db0003adf0f1 Mon Sep 17 00:00:00 2001 From: Yuan Fu 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=3DUTF-8 Content-Transfer-Encoding: 8bit Now you can save a gdb window configuration to a file with =E2=80=98gdb-store-window-configuration=E2=80=99 and restore it from a file with =E2=80=98gdb-restore-window-configuration=E2=80=99. * lisp/progmodes/gdb-mi.el (require): add pcase, wrap inside =E2=80=98eval-when-compile=E2=80=99 (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)) =20 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default)) @@ -589,6 +590,13 @@ gdb-show-main :group 'gdb :version "22.1") =20 +(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= *.") =20 @@ -4609,6 +4617,126 @@ gdb-setup-windows nil win5)) (select-window win0))) =20 +(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 =3D (gdb-rules-buffer-mode rule) + for type =3D (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-parameter= s)) + 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-bu= ffer-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 --=20 2.23.0 --=-=-=--