Merged from miles@gnu.org--gnu-2005 (patch 34-36, 142-158)
[emacs.git] / lisp / progmodes / gdb-ui.el
blob00da2e70dd72915145742d169f6a0549dcf5758b
1 ;;; gdb-ui.el --- User Interface for running GDB
3 ;; Author: Nick Roberts <nickrob@gnu.org>
4 ;; Maintainer: FSF
5 ;; Keywords: unix, tools
7 ;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; This mode acts as a graphical user interface to GDB. You can interact with
29 ;; GDB through the GUD buffer in the usual way, but there are also further
30 ;; buffers which control the execution and describe the state of your program.
31 ;; It separates the input/output of your program from that of GDB, if
32 ;; required, and watches expressions in the speedbar. It also uses features of
33 ;; Emacs 21 such as the fringe/display margin for breakpoints, and the toolbar
34 ;; (see the GDB Graphical Interface section in the Emacs info manual).
36 ;; By default, M-x gdb will start the debugger. However, if you have customised
37 ;; gud-gdb-command-name, then start it with M-x gdba.
39 ;; This file has evolved from gdba.el that was included with GDB 5.0 and
40 ;; written by Tom Lord and Jim Kingdon. It uses GDB's annotation interface.
41 ;; You don't need to know about annotations to use this mode as a debugger,
42 ;; but if you are interested developing the mode itself, then see the
43 ;; Annotations section in the GDB info manual.
45 ;; GDB developers plan to make the annotation interface obsolete. A new
46 ;; interface called GDB/MI (machine interface) has been designed to replace
47 ;; it. Some GDB/MI commands are used in this file through the CLI command
48 ;; 'interpreter mi <mi-command>'. A file called gdb-mi.el is included with
49 ;; GDB (6.2 onwards) that uses GDB/MI as the primary interface to GDB. It is
50 ;; still under development and is part of a process to migrate Emacs from
51 ;; annotations to GDB/MI.
53 ;; Known Bugs:
55 ;; TODO:
56 ;; 1) Use MI command -data-read-memory for memory window.
57 ;; 2) Highlight changed register values (use MI commands
58 ;; -data-list-register-values and -data-list-changed-registers instead
59 ;; of 'info registers'.
60 ;; 3) Use tree-widget.el instead of the speedbar for watch-expressions?
61 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
62 ;; 5) After release of 22.1 use '-var-list-children --all-values'
63 ;; and '-stack-list-locals 2' which need GDB 6.1 onwards.
65 ;;; Code:
67 (require 'gud)
69 (defvar gdb-current-address "main" "Initialisation for Assembler buffer.")
70 (defvar gdb-previous-address nil)
71 (defvar gdb-memory-address "main")
72 (defvar gdb-previous-frame nil)
73 (defvar gdb-current-frame nil)
74 (defvar gdb-current-stack-level nil)
75 (defvar gdb-current-language nil)
76 (defvar gdb-var-list nil "List of variables in watch window.")
77 (defvar gdb-var-changed nil "Non-nil means that gdb-var-list has changed.")
78 (defvar gdb-buffer-type nil)
79 (defvar gdb-overlay-arrow-position nil)
80 (defvar gdb-server-prefix nil)
81 (defvar gdb-flush-pending-output nil)
82 (defvar gdb-location-list nil "List of directories for source files.")
83 (defvar gdb-find-file-unhook nil)
85 (defvar gdb-buffer-type nil
86 "One of the symbols bound in `gdb-buffer-rules'.")
88 (defvar gdb-input-queue ()
89 "A list of gdb command objects.")
91 (defvar gdb-prompting nil
92 "True when gdb is idle with no pending input.")
94 (defvar gdb-output-sink 'user
95 "The disposition of the output of the current gdb command.
96 Possible values are these symbols:
98 `user' -- gdb output should be copied to the GUD buffer
99 for the user to see.
101 `inferior' -- gdb output should be copied to the inferior-io buffer
103 `pre-emacs' -- output should be ignored util the post-prompt
104 annotation is received. Then the output-sink
105 becomes:...
106 `emacs' -- output should be collected in the partial-output-buffer
107 for subsequent processing by a command. This is the
108 disposition of output generated by commands that
109 gdb mode sends to gdb on its own behalf.
110 `post-emacs' -- ignore output until the prompt annotation is
111 received, then go to USER disposition.
113 gdba (gdb-ui.el) uses all five values, gdbmi (gdb-mi.el) only two
114 \(`user' and `emacs').")
116 (defvar gdb-current-item nil
117 "The most recent command item sent to gdb.")
119 (defvar gdb-pending-triggers '()
120 "A list of trigger functions that have run later than their output
121 handlers.")
123 ;; end of gdb variables
125 ;;;###autoload
126 (defun gdba (command-line)
127 "Run gdb on program FILE in buffer *gud-FILE*.
128 The directory containing FILE becomes the initial working directory
129 and source-file directory for your debugger.
131 If `gdb-many-windows' is nil (the default value) then gdb just
132 pops up the GUD buffer unless `gdb-show-main' is t. In this case
133 it starts with two windows: one displaying the GUD buffer and the
134 other with the source file with the main routine of the inferior.
136 If `gdb-many-windows' is t, regardless of the value of
137 `gdb-show-main', the layout below will appear unless
138 `gdb-use-inferior-io-buffer' is nil when the source buffer
139 occupies the full width of the frame. Keybindings are given in
140 relevant buffer.
142 Watch expressions appear in the speedbar/slowbar.
144 The following commands help control operation :
146 `gdb-many-windows' - Toggle the number of windows gdb uses.
147 `gdb-restore-windows' - To restore the window layout.
149 See Info node `(emacs)GDB Graphical Interface' for a more
150 detailed description of this mode.
153 ---------------------------------------------------------------------
154 GDB Toolbar
155 ---------------------------------------------------------------------
156 GUD buffer (I/O of GDB) | Locals buffer
160 ---------------------------------------------------------------------
161 Source buffer | Input/Output (of inferior) buffer
162 | (comint-mode)
169 ---------------------------------------------------------------------
170 Stack buffer | Breakpoints buffer
171 RET gdb-frames-select | SPC gdb-toggle-breakpoint
172 | RET gdb-goto-breakpoint
173 | d gdb-delete-breakpoint
174 ---------------------------------------------------------------------"
176 (interactive (list (gud-query-cmdline 'gdba)))
178 ;; Let's start with a basic gud-gdb buffer and then modify it a bit.
179 (gdb command-line)
180 (gdb-ann3))
182 (defvar gdb-debug-log nil)
184 (defcustom gdb-enable-debug-log nil
185 "Non-nil means record the process input and output in `gdb-debug-log'."
186 :type 'boolean
187 :group 'gud
188 :version "22.1")
190 (defcustom gdb-use-inferior-io-buffer nil
191 "Non-nil means display output from the inferior in a separate buffer."
192 :type 'boolean
193 :group 'gud
194 :version "22.1")
196 (defun gdb-set-gud-minor-mode (buffer)
197 "Set gud-minor-mode from find-file if appropriate."
198 (goto-char (point-min))
199 (unless (search-forward "No source file named " nil t)
200 (condition-case nil
201 (gdb-enqueue-input
202 (list (concat gdb-server-prefix "info source\n")
203 `(lambda () (gdb-set-gud-minor-mode-1 ,buffer))))
204 (error (setq gdb-find-file-unhook t)))))
206 (defun gdb-set-gud-minor-mode-1 (buffer)
207 (goto-char (point-min))
208 (if (and (search-forward "Located in " nil t)
209 (looking-at "\\S-*")
210 (string-equal (buffer-file-name buffer)
211 (match-string 0)))
212 (with-current-buffer buffer
213 (set (make-local-variable 'gud-minor-mode) 'gdba)
214 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))))
216 (defun gdb-set-gud-minor-mode-existing-buffers ()
217 (dolist (buffer (buffer-list))
218 (let ((file (buffer-file-name buffer)))
219 (if file
220 (progn
221 (gdb-enqueue-input
222 (list (concat gdb-server-prefix "list "
223 (file-name-nondirectory file) ":1\n")
224 `(lambda () (gdb-set-gud-minor-mode ,buffer)))))))))
226 (defun gdb-ann3 ()
227 (setq gdb-debug-log nil)
228 (set (make-local-variable 'gud-minor-mode) 'gdba)
229 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter)
231 (gud-def gud-break (if (not (string-equal mode-name "Machine"))
232 (gud-call "break %f:%l" arg)
233 (save-excursion
234 (beginning-of-line)
235 (forward-char 2)
236 (gud-call "break *%a" arg)))
237 "\C-b" "Set breakpoint at current line or address.")
239 (gud-def gud-remove (if (not (string-equal mode-name "Machine"))
240 (gud-call "clear %f:%l" arg)
241 (save-excursion
242 (beginning-of-line)
243 (forward-char 2)
244 (gud-call "clear *%a" arg)))
245 "\C-d" "Remove breakpoint at current line or address.")
247 (gud-def gud-until (if (not (string-equal mode-name "Machine"))
248 (gud-call "until %f:%l" arg)
249 (save-excursion
250 (beginning-of-line)
251 (forward-char 2)
252 (gud-call "until *%a" arg)))
253 "\C-u" "Continue to current line or address.")
255 (define-key gud-minor-mode-map [left-margin mouse-1]
256 'gdb-mouse-set-clear-breakpoint)
257 (define-key gud-minor-mode-map [left-fringe mouse-1]
258 'gdb-mouse-set-clear-breakpoint)
259 (define-key gud-minor-mode-map [left-margin mouse-3]
260 'gdb-mouse-toggle-breakpoint)
261 ; (define-key gud-minor-mode-map [left-fringe mouse-3]
262 ; 'gdb-mouse-toggle-breakpoint)
264 (setq comint-input-sender 'gdb-send)
266 ;; (re-)initialize
267 (setq gdb-current-address "main")
268 (setq gdb-previous-address nil)
269 (setq gdb-memory-address "main")
270 (setq gdb-previous-frame nil)
271 (setq gdb-current-frame nil)
272 (setq gdb-current-stack-level nil)
273 (setq gdb-var-list nil)
274 (setq gdb-var-changed nil)
275 (setq gdb-first-prompt nil)
276 (setq gdb-prompting nil)
277 (setq gdb-input-queue nil)
278 (setq gdb-current-item nil)
279 (setq gdb-pending-triggers nil)
280 (setq gdb-output-sink 'user)
281 (setq gdb-server-prefix "server ")
282 (setq gdb-flush-pending-output nil)
283 (setq gdb-location-list nil)
284 (setq gdb-find-file-unhook nil)
286 (setq gdb-buffer-type 'gdba)
288 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io))
290 (if (eq window-system 'w32)
291 (gdb-enqueue-input (list "set new-console off\n" 'ignore)))
292 (gdb-enqueue-input (list "set height 0\n" 'ignore))
293 (gdb-enqueue-input (list "set width 0\n" 'ignore))
294 ;; find source file and compilation directory here
295 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program
296 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program
297 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info))
299 (gdb-set-gud-minor-mode-existing-buffers)
300 (run-hooks 'gdba-mode-hook))
302 (defcustom gdb-use-colon-colon-notation nil
303 "If non-nil use FUN::VAR format to display variables in the speedbar." ;
304 :type 'boolean
305 :group 'gud
306 :version "22.1")
308 (defun gud-watch ()
309 "Watch expression at point."
310 (interactive)
311 (require 'tooltip)
312 (let ((expr (tooltip-identifier-from-point (point))))
313 (if (and (string-equal gdb-current-language "c")
314 gdb-use-colon-colon-notation gdb-current-frame)
315 (setq expr (concat gdb-current-frame "::" expr)))
316 (catch 'already-watched
317 (dolist (var gdb-var-list)
318 (if (string-equal expr (car var)) (throw 'already-watched nil)))
319 (set-text-properties 0 (length expr) nil expr)
320 (gdb-enqueue-input
321 (list
322 (if (eq gud-minor-mode 'gdba)
323 (concat "server interpreter mi \"-var-create - * " expr "\"\n")
324 (concat"-var-create - * " expr "\n"))
325 `(lambda () (gdb-var-create-handler ,expr))))))
326 (select-window (get-buffer-window gud-comint-buffer 0)))
328 (defconst gdb-var-create-regexp
329 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"")
331 (defun gdb-var-create-handler (expr)
332 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
333 (goto-char (point-min))
334 (if (re-search-forward gdb-var-create-regexp nil t)
335 (let ((var (list expr
336 (match-string 1)
337 (match-string 2)
338 (match-string 3)
339 nil nil)))
340 (push var gdb-var-list)
341 (speedbar 1)
342 (if (equal (nth 2 var) "0")
343 (gdb-enqueue-input
344 (list (concat "server interpreter mi \"-var-evaluate-expression "
345 (nth 1 var) "\"\n")
346 `(lambda () (gdb-var-evaluate-expression-handler
347 ,(nth 1 var) nil))))
348 (setq gdb-var-changed t)))
349 (if (re-search-forward "Undefined command" nil t)
350 (message "Watching expressions requires gdb 6.0 onwards")
351 (message "No symbol %s in current context." expr)))))
353 (defun gdb-var-evaluate-expression-handler (varnum changed)
354 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
355 (goto-char (point-min))
356 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t)
357 (catch 'var-found
358 (let ((num 0))
359 (dolist (var gdb-var-list)
360 (if (string-equal varnum (cadr var))
361 (progn
362 (if changed (setcar (nthcdr 5 var) t))
363 (setcar (nthcdr 4 var) (match-string 1))
364 (setcar (nthcdr num gdb-var-list) var)
365 (throw 'var-found nil)))
366 (setq num (+ num 1))))))
367 (setq gdb-var-changed t))
369 (defun gdb-var-list-children (varnum)
370 (gdb-enqueue-input
371 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n")
372 `(lambda () (gdb-var-list-children-handler ,varnum)))))
374 (defconst gdb-var-list-children-regexp
375 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"")
377 (defun gdb-var-list-children-handler (varnum)
378 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
379 (goto-char (point-min))
380 (let ((var-list nil))
381 (catch 'child-already-watched
382 (dolist (var gdb-var-list)
383 (if (string-equal varnum (cadr var))
384 (progn
385 (push var var-list)
386 (while (re-search-forward gdb-var-list-children-regexp nil t)
387 (let ((varchild (list (match-string 2)
388 (match-string 1)
389 (match-string 3)
390 nil nil nil)))
391 (if (looking-at ",type=\"\\(.*?\\)\"")
392 (setcar (nthcdr 3 varchild) (match-string 1)))
393 (dolist (var1 gdb-var-list)
394 (if (string-equal (cadr var1) (cadr varchild))
395 (throw 'child-already-watched nil)))
396 (push varchild var-list)
397 (if (equal (nth 2 varchild) "0")
398 (gdb-enqueue-input
399 (list
400 (concat
401 "server interpreter mi \"-var-evaluate-expression "
402 (nth 1 varchild) "\"\n")
403 `(lambda () (gdb-var-evaluate-expression-handler
404 ,(nth 1 varchild) nil))))))))
405 (push var var-list)))
406 (setq gdb-var-list (nreverse var-list))))))
408 (defun gdb-var-update ()
409 (if (not (member 'gdb-var-update gdb-pending-triggers))
410 (progn
411 (gdb-enqueue-input
412 (list
413 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
414 "server interpreter mi \"-var-update *\"\n"
415 "-var-update *\n")
416 'gdb-var-update-handler))
417 (push 'gdb-var-update gdb-pending-triggers))))
419 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"")
421 (defun gdb-var-update-handler ()
422 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
423 (goto-char (point-min))
424 (while (re-search-forward gdb-var-update-regexp nil t)
425 (let ((varnum (match-string 1)))
426 (gdb-enqueue-input
427 (list
428 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
429 (concat "server interpreter mi \"-var-evaluate-expression "
430 varnum "\"\n")
431 (concat "-var-evaluate-expression " varnum "\n"))
432 `(lambda () (gdb-var-evaluate-expression-handler
433 ,varnum t)))))))
434 (setq gdb-pending-triggers
435 (delq 'gdb-var-update gdb-pending-triggers))
436 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
437 ;; dummy command to update speedbar at right time
438 (gdb-enqueue-input (list "server pwd\n" 'gdb-speedbar-timer-fn))
439 ;; keep gdb-pending-triggers non-nil till end
440 (push 'gdb-speedbar-timer gdb-pending-triggers)))
442 (defun gdb-speedbar-timer-fn ()
443 (setq gdb-pending-triggers
444 (delq 'gdb-speedbar-timer gdb-pending-triggers))
445 (with-current-buffer gud-comint-buffer
446 (speedbar-timer-fn)))
448 (defun gdb-var-delete ()
449 "Delete watched expression from the speedbar."
450 (interactive)
451 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
452 (let ((text (speedbar-line-text)))
453 (string-match "\\(\\S-+\\)" text)
454 (let* ((expr (match-string 1 text))
455 (var (assoc expr gdb-var-list))
456 (varnum (cadr var)))
457 (unless (string-match "\\." varnum)
458 (gdb-enqueue-input
459 (list
460 (if (with-current-buffer gud-comint-buffer
461 (eq gud-minor-mode 'gdba))
462 (concat "server interpreter mi \"-var-delete " varnum "\"\n")
463 (concat "-var-delete " varnum "\n"))
464 'ignore))
465 (setq gdb-var-list (delq var gdb-var-list))
466 (dolist (varchild gdb-var-list)
467 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild))
468 (setq gdb-var-list (delq varchild gdb-var-list))))
469 (setq gdb-var-changed t))))))
471 (defun gdb-edit-value (text token indent)
472 "Assign a value to a variable displayed in the speedbar."
473 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list))
474 (varnum (cadr var)) (value))
475 (setq value (read-string "New value: "))
476 (gdb-enqueue-input
477 (list
478 (if (with-current-buffer gud-comint-buffer
479 (eq gud-minor-mode 'gdba))
480 (concat "server interpreter mi \"-var-assign " varnum " " value "\"\n")
481 (concat "-var-assign " varnum " " value "\n"))
482 'ignore))))
484 (defcustom gdb-show-changed-values t
485 "If non-nil highlight values that have recently changed in the speedbar.
486 The highlighting is done with `font-lock-warning-face'."
487 :type 'boolean
488 :group 'gud
489 :version "22.1")
491 (defun gdb-speedbar-expand-node (text token indent)
492 "Expand the node the user clicked on.
493 TEXT is the text of the button we clicked on, a + or - item.
494 TOKEN is data related to this node.
495 INDENT is the current indentation depth."
496 (cond ((string-match "+" text) ;expand this node
497 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
498 (gdb-var-list-children token)
499 (gdbmi-var-list-children token)))
500 ((string-match "-" text) ;contract this node
501 (dolist (var gdb-var-list)
502 (if (string-match (concat token "\\.") (nth 1 var))
503 (setq gdb-var-list (delq var gdb-var-list))))
504 (setq gdb-var-changed t))))
506 (defun gdb-get-target-string ()
507 (with-current-buffer gud-comint-buffer
508 gud-target-name))
512 ;; gdb buffers.
514 ;; Each buffer has a TYPE -- a symbol that identifies the function
515 ;; of that particular buffer.
517 ;; The usual gdb interaction buffer is given the type `gdba' and
518 ;; is constructed specially.
520 ;; Others are constructed by gdb-get-create-buffer and
521 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
523 (defvar gdb-buffer-rules-assoc '())
525 (defun gdb-get-buffer (key)
526 "Return the gdb buffer tagged with type KEY.
527 The key should be one of the cars in `gdb-buffer-rules-assoc'."
528 (save-excursion
529 (gdb-look-for-tagged-buffer key (buffer-list))))
531 (defun gdb-get-create-buffer (key)
532 "Create a new gdb buffer of the type specified by KEY.
533 The key should be one of the cars in `gdb-buffer-rules-assoc'."
534 (or (gdb-get-buffer key)
535 (let* ((rules (assoc key gdb-buffer-rules-assoc))
536 (name (funcall (gdb-rules-name-maker rules)))
537 (new (get-buffer-create name)))
538 (with-current-buffer new
539 (let ((trigger))
540 (if (cdr (cdr rules))
541 (setq trigger (funcall (car (cdr (cdr rules))))))
542 (set (make-local-variable 'gdb-buffer-type) key)
543 (set (make-local-variable 'gud-minor-mode)
544 (with-current-buffer gud-comint-buffer gud-minor-mode))
545 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map)
546 (if trigger (funcall trigger)))
547 new))))
549 (defun gdb-rules-name-maker (rules) (car (cdr rules)))
551 (defun gdb-look-for-tagged-buffer (key bufs)
552 (let ((retval nil))
553 (while (and (not retval) bufs)
554 (set-buffer (car bufs))
555 (if (eq gdb-buffer-type key)
556 (setq retval (car bufs)))
557 (setq bufs (cdr bufs)))
558 retval))
561 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
562 ;; at least one and possible more functions. The functions have these
563 ;; roles in defining a buffer type:
565 ;; NAME - Return a name for this buffer type.
567 ;; The remaining function(s) are optional:
569 ;; MODE - called in a new buffer with no arguments, should establish
570 ;; the proper mode for the buffer.
573 (defun gdb-set-buffer-rules (buffer-type &rest rules)
574 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
575 (if binding
576 (setcdr binding rules)
577 (push (cons buffer-type rules)
578 gdb-buffer-rules-assoc))))
580 ;; GUD buffers are an exception to the rules
581 (gdb-set-buffer-rules 'gdba 'error)
584 ;; Partial-output buffer : This accumulates output from a command executed on
585 ;; behalf of emacs (rather than the user).
587 (gdb-set-buffer-rules 'gdb-partial-output-buffer
588 'gdb-partial-output-name)
590 (defun gdb-partial-output-name ()
591 (concat "*partial-output-"
592 (gdb-get-target-string)
593 "*"))
596 (gdb-set-buffer-rules 'gdb-inferior-io
597 'gdb-inferior-io-name
598 'gdb-inferior-io-mode)
600 (defun gdb-inferior-io-name ()
601 (concat "*input/output of "
602 (gdb-get-target-string)
603 "*"))
605 (defvar gdb-inferior-io-mode-map
606 (let ((map (make-sparse-keymap)))
607 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
608 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop)
609 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit)
610 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof)
611 map))
613 (define-derived-mode gdb-inferior-io-mode comint-mode "Inferior I/O"
614 "Major mode for gdb inferior-io."
615 :syntax-table nil :abbrev-table nil
616 ;; We want to use comint because it has various nifty and familiar
617 ;; features. We don't need a process, but comint wants one, so create
618 ;; a dummy one.
619 (make-comint-in-buffer
620 (substring (buffer-name) 1 (- (length (buffer-name)) 1))
621 (current-buffer) "hexl")
622 (setq comint-input-sender 'gdb-inferior-io-sender))
624 (defun gdb-inferior-io-sender (proc string)
625 ;; PROC is the pseudo-process created to satisfy comint.
626 (with-current-buffer (process-buffer proc)
627 (setq proc (get-buffer-process gud-comint-buffer))
628 (process-send-string proc string)
629 (process-send-string proc "\n")))
631 (defun gdb-inferior-io-interrupt ()
632 "Interrupt the program being debugged."
633 (interactive)
634 (interrupt-process
635 (get-buffer-process gud-comint-buffer) comint-ptyp))
637 (defun gdb-inferior-io-quit ()
638 "Send quit signal to the program being debugged."
639 (interactive)
640 (quit-process
641 (get-buffer-process gud-comint-buffer) comint-ptyp))
643 (defun gdb-inferior-io-stop ()
644 "Stop the program being debugged."
645 (interactive)
646 (stop-process
647 (get-buffer-process gud-comint-buffer) comint-ptyp))
649 (defun gdb-inferior-io-eof ()
650 "Send end-of-file to the program being debugged."
651 (interactive)
652 (process-send-eof
653 (get-buffer-process gud-comint-buffer)))
657 ;; gdb communications
660 ;; INPUT: things sent to gdb
662 ;; The queues are lists. Each element is either a string (indicating user or
663 ;; user-like input) or a list of the form:
665 ;; (INPUT-STRING HANDLER-FN)
667 ;; The handler function will be called from the partial-output buffer when the
668 ;; command completes. This is the way to write commands which invoke gdb
669 ;; commands autonomously.
671 ;; These lists are consumed tail first.
674 (defun gdb-send (proc string)
675 "A comint send filter for gdb.
676 This filter may simply queue input for a later time."
677 (if gud-running
678 (process-send-string proc (concat string "\n"))
679 (gdb-enqueue-input (concat string "\n"))))
681 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
682 ;; is a query, or other non-top-level prompt.
684 (defun gdb-enqueue-input (item)
685 (if gdb-prompting
686 (progn
687 (gdb-send-item item)
688 (setq gdb-prompting nil))
689 (push item gdb-input-queue)))
691 (defun gdb-dequeue-input ()
692 (let ((queue gdb-input-queue))
693 (and queue
694 (let ((last (car (last queue))))
695 (unless (nbutlast queue) (setq gdb-input-queue '()))
696 last))))
698 (defun gdb-send-item (item)
699 (setq gdb-flush-pending-output nil)
700 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log))
701 (setq gdb-current-item item)
702 (with-current-buffer gud-comint-buffer
703 (if (eq gud-minor-mode 'gdba)
704 (if (stringp item)
705 (progn
706 (setq gdb-output-sink 'user)
707 (process-send-string (get-buffer-process gud-comint-buffer) item))
708 (progn
709 (gdb-clear-partial-output)
710 (setq gdb-output-sink 'pre-emacs)
711 (process-send-string (get-buffer-process gud-comint-buffer)
712 (car item))))
713 ;; case: eq gud-minor-mode 'gdbmi
714 (gdb-clear-partial-output)
715 (setq gdb-output-sink 'emacs)
716 (process-send-string (get-buffer-process gud-comint-buffer)
717 (car item)))))
720 ;; output -- things gdb prints to emacs
722 ;; GDB output is a stream interrupted by annotations.
723 ;; Annotations can be recognized by their beginning
724 ;; with \C-j\C-z\C-z<tag><opt>\C-j
726 ;; The tag is a string obeying symbol syntax.
728 ;; The optional part `<opt>' can be either the empty string
729 ;; or a space followed by more data relating to the annotation.
730 ;; For example, the SOURCE annotation is followed by a filename,
731 ;; line number and various useless goo. This data must not include
732 ;; any newlines.
735 (defcustom gud-gdba-command-name "gdb -annotate=3"
736 "Default command to execute an executable under the GDB-UI debugger."
737 :type 'string
738 :group 'gud
739 :version "22.1")
741 (defvar gdb-annotation-rules
742 '(("pre-prompt" gdb-pre-prompt)
743 ("prompt" gdb-prompt)
744 ("commands" gdb-subprompt)
745 ("overload-choice" gdb-subprompt)
746 ("query" gdb-subprompt)
747 ;; Need this prompt for GDB 6.1
748 ("nquery" gdb-subprompt)
749 ("prompt-for-continue" gdb-subprompt)
750 ("post-prompt" gdb-post-prompt)
751 ("source" gdb-source)
752 ("starting" gdb-starting)
753 ("exited" gdb-stopping)
754 ("signalled" gdb-stopping)
755 ("signal" gdb-stopping)
756 ("breakpoint" gdb-stopping)
757 ("watchpoint" gdb-stopping)
758 ("frame-begin" gdb-frame-begin)
759 ("stopped" gdb-stopped)
760 ) "An assoc mapping annotation tags to functions which process them.")
762 (defun gdb-resync()
763 (setq gdb-flush-pending-output t)
764 (setq gud-running nil)
765 (setq gdb-output-sink 'user)
766 (setq gdb-input-queue nil)
767 (setq gdb-pending-triggers nil)
768 (setq gdb-prompting t))
770 (defconst gdb-source-spec-regexp
771 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:\\(0x[a-f0-9]*\\)")
773 ;; Do not use this except as an annotation handler.
774 (defun gdb-source (args)
775 (string-match gdb-source-spec-regexp args)
776 ;; Extract the frame position from the marker.
777 (setq gud-last-frame
778 (cons
779 (match-string 1 args)
780 (string-to-int (match-string 2 args))))
781 (setq gdb-current-address (match-string 3 args))
782 ;; cover for auto-display output which comes *before*
783 ;; stopped annotation
784 (if (eq gdb-output-sink 'inferior) (setq gdb-output-sink 'user)))
786 (defun gdb-pre-prompt (ignored)
787 "An annotation handler for `pre-prompt'.
788 This terminates the collection of output from a previous command if that
789 happens to be in effect."
790 (let ((sink gdb-output-sink))
791 (cond
792 ((eq sink 'user) t)
793 ((eq sink 'emacs)
794 (setq gdb-output-sink 'post-emacs))
796 (gdb-resync)
797 (error "Phase error in gdb-pre-prompt (got %s)" sink)))))
799 (defun gdb-prompt (ignored)
800 "An annotation handler for `prompt'.
801 This sends the next command (if any) to gdb."
802 (when gdb-first-prompt (gdb-ann3))
803 (let ((sink gdb-output-sink))
804 (cond
805 ((eq sink 'user) t)
806 ((eq sink 'post-emacs)
807 (setq gdb-output-sink 'user)
808 (let ((handler
809 (car (cdr gdb-current-item))))
810 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
811 (funcall handler))))
813 (gdb-resync)
814 (error "Phase error in gdb-prompt (got %s)" sink))))
815 (let ((input (gdb-dequeue-input)))
816 (if input
817 (gdb-send-item input)
818 (progn
819 (setq gdb-prompting t)
820 (gud-display-frame)))))
822 (defun gdb-subprompt (ignored)
823 "An annotation handler for non-top-level prompts."
824 (setq gdb-prompting t))
826 (defun gdb-starting (ignored)
827 "An annotation handler for `starting'.
828 This says that I/O for the subprocess is now the program being debugged,
829 not GDB."
830 (let ((sink gdb-output-sink))
831 (cond
832 ((eq sink 'user)
833 (progn
834 (setq gud-running t)
835 (if gdb-use-inferior-io-buffer
836 (setq gdb-output-sink 'inferior))))
838 (gdb-resync)
839 (error "Unexpected `starting' annotation")))))
841 (defun gdb-stopping (ignored)
842 "An annotation handler for `exited' and other annotations.
843 They say that I/O for the subprocess is now GDB, not the program
844 being debugged."
845 (if gdb-use-inferior-io-buffer
846 (let ((sink gdb-output-sink))
847 (cond
848 ((eq sink 'inferior)
849 (setq gdb-output-sink 'user))
851 (gdb-resync)
852 (error "Unexpected stopping annotation"))))))
854 (defun gdb-frame-begin (ignored)
855 (let ((sink gdb-output-sink))
856 (cond
857 ((eq sink 'inferior)
858 (setq gdb-output-sink 'user))
859 ((eq sink 'user) t)
860 ((eq sink 'emacs) t)
862 (gdb-resync)
863 (error "Unexpected frame-begin annotation (%S)" sink)))))
865 (defun gdb-stopped (ignored)
866 "An annotation handler for `stopped'.
867 It is just like `gdb-stopping', except that if we already set the output
868 sink to `user' in `gdb-stopping', that is fine."
869 (setq gud-running nil)
870 (let ((sink gdb-output-sink))
871 (cond
872 ((eq sink 'inferior)
873 (setq gdb-output-sink 'user))
874 ((eq sink 'user) t)
876 (gdb-resync)
877 (error "Unexpected stopped annotation")))))
879 (defun gdb-post-prompt (ignored)
880 "An annotation handler for `post-prompt'.
881 This begins the collection of output from the current command if that
882 happens to be appropriate."
883 (unless gdb-pending-triggers
884 (gdb-get-current-frame)
885 (gdb-invalidate-frames)
886 (gdb-invalidate-breakpoints)
887 (gdb-invalidate-assembler)
888 (gdb-invalidate-registers)
889 (gdb-invalidate-memory)
890 (gdb-invalidate-locals)
891 (gdb-invalidate-threads)
892 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3.
893 ;; FIXME: with GDB-6 on Darwin, this might very well work.
894 ;; only needed/used with speedbar/watch expressions
895 (when (and (boundp 'speedbar-frame) (frame-live-p speedbar-frame))
896 (setq gdb-var-changed t) ; force update
897 (dolist (var gdb-var-list)
898 (setcar (nthcdr 5 var) nil))
899 (gdb-var-update))))
900 (let ((sink gdb-output-sink))
901 (cond
902 ((eq sink 'user) t)
903 ((eq sink 'pre-emacs)
904 (setq gdb-output-sink 'emacs))
906 (gdb-resync)
907 (error "Phase error in gdb-post-prompt (got %s)" sink)))))
909 (defun gud-gdba-marker-filter (string)
910 "A gud marker filter for gdb. Handle a burst of output from GDB."
911 (if gdb-flush-pending-output
913 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log))
914 ;; Recall the left over gud-marker-acc from last time
915 (setq gud-marker-acc (concat gud-marker-acc string))
916 ;; Start accumulating output for the GUD buffer
917 (let ((output ""))
919 ;; Process all the complete markers in this chunk.
920 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc)
921 (let ((annotation (match-string 1 gud-marker-acc)))
923 ;; Stuff prior to the match is just ordinary output.
924 ;; It is either concatenated to OUTPUT or directed
925 ;; elsewhere.
926 (setq output
927 (gdb-concat-output
928 output
929 (substring gud-marker-acc 0 (match-beginning 0))))
931 ;; Take that stuff off the gud-marker-acc.
932 (setq gud-marker-acc (substring gud-marker-acc (match-end 0)))
934 ;; Parse the tag from the annotation, and maybe its arguments.
935 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation)
936 (let* ((annotation-type (match-string 1 annotation))
937 (annotation-arguments (match-string 2 annotation))
938 (annotation-rule (assoc annotation-type
939 gdb-annotation-rules)))
940 ;; Call the handler for this annotation.
941 (if annotation-rule
942 (funcall (car (cdr annotation-rule))
943 annotation-arguments)
944 ;; Else the annotation is not recognized. Ignore it silently,
945 ;; so that GDB can add new annotations without causing
946 ;; us to blow up.
947 ))))
949 ;; Does the remaining text end in a partial line?
950 ;; If it does, then keep part of the gud-marker-acc until we get more.
951 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'"
952 gud-marker-acc)
953 (progn
954 ;; Everything before the potential marker start can be output.
955 (setq output
956 (gdb-concat-output output
957 (substring gud-marker-acc 0
958 (match-beginning 0))))
960 ;; Everything after, we save, to combine with later input.
961 (setq gud-marker-acc (substring gud-marker-acc (match-beginning 0))))
963 ;; In case we know the gud-marker-acc contains no partial annotations:
964 (progn
965 (setq output (gdb-concat-output output gud-marker-acc))
966 (setq gud-marker-acc "")))
967 output)))
969 (defun gdb-concat-output (so-far new)
970 (let ((sink gdb-output-sink))
971 (cond
972 ((eq sink 'user) (concat so-far new))
973 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
974 ((eq sink 'emacs)
975 (gdb-append-to-partial-output new)
976 so-far)
977 ((eq sink 'inferior)
978 (gdb-append-to-inferior-io new)
979 so-far)
981 (gdb-resync)
982 (error "Bogon output sink %S" sink)))))
984 (defun gdb-append-to-partial-output (string)
985 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
986 (goto-char (point-max))
987 (insert string)))
989 (defun gdb-clear-partial-output ()
990 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
991 (erase-buffer)))
993 (defun gdb-append-to-inferior-io (string)
994 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
995 (goto-char (point-max))
996 (insert-before-markers string))
997 (if (not (string-equal string ""))
998 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io))))
1000 (defun gdb-clear-inferior-io ()
1001 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io)
1002 (erase-buffer)))
1005 ;; One trick is to have a command who's output is always available in a buffer
1006 ;; of it's own, and is always up to date. We build several buffers of this
1007 ;; type.
1009 ;; There are two aspects to this: gdb has to tell us when the output for that
1010 ;; command might have changed, and we have to be able to run the command
1011 ;; behind the user's back.
1013 ;; The output phasing associated with the variable gdb-output-sink
1014 ;; help us to run commands behind the user's back.
1016 ;; Below is the code for specificly managing buffers of output from one
1017 ;; command.
1020 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES
1021 ;; It adds an input for the command we are tracking. It should be the
1022 ;; annotation rule binding of whatever gdb sends to tell us this command
1023 ;; might have changed it's output.
1025 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1026 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1027 ;; input in the input queue (see comment about ``gdb communications'' above).
1029 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1030 output-handler)
1031 `(defun ,name (&optional ignored)
1032 (if (and (,demand-predicate)
1033 (not (member ',name
1034 gdb-pending-triggers)))
1035 (progn
1036 (gdb-enqueue-input
1037 (list ,gdb-command ',output-handler))
1038 (push ',name gdb-pending-triggers)))))
1040 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1041 `(defun ,name ()
1042 (setq gdb-pending-triggers
1043 (delq ',trigger
1044 gdb-pending-triggers))
1045 (let ((buf (gdb-get-buffer ',buf-key)))
1046 (and buf
1047 (with-current-buffer buf
1048 (let ((p (point))
1049 (buffer-read-only nil))
1050 (erase-buffer)
1051 (insert-buffer-substring (gdb-get-create-buffer
1052 'gdb-partial-output-buffer))
1053 (goto-char p)))))
1054 ;; put customisation here
1055 (,custom-defun)))
1057 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command
1058 output-handler-name custom-defun)
1059 `(progn
1060 (def-gdb-auto-update-trigger ,trigger-name
1061 ;; The demand predicate:
1062 (lambda () (gdb-get-buffer ',buffer-key))
1063 ,gdb-command
1064 ,output-handler-name)
1065 (def-gdb-auto-update-handler ,output-handler-name
1066 ,trigger-name ,buffer-key ,custom-defun)))
1070 ;; Breakpoint buffer : This displays the output of `info breakpoints'.
1072 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1073 'gdb-breakpoints-buffer-name
1074 'gdb-breakpoints-mode)
1076 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1077 ;; This defines the auto update rule for buffers of type
1078 ;; `gdb-breakpoints-buffer'.
1080 ;; It defines a function to serve as the annotation handler that
1081 ;; handles the `foo-invalidated' message. That function is called:
1082 gdb-invalidate-breakpoints
1084 ;; To update the buffer, this command is sent to gdb.
1085 "server info breakpoints\n"
1087 ;; This also defines a function to be the handler for the output
1088 ;; from the command above. That function will copy the output into
1089 ;; the appropriately typed buffer. That function will be called:
1090 gdb-info-breakpoints-handler
1091 ;; buffer specific functions
1092 gdb-info-breakpoints-custom)
1094 (defconst breakpoint-xpm-data
1095 "/* XPM */
1096 static char *magick[] = {
1097 /* columns rows colors chars-per-pixel */
1098 \"10 10 2 1\",
1099 \" c red\",
1100 \"+ c None\",
1101 /* pixels */
1102 \"+++ +++\",
1103 \"++ ++\",
1104 \"+ +\",
1105 \" \",
1106 \" \",
1107 \" \",
1108 \" \",
1109 \"+ +\",
1110 \"++ ++\",
1111 \"+++ +++\",
1113 "XPM data used for breakpoint icon.")
1115 (defconst breakpoint-enabled-pbm-data
1117 10 10\",
1118 0 0 0 0 1 1 1 1 0 0 0 0
1119 0 0 0 1 1 1 1 1 1 0 0 0
1120 0 0 1 1 1 1 1 1 1 1 0 0
1121 0 1 1 1 1 1 1 1 1 1 1 0
1122 0 1 1 1 1 1 1 1 1 1 1 0
1123 0 1 1 1 1 1 1 1 1 1 1 0
1124 0 1 1 1 1 1 1 1 1 1 1 0
1125 0 0 1 1 1 1 1 1 1 1 0 0
1126 0 0 0 1 1 1 1 1 1 0 0 0
1127 0 0 0 0 1 1 1 1 0 0 0 0"
1128 "PBM data used for enabled breakpoint icon.")
1130 (defconst breakpoint-disabled-pbm-data
1132 10 10\",
1133 0 0 1 0 1 0 1 0 0 0
1134 0 1 0 1 0 1 0 1 0 0
1135 1 0 1 0 1 0 1 0 1 0
1136 0 1 0 1 0 1 0 1 0 1
1137 1 0 1 0 1 0 1 0 1 0
1138 0 1 0 1 0 1 0 1 0 1
1139 1 0 1 0 1 0 1 0 1 0
1140 0 1 0 1 0 1 0 1 0 1
1141 0 0 1 0 1 0 1 0 1 0
1142 0 0 0 1 0 1 0 1 0 0"
1143 "PBM data used for disabled breakpoint icon.")
1145 (defvar breakpoint-enabled-icon nil
1146 "Icon for enabled breakpoint in display margin.")
1148 (defvar breakpoint-disabled-icon nil
1149 "Icon for disabled breakpoint in display margin.")
1151 ;; Bitmap for breakpoint in fringe
1152 (when (fboundp 'define-fringe-bitmap)
1153 (define-fringe-bitmap 'breakpoint
1154 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))
1156 (defface breakpoint-enabled-bitmap-face
1157 '((t
1158 :inherit fringe
1159 :foreground "red"))
1160 "Face for enabled breakpoint icon in fringe."
1161 :group 'gud)
1163 (defface breakpoint-disabled-bitmap-face
1164 '((t
1165 :inherit fringe
1166 :foreground "grey60"))
1167 "Face for disabled breakpoint icon in fringe."
1168 :group 'gud)
1171 ;;-put breakpoint icons in relevant margins (even those set in the GUD buffer)
1172 (defun gdb-info-breakpoints-custom ()
1173 (let ((flag) (bptno))
1174 ;; remove all breakpoint-icons in source buffers but not assembler buffer
1175 (dolist (buffer (buffer-list))
1176 (with-current-buffer buffer
1177 (if (and (eq gud-minor-mode 'gdba)
1178 (not (string-match "\\`\\*.+\\*\\'" (buffer-name))))
1179 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1180 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
1181 (save-excursion
1182 (goto-char (point-min))
1183 (while (< (point) (- (point-max) 1))
1184 (forward-line 1)
1185 (if (looking-at "[^\t].*breakpoint")
1186 (progn
1187 (looking-at "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)")
1188 (setq bptno (match-string 1))
1189 (setq flag (char-after (match-beginning 2)))
1190 (beginning-of-line)
1191 (if (re-search-forward " in .* at\\s-+" nil t)
1192 (progn
1193 (looking-at "\\(\\S-+\\):\\([0-9]+\\)")
1194 (let ((line (match-string 2)) (buffer-read-only nil)
1195 (file (match-string 1)))
1196 (add-text-properties (point-at-bol) (point-at-eol)
1197 '(mouse-face highlight
1198 help-echo "mouse-2, RET: visit breakpoint"))
1199 (unless (file-exists-p file)
1200 (setq file (cdr (assoc bptno gdb-location-list))))
1201 (unless (string-equal file "File not found")
1202 (if file
1203 (with-current-buffer (find-file-noselect file)
1204 (set (make-local-variable 'gud-minor-mode)
1205 'gdba)
1206 (set (make-local-variable 'tool-bar-map)
1207 gud-tool-bar-map)
1208 ;; only want one breakpoint icon at each location
1209 (save-excursion
1210 (goto-line (string-to-number line))
1211 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))
1212 (gdb-enqueue-input
1213 (list (concat "list "
1214 (match-string-no-properties 1) ":1\n")
1215 'ignore))
1216 (gdb-enqueue-input
1217 (list "info source\n"
1218 `(lambda () (gdb-get-location
1219 ,bptno ,line ,flag)))))))))))
1220 (end-of-line)))))
1221 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom)))
1223 (defun gdb-mouse-set-clear-breakpoint (event)
1224 "Set/clear breakpoint in left fringe/margin with mouse click."
1225 (interactive "e")
1226 (mouse-minibuffer-check event)
1227 (let ((posn (event-end event)))
1228 (if (numberp (posn-point posn))
1229 (with-selected-window (posn-window posn)
1230 (save-excursion
1231 (goto-char (posn-point posn))
1232 (if (or (posn-object posn)
1233 (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1234 'breakpoint))
1235 (gud-remove nil)
1236 (gud-break nil)))))))
1238 (defun gdb-mouse-toggle-breakpoint (event)
1239 "Enable/disable breakpoint in left fringe/margin with mouse click."
1240 (interactive "e")
1241 (mouse-minibuffer-check event)
1242 (let ((posn (event-end event)))
1243 (if (numberp (posn-point posn))
1244 (with-selected-window (posn-window posn)
1245 (save-excursion
1246 (goto-char (posn-point posn))
1248 ; (or
1249 (posn-object posn)
1250 ; (eq (car (fringe-bitmaps-at-pos (posn-point posn)))
1251 ; 'breakpoint))
1252 (gdb-enqueue-input
1253 (list
1254 (let ((bptno (get-text-property
1255 0 'gdb-bptno (car (posn-string posn)))))
1256 (concat
1257 (if (get-text-property
1258 0 'gdb-enabled (car (posn-string posn)))
1259 "disable "
1260 "enable ")
1261 bptno "\n")) 'ignore))))))))
1263 (defun gdb-breakpoints-buffer-name ()
1264 (with-current-buffer gud-comint-buffer
1265 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1267 (defun gdb-display-breakpoints-buffer ()
1268 "Display status of user-settable breakpoints."
1269 (interactive)
1270 (gdb-display-buffer
1271 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1273 (defconst gdb-frame-parameters
1274 '((height . 14) (width . 80)
1275 (unsplittable . t)
1276 (tool-bar-lines . nil)
1277 (menu-bar-lines . nil)
1278 (minibuffer . nil)))
1280 (defun gdb-frame-breakpoints-buffer ()
1281 "Display status of user-settable breakpoints in a new frame."
1282 (interactive)
1283 (let ((special-display-regexps (append special-display-regexps '(".*")))
1284 (special-display-frame-alist gdb-frame-parameters))
1285 (display-buffer (gdb-get-create-buffer 'gdb-breakpoints-buffer))))
1287 (defvar gdb-breakpoints-mode-map
1288 (let ((map (make-sparse-keymap))
1289 (menu (make-sparse-keymap "Breakpoints")))
1290 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1291 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1292 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1294 (suppress-keymap map)
1295 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1296 (define-key map " " 'gdb-toggle-breakpoint)
1297 (define-key map "d" 'gdb-delete-breakpoint)
1298 (define-key map "q" 'kill-this-buffer)
1299 (define-key map "\r" 'gdb-goto-breakpoint)
1300 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1301 map))
1303 (defun gdb-breakpoints-mode ()
1304 "Major mode for gdb breakpoints.
1306 \\{gdb-breakpoints-mode-map}"
1307 (kill-all-local-variables)
1308 (setq major-mode 'gdb-breakpoints-mode)
1309 (setq mode-name "Breakpoints")
1310 (use-local-map gdb-breakpoints-mode-map)
1311 (setq buffer-read-only t)
1312 (run-mode-hooks 'gdb-breakpoints-mode-hook)
1313 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1314 'gdb-invalidate-breakpoints
1315 'gdbmi-invalidate-breakpoints))
1317 (defun gdb-toggle-breakpoint ()
1318 "Enable/disable breakpoint at current line."
1319 (interactive)
1320 (save-excursion
1321 (beginning-of-line 1)
1322 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1323 (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")
1324 (looking-at
1325 "\\([0-9]+\\)\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*\\S-*\\s-*\\S-*:[0-9]+"))
1326 (gdb-enqueue-input
1327 (list
1328 (concat gdb-server-prefix
1329 (if (eq ?y (char-after (match-beginning 2)))
1330 "disable "
1331 "enable ")
1332 (match-string 1) "\n") 'ignore))
1333 (error "Not recognized as break/watchpoint line"))))
1335 (defun gdb-delete-breakpoint ()
1336 "Delete the breakpoint at current line."
1337 (interactive)
1338 (beginning-of-line 1)
1339 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1340 (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")
1341 (looking-at
1342 "\\([0-9]+\\)\\s-*\\S-*\\s-*\\S-*\\s-*.\\s-*\\S-*\\s-*\\S-*:[0-9]+"))
1343 (gdb-enqueue-input
1344 (list
1345 (concat gdb-server-prefix "delete " (match-string 1) "\n") 'ignore))
1346 (error "Not recognized as break/watchpoint line")))
1348 (defun gdb-goto-breakpoint (&optional event)
1349 "Display the breakpoint location specified at current line."
1350 (interactive (list last-input-event))
1351 (if event (mouse-set-point event))
1352 (save-excursion
1353 (beginning-of-line 1)
1354 (if (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1355 (looking-at "\\([0-9]+\\) .* in .* at\\s-+\\(\\S-*\\):\\([0-9]+\\)")
1356 (looking-at
1357 "\\([0-9]+\\)\\s-*\\S-*\\s-*\\S-*\\s-*.\\s-*\\S-*\\s-*\\(\\S-*\\):\\([0-9]+\\)"))
1358 (let ((bptno (match-string 1))
1359 (file (match-string 2))
1360 (line (match-string 3)))
1361 (save-selected-window
1362 (let* ((buf (find-file-noselect (if (file-exists-p file)
1363 file
1364 (cdr (assoc bptno gdb-location-list)))))
1365 (window (display-buffer buf)))
1366 (with-current-buffer buf
1367 (goto-line (string-to-number line))
1368 (set-window-point window (point))))))
1369 (error "Not recognized as break/watchpoint line"))))
1372 ;; Frames buffer. This displays a perpetually correct bactracktrace
1373 ;; (from the command `where').
1375 ;; Alas, if your stack is deep, it is costly.
1377 (gdb-set-buffer-rules 'gdb-stack-buffer
1378 'gdb-stack-buffer-name
1379 'gdb-frames-mode)
1381 (def-gdb-auto-updated-buffer gdb-stack-buffer
1382 gdb-invalidate-frames
1383 "server where\n"
1384 gdb-info-frames-handler
1385 gdb-info-frames-custom)
1387 (defun gdb-info-frames-custom ()
1388 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
1389 (save-excursion
1390 (let ((buffer-read-only nil))
1391 (goto-char (point-min))
1392 (while (< (point) (point-max))
1393 (add-text-properties (point-at-bol) (point-at-eol)
1394 '(mouse-face highlight
1395 help-echo "mouse-2, RET: Select frame"))
1396 (beginning-of-line)
1397 (when (and (looking-at "^#\\([0-9]+\\)")
1398 (equal (match-string 1) gdb-current-stack-level))
1399 (put-text-property (point-at-bol) (point-at-eol)
1400 'face '(:inverse-video t)))
1401 (forward-line 1))))))
1403 (defun gdb-stack-buffer-name ()
1404 (with-current-buffer gud-comint-buffer
1405 (concat "*stack frames of " (gdb-get-target-string) "*")))
1407 (defun gdb-display-stack-buffer ()
1408 "Display backtrace of current stack."
1409 (interactive)
1410 (gdb-display-buffer
1411 (gdb-get-create-buffer 'gdb-stack-buffer)))
1413 (defun gdb-frame-stack-buffer ()
1414 "Display backtrace of current stack in a new frame."
1415 (interactive)
1416 (let ((special-display-regexps (append special-display-regexps '(".*")))
1417 (special-display-frame-alist gdb-frame-parameters))
1418 (display-buffer (gdb-get-create-buffer 'gdb-stack-buffer))))
1420 (defvar gdb-frames-mode-map
1421 (let ((map (make-sparse-keymap)))
1422 (suppress-keymap map)
1423 (define-key map "q" 'kill-this-buffer)
1424 (define-key map "\r" 'gdb-frames-select)
1425 (define-key map [mouse-2] 'gdb-frames-select)
1426 map))
1428 (defun gdb-frames-mode ()
1429 "Major mode for gdb frames.
1431 \\{gdb-frames-mode-map}"
1432 (kill-all-local-variables)
1433 (setq major-mode 'gdb-frames-mode)
1434 (setq mode-name "Frames")
1435 (setq buffer-read-only t)
1436 (use-local-map gdb-frames-mode-map)
1437 (font-lock-mode -1)
1438 (run-mode-hooks 'gdb-frames-mode-hook)
1439 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1440 'gdb-invalidate-frames
1441 'gdbmi-invalidate-frames))
1443 (defun gdb-get-frame-number ()
1444 (save-excursion
1445 (let* ((pos (re-search-backward "^#*\\([0-9]*\\)" nil t))
1446 (n (or (and pos (match-string-no-properties 1)) "0")))
1447 n)))
1449 (defun gdb-frames-select (&optional event)
1450 "Select the frame and display the relevant source."
1451 (interactive (list last-input-event))
1452 (if event (mouse-set-point event))
1453 (gdb-enqueue-input
1454 (list (concat gdb-server-prefix "frame " (gdb-get-frame-number) "\n") 'ignore))
1455 (gud-display-frame))
1458 ;; Threads buffer. This displays a selectable thread list.
1460 (gdb-set-buffer-rules 'gdb-threads-buffer
1461 'gdb-threads-buffer-name
1462 'gdb-threads-mode)
1464 (def-gdb-auto-updated-buffer gdb-threads-buffer
1465 gdb-invalidate-threads
1466 (concat gdb-server-prefix "info threads\n")
1467 gdb-info-threads-handler
1468 gdb-info-threads-custom)
1470 (defun gdb-info-threads-custom ()
1471 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer)
1472 (let ((buffer-read-only nil))
1473 (goto-char (point-min))
1474 (while (< (point) (point-max))
1475 (add-text-properties (point-at-bol) (point-at-eol)
1476 '(mouse-face highlight
1477 help-echo "mouse-2, RET: select thread"))
1478 (forward-line 1)))))
1480 (defun gdb-threads-buffer-name ()
1481 (with-current-buffer gud-comint-buffer
1482 (concat "*threads of " (gdb-get-target-string) "*")))
1484 (defun gdb-display-threads-buffer ()
1485 "Display IDs of currently known threads."
1486 (interactive)
1487 (gdb-display-buffer
1488 (gdb-get-create-buffer 'gdb-threads-buffer)))
1490 (defun gdb-frame-threads-buffer ()
1491 "Display IDs of currently known threads in a new frame."
1492 (interactive)
1493 (let ((special-display-regexps (append special-display-regexps '(".*")))
1494 (special-display-frame-alist gdb-frame-parameters))
1495 (display-buffer (gdb-get-create-buffer 'gdb-threads-buffer))))
1497 (defvar gdb-threads-mode-map
1498 (let ((map (make-sparse-keymap)))
1499 (suppress-keymap map)
1500 (define-key map "q" 'kill-this-buffer)
1501 (define-key map "\r" 'gdb-threads-select)
1502 (define-key map [mouse-2] 'gdb-threads-select)
1503 map))
1505 (defun gdb-threads-mode ()
1506 "Major mode for gdb frames.
1508 \\{gdb-threads-mode-map}"
1509 (kill-all-local-variables)
1510 (setq major-mode 'gdb-threads-mode)
1511 (setq mode-name "Threads")
1512 (setq buffer-read-only t)
1513 (use-local-map gdb-threads-mode-map)
1514 (run-mode-hooks 'gdb-threads-mode-hook)
1515 'gdb-invalidate-threads)
1517 (defun gdb-get-thread-number ()
1518 (save-excursion
1519 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t)
1520 (match-string-no-properties 1)))
1522 (defun gdb-threads-select (&optional event)
1523 "Select the thread and display the relevant source."
1524 (interactive (list last-input-event))
1525 (if event (mouse-set-point event))
1526 (gdb-enqueue-input
1527 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore))
1528 (gud-display-frame))
1531 ;; Registers buffer.
1533 (gdb-set-buffer-rules 'gdb-registers-buffer
1534 'gdb-registers-buffer-name
1535 'gdb-registers-mode)
1537 (def-gdb-auto-updated-buffer gdb-registers-buffer
1538 gdb-invalidate-registers
1539 (concat gdb-server-prefix "info registers\n")
1540 gdb-info-registers-handler
1541 gdb-info-registers-custom)
1543 (defun gdb-info-registers-custom ())
1545 (defvar gdb-registers-mode-map
1546 (let ((map (make-sparse-keymap)))
1547 (suppress-keymap map)
1548 (define-key map "q" 'kill-this-buffer)
1549 map))
1551 (defun gdb-registers-mode ()
1552 "Major mode for gdb registers.
1554 \\{gdb-registers-mode-map}"
1555 (kill-all-local-variables)
1556 (setq major-mode 'gdb-registers-mode)
1557 (setq mode-name "Registers")
1558 (setq buffer-read-only t)
1559 (use-local-map gdb-registers-mode-map)
1560 (run-mode-hooks 'gdb-registers-mode-hook)
1561 'gdb-invalidate-registers)
1563 (defun gdb-registers-buffer-name ()
1564 (with-current-buffer gud-comint-buffer
1565 (concat "*registers of " (gdb-get-target-string) "*")))
1567 (defun gdb-display-registers-buffer ()
1568 "Display integer register contents."
1569 (interactive)
1570 (gdb-display-buffer
1571 (gdb-get-create-buffer 'gdb-registers-buffer)))
1573 (defun gdb-frame-registers-buffer ()
1574 "Display integer register contents in a new frame."
1575 (interactive)
1576 (let ((special-display-regexps (append special-display-regexps '(".*")))
1577 (special-display-frame-alist gdb-frame-parameters))
1578 (display-buffer (gdb-get-create-buffer 'gdb-registers-buffer))))
1580 ;; Memory buffer.
1582 (defcustom gdb-memory-repeat-count 32
1583 "Number of data items in memory window."
1584 :type 'integer
1585 :group 'gud
1586 :version "22.1")
1588 (defcustom gdb-memory-format "x"
1589 "Display format of data items in memory window."
1590 :type '(choice (const :tag "Hexadecimal" "x")
1591 (const :tag "Signed decimal" "d")
1592 (const :tag "Unsigned decimal" "u")
1593 (const :tag "Octal" "o")
1594 (const :tag "Binary" "t"))
1595 :group 'gud
1596 :version "22.1")
1598 (defcustom gdb-memory-unit "w"
1599 "Unit size of data items in memory window."
1600 :type '(choice (const :tag "Byte" "b")
1601 (const :tag "Halfword" "h")
1602 (const :tag "Word" "w")
1603 (const :tag "Giant word" "g"))
1604 :group 'gud
1605 :version "22.1")
1607 (gdb-set-buffer-rules 'gdb-memory-buffer
1608 'gdb-memory-buffer-name
1609 'gdb-memory-mode)
1611 (def-gdb-auto-updated-buffer gdb-memory-buffer
1612 gdb-invalidate-memory
1613 (concat gdb-server-prefix "x/" (number-to-string gdb-memory-repeat-count)
1614 gdb-memory-format gdb-memory-unit " " gdb-memory-address "\n")
1615 gdb-read-memory-handler
1616 gdb-read-memory-custom)
1618 (defun gdb-read-memory-custom ())
1620 (defvar gdb-memory-mode-map
1621 (let ((map (make-sparse-keymap)))
1622 (suppress-keymap map)
1623 (define-key map "q" 'kill-this-buffer)
1624 map))
1626 (defun gdb-memory-set-address (event)
1627 "Set the start memory address."
1628 (interactive "e")
1629 (save-selected-window
1630 (select-window (posn-window (event-start event)))
1631 (let ((arg (read-from-minibuffer "Memory address: ")))
1632 (setq gdb-memory-address arg))
1633 (gdb-invalidate-memory)))
1635 (defun gdb-memory-set-repeat-count (event)
1636 "Set the number of data items in memory window."
1637 (interactive "e")
1638 (save-selected-window
1639 (select-window (posn-window (event-start event)))
1640 (let* ((arg (read-from-minibuffer "Repeat count: "))
1641 (count (string-to-int arg)))
1642 (if (< count 0)
1643 (error "Non-negative numbers only")
1644 (customize-set-variable 'gdb-memory-repeat-count count)
1645 (gdb-invalidate-memory)))))
1647 (defun gdb-memory-format-binary ()
1648 "Set the display format to binary."
1649 (interactive)
1650 (customize-set-variable 'gdb-memory-format "t")
1651 (gdb-invalidate-memory))
1653 (defun gdb-memory-format-octal ()
1654 "Set the display format to octal."
1655 (interactive)
1656 (customize-set-variable 'gdb-memory-format "o")
1657 (gdb-invalidate-memory))
1659 (defun gdb-memory-format-unsigned ()
1660 "Set the display format to unsigned decimal."
1661 (interactive)
1662 (customize-set-variable 'gdb-memory-format "u")
1663 (gdb-invalidate-memory))
1665 (defun gdb-memory-format-signed ()
1666 "Set the display format to decimal."
1667 (interactive)
1668 (customize-set-variable 'gdb-memory-format "d")
1669 (gdb-invalidate-memory))
1671 (defun gdb-memory-format-hexadecimal ()
1672 "Set the display format to hexadecimal."
1673 (interactive)
1674 (customize-set-variable 'gdb-memory-format "x")
1675 (gdb-invalidate-memory))
1677 (defvar gdb-memory-format-keymap
1678 (let ((map (make-sparse-keymap)))
1679 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
1680 map)
1681 "Keymap to select format in the header line.")
1683 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
1684 "Menu of display formats in the header line.")
1686 (define-key gdb-memory-format-menu [binary]
1687 '(menu-item "Binary" gdb-memory-format-binary
1688 :button (:radio . (equal gdb-memory-format "t"))))
1689 (define-key gdb-memory-format-menu [octal]
1690 '(menu-item "Octal" gdb-memory-format-octal
1691 :button (:radio . (equal gdb-memory-format "o"))))
1692 (define-key gdb-memory-format-menu [unsigned]
1693 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
1694 :button (:radio . (equal gdb-memory-format "u"))))
1695 (define-key gdb-memory-format-menu [signed]
1696 '(menu-item "Signed Decimal" gdb-memory-format-signed
1697 :button (:radio . (equal gdb-memory-format "d"))))
1698 (define-key gdb-memory-format-menu [hexadecimal]
1699 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
1700 :button (:radio . (equal gdb-memory-format "x"))))
1702 (defun gdb-memory-format-menu (event)
1703 (interactive "@e")
1704 (x-popup-menu event gdb-memory-format-menu))
1706 (defun gdb-memory-format-menu-1 (event)
1707 (interactive "e")
1708 (save-selected-window
1709 (select-window (posn-window (event-start event)))
1710 (let* ((selection (gdb-memory-format-menu event))
1711 (binding (and selection (lookup-key gdb-memory-format-menu
1712 (vector (car selection))))))
1713 (if binding (call-interactively binding)))))
1715 (defun gdb-memory-unit-giant ()
1716 "Set the unit size to giant words (eight bytes)."
1717 (interactive)
1718 (customize-set-variable 'gdb-memory-unit "g")
1719 (gdb-invalidate-memory))
1721 (defun gdb-memory-unit-word ()
1722 "Set the unit size to words (four bytes)."
1723 (interactive)
1724 (customize-set-variable 'gdb-memory-unit "w")
1725 (gdb-invalidate-memory))
1727 (defun gdb-memory-unit-halfword ()
1728 "Set the unit size to halfwords (two bytes)."
1729 (interactive)
1730 (customize-set-variable 'gdb-memory-unit "h")
1731 (gdb-invalidate-memory))
1733 (defun gdb-memory-unit-byte ()
1734 "Set the unit size to bytes."
1735 (interactive)
1736 (customize-set-variable 'gdb-memory-unit "b")
1737 (gdb-invalidate-memory))
1739 (defvar gdb-memory-unit-keymap
1740 (let ((map (make-sparse-keymap)))
1741 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
1742 map)
1743 "Keymap to select units in the header line.")
1745 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
1746 "Menu of units in the header line.")
1748 (define-key gdb-memory-unit-menu [giantwords]
1749 '(menu-item "Giant words" gdb-memory-unit-giant
1750 :button (:radio . (equal gdb-memory-unit "g"))))
1751 (define-key gdb-memory-unit-menu [words]
1752 '(menu-item "Words" gdb-memory-unit-word
1753 :button (:radio . (equal gdb-memory-unit "w"))))
1754 (define-key gdb-memory-unit-menu [halfwords]
1755 '(menu-item "Halfwords" gdb-memory-unit-halfword
1756 :button (:radio . (equal gdb-memory-unit "h"))))
1757 (define-key gdb-memory-unit-menu [bytes]
1758 '(menu-item "Bytes" gdb-memory-unit-byte
1759 :button (:radio . (equal gdb-memory-unit "b"))))
1761 (defun gdb-memory-unit-menu (event)
1762 (interactive "@e")
1763 (x-popup-menu event gdb-memory-unit-menu))
1765 (defun gdb-memory-unit-menu-1 (event)
1766 (interactive "e")
1767 (save-selected-window
1768 (select-window (posn-window (event-start event)))
1769 (let* ((selection (gdb-memory-unit-menu event))
1770 (binding (and selection (lookup-key gdb-memory-unit-menu
1771 (vector (car selection))))))
1772 (if binding (call-interactively binding)))))
1774 ;;from make-mode-line-mouse-map
1775 (defun gdb-make-header-line-mouse-map (mouse function) "\
1776 Return a keymap with single entry for mouse key MOUSE on the header line.
1777 MOUSE is defined to run function FUNCTION with no args in the buffer
1778 corresponding to the mode line clicked."
1779 (let ((map (make-sparse-keymap)))
1780 (define-key map (vector 'header-line mouse) function)
1781 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
1782 map))
1784 (defun gdb-memory-mode ()
1785 "Major mode for examining memory.
1787 \\{gdb-memory-mode-map}"
1788 (kill-all-local-variables)
1789 (setq major-mode 'gdb-memory-mode)
1790 (setq mode-name "Memory")
1791 (setq buffer-read-only t)
1792 (use-local-map gdb-memory-mode-map)
1793 (setq header-line-format
1794 '(:eval
1795 (concat
1796 "Read address: "
1797 (propertize gdb-memory-address
1798 'face font-lock-warning-face
1799 'help-echo (purecopy "mouse-1: Set memory address")
1800 'local-map (purecopy (gdb-make-header-line-mouse-map
1801 'mouse-1
1802 #'gdb-memory-set-address)))
1803 " Repeat Count: "
1804 (propertize (number-to-string gdb-memory-repeat-count)
1805 'face font-lock-warning-face
1806 'help-echo (purecopy "mouse-1: Set repeat count")
1807 'local-map (purecopy (gdb-make-header-line-mouse-map
1808 'mouse-1
1809 #'gdb-memory-set-repeat-count)))
1810 " Display Format: "
1811 (propertize gdb-memory-format
1812 'face font-lock-warning-face
1813 'help-echo (purecopy "mouse-3: Select display format")
1814 'local-map gdb-memory-format-keymap)
1815 " Unit Size: "
1816 (propertize gdb-memory-unit
1817 'face font-lock-warning-face
1818 'help-echo (purecopy "mouse-3: Select unit size")
1819 'local-map gdb-memory-unit-keymap))))
1820 (run-mode-hooks 'gdb-memory-mode-hook)
1821 'gdb-invalidate-memory)
1823 (defun gdb-memory-buffer-name ()
1824 (with-current-buffer gud-comint-buffer
1825 (concat "*memory of " (gdb-get-target-string) "*")))
1827 (defun gdb-display-memory-buffer ()
1828 "Display memory contents."
1829 (interactive)
1830 (gdb-display-buffer
1831 (gdb-get-create-buffer 'gdb-memory-buffer)))
1833 (defun gdb-frame-memory-buffer ()
1834 "Display memory contents in a new frame."
1835 (interactive)
1836 (let ((special-display-regexps (append special-display-regexps '(".*")))
1837 (special-display-frame-alist gdb-frame-parameters))
1838 (display-buffer (gdb-get-create-buffer 'gdb-memory-buffer))))
1841 ;; Locals buffer.
1843 (gdb-set-buffer-rules 'gdb-locals-buffer
1844 'gdb-locals-buffer-name
1845 'gdb-locals-mode)
1847 (def-gdb-auto-updated-buffer gdb-locals-buffer
1848 gdb-invalidate-locals
1849 "server info locals\n"
1850 gdb-info-locals-handler
1851 gdb-info-locals-custom)
1853 ;; Abbreviate for arrays and structures.
1854 ;; These can be expanded using gud-display.
1855 (defun gdb-info-locals-handler nil
1856 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
1857 gdb-pending-triggers))
1858 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
1859 (with-current-buffer buf
1860 (goto-char (point-min))
1861 (while (re-search-forward "^ .*\n" nil t)
1862 (replace-match "" nil nil))
1863 (goto-char (point-min))
1864 (while (re-search-forward "{[-0-9, {}\]*\n" nil t)
1865 (replace-match "(array);\n" nil nil))
1866 (goto-char (point-min))
1867 (while (re-search-forward "{.*=.*\n" nil t)
1868 (replace-match "(structure);\n" nil nil))))
1869 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
1870 (and buf (with-current-buffer buf
1871 (let ((p (point))
1872 (buffer-read-only nil))
1873 (delete-region (point-min) (point-max))
1874 (insert-buffer-substring (gdb-get-create-buffer
1875 'gdb-partial-output-buffer))
1876 (goto-char p)))))
1877 (run-hooks 'gdb-info-locals-hook))
1879 (defun gdb-info-locals-custom ()
1880 nil)
1882 (defvar gdb-locals-mode-map
1883 (let ((map (make-sparse-keymap)))
1884 (suppress-keymap map)
1885 (define-key map "q" 'kill-this-buffer)
1886 map))
1888 (defun gdb-locals-mode ()
1889 "Major mode for gdb locals.
1891 \\{gdb-locals-mode-map}"
1892 (kill-all-local-variables)
1893 (setq major-mode 'gdb-locals-mode)
1894 (setq mode-name (concat "Locals:" gdb-current-frame))
1895 (setq buffer-read-only t)
1896 (use-local-map gdb-locals-mode-map)
1897 (run-mode-hooks 'gdb-locals-mode-hook)
1898 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba))
1899 'gdb-invalidate-locals
1900 'gdbmi-invalidate-locals))
1902 (defun gdb-locals-buffer-name ()
1903 (with-current-buffer gud-comint-buffer
1904 (concat "*locals of " (gdb-get-target-string) "*")))
1906 (defun gdb-display-locals-buffer ()
1907 "Display local variables of current stack and their values."
1908 (interactive)
1909 (gdb-display-buffer
1910 (gdb-get-create-buffer 'gdb-locals-buffer)))
1912 (defun gdb-frame-locals-buffer ()
1913 "Display local variables of current stack and their values in a new frame."
1914 (interactive)
1915 (let ((special-display-regexps (append special-display-regexps '(".*")))
1916 (special-display-frame-alist gdb-frame-parameters))
1917 (display-buffer (gdb-get-create-buffer 'gdb-locals-buffer))))
1920 ;;;; Window management
1921 (defun gdb-display-buffer (buf &optional size)
1922 (let ((answer (get-buffer-window buf 0))
1923 (must-split nil))
1924 (if answer
1925 (display-buffer buf) ;Raise the frame if necessary.
1926 ;; The buffer is not yet displayed.
1927 (pop-to-buffer gud-comint-buffer) ;Select the right frame.
1928 (let ((window (get-lru-window)))
1929 (if window
1930 (progn
1931 (set-window-buffer window buf)
1932 (setq answer window))
1933 (setq must-split t)))
1934 (if must-split
1935 (let* ((largest (get-largest-window))
1936 (cur-size (window-height largest))
1937 (new-size (and size (< size cur-size) (- cur-size size))))
1938 (setq answer (split-window largest new-size))
1939 (set-window-buffer answer buf)
1940 (set-window-dedicated-p answer t)))
1941 answer)))
1944 ;;; Shared keymap initialization:
1946 (let ((menu (make-sparse-keymap "GDB-Windows")))
1947 (define-key gud-menu-map [displays]
1948 `(menu-item "GDB-Windows" ,menu :visible (eq gud-minor-mode 'gdba)))
1949 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
1950 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
1951 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
1952 (define-key menu [assembler] '("Machine" . gdb-display-assembler-buffer))
1953 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
1954 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
1955 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
1956 (define-key menu [breakpoints] '("Breakpoints" . gdb-display-breakpoints-buffer)))
1958 (let ((menu (make-sparse-keymap "GDB-Frames")))
1959 (define-key gud-menu-map [frames]
1960 `(menu-item "GDB-Frames" ,menu :visible (eq gud-minor-mode 'gdba)))
1961 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
1962 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
1963 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
1964 (define-key menu [assembler] '("Machine" . gdb-frame-assembler-buffer))
1965 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
1966 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
1967 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
1968 (define-key menu [breakpoints] '("Breakpoints" . gdb-frame-breakpoints-buffer)))
1970 (let ((menu (make-sparse-keymap "GDB-UI")))
1971 (define-key gud-menu-map [ui]
1972 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba)))
1973 (define-key menu [gdb-restore-windows]
1974 '("Restore Window Layout" . gdb-restore-windows))
1975 (define-key menu [gdb-many-windows]
1976 (menu-bar-make-toggle gdb-many-windows gdb-many-windows
1977 "Display Other Windows" "Many windows %s"
1978 "Toggle display of locals, stack and breakpoint information")))
1980 (defun gdb-frame-gdb-buffer ()
1981 "Display GUD buffer in a new frame."
1982 (interactive)
1983 (select-frame (make-frame gdb-frame-parameters))
1984 (switch-to-buffer (gdb-get-create-buffer 'gdba))
1985 (set-window-dedicated-p (selected-window) t))
1987 (defun gdb-display-gdb-buffer ()
1988 "Display GUD buffer."
1989 (interactive)
1990 (gdb-display-buffer
1991 (gdb-get-create-buffer 'gdba)))
1993 (defvar gdb-main-file nil "Source file from which program execution begins.")
1995 (defcustom gdb-show-main nil
1996 "Nil means don't display source file containing the main routine."
1997 :type 'boolean
1998 :group 'gud
1999 :version "22.1")
2001 (defun gdb-set-window-buffer (name)
2002 (set-window-buffer (selected-window) (get-buffer name))
2003 (set-window-dedicated-p (selected-window) t))
2005 (defun gdb-setup-windows ()
2006 "Layout the window pattern for gdb-many-windows."
2007 (gdb-display-locals-buffer)
2008 (gdb-display-stack-buffer)
2009 (delete-other-windows)
2010 (gdb-display-breakpoints-buffer)
2011 (delete-other-windows)
2012 ; Don't dedicate.
2013 (pop-to-buffer gud-comint-buffer)
2014 (split-window nil ( / ( * (window-height) 3) 4))
2015 (split-window nil ( / (window-height) 3))
2016 (split-window-horizontally)
2017 (other-window 1)
2018 (gdb-set-window-buffer (gdb-locals-buffer-name))
2019 (other-window 1)
2020 (switch-to-buffer
2021 (if gud-last-last-frame
2022 (gud-find-file (car gud-last-last-frame))
2023 (gud-find-file gdb-main-file)))
2024 (when gdb-use-inferior-io-buffer
2025 (split-window-horizontally)
2026 (other-window 1)
2027 (gdb-set-window-buffer (gdb-inferior-io-name)))
2028 (other-window 1)
2029 (gdb-set-window-buffer (gdb-stack-buffer-name))
2030 (split-window-horizontally)
2031 (other-window 1)
2032 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
2033 (other-window 1))
2035 (defcustom gdb-many-windows nil
2036 "Nil means just pop up the GUD buffer unless `gdb-show-main' is t.
2037 In this case it starts with two windows: one displaying the GUD
2038 buffer and the other with the source file with the main routine
2039 of the inferior. Non-nil means display the layout shown for
2040 `gdba'."
2041 :type 'boolean
2042 :group 'gud
2043 :version "22.1")
2045 (defun gdb-many-windows (arg)
2046 "Toggle the number of windows in the basic arrangement."
2047 (interactive "P")
2048 (setq gdb-many-windows
2049 (if (null arg)
2050 (not gdb-many-windows)
2051 (> (prefix-numeric-value arg) 0)))
2052 (condition-case nil
2053 (gdb-restore-windows)
2054 (error nil)))
2056 (defun gdb-restore-windows ()
2057 "Restore the basic arrangement of windows used by gdba.
2058 This arrangement depends on the value of `gdb-many-windows'."
2059 (interactive)
2060 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
2061 (delete-other-windows)
2062 (if gdb-many-windows
2063 (gdb-setup-windows)
2064 (split-window)
2065 (other-window 1)
2066 (switch-to-buffer
2067 (if gud-last-last-frame
2068 (gud-find-file (car gud-last-last-frame))
2069 (gud-find-file gdb-main-file)))
2070 (other-window 1)))
2072 (defun gdb-reset ()
2073 "Exit a debugging session cleanly.
2074 Kills the gdb buffers and resets the source buffers."
2075 (dolist (buffer (buffer-list))
2076 (unless (eq buffer gud-comint-buffer)
2077 (with-current-buffer buffer
2078 (if (memq gud-minor-mode '(gdbmi gdba))
2079 (if (string-match "\\`\\*.+\\*\\'" (buffer-name))
2080 (kill-buffer nil)
2081 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
2082 (setq gud-minor-mode nil)
2083 (kill-local-variable 'tool-bar-map)
2084 (setq gud-running nil))))))
2085 (when (markerp gdb-overlay-arrow-position)
2086 (move-marker gdb-overlay-arrow-position nil)
2087 (setq gdb-overlay-arrow-position nil))
2088 (setq overlay-arrow-variable-list
2089 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list)))
2091 (defun gdb-source-info ()
2092 "Find the source file where the program starts and displays it with related
2093 buffers."
2094 (goto-char (point-min))
2095 (if (and (search-forward "Located in " nil t)
2096 (looking-at "\\S-*"))
2097 (setq gdb-main-file (match-string 0)))
2098 (if gdb-many-windows
2099 (gdb-setup-windows)
2100 (gdb-get-create-buffer 'gdb-breakpoints-buffer)
2101 (if gdb-show-main
2102 (let ((pop-up-windows t))
2103 (display-buffer (gud-find-file gdb-main-file))))))
2105 (defun gdb-get-location (bptno line flag)
2106 "Find the directory containing the relevant source file.
2107 Put in buffer and place breakpoint icon."
2108 (goto-char (point-min))
2109 (catch 'file-not-found
2110 (if (search-forward "Located in " nil t)
2111 (if (looking-at "\\S-*")
2112 (push (cons bptno (match-string 0)) gdb-location-list))
2113 (gdb-resync)
2114 (push (cons bptno "File not found") gdb-location-list)
2115 (if (eq window-system 'x)
2116 (x-popup-dialog
2117 t '("Cannot find source file for breakpoint location.\n\
2118 Add directory to search path for source files using the GDB command, dir."
2119 ("Ok" . nil)))
2120 (message "Cannot find source file for breakpoint location.\n\
2121 Add directory to search path for source files using the GDB command, dir."))
2122 (throw 'file-not-found nil))
2123 (with-current-buffer
2124 (find-file-noselect (match-string 0))
2125 (save-current-buffer
2126 (set (make-local-variable 'gud-minor-mode) 'gdba)
2127 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map))
2128 ;; only want one breakpoint icon at each location
2129 (save-excursion
2130 (goto-line (string-to-number line))
2131 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))
2133 (add-hook 'find-file-hook 'gdb-find-file-hook)
2135 (defun gdb-find-file-hook ()
2136 (if (and (not gdb-find-file-unhook)
2137 ;; in case gud or gdb-ui is just loaded
2138 gud-comint-buffer
2139 (buffer-name gud-comint-buffer)
2140 (with-current-buffer gud-comint-buffer
2141 (eq gud-minor-mode 'gdba)))
2142 (condition-case nil
2143 (gdb-enqueue-input
2144 (list (concat gdb-server-prefix "list "
2145 (file-name-nondirectory buffer-file-name)
2146 ":1\n")
2147 `(lambda () (gdb-set-gud-minor-mode ,(current-buffer)))))
2148 (error (setq gdb-find-file-unhook t)))))
2150 ;;from put-image
2151 (defun gdb-put-string (putstring pos &optional dprop)
2152 "Put string PUTSTRING in front of POS in the current buffer.
2153 PUTSTRING is displayed by putting an overlay into the current buffer with a
2154 `before-string' STRING that has a `display' property whose value is
2155 PUTSTRING."
2156 (let ((string (make-string 1 ?x))
2157 (buffer (current-buffer)))
2158 (setq putstring (copy-sequence putstring))
2159 (let ((overlay (make-overlay pos pos buffer))
2160 (prop (or dprop
2161 (list (list 'margin 'left-margin) putstring))))
2162 (put-text-property 0 (length string) 'display prop string)
2163 (overlay-put overlay 'put-break t)
2164 (overlay-put overlay 'before-string string))))
2166 ;;from remove-images
2167 (defun gdb-remove-strings (start end &optional buffer)
2168 "Remove strings between START and END in BUFFER.
2169 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
2170 BUFFER nil or omitted means use the current buffer."
2171 (unless buffer
2172 (setq buffer (current-buffer)))
2173 (dolist (overlay (overlays-in start end))
2174 (when (overlay-get overlay 'put-break)
2175 (delete-overlay overlay))))
2177 (defun gdb-put-breakpoint-icon (enabled bptno)
2178 (let ((start (progn (beginning-of-line) (- (point) 1)))
2179 (end (progn (end-of-line) (+ (point) 1)))
2180 (putstring (if enabled "B" "b")))
2181 (add-text-properties
2182 0 1 '(help-echo "mouse-1: set/clear bkpt, mouse-3: enable/disable bkpt")
2183 putstring)
2184 (if enabled (add-text-properties
2185 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
2186 (add-text-properties
2187 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
2188 (gdb-remove-breakpoint-icons start end)
2189 (if (display-images-p)
2190 (if (>= (car (window-fringes)) 8)
2191 (gdb-put-string
2192 nil (1+ start)
2193 `(left-fringe breakpoint
2194 ,(if enabled
2195 'breakpoint-enabled-bitmap-face
2196 'breakpoint-disabled-bitmap-face)))
2197 (when (< left-margin-width 2)
2198 (save-current-buffer
2199 (setq left-margin-width 2)
2200 (if (get-buffer-window (current-buffer) 0)
2201 (set-window-margins
2202 (get-buffer-window (current-buffer) 0)
2203 left-margin-width right-margin-width))))
2204 (put-image
2205 (if enabled
2206 (or breakpoint-enabled-icon
2207 (setq breakpoint-enabled-icon
2208 (find-image `((:type xpm :data
2209 ,breakpoint-xpm-data
2210 :ascent 100 :pointer hand)
2211 (:type pbm :data
2212 ,breakpoint-enabled-pbm-data
2213 :ascent 100 :pointer hand)))))
2214 (or breakpoint-disabled-icon
2215 (setq breakpoint-disabled-icon
2216 (find-image `((:type xpm :data
2217 ,breakpoint-xpm-data
2218 :conversion disabled
2219 :ascent 100)
2220 (:type pbm :data
2221 ,breakpoint-disabled-pbm-data
2222 :ascent 100))))))
2223 (+ start 1)
2224 putstring
2225 'left-margin))
2226 (when (< left-margin-width 2)
2227 (save-current-buffer
2228 (setq left-margin-width 2)
2229 (if (get-buffer-window (current-buffer) 0)
2230 (set-window-margins
2231 (get-buffer-window (current-buffer) 0)
2232 left-margin-width right-margin-width))))
2233 (gdb-put-string putstring (1+ start)))))
2235 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
2236 (gdb-remove-strings start end)
2237 (if (display-images-p)
2238 (remove-images start end))
2239 (when remove-margin
2240 (setq left-margin-width 0)
2241 (if (get-buffer-window (current-buffer) 0)
2242 (set-window-margins
2243 (get-buffer-window (current-buffer) 0)
2244 left-margin-width right-margin-width))))
2248 ;; Assembler buffer.
2250 (gdb-set-buffer-rules 'gdb-assembler-buffer
2251 'gdb-assembler-buffer-name
2252 'gdb-assembler-mode)
2254 (def-gdb-auto-updated-buffer gdb-assembler-buffer
2255 gdb-invalidate-assembler
2256 (concat gdb-server-prefix "disassemble " gdb-current-address "\n")
2257 gdb-assembler-handler
2258 gdb-assembler-custom)
2260 (defun gdb-assembler-custom ()
2261 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2262 (pos 1) (address) (flag) (bptno))
2263 (with-current-buffer buffer
2264 (if (not (equal gdb-current-address "main"))
2265 (progn
2266 (goto-char (point-min))
2267 (if (re-search-forward gdb-current-address nil t)
2268 (progn
2269 (setq pos (point))
2270 (beginning-of-line)
2271 (or gdb-overlay-arrow-position
2272 (setq gdb-overlay-arrow-position (make-marker)))
2273 (set-marker gdb-overlay-arrow-position
2274 (point) (current-buffer))))))
2275 ;; remove all breakpoint-icons in assembler buffer before updating.
2276 (gdb-remove-breakpoint-icons (point-min) (point-max)))
2277 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer)
2278 (goto-char (point-min))
2279 (while (< (point) (- (point-max) 1))
2280 (forward-line 1)
2281 (if (looking-at "[^\t].*breakpoint")
2282 (progn
2283 (looking-at
2284 "\\([0-9]+\\)\\s-+\\S-+\\s-+\\S-+\\s-+\\(.\\)\\s-+0x\\(\\S-+\\)")
2285 (setq bptno (match-string 1))
2286 (setq flag (char-after (match-beginning 2)))
2287 (setq address (match-string 3))
2288 ;; remove leading 0s from output of info break.
2289 (if (string-match "^0+\\(.*\\)" address)
2290 (setq address (match-string 1 address)))
2291 (with-current-buffer buffer
2292 (goto-char (point-min))
2293 (if (re-search-forward address nil t)
2294 (gdb-put-breakpoint-icon (eq flag ?y) bptno)))))))
2295 (if (not (equal gdb-current-address "main"))
2296 (set-window-point (get-buffer-window buffer 0) pos))))
2298 (defvar gdb-assembler-mode-map
2299 (let ((map (make-sparse-keymap)))
2300 (suppress-keymap map)
2301 (define-key map "q" 'kill-this-buffer)
2302 map))
2304 (defvar gdb-assembler-font-lock-keywords
2305 '(;; <__function.name+n>
2306 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2307 (1 font-lock-function-name-face))
2308 ;; 0xNNNNNNNN <__function.name+n>: opcode
2309 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2310 (4 font-lock-keyword-face))
2311 ;; %register(at least i386)
2312 ("%\\sw+" . font-lock-variable-name-face)
2313 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2314 (1 font-lock-comment-face)
2315 (2 font-lock-function-name-face))
2316 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2317 "Font lock keywords used in `gdb-assembler-mode'.")
2319 (defun gdb-assembler-mode ()
2320 "Major mode for viewing code assembler.
2322 \\{gdb-assembler-mode-map}"
2323 (kill-all-local-variables)
2324 (setq major-mode 'gdb-assembler-mode)
2325 (setq mode-name "Machine")
2326 (setq gdb-overlay-arrow-position nil)
2327 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2328 (put 'gdb-overlay-arrow-position 'overlay-arrow-string "=>")
2329 (setq fringes-outside-margins t)
2330 (setq buffer-read-only t)
2331 (use-local-map gdb-assembler-mode-map)
2332 (gdb-invalidate-assembler)
2333 (set (make-local-variable 'font-lock-defaults)
2334 '(gdb-assembler-font-lock-keywords))
2335 (run-mode-hooks 'gdb-assembler-mode-hook)
2336 'gdb-invalidate-assembler)
2338 (defun gdb-assembler-buffer-name ()
2339 (with-current-buffer gud-comint-buffer
2340 (concat "*Machine Code " (gdb-get-target-string) "*")))
2342 (defun gdb-display-assembler-buffer ()
2343 "Display disassembly view."
2344 (interactive)
2345 (gdb-display-buffer
2346 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2348 (defun gdb-frame-assembler-buffer ()
2349 "Display disassembly view in a new frame."
2350 (interactive)
2351 (let ((special-display-regexps (append special-display-regexps '(".*")))
2352 (special-display-frame-alist gdb-frame-parameters))
2353 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer))))
2355 ;; modified because if gdb-current-address has changed value a new command
2356 ;; must be enqueued to update the buffer with the new output
2357 (defun gdb-invalidate-assembler (&optional ignored)
2358 (if (gdb-get-buffer 'gdb-assembler-buffer)
2359 (progn
2360 (unless (string-equal gdb-current-frame gdb-previous-frame)
2361 (if (or (not (member 'gdb-invalidate-assembler
2362 gdb-pending-triggers))
2363 (not (string-equal gdb-current-address
2364 gdb-previous-address)))
2365 (progn
2366 ;; take previous disassemble command off the queue
2367 (with-current-buffer gud-comint-buffer
2368 (let ((queue gdb-input-queue))
2369 (dolist (item queue)
2370 (if (equal (cdr item) '(gdb-assembler-handler))
2371 (setq gdb-input-queue
2372 (delete item gdb-input-queue))))))
2373 (gdb-enqueue-input
2374 (list (concat gdb-server-prefix "disassemble " gdb-current-address "\n")
2375 'gdb-assembler-handler))
2376 (push 'gdb-invalidate-assembler gdb-pending-triggers)
2377 (setq gdb-previous-address gdb-current-address)
2378 (setq gdb-previous-frame gdb-current-frame)))))))
2380 (defun gdb-get-current-frame ()
2381 (if (not (member 'gdb-get-current-frame gdb-pending-triggers))
2382 (progn
2383 (gdb-enqueue-input
2384 (list (concat gdb-server-prefix "info frame\n") 'gdb-frame-handler))
2385 (push 'gdb-get-current-frame
2386 gdb-pending-triggers))))
2388 (defun gdb-frame-handler ()
2389 (setq gdb-pending-triggers
2390 (delq 'gdb-get-current-frame gdb-pending-triggers))
2391 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer)
2392 (goto-char (point-min))
2393 (if (looking-at "Stack level \\([0-9]+\\)")
2394 (setq gdb-current-stack-level (match-string 1)))
2395 (forward-line)
2396 (if (looking-at ".*=\\s-+0x\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*?\\);? ")
2397 (progn
2398 (setq gdb-current-frame (match-string 2))
2399 (if (gdb-get-buffer 'gdb-locals-buffer)
2400 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2401 (setq mode-name (concat "Locals:" gdb-current-frame))))
2402 (let ((address (match-string 1)))
2403 ;; remove leading 0s from output of info frame command.
2404 (if (string-match "^0+\\(.*\\)" address)
2405 (setq gdb-current-address
2406 (concat "0x" (match-string 1 address)))
2407 (setq gdb-current-address (concat "0x" address))))
2408 (if (not (re-search-forward "(\\S-*:[0-9]*);" nil t))
2409 ;;update with new frame for machine code if necessary
2410 (gdb-invalidate-assembler)))))
2411 (if (re-search-forward " source language \\(\\S-*\\)\." nil t)
2412 (setq gdb-current-language (match-string 1))))
2414 (provide 'gdb-ui)
2416 ;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352
2417 ;;; gdb-ui.el ends here