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