all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* gdb-mi.el supports set breakpoints when debugged program is running
@ 2023-08-23  8:47 Diancheng Wang
  0 siblings, 0 replies; only message in thread
From: Diancheng Wang @ 2023-08-23  8:47 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 285 bytes --]

Hi,

Gdb can set breakpoints when debugged program is running in non-stop
mode, but gdb-mi.el does not support this even when `gdb-non-stop' is t.
It is caused by that `gud-def' sends nothing if `gud-running' is t.

The fixed patch is attached.

BTW. my assignment number is 1597467.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gdb-mi.el-Enable-to-set-breakpoints-even-all-threads.patch --]
[-- Type: text/x-diff, Size: 5558 bytes --]

From 35f322c375124643e1119ea23259a4730e86af51 Mon Sep 17 00:00:00 2001
From: Diancheng Wang <diancheng@gmail.com>
Date: Wed, 9 Aug 2023 10:35:12 +0800
Subject: [PATCH] gdb-mi.el: Enable to set breakpoints even all threads of
 debugee are running.

---
 lisp/progmodes/gdb-mi.el | 16 +++++++++-------
 lisp/progmodes/gud.el    | 22 ++++++++++++++--------
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index a1091de43e9..3aaee723bac 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -928,7 +928,7 @@ gdb
           (setq-local comint-input-ring-file-name hfile))
       (comint-read-input-ring t)))
   (gud-def gud-tbreak "tbreak %f:%l" "\C-t"
-	   "Set temporary breakpoint at current line.")
+	   "Set temporary breakpoint at current line." t)
   (gud-def gud-jump
 	   (progn (gud-call "tbreak %f:%l" arg) (gud-call "jump %f:%l"))
 	   "\C-j" "Set execution address to current line.")
@@ -959,7 +959,7 @@ gdb
 	   "Finish executing current function.")
   (gud-def gud-run    "-exec-run"
            nil
-           "Run the program.")
+           "Run the program." t)
 
   (gud-def gud-break (if (not (string-match "Disassembly" mode-name))
 			 (gud-call "break %f:%l" arg)
@@ -967,7 +967,7 @@ gdb
 			 (beginning-of-line)
 			 (forward-char 2)
 			 (gud-call "break *%a" arg)))
-	   "\C-b" "Set breakpoint at current line or address.")
+	   "\C-b" "Set breakpoint at current line or address." t)
 
   (gud-def gud-remove (if (not (string-match "Disassembly" mode-name))
 			  (gud-call "clear %f:%l" arg)
@@ -975,7 +975,7 @@ gdb
 			  (beginning-of-line)
 			  (forward-char 2)
 			  (gud-call "clear *%a" arg)))
-	   "\C-d" "Remove breakpoint at current line or address.")
+	   "\C-d" "Remove breakpoint at current line or address." t)
 
   ;; -exec-until doesn't support --all yet
   (gud-def gud-until  (if (not (string-match "Disassembly" mode-name))
@@ -2671,9 +2671,11 @@ gdb-starting
   ;; Set `gdb-non-stop' when `gdb-last-command' is a CLI background
   ;; running command e.g. "run &", attach &" or a MI command
   ;; e.g. "-exec-run" or "-exec-attach".
-  (when (or (string-match "&\s*$" gdb-last-command)
-            (string-match "^-" gdb-last-command))
-    (gdb-try-check-target-async-support))
+  (if (or (string-match "&\s*$" gdb-last-command)
+          (string-match "^-" gdb-last-command))
+      (progn (gdb-try-check-target-async-support)
+             (setq gud-async-running t))
+    (setq gud-async-running nil))
 
   (gdb-force-mode-line-update
    (propertize gdb-inferior-status 'face font-lock-type-face))
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 09860a4cbde..c5e188c0a32 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -128,6 +128,10 @@ gud-running
   "Non-nil if debugged program is running.
 Used to gray out relevant toolbar icons.")
 
+(defvar gud-async-running nil
+  "Non-nil if debugged program is running in async mode.
+Check it when `gud-running' is t")
+
 (defvar gud-target-name "--unknown--"
   "The apparent name of the program being debugged in a gud buffer.")
 
@@ -261,13 +265,13 @@ gud-menu-map
      :visible (memq gud-minor-mode
 		    '(gdbmi gdb guiler dbx xdb jdb pdb))]
     ["Set Breakpoint" gud-break
-     :enable (not gud-running)
+     :enable (or (not gud-running) gud-async-running)
      :visible (gud-tool-bar-item-visible-no-fringe)]
     ["Temporary Breakpoint" gud-tbreak
-     :enable (not gud-running)
+     :enable (or (not gud-running) gud-async-running)
      :visible (memq gud-minor-mode '(gdbmi gdb sdb xdb))]
     ["Remove Breakpoint" gud-remove
-     :enable (not gud-running)
+     :enable (or (not gud-running) gud-async-running)
      :visible (gud-tool-bar-item-visible-no-fringe)]
     ["Continue to selection" gud-until
      :enable (not gud-running)
@@ -283,7 +287,7 @@ gud-menu-map
      :visible (and (eq gud-minor-mode 'gdbmi)
                    (gdb-show-run-p))]
     ["Run" gud-run
-     :enable (not gud-running)
+     :enable (or (not gud-running) gud-async-running)
      :visible (or (memq gud-minor-mode '(gdb dbx jdb))
 		  (and (eq gud-minor-mode 'gdbmi)
 		       (or (not (gdb-show-run-p))
@@ -403,13 +407,15 @@ gud-find-file
 ;; Of course you may use `gud-def' with any other debugger command, including
 ;; user defined ones.
 
-;; A macro call like (gud-def FUNC CMD KEY DOC) expands to a form
+;; A macro call like (gud-def FUNC CMD KEY DOC ASYNC-OK) expands to a form
 ;; which defines FUNC to send the command CMD to the debugger, gives
 ;; it the docstring DOC, and binds that function to KEY in the GUD
-;; major mode.  The function is also bound in the global keymap with the
+;; major mode. The FUNC still sends CMD when both ASYNC-OK and
+;; `gud-async-running' are t even `gud-running' is t.
+;; The function is also bound in the global keymap with the
 ;; GUD prefix.
 
-(defmacro gud-def (func cmd key &optional doc)
+(defmacro gud-def (func cmd key &optional doc async-ok)
   "Define FUNC to be a command sending CMD and bound to KEY, with
 optional doc string DOC.  Certain %-escapes in the string arguments
 are interpreted specially if present.  These are:
@@ -434,7 +440,7 @@ gud-def
      (defalias ',func (lambda (arg)
        ,@(if doc (list doc))
        (interactive "p")
-       (if (not gud-running)
+       (if (or (not gud-running) ,(and async-ok gud-async-running))
 	 ,(if (stringp cmd)
 	      `(gud-call ,cmd arg)
 	    ;; Unused lexical warning if cmd does not use "arg".
-- 
2.27.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-08-23  8:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-23  8:47 gdb-mi.el supports set breakpoints when debugged program is running Diancheng Wang

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.