Subject: bug#59838: 30.0.50; [PATCH] Save history in GDB session

From: Manuel Giraud <[email-masked]>
Date: Fri, 09 Dec 2022 10:02:40 +0100

Hi,

I think I have found the right place.  I've tested it with "M-x gdb"
doing an explicit "quit" or using `C-d'.  I've also tested with "M-x
gud-gdb".  Now I think we'll need a patch to gitignore the .gbd_history
files into the emacs directory.
>From 38d29bb31a821e0b03444e4008b80b39834ef842 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Mon, 5 Dec 2022 17:48:15 +0100
Subject: [PATCH] Fix GDB save history (bug#59838)

* lisp/progmodes/gdb-mi.el (gdb-reset): Save GDB comint history.
(gdb-delchar-or-quit): Remove useless progn and add comment.
---
 lisp/progmodes/gdb-mi.el | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index e8d8f9104e..a7839c34af 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -1113,13 +1113,13 @@ gdb-delchar-or-quit
              (process-live-p proc)
 	     (not gud-running)
 	     (= (point) (marker-position (process-mark proc))))
-	;; Sending an EOF does not work with GDB-MI; submit an
-	;; explicit quit command.
-	(progn
-          (if (> gdb-control-level 0)
-              (process-send-eof proc)
-            (insert "quit")
-            (comint-send-input t t)))
+      ;; Exit a recursive reading loop or quit.
+      (if (> gdb-control-level 0)
+          (process-send-eof proc)
+        ;; Sending an EOF does not work with GDB-MI; submit an
+        ;; explicit quit command.
+        (insert "quit")
+        (comint-send-input t t))
       (delete-char arg))))
 
 (defvar gdb-define-alist nil "Alist of #define directives for GUD tooltips.")
@@ -5124,6 +5124,8 @@ gdb-restore-windows
 (defun gdb-reset ()
   "Exit a debugging session cleanly.
 Kills the gdb buffers, and resets variables and the source buffers."
+  ;; Save GDB history
+  (comint-write-input-ring)
   ;; The gdb-inferior buffer has a pty hooked up to the main gdb
   ;; process.  This pty must be deleted explicitly.
   (let ((pty (get-process "gdb-inferior")))
-- 
2.38.1

-- 
Manuel Giraud