Function: gdb
gdb is an autoloaded, interactive and byte-compiled function defined
in gdb-mi.el.gz.
Signature
(gdb COMMAND-LINE)
Documentation
Run gdb passing it COMMAND-LINE as arguments.
If COMMAND-LINE names a program FILE to debug, gdb will run in
a buffer named *gud-FILE*, and the directory containing FILE
becomes the initial working directory and source-file directory
for your debugger.
If COMMAND-LINE requests that gdb attaches to a process PID, gdb
will run in *gud-PID*, otherwise it will run in *gud*; in these
cases the initial working directory is the default-directory of
the buffer in which this command was invoked.
COMMAND-LINE should include "-i=mi" to use gdb's MI text interface. Note that the old "--annotate" option is no longer supported.
If option gdb-many-windows(var)/gdb-many-windows(fun) is nil (the default value) then gdb just
pops up the GUD buffer unless gdb-show-main is t. In this case
it starts with two windows: one displaying the GUD buffer and the
other with the source file with the main routine of the inferior.
If option gdb-many-windows(var)/gdb-many-windows(fun) is t, regardless of the value of
gdb-show-main, the layout below will appear. Keybindings are
shown in some of the buffers.
Watch expressions appear in the speedbar/slowbar.
The following commands help control operation :
gdb-many-windows(var)/gdb-many-windows(fun) - Toggle the number of windows gdb uses.
gdb-restore-windows - To restore the window layout.
See Info node (emacs)GDB Graphical Interface for a more detailed description of this mode.
+----------------------------------------------------------------------+
| GDB Toolbar |
+-----------------------------------+----------------------------------+
| GUD buffer (I/O of GDB) | Locals buffer |
| | |
| | |
| | |
+-----------------------------------+----------------------------------+
| Source buffer | I/O buffer (of debugged program) |
| | (comint-mode) |
| | |
| | |
| | |
| | |
| | |
| | |
+-----------------------------------+----------------------------------+
| Stack buffer | Breakpoints buffer |
| RET gdb-select-frame | SPC gdb-toggle-breakpoint |
| | RET gdb-goto-breakpoint |
| | D gdb-delete-breakpoint |
+-----------------------------------+----------------------------------+
Probably introduced at or before Emacs version 18.50.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/gdb-mi.el.gz
;;;###autoload
(defun gdb (command-line)
"Run gdb passing it COMMAND-LINE as arguments.
If COMMAND-LINE names a program FILE to debug, gdb will run in
a buffer named *gud-FILE*, and the directory containing FILE
becomes the initial working directory and source-file directory
for your debugger.
If COMMAND-LINE requests that gdb attaches to a process PID, gdb
will run in *gud-PID*, otherwise it will run in *gud*; in these
cases the initial working directory is the `default-directory' of
the buffer in which this command was invoked.
COMMAND-LINE should include \"-i=mi\" to use gdb's MI text interface.
Note that the old \"--annotate\" option is no longer supported.
If option `gdb-many-windows' is nil (the default value) then gdb just
pops up the GUD buffer unless `gdb-show-main' is t. In this case
it starts with two windows: one displaying the GUD buffer and the
other with the source file with the main routine of the inferior.
If option `gdb-many-windows' is t, regardless of the value of
`gdb-show-main', the layout below will appear. Keybindings are
shown in some of the buffers.
Watch expressions appear in the speedbar/slowbar.
The following commands help control operation :
`gdb-many-windows' - Toggle the number of windows gdb uses.
`gdb-restore-windows' - To restore the window layout.
See Info node `(emacs)GDB Graphical Interface' for a more
detailed description of this mode.
+----------------------------------------------------------------------+
| GDB Toolbar |
+-----------------------------------+----------------------------------+
| GUD buffer (I/O of GDB) | Locals buffer |
| | |
| | |
| | |
+-----------------------------------+----------------------------------+
| Source buffer | I/O buffer (of debugged program) |
| | (comint-mode) |
| | |
| | |
| | |
| | |
| | |
| | |
+-----------------------------------+----------------------------------+
| Stack buffer | Breakpoints buffer |
| RET gdb-select-frame | SPC gdb-toggle-breakpoint |
| | RET gdb-goto-breakpoint |
| | D gdb-delete-breakpoint |
+-----------------------------------+----------------------------------+"
;;
(interactive (list (gud-query-cmdline 'gdb)))
(when (and gud-comint-buffer
(buffer-name gud-comint-buffer)
(get-buffer-process gud-comint-buffer)
(with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)))
(gdb-restore-windows)
(error
"Multiple debugging requires restarting in text command mode"))
;; Save window configuration before starting gdb so we can restore
;; it after gdb quits. Save it regardless of the value of
;; `gdb-restore-window-configuration-after-quit'.
(setq gdb--window-configuration-before (window-state-get))
;;
(gud-common-init command-line nil 'gud-gdbmi-marker-filter)
;; Setup a temporary process filter to warn when GDB was not started
;; with -i=mi.
(let ((proc (get-buffer-process gud-comint-buffer)))
(add-function :around (process-filter proc) #'gdb--check-interpreter))
(setq-local gud-minor-mode 'gdbmi)
(setq-local gdb-control-level 0)
(setq comint-input-sender 'gdb-send)
(when (ring-empty-p comint-input-ring) ; cf shell-mode
(let ((hfile (expand-file-name (or (getenv "GDBHISTFILE")
(if (eq system-type 'ms-dos)
"_gdb_history"
".gdb_history"))))
;; gdb defaults to 256, but we'll default to comint-input-ring-size.
(hsize (getenv "HISTSIZE")))
(dolist (file (append '("~/.gdbinit")
(unless (string-equal (expand-file-name ".")
(expand-file-name "~"))
'(".gdbinit"))))
(if (file-readable-p (setq file (expand-file-name file)))
(with-temp-buffer
(insert-file-contents file)
;; TODO? check for "set history save\\( *on\\)?" and do
;; not use history otherwise?
(while (re-search-forward
"^ *set history \\(filename\\|size\\) *\\(.*\\)" nil t)
(cond ((string-equal (match-string 1) "filename")
(setq hfile (expand-file-name
(match-string 2)
(file-name-directory file))))
((string-equal (match-string 1) "size")
(setq hsize (match-string 2))))))))
(and (stringp hsize)
(integerp (setq hsize (string-to-number hsize)))
(> hsize 0)
(setq-local comint-input-ring-size hsize))
(if (stringp hfile)
(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.")
(gud-def gud-jump
(progn (gud-call "tbreak %f:%l" arg) (gud-call "jump %f:%l"))
"\C-j" "Set execution address to current line.")
(gud-def gud-up "up %p" "<" "Up N stack frames (numeric arg).")
(gud-def gud-down "down %p" ">" "Down N stack frames (numeric arg).")
(gud-def gud-print "print %e" "\C-p" "Evaluate C expression at point.")
(gud-def gud-pstar "print* %e" nil
"Evaluate C dereferenced pointer expression at point.")
(gud-def gud-step (gdb-gud-context-call "-exec-step" "%p" t)
"\C-s"
"Step one source line with display.")
(gud-def gud-stepi (gdb-gud-context-call "-exec-step-instruction" "%p" t)
"\C-i"
"Step one instruction with display.")
(gud-def gud-next (gdb-gud-context-call "-exec-next" "%p" t)
"\C-n"
"Step one line (skip functions).")
(gud-def gud-nexti (gdb-gud-context-call "-exec-next-instruction" "%p" t)
nil
"Step one instruction (skip functions).")
(gud-def gud-cont (gdb-gud-context-call "-exec-continue")
"\C-r"
"Continue with display.")
(gud-def gud-finish (gdb-gud-context-call "-exec-finish" nil t)
"\C-f"
"Finish executing current function.")
(gud-def gud-run "-exec-run"
nil
"Run the program.")
(gud-def gud-break (if (not (string-match "Disassembly" mode-name))
(gud-call "break %f:%l" arg)
(save-excursion
(beginning-of-line)
(forward-char 2)
(gud-call "break *%a" arg)))
"\C-b" "Set breakpoint at current line or address.")
(gud-def gud-remove (if (not (string-match "Disassembly" mode-name))
(gud-call "clear %f:%l" arg)
(save-excursion
(beginning-of-line)
(forward-char 2)
(gud-call "clear *%a" arg)))
"\C-d" "Remove breakpoint at current line or address.")
;; -exec-until doesn't support --all yet
(gud-def gud-until (if (not (string-match "Disassembly" mode-name))
(gud-call "-exec-until %f:%l" arg)
(save-excursion
(beginning-of-line)
(forward-char 2)
(gud-call "-exec-until *%a" arg)))
"\C-u" "Continue to current line or address.")
(gud-def
gud-go (progn
(when (and current-prefix-arg arg)
(gud-call (concat "-exec-arguments "
(read-string "Arguments to exec-run: "))))
(gud-call
(if gdb-active-process
(gdb-gud-context-command "-exec-continue")
"-exec-run")))
"\C-v" "Start or continue execution. Use a prefix to specify arguments.")
;; For debugging Emacs only.
(gud-def gud-pp
(gud-call
(concat
"pp " (if (eq (buffer-local-value
'major-mode (window-buffer)) 'speedbar-mode)
(gdb-find-watch-expression) "%e")) arg)
nil "Print the Emacs s-expression.")
(define-key gud-minor-mode-map [left-margin mouse-1]
'gdb-mouse-set-clear-breakpoint)
(define-key gud-minor-mode-map [left-fringe mouse-1]
'gdb-mouse-set-clear-breakpoint)
(define-key gud-minor-mode-map [left-margin C-mouse-1]
'gdb-mouse-toggle-breakpoint-margin)
(define-key gud-minor-mode-map [left-fringe C-mouse-1]
'gdb-mouse-toggle-breakpoint-fringe)
(define-key gud-minor-mode-map [left-margin drag-mouse-1]
'gdb-mouse-until)
(define-key gud-minor-mode-map [left-fringe drag-mouse-1]
'gdb-mouse-until)
(define-key gud-minor-mode-map [left-margin mouse-3]
'gdb-mouse-until)
(define-key gud-minor-mode-map [left-fringe mouse-3]
'gdb-mouse-until)
(define-key gud-minor-mode-map [left-margin C-drag-mouse-1]
'gdb-mouse-jump)
(define-key gud-minor-mode-map [left-fringe C-drag-mouse-1]
'gdb-mouse-jump)
(define-key gud-minor-mode-map [left-fringe C-mouse-3]
'gdb-mouse-jump)
(define-key gud-minor-mode-map [left-margin C-mouse-3]
'gdb-mouse-jump)
(gud-set-repeat-map-property 'gud-gdb-repeat-map)
(setq-local gud-gdb-completion-function 'gud-gdbmi-completions)
(add-hook 'completion-at-point-functions #'gud-gdb-completion-at-point
nil 'local)
(local-set-key "\C-i" 'completion-at-point)
(local-set-key [remap comint-delchar-or-maybe-eof] 'gdb-delchar-or-quit)
(setq gdb-first-prompt t)
(setq gud-running nil)
(gdb-update)
(run-hooks 'gdb-mode-hook))