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: Mon, 14 Oct 2019 23:05:22 -0400 Message-ID: References: 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="44387"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Emacs developers To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 15 05:05:40 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 1iKD9Y-000BR3-Fl for ged-emacs-devel@m.gmane.org; Tue, 15 Oct 2019 05:05:40 +0200 Original-Received: from localhost ([::1]:59738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKD9W-0004DH-Mu for ged-emacs-devel@m.gmane.org; Mon, 14 Oct 2019 23:05:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50356) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iKD9O-0004D6-On for emacs-devel@gnu.org; Mon, 14 Oct 2019 23:05:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iKD9N-00038L-7R for emacs-devel@gnu.org; Mon, 14 Oct 2019 23:05:30 -0400 Original-Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]:33499) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iKD9M-00037A-VH for emacs-devel@gnu.org; Mon, 14 Oct 2019 23:05:29 -0400 Original-Received: by mail-qt1-x830.google.com with SMTP id r5so28554063qtd.0 for ; Mon, 14 Oct 2019 20:05:28 -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=4vZJk8OUoANOoP1+xQgELMJyr7Cgj+JybJdJ7AoN8ys=; b=RwkPZJ2GZzr8bGLAbwYby//zy2i++YeuVNeEhG/p5VPTr74m80Aaqq0AxWVGoyhl2s NLgAFKhxVr4ctFXS/Gyx1CZK54MBbsL9bZJQ7XViTePMd66AApiFOrwKAbQx3gkWE7d4 aoqX6NjozsrzulSw8WojWfU/mjvhWs0e05kWnxNQrrZqCdFrH1YhJ4seEj/y/aLF7TxK Ck6MOstS79rd76mchKfq5P2xHWvkbIrfM+KnMGEI3kV+xWkVVSnrIq2/PXwM85IFL+lB +rkpze+FeUJP8LCNCx9JGImTIB8LRTiFai1mFQLVn07J9nHtazoX8KPZCwo92pm09Izc eP6Q== 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=4vZJk8OUoANOoP1+xQgELMJyr7Cgj+JybJdJ7AoN8ys=; b=Zwt6G/gUetxpTFoIyJKi1xTOk9h2JOf3I//1INBzb89lcpzfAO3KGPHUdRGkXbQ8HL eO/GA/siGRIB/C87wSZ/0nHW32vxZA2ZbuCYYMCXRSnRGRHbLff72O+uhOb7u3DFHJTK j9i8wB/RxY+wYGtiZRH8QUe6LJfYUrhoYlNnJNiEb+4H6aiB3xf8pCL5AagWDyshMqgo Gaq2PYWNbmI0z8LyjG/ghz5IHWc6Ct4TFPyE36+xK9bXCnL3YilZdhafskyJOQEN/Qgz MFuZrnirqGl72/WZUkvwBr/Wej/RSNPMD2sHVWBcf2fxoneqqaty4idZaEMKKjHg2e26 4B3A== X-Gm-Message-State: APjAAAVjLnNvyp3QwZW/yIlbqSnQ/kSJHRQmJ6iUplKBI0QYOaJ60UcM nSx8BGO3CWuIlljor0aemlJXjJdsXVI= X-Google-Smtp-Source: APXvYqxs81LYAz9ngLM5OymxGLxVKq4LeK9QY8eWntHtJ55j5fNICG3WhEQEFp/UfOms2fZ2y+TPFw== X-Received: by 2002:a05:6214:5cd:: with SMTP id t13mr35085517qvz.86.1571108728059; Mon, 14 Oct 2019 20:05:28 -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 w2sm11976522qtc.59.2019.10.14.20.05.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 20:05:27 -0700 (PDT) Original-Received: by missSilver.localdomain (Postfix, from userid 501) id F02C420290AA39; Mon, 14 Oct 2019 23:05:22 -0400 (EDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::830 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:241031 Archived-At: --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-Add-window-configuration-save-restore-feature-for-gd.patch Content-Transfer-Encoding: quoted-printable >From a88ede26b81a1372a74696314fe6c7ed288f730e Mon Sep 17 00:00:00 2001 From: Yuan Fu 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=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 (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) =20 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default)) @@ -4609,6 +4610,131 @@ 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 + (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 =3D (gdb-rules-buffer-mode rule) + for type =3D (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-parameter= s)) + 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-buff= er-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 w= indow + ;; we remove that buffer from `existing-gdb-buffer-list' + ;; this way we avoid displaying the same buffer in two wi= ndows + (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 --=-=-=--