Function: gdb-stopped
gdb-stopped is a byte-compiled function defined in gdb-mi.el.gz.
Signature
(gdb-stopped TOKEN OUTPUT-FIELD)
Documentation
Given the contents of *stopped MI async record, select new current thread and update GDB buffers.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/gdb-mi.el.gz
;; -break-insert -t didn't give a reason before gdb 6.9
(defun gdb-stopped (_token output-field)
"Given the contents of *stopped MI async record, select new
current thread and update GDB buffers."
;; Reason is available with target-async only
(let* ((result (gdb-mi--from-string output-field))
(reason (gdb-mi--field result 'reason))
(thread-id (gdb-mi--field result 'thread-id))
(retval (gdb-mi--field result 'return-value))
(varnum (gdb-mi--field result 'gdb-result-var)))
;; -data-list-register-names needs to be issued for any stopped
;; thread
(when (not gdb-register-names)
(gdb-input (concat "-data-list-register-names"
(if gdb-supports-non-stop
(concat " --thread " thread-id)))
'gdb-register-names-handler))
;; Don't set gud-last-frame here as it's currently done in
;; gdb-frame-handler because synchronous GDB doesn't give these fields
;; with CLI.
;;(when file
;; (setq
;; ;; Extract the frame position from the marker.
;; gud-last-frame (cons file
;; (string-to-number
;; (match-string 6 gud-marker-acc)))))
(setq gdb-inferior-status (or reason "unknown"))
(gdb-force-mode-line-update
(propertize gdb-inferior-status 'face 'font-lock-warning-face))
(if (string-equal reason "exited-normally")
(setq gdb-active-process nil))
(when (and retval varnum
;; When the user typed CLI commands, GDB/MI helpfully
;; includes the "Value returned" response in the "~"
;; record; here we avoid displaying it twice.
(not (string-match "^Value returned is " gdb-filter-output)))
(setq gdb-filter-output
(concat gdb-filter-output
(format "Value returned is %s = %s\n" varnum retval))))
;; Select new current thread.
;; Don't switch if we have no reasons selected
(when gdb-switch-reasons
;; Switch from another stopped thread only if we have
;; gdb-switch-when-another-stopped:
(when (or gdb-switch-when-another-stopped
(not (string= "stopped"
(gdb-mi--field (gdb-current-buffer-thread) 'state))))
;; Switch if current reason has been selected or we have no
;; reasons
(if (or (eq gdb-switch-reasons t)
(member reason gdb-switch-reasons))
(when (not (string-equal gdb-thread-number thread-id))
(message "Switched to thread %s" thread-id)
(gdb-setq-thread-number thread-id))
(message "Thread %s stopped" thread-id))))
;; Print "(gdb)" to GUD console
(when gdb-first-done-or-error
;; If running target with a non-background CLI command
;; e.g. "run" (no trailing '&'), target async feature can only
;; be checked when when the program stops for the first time
(gdb-try-check-target-async-support)
(setq gdb-filter-output (concat gdb-filter-output gdb-prompt-name)))
;; In non-stop, we update information as soon as another thread gets
;; stopped
(when (or gdb-first-done-or-error
gdb-non-stop)
;; In all-stop this updates gud-running properly as well.
(gdb-update)
(setq gdb-first-done-or-error nil))
(run-hook-with-args 'gdb-stopped-functions result)))