comparison lisp/gdb-ui.el @ 48921:3aa5ba679145

Remove the concept of an instance. This means that a lot of functions have been renamed. Accessors are prefixed with gdb-get, setters with gdb-set and the word instance has been removed from many function and variable names. (gdb-display-buffer): Protect source buffer as well as GUD buffer when requesting new buffers. (gdb-source-info): Two changes : Don't create display buffer automatically, compute source window correctly.
author Nick Roberts <nickrob@snap.net.nz>
date Sat, 21 Dec 2002 23:00:12 +0000
parents f774c94b3b5e
children 1abfa35a3a5a
comparison
equal deleted inserted replaced
48920:e6c22638134b 48921:3aa5ba679145
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA. 24 ;; Boston, MA 02111-1307, USA.
25 25
26 ;;; Commentary: 26 ;;; Commentary:
27 27
28 ;; This file is based on gdba.el written by Jim Kingdon from GDB 5.0 and uses 28 ;; This file is based on gdba.el from GDB 5.0 written by Jim Kingdon and uses
29 ;; GDB's annotation interface. You don't need to know about annotations but 29 ;; GDB's annotation interface. You don't need to know about annotations but
30 ;; If you are interested developing this mode see the Annotations section in 30 ;; If you are interested developing this mode see the Annotations section in
31 ;; the GDB info manual). 31 ;; the GDB info manual).
32 ;; 32 ;;
33 ;; It has been extended to use features of Emacs 21 such as the display 33 ;; It has been extended to use features of Emacs 21 such as the display
34 ;; margin for breakpoints and the toolbar. It also has new buffers and lots 34 ;; margin for breakpoints and the toolbar. It also has new buffers and lots
35 ;; of other new features such as formatted auto-display of arrays and 35 ;; of other new features such as formatted auto-display of arrays and
36 ;; structures (see the GDB-UI in the Emacs info manual). 36 ;; structures (see the GDB-UI section in the Emacs info manual).
37 ;;
38 ;; Known Bugs: Does not auto-display arrays of structures or structures
39 ;; containing arrays properly.
37 40
38 ;;; Code: 41 ;;; Code:
39 42
40 (require 'gud) 43 (require 'gud)
41 44
126 (setq gdb-main-or-pc "main") 129 (setq gdb-main-or-pc "main")
127 (setq gdb-current-address nil) 130 (setq gdb-current-address nil)
128 (setq gdb-display-in-progress nil) 131 (setq gdb-display-in-progress nil)
129 (setq gdb-dive nil) 132 (setq gdb-dive nil)
130 133
131 (mapc 'make-local-variable gdb-instance-variables) 134 (mapc 'make-local-variable gdb-variables)
132 (setq gdb-buffer-type 'gdba) 135 (setq gdb-buffer-type 'gdba)
133 136
134 (gdb-clear-inferior-io) 137 (gdb-clear-inferior-io)
135 138
136 ;; find source file and compilation directory here 139 ;; find source file and compilation directory here
137 (gdb-instance-enqueue-input (list "server list\n" 'ignore)) 140 (gdb-enqueue-input (list "server list\n" 'ignore))
138 (gdb-instance-enqueue-input (list "server info source\n" 141 (gdb-enqueue-input (list "server info source\n"
139 'gdb-source-info)) 142 'gdb-source-info))
140 143
141 (run-hooks 'gdba-mode-hook)) 144 (run-hooks 'gdba-mode-hook))
142 145
143 (defun gud-display () 146 (defun gud-display ()
144 "Display (possibly dereferenced) C expression at point." 147 "Display (possibly dereferenced) C expression at point."
145 (interactive) 148 (interactive)
146 (save-excursion 149 (save-excursion
147 (let ((expr (gud-find-c-expr))) 150 (let ((expr (gud-find-c-expr)))
148 (gdb-instance-enqueue-input 151 (gdb-enqueue-input
149 (list (concat "server whatis " expr "\n") 152 (list (concat "server whatis " expr "\n")
150 `(lambda () (gud-display1 ,expr))))))) 153 `(lambda () (gud-display1 ,expr)))))))
151 154
152 (defun gud-display1 (expr) 155 (defun gud-display1 (expr)
153 (goto-char (point-min)) 156 (goto-char (point-min))
154 (if (re-search-forward "\*" nil t) 157 (if (re-search-forward "\*" nil t)
155 (gdb-instance-enqueue-input 158 (gdb-enqueue-input
156 (list (concat "server display* " expr "\n") 'ignore)) 159 (list (concat "server display* " expr "\n") 'ignore))
157 (gdb-instance-enqueue-input 160 (gdb-enqueue-input
158 (list (concat "server display " expr "\n") 'ignore)))) 161 (list (concat "server display " expr "\n") 'ignore))))
159 162
160 163
161 ;; The completion process filter is installed temporarily to slurp the 164 ;; The completion process filter is installed temporarily to slurp the
162 ;; output of GDB up to the next prompt and build the completion list. 165 ;; output of GDB up to the next prompt and build the completion list.
163 ;; It must also handle annotations. 166 ;; It must also handle annotations.
164 167
165 168
166 ;; ====================================================================== 169 ;; ======================================================================
167 ;; 170 ;;
168 ;; In this world, there are gdb instance objects (of unspecified 171 ;; In this world, there are gdb variables (of unspecified
169 ;; representation) and buffers associated with those objects. 172 ;; representation) and buffers associated with those objects.
170 ;; 173 ;; The list of variables is built up by the expansions of
171 174 ;; def-gdb-variable
172 ;; 175
173 ;; gdb-instance objects 176 (defvar gdb-variables '()
174 ;; 177 "A list of variables that are local to the GUD buffer.")
175
176 (defvar gdb-instance-variables '()
177 "A list of variables that are local to the GUD buffer associated
178 with a gdb instance.")
179
180 ;;; The list of instance variables is built up by the expansions of
181 ;;; DEF-GDB-VARIABLE
182 ;;;
183 178
184 (defmacro def-gdb-var (root-symbol &optional default doc) 179 (defmacro def-gdb-var (root-symbol &optional default doc)
185 (let* ((root (symbol-name root-symbol)) 180 (let* ((root (symbol-name root-symbol))
186 (accessor (intern (concat "gdb-instance-" root))) 181 (accessor (intern (concat "gdb-get-" root)))
187 (setter (intern (concat "set-gdb-instance-" root))) 182 (setter (intern (concat "gdb-set-" root)))
188 (name (intern (concat "gdb-" root)))) 183 (name (intern (concat "gdb-" root))))
189 `(progn 184 `(progn
190 (defvar ,name ,default ,doc) 185 (defvar ,name ,default ,doc)
191 (if (not (memq ',name gdb-instance-variables)) 186 (if (not (memq ',name gdb-variables))
192 (push ',name gdb-instance-variables)) 187 (push ',name gdb-variables))
193 (defun ,accessor () 188 (defun ,accessor ()
194 (buffer-local-value ',name gud-comint-buffer)) 189 (buffer-local-value ',name gud-comint-buffer))
195 (defun ,setter (val) 190 (defun ,setter (val)
196 (with-current-buffer gud-comint-buffer 191 (with-current-buffer gud-comint-buffer
197 (setq ,name val)))))) 192 (setq ,name val))))))
198 193
199 (def-gdb-var buffer-type nil 194 (def-gdb-var buffer-type nil
200 "One of the symbols bound in gdb-instance-buffer-rules") 195 "One of the symbols bound in gdb-buffer-rules")
201 196
202 (def-gdb-var burst "" 197 (def-gdb-var burst ""
203 "A string of characters from gdb that have not yet been processed.") 198 "A string of characters from gdb that have not yet been processed.")
204 199
205 (def-gdb-var input-queue () 200 (def-gdb-var input-queue ()
236 231
237 (def-gdb-var pending-triggers '() 232 (def-gdb-var pending-triggers '()
238 "A list of trigger functions that have run later than their output 233 "A list of trigger functions that have run later than their output
239 handlers.") 234 handlers.")
240 235
241 ;; end of instance vars 236 ;; end of gdb variables
242 237
243 (defun gdb-instance-target-string () 238 (defun gdb-get-target-string ()
244 (with-current-buffer gud-comint-buffer 239 (with-current-buffer gud-comint-buffer
245 gud-target-name)) 240 gud-target-name))
246 241
247 242
248 ;; 243 ;;
249 ;; Instance Buffers. 244 ;; gdb buffers.
250 ;;
251
252 ;; More than one buffer can be associated with a gdb instance.
253 ;; 245 ;;
254 ;; Each buffer has a TYPE -- a symbol that identifies the function 246 ;; Each buffer has a TYPE -- a symbol that identifies the function
255 ;; of that particular buffer. 247 ;; of that particular buffer.
256 ;; 248 ;;
257 ;; The usual gdb interaction buffer is given the type `gdba' and 249 ;; The usual gdb interaction buffer is given the type `gdba' and
258 ;; is constructed specially. 250 ;; is constructed specially.
259 ;; 251 ;;
260 ;; Others are constructed by gdb-get-create-instance-buffer and 252 ;; Others are constructed by gdb-get-create-buffer and
261 ;; named according to the rules set forth in the gdb-instance-buffer-rules-assoc 253 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
262 254
263 (defvar gdb-instance-buffer-rules-assoc '()) 255 (defvar gdb-buffer-rules-assoc '())
264 256
265 (defun gdb-get-instance-buffer (key) 257 (defun gdb-get-buffer (key)
266 "Return the instance buffer tagged with type KEY. 258 "Return the gdb buffer tagged with type KEY.
267 The key should be one of the cars in `gdb-instance-buffer-rules-assoc'." 259 The key should be one of the cars in `gdb-buffer-rules-assoc'."
268 (save-excursion 260 (save-excursion
269 (gdb-look-for-tagged-buffer key (buffer-list)))) 261 (gdb-look-for-tagged-buffer key (buffer-list))))
270 262
271 (defun gdb-get-create-instance-buffer (key) 263 (defun gdb-get-create-buffer (key)
272 "Create a new gdb instance buffer of the type specified by KEY. 264 "Create a new gdb buffer of the type specified by KEY.
273 The key should be one of the cars in `gdb-instance-buffer-rules-assoc'." 265 The key should be one of the cars in `gdb-buffer-rules-assoc'."
274 (or (gdb-get-instance-buffer key) 266 (or (gdb-get-buffer key)
275 (let* ((rules (assoc key gdb-instance-buffer-rules-assoc)) 267 (let* ((rules (assoc key gdb-buffer-rules-assoc))
276 (name (funcall (gdb-rules-name-maker rules))) 268 (name (funcall (gdb-rules-name-maker rules)))
277 (new (get-buffer-create name))) 269 (new (get-buffer-create name)))
278 (with-current-buffer new 270 (with-current-buffer new
279 ;; FIXME: This should be set after calling the function, since the 271 ;; FIXME: This should be set after calling the function, since the
280 ;; function should run kill-all-local-variables. 272 ;; function should run kill-all-local-variables.
300 ;; 292 ;;
301 ;; This assoc maps buffer type symbols to rules. Each rule is a list of 293 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
302 ;; at least one and possible more functions. The functions have these 294 ;; at least one and possible more functions. The functions have these
303 ;; roles in defining a buffer type: 295 ;; roles in defining a buffer type:
304 ;; 296 ;;
305 ;; NAME - take an instance, return a name for this type buffer for that 297 ;; NAME - Return a name for this buffer type.
306 ;; instance. 298 ;;
307 ;; The remaining function(s) are optional: 299 ;; The remaining function(s) are optional:
308 ;; 300 ;;
309 ;; MODE - called in new new buffer with no arguments, should establish 301 ;; MODE - called in a new buffer with no arguments, should establish
310 ;; the proper mode for the buffer. 302 ;; the proper mode for the buffer.
311 ;; 303 ;;
312 304
313 (defun gdb-set-instance-buffer-rules (buffer-type &rest rules) 305 (defun gdb-set-buffer-rules (buffer-type &rest rules)
314 (let ((binding (assoc buffer-type gdb-instance-buffer-rules-assoc))) 306 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc)))
315 (if binding 307 (if binding
316 (setcdr binding rules) 308 (setcdr binding rules)
317 (push (cons buffer-type rules) 309 (push (cons buffer-type rules)
318 gdb-instance-buffer-rules-assoc)))) 310 gdb-buffer-rules-assoc))))
319 311
320 ;; GUD buffers are an exception to the rules 312 ;; GUD buffers are an exception to the rules
321 (gdb-set-instance-buffer-rules 'gdba 'error) 313 (gdb-set-buffer-rules 'gdba 'error)
322 314
323 ;; 315 ;;
324 ;; partial-output buffers 316 ;; partial-output buffers
325 ;; 317 ;;
326 ;; These accumulate output from a command executed on 318 ;; These accumulate output from a command executed on
327 ;; behalf of emacs (rather than the user). 319 ;; behalf of emacs (rather than the user).
328 ;; 320 ;;
329 321
330 (gdb-set-instance-buffer-rules 'gdb-partial-output-buffer 322 (gdb-set-buffer-rules 'gdb-partial-output-buffer
331 'gdb-partial-output-name) 323 'gdb-partial-output-name)
332 324
333 (defun gdb-partial-output-name () 325 (defun gdb-partial-output-name ()
334 (concat "*partial-output-" 326 (concat "*partial-output-"
335 (gdb-instance-target-string) 327 (gdb-get-target-string)
336 "*")) 328 "*"))
337 329
338 330
339 (gdb-set-instance-buffer-rules 'gdb-inferior-io 331 (gdb-set-buffer-rules 'gdb-inferior-io
340 'gdb-inferior-io-name 332 'gdb-inferior-io-name
341 'gdb-inferior-io-mode) 333 'gdb-inferior-io-mode)
342 334
343 (defun gdb-inferior-io-name () 335 (defun gdb-inferior-io-name ()
344 (concat "*input/output of " 336 (concat "*input/output of "
345 (gdb-instance-target-string) 337 (gdb-get-target-string)
346 "*")) 338 "*"))
347 339
348 (defvar gdb-inferior-io-mode-map 340 (defvar gdb-inferior-io-mode-map
349 (let ((map (make-sparse-keymap))) 341 (let ((map (make-sparse-keymap)))
350 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt) 342 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt)
400 ;; gdb communications 392 ;; gdb communications
401 ;; 393 ;;
402 394
403 ;; INPUT: things sent to gdb 395 ;; INPUT: things sent to gdb
404 ;; 396 ;;
405 ;; Each instance has a high and low priority 397 ;; There is a high and low priority input queue. Low priority input is sent
406 ;; input queue. Low priority input is sent only 398 ;; only when the high priority queue is idle.
407 ;; when the high priority queue is idle. 399 ;;
408 ;; 400 ;; The queues are lists. Each element is either a string (indicating user or
409 ;; The queues are lists. Each element is either 401 ;; user-like input) or a list of the form:
410 ;; a string (indicating user or user-like input)
411 ;; or a list of the form:
412 ;; 402 ;;
413 ;; (INPUT-STRING HANDLER-FN) 403 ;; (INPUT-STRING HANDLER-FN)
414 ;; 404 ;;
415 ;; 405 ;; The handler function will be called from the partial-output buffer when the
416 ;; The handler function will be called from the 406 ;; command completes. This is the way to write commands which invoke gdb
417 ;; partial-output buffer when the command completes. 407 ;; commands autonomously.
418 ;; This is the way to write commands which
419 ;; invoke gdb commands autonomously.
420 ;; 408 ;;
421 ;; These lists are consumed tail first. 409 ;; These lists are consumed tail first.
422 ;; 410 ;;
423 411
424 (defun gdb-send (proc string) 412 (defun gdb-send (proc string)
425 "A comint send filter for gdb. 413 "A comint send filter for gdb.
426 This filter may simply queue output for a later time." 414 This filter may simply queue output for a later time."
427 (gdb-instance-enqueue-input (concat string "\n"))) 415 (gdb-enqueue-input (concat string "\n")))
428 416
429 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it 417 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it
430 ;; is a query, or other non-top-level prompt. To guarantee stuff will get 418 ;; is a query, or other non-top-level prompt. To guarantee stuff will get
431 ;; sent to the top-level prompt, currently it must be put in the idle queue. 419 ;; sent to the top-level prompt, currently it must be put in the idle queue.
432 ;; ^^^^^^^^^ 420 ;; ^^^^^^^^^
433 ;; [This should encourage gdb extensions that invoke gdb commands to let 421 ;; [This should encourage gdb extensions that invoke gdb commands to let
434 ;; the user go first; it is not a bug. -t] 422 ;; the user go first; it is not a bug. -t]
435 ;; 423 ;;
436 424
437 (defun gdb-instance-enqueue-input (item) 425 (defun gdb-enqueue-input (item)
438 (if (gdb-instance-prompting) 426 (if (gdb-get-prompting)
439 (progn 427 (progn
440 (gdb-send-item item) 428 (gdb-send-item item)
441 (set-gdb-instance-prompting nil)) 429 (gdb-set-prompting nil))
442 (set-gdb-instance-input-queue 430 (gdb-set-input-queue
443 (cons item (gdb-instance-input-queue))))) 431 (cons item (gdb-get-input-queue)))))
444 432
445 (defun gdb-instance-dequeue-input () 433 (defun gdb-dequeue-input ()
446 (let ((queue (gdb-instance-input-queue))) 434 (let ((queue (gdb-get-input-queue)))
447 (and queue 435 (and queue
448 (if (not (cdr queue)) 436 (if (not (cdr queue))
449 (let ((answer (car queue))) 437 (let ((answer (car queue)))
450 (set-gdb-instance-input-queue '()) 438 (gdb-set-input-queue '())
451 answer) 439 answer)
452 (gdb-take-last-elt queue))))) 440 (gdb-take-last-elt queue)))))
453 441
454 (defun gdb-instance-enqueue-idle-input (item) 442 (defun gdb-enqueue-idle-input (item)
455 (if (and (gdb-instance-prompting) 443 (if (and (gdb-get-prompting)
456 (not (gdb-instance-input-queue))) 444 (not (gdb-get-input-queue)))
457 (progn 445 (progn
458 (gdb-send-item item) 446 (gdb-send-item item)
459 (set-gdb-instance-prompting nil)) 447 (gdb-set-prompting nil))
460 (set-gdb-instance-idle-input-queue 448 (gdb-set-idle-input-queue
461 (cons item (gdb-instance-idle-input-queue))))) 449 (cons item (gdb-get-idle-input-queue)))))
462 450
463 (defun gdb-instance-dequeue-idle-input () 451 (defun gdb-dequeue-idle-input ()
464 (let ((queue (gdb-instance-idle-input-queue))) 452 (let ((queue (gdb-get-idle-input-queue)))
465 (and queue 453 (and queue
466 (if (not (cdr queue)) 454 (if (not (cdr queue))
467 (let ((answer (car queue))) 455 (let ((answer (car queue)))
468 (set-gdb-instance-idle-input-queue '()) 456 (gdb-set-idle-input-queue '())
469 answer) 457 answer)
470 (gdb-take-last-elt queue))))) 458 (gdb-take-last-elt queue)))))
471 459
472 ;; Don't use this in general. 460 ;; Don't use this in general.
473 (defun gdb-take-last-elt (l) 461 (defun gdb-take-last-elt (l)
474 (if (cdr (cdr l)) 462 (if (cdr (cdr l))
475 (gdb-take-last-elt (cdr l)) 463 (gdb-take-last-elt (cdr l))
494 ;; any newlines. 482 ;; any newlines.
495 ;; 483 ;;
496 484
497 (defcustom gud-gdba-command-name "gdb -annotate=2" 485 (defcustom gud-gdba-command-name "gdb -annotate=2"
498 "Default command to execute an executable under the GDB-UI debugger." 486 "Default command to execute an executable under the GDB-UI debugger."
499 :type 'string 487 :type 'string
500 :group 'gud) 488 :group 'gud)
501 489
502 (defvar gdb-annotation-rules 490 (defvar gdb-annotation-rules
503 '(("frames-invalid" gdb-invalidate-frame-and-assembler) 491 '(("frames-invalid" gdb-invalidate-frame-and-assembler)
504 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler) 492 ("breakpoints-invalid" gdb-invalidate-breakpoints-and-assembler)
505 ("pre-prompt" gdb-pre-prompt) 493 ("pre-prompt" gdb-pre-prompt)
548 (gdb-invalidate-assembler)) 536 (gdb-invalidate-assembler))
549 537
550 (defun gdb-prompt (ignored) 538 (defun gdb-prompt (ignored)
551 "An annotation handler for `prompt'. 539 "An annotation handler for `prompt'.
552 This sends the next command (if any) to gdb." 540 This sends the next command (if any) to gdb."
553 (let ((sink (gdb-instance-output-sink))) 541 (let ((sink (gdb-get-output-sink)))
554 (cond 542 (cond
555 ((eq sink 'user) t) 543 ((eq sink 'user) t)
556 ((eq sink 'post-emacs) 544 ((eq sink 'post-emacs)
557 (set-gdb-instance-output-sink 'user)) 545 (gdb-set-output-sink 'user))
558 (t 546 (t
559 (set-gdb-instance-output-sink 'user) 547 (gdb-set-output-sink 'user)
560 (error "Phase error in gdb-prompt (got %s)" sink)))) 548 (error "Phase error in gdb-prompt (got %s)" sink))))
561 (let ((highest (gdb-instance-dequeue-input))) 549 (let ((highest (gdb-dequeue-input)))
562 (if highest 550 (if highest
563 (gdb-send-item highest) 551 (gdb-send-item highest)
564 (let ((lowest (gdb-instance-dequeue-idle-input))) 552 (let ((lowest (gdb-dequeue-idle-input)))
565 (if lowest 553 (if lowest
566 (gdb-send-item lowest) 554 (gdb-send-item lowest)
567 (progn 555 (progn
568 (set-gdb-instance-prompting t) 556 (gdb-set-prompting t)
569 (gud-display-frame))))))) 557 (gud-display-frame)))))))
570 558
571 (defun gdb-subprompt (ignored) 559 (defun gdb-subprompt (ignored)
572 "An annotation handler for non-top-level prompts." 560 "An annotation handler for non-top-level prompts."
573 (let ((highest (gdb-instance-dequeue-input))) 561 (let ((highest (gdb-dequeue-input)))
574 (if highest 562 (if highest
575 (gdb-send-item highest) 563 (gdb-send-item highest)
576 (set-gdb-instance-prompting t)))) 564 (gdb-set-prompting t))))
577 565
578 (defun gdb-send-item (item) 566 (defun gdb-send-item (item)
579 (set-gdb-instance-current-item item) 567 (gdb-set-current-item item)
580 (if (stringp item) 568 (if (stringp item)
581 (progn 569 (progn
582 (set-gdb-instance-output-sink 'user) 570 (gdb-set-output-sink 'user)
583 (process-send-string (get-buffer-process gud-comint-buffer) item)) 571 (process-send-string (get-buffer-process gud-comint-buffer) item))
584 (progn 572 (progn
585 (gdb-clear-partial-output) 573 (gdb-clear-partial-output)
586 (set-gdb-instance-output-sink 'pre-emacs) 574 (gdb-set-output-sink 'pre-emacs)
587 (process-send-string (get-buffer-process gud-comint-buffer) 575 (process-send-string (get-buffer-process gud-comint-buffer)
588 (car item))))) 576 (car item)))))
589 577
590 (defun gdb-pre-prompt (ignored) 578 (defun gdb-pre-prompt (ignored)
591 "An annotation handler for `pre-prompt'. This terminates the collection of 579 "An annotation handler for `pre-prompt'. This terminates the collection of
592 output from a previous command if that happens to be in effect." 580 output from a previous command if that happens to be in effect."
593 (let ((sink (gdb-instance-output-sink))) 581 (let ((sink (gdb-get-output-sink)))
594 (cond 582 (cond
595 ((eq sink 'user) t) 583 ((eq sink 'user) t)
596 ((eq sink 'emacs) 584 ((eq sink 'emacs)
597 (set-gdb-instance-output-sink 'post-emacs) 585 (gdb-set-output-sink 'post-emacs)
598 (let ((handler 586 (let ((handler
599 (car (cdr (gdb-instance-current-item))))) 587 (car (cdr (gdb-get-current-item)))))
600 (save-excursion 588 (save-excursion
601 (set-buffer (gdb-get-create-instance-buffer 589 (set-buffer (gdb-get-create-buffer
602 'gdb-partial-output-buffer)) 590 'gdb-partial-output-buffer))
603 (funcall handler)))) 591 (funcall handler))))
604 (t 592 (t
605 (set-gdb-instance-output-sink 'user) 593 (gdb-set-output-sink 'user)
606 (error "Output sink phase error 1"))))) 594 (error "Output sink phase error 1")))))
607 595
608 (defun gdb-starting (ignored) 596 (defun gdb-starting (ignored)
609 "An annotation handler for `starting'. This says that I/O for the 597 "An annotation handler for `starting'. This says that I/O for the
610 subprocess is now the program being debugged, not GDB." 598 subprocess is now the program being debugged, not GDB."
611 (let ((sink (gdb-instance-output-sink))) 599 (let ((sink (gdb-get-output-sink)))
612 (cond 600 (cond
613 ((eq sink 'user) 601 ((eq sink 'user)
614 (progn 602 (progn
615 (setq gud-running t) 603 (setq gud-running t)
616 (set-gdb-instance-output-sink 'inferior))) 604 (gdb-set-output-sink 'inferior)))
617 (t (error "Unexpected `starting' annotation"))))) 605 (t (error "Unexpected `starting' annotation")))))
618 606
619 (defun gdb-stopping (ignored) 607 (defun gdb-stopping (ignored)
620 "An annotation handler for `exited' and other annotations which say that I/O 608 "An annotation handler for `exited' and other annotations which say that I/O
621 for the subprocess is now GDB, not the program being debugged." 609 for the subprocess is now GDB, not the program being debugged."
622 (let ((sink (gdb-instance-output-sink))) 610 (let ((sink (gdb-get-output-sink)))
623 (cond 611 (cond
624 ((eq sink 'inferior) 612 ((eq sink 'inferior)
625 (set-gdb-instance-output-sink 'user)) 613 (gdb-set-output-sink 'user))
626 (t (error "Unexpected stopping annotation"))))) 614 (t (error "Unexpected stopping annotation")))))
627 615
628 (defun gdb-stopped (ignored) 616 (defun gdb-stopped (ignored)
629 "An annotation handler for `stopped'. It is just like gdb-stopping, except 617 "An annotation handler for `stopped'. It is just like gdb-stopping, except
630 that if we already set the output sink to 'user in gdb-stopping, that is fine." 618 that if we already set the output sink to 'user in gdb-stopping, that is fine."
631 (setq gud-running nil) 619 (setq gud-running nil)
632 (let ((sink (gdb-instance-output-sink))) 620 (let ((sink (gdb-get-output-sink)))
633 (cond 621 (cond
634 ((eq sink 'inferior) 622 ((eq sink 'inferior)
635 (set-gdb-instance-output-sink 'user)) 623 (gdb-set-output-sink 'user))
636 ((eq sink 'user) t) 624 ((eq sink 'user) t)
637 (t (error "Unexpected stopped annotation"))))) 625 (t (error "Unexpected stopped annotation")))))
638 626
639 (defun gdb-frame-begin (ignored) 627 (defun gdb-frame-begin (ignored)
640 (let ((sink (gdb-instance-output-sink))) 628 (let ((sink (gdb-get-output-sink)))
641 (cond 629 (cond
642 ((eq sink 'inferior) 630 ((eq sink 'inferior)
643 (set-gdb-instance-output-sink 'user)) 631 (gdb-set-output-sink 'user))
644 ((eq sink 'user) t) 632 ((eq sink 'user) t)
645 ((eq sink 'emacs) t) 633 ((eq sink 'emacs) t)
646 (t (error "Unexpected frame-begin annotation (%S)" sink))))) 634 (t (error "Unexpected frame-begin annotation (%S)" sink)))))
647 635
648 (defun gdb-post-prompt (ignored) 636 (defun gdb-post-prompt (ignored)
649 "An annotation handler for `post-prompt'. This begins the collection of 637 "An annotation handler for `post-prompt'. This begins the collection of
650 output from the current command if that happens to be appropriate." 638 output from the current command if that happens to be appropriate."
651 (if (not (gdb-instance-pending-triggers)) 639 (if (not (gdb-get-pending-triggers))
652 (progn 640 (progn
653 (gdb-invalidate-registers ignored) 641 (gdb-invalidate-registers ignored)
654 (gdb-invalidate-locals ignored) 642 (gdb-invalidate-locals ignored)
655 (gdb-invalidate-display ignored))) 643 (gdb-invalidate-display ignored)))
656 (let ((sink (gdb-instance-output-sink))) 644 (let ((sink (gdb-get-output-sink)))
657 (cond 645 (cond
658 ((eq sink 'user) t) 646 ((eq sink 'user) t)
659 ((eq sink 'pre-emacs) 647 ((eq sink 'pre-emacs)
660 (set-gdb-instance-output-sink 'emacs)) 648 (gdb-set-output-sink 'emacs))
661 (t 649 (t
662 (set-gdb-instance-output-sink 'user) 650 (gdb-set-output-sink 'user)
663 (error "Output sink phase error 3"))))) 651 (error "Output sink phase error 3")))))
664 652
665 ;; If we get an error whilst evaluating one of the expressions 653 ;; If we get an error whilst evaluating one of the expressions
666 ;; we won't get the display-end annotation. Set the sink back to 654 ;; we won't get the display-end annotation. Set the sink back to
667 ;; user to make sure that the error message is seen 655 ;; user to make sure that the error message is seen
668 (defun gdb-error-begin (ignored) 656 (defun gdb-error-begin (ignored)
669 (set-gdb-instance-output-sink 'user)) 657 (gdb-set-output-sink 'user))
670 658
671 (defun gdb-display-begin (ignored) 659 (defun gdb-display-begin (ignored)
672 (if (gdb-get-instance-buffer 'gdb-display-buffer) 660 (gdb-set-output-sink 'emacs)
673 (progn 661 (gdb-clear-partial-output)
674 (set-gdb-instance-output-sink 'emacs) 662 (setq gdb-display-in-progress t))
675 (gdb-clear-partial-output)
676 (setq gdb-display-in-progress t))
677 (set-gdb-instance-output-sink 'user)))
678 663
679 (defvar gdb-expression-buffer-name) 664 (defvar gdb-expression-buffer-name)
680 (defvar gdb-display-number) 665 (defvar gdb-display-number)
681 (defvar gdb-dive-display-number) 666 (defvar gdb-dive-display-number)
682 667
683 (defun gdb-display-number-end (ignored) 668 (defun gdb-display-number-end (ignored)
684 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 669 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
685 (setq gdb-display-number (buffer-string)) 670 (setq gdb-display-number (buffer-string))
686 (setq gdb-expression-buffer-name 671 (setq gdb-expression-buffer-name
687 (concat "*display " gdb-display-number "*")) 672 (concat "*display " gdb-display-number "*"))
688 (save-excursion 673 (save-excursion
689 (if (progn 674 (if (progn
705 (gdb-expressions-mode) 690 (gdb-expressions-mode)
706 (make-frame '((height . 20) (width . 40) 691 (make-frame '((height . 20) (width . 40)
707 (tool-bar-lines . nil) 692 (tool-bar-lines . nil)
708 (menu-bar-lines . nil) 693 (menu-bar-lines . nil)
709 (minibuffer . nil))))))) 694 (minibuffer . nil)))))))
710 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 695 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
711 (setq gdb-dive nil)) 696 (setq gdb-dive nil))
712 697
713 (defvar gdb-current-frame nil) 698 (defvar gdb-current-frame nil)
714 (defvar gdb-nesting-level) 699 (defvar gdb-nesting-level)
715 (defvar gdb-expression) 700 (defvar gdb-expression)
719 (defun gdb-delete-line () 704 (defun gdb-delete-line ()
720 "Delete the current line." 705 "Delete the current line."
721 (delete-region (line-beginning-position) (line-beginning-position 2))) 706 (delete-region (line-beginning-position) (line-beginning-position 2)))
722 707
723 (defun gdb-display-end (ignored) 708 (defun gdb-display-end (ignored)
724 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 709 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
725 (goto-char (point-min)) 710 (goto-char (point-min))
726 (search-forward ": ") 711 (search-forward ": ")
727 (looking-at "\\(.*?\\) =") 712 (looking-at "\\(.*?\\) =")
728 (let ((char "") 713 (let ((char "")
729 (gdb-temp-value (match-string 1))) 714 (gdb-temp-value (match-string 1)))
748 (save-excursion 733 (save-excursion
749 (set-buffer gdb-expression-buffer-name) 734 (set-buffer gdb-expression-buffer-name)
750 (setq buffer-read-only nil) 735 (setq buffer-read-only nil)
751 (delete-region (point-min) (point-max)) 736 (delete-region (point-min) (point-max))
752 (insert-buffer-substring 737 (insert-buffer-substring
753 (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 738 (gdb-get-buffer 'gdb-partial-output-buffer))
754 (setq buffer-read-only t))) 739 (setq buffer-read-only t)))
755 ;; display expression name... 740 ;; display expression name...
756 (goto-char (point-min)) 741 (goto-char (point-min))
757 (let ((start (progn (point))) 742 (let ((start (progn (point)))
758 (end (progn (end-of-line) (point)))) 743 (end (progn (end-of-line) (point))))
759 (save-excursion 744 (save-excursion
760 (set-buffer gdb-expression-buffer-name) 745 (set-buffer gdb-expression-buffer-name)
761 (setq buffer-read-only nil) 746 (setq buffer-read-only nil)
762 (delete-region (point-min) (point-max)) 747 (delete-region (point-min) (point-max))
763 (insert-buffer-substring (gdb-get-instance-buffer 748 (insert-buffer-substring (gdb-get-buffer
764 'gdb-partial-output-buffer) 749 'gdb-partial-output-buffer)
765 start end) 750 start end)
766 (insert "\n"))) 751 (insert "\n")))
767 (goto-char (point-min)) 752 (goto-char (point-min))
768 (re-search-forward "##" nil t) 753 (re-search-forward "##" nil t)
775 (if (looking-at "field-begin \\(.\\)") 760 (if (looking-at "field-begin \\(.\\)")
776 (progn 761 (progn
777 (setq gdb-annotation-arg (match-string 1)) 762 (setq gdb-annotation-arg (match-string 1))
778 (gdb-field-format-begin)))) 763 (gdb-field-format-begin))))
779 (save-excursion 764 (save-excursion
780 (set-buffer gdb-expression-buffer-name) 765 (set-buffer gdb-expression-buffer-name)
781 (if gdb-dive-display-number 766 (if gdb-dive-display-number
782 (progn 767 (progn
783 (setq buffer-read-only nil) 768 (setq buffer-read-only nil)
784 (goto-char (point-max)) 769 (goto-char (point-max))
785 (insert "\n") 770 (insert "\n")
786 (insert-text-button "[back]" 'type 'gdb-display-back) 771 (insert-text-button "[back]" 'type 'gdb-display-back)
787 (setq buffer-read-only t)))) 772 (setq buffer-read-only t))))
788 (gdb-clear-partial-output) 773 (gdb-clear-partial-output)
789 (set-gdb-instance-output-sink 'user) 774 (gdb-set-output-sink 'user)
790 (setq gdb-display-in-progress nil)) 775 (setq gdb-display-in-progress nil))
791 776
792 (define-button-type 'gdb-display-back 777 (define-button-type 'gdb-display-back
793 'help-echo (purecopy "mouse-2, RET: go back to previous display buffer") 778 'help-echo (purecopy "mouse-2, RET: go back to previous display buffer")
794 'action (lambda (button) (gdb-display-go-back))) 779 'action (lambda (button) (gdb-display-go-back)))
795 780
796 (defun gdb-display-go-back () 781 (defun gdb-display-go-back ()
797 ;; delete display so they don't accumulate and delete buffer 782 ;; delete display so they don't accumulate and delete buffer
798 (let ((number gdb-display-number)) 783 (let ((number gdb-display-number))
799 (gdb-instance-enqueue-input 784 (gdb-enqueue-input
800 (list (concat "server delete display " number "\n") 'ignore)) 785 (list (concat "server delete display " number "\n") 'ignore))
801 (switch-to-buffer (concat "*display " gdb-dive-display-number "*")) 786 (switch-to-buffer (concat "*display " gdb-dive-display-number "*"))
802 (kill-buffer (get-buffer (concat "*display " number "*"))))) 787 (kill-buffer (get-buffer (concat "*display " number "*")))))
803 788
804 ;; prefix annotations with ## and process whole output in one chunk 789 ;; prefix annotations with ## and process whole output in one chunk
808 ;; might also be useful for arrays of structures and structures with arrays. 793 ;; might also be useful for arrays of structures and structures with arrays.
809 (defun gdb-array-section-begin (args) 794 (defun gdb-array-section-begin (args)
810 (if gdb-display-in-progress 795 (if gdb-display-in-progress
811 (progn 796 (progn
812 (save-excursion 797 (save-excursion
813 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 798 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
814 (goto-char (point-max)) 799 (goto-char (point-max))
815 (insert (concat "\n##array-section-begin " args "\n")))))) 800 (insert (concat "\n##array-section-begin " args "\n"))))))
816 801
817 (defun gdb-array-section-end (ignored) 802 (defun gdb-array-section-end (ignored)
818 (if gdb-display-in-progress 803 (if gdb-display-in-progress
819 (progn 804 (progn
820 (save-excursion 805 (save-excursion
821 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 806 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
822 (goto-char (point-max)) 807 (goto-char (point-max))
823 (insert "\n##array-section-end\n"))))) 808 (insert "\n##array-section-end\n")))))
824 809
825 (defun gdb-field-begin (args) 810 (defun gdb-field-begin (args)
826 (if gdb-display-in-progress 811 (if gdb-display-in-progress
827 (progn 812 (progn
828 (save-excursion 813 (save-excursion
829 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 814 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
830 (goto-char (point-max)) 815 (goto-char (point-max))
831 (insert (concat "\n##field-begin " args "\n")))))) 816 (insert (concat "\n##field-begin " args "\n"))))))
832 817
833 (defun gdb-field-end (ignored) 818 (defun gdb-field-end (ignored)
834 (if gdb-display-in-progress 819 (if gdb-display-in-progress
835 (progn 820 (progn
836 (save-excursion 821 (save-excursion
837 (set-buffer (gdb-get-instance-buffer 'gdb-partial-output-buffer)) 822 (set-buffer (gdb-get-buffer 'gdb-partial-output-buffer))
838 (goto-char (point-max)) 823 (goto-char (point-max))
839 (insert "\n##field-end\n"))))) 824 (insert "\n##field-end\n")))))
840 825
841 (defun gdb-elt (ignored) 826 (defun gdb-elt (ignored)
842 (if gdb-display-in-progress 827 (if gdb-display-in-progress
902 ;; * not needed for components of a pointer to a structure in gdb 887 ;; * not needed for components of a pointer to a structure in gdb
903 (if (string-equal "*" (substring gdb-full-expression 0 1)) 888 (if (string-equal "*" (substring gdb-full-expression 0 1))
904 (setq gdb-full-expression (substring gdb-full-expression 1 nil))) 889 (setq gdb-full-expression (substring gdb-full-expression 1 nil)))
905 (setq gdb-full-expression 890 (setq gdb-full-expression
906 (concat gdb-full-expression gdb-part-expression "." gdb-last-field)) 891 (concat gdb-full-expression gdb-part-expression "." gdb-last-field))
907 (gdb-instance-enqueue-input 892 (gdb-enqueue-input
908 (list (concat "server display" gdb-display-char 893 (list (concat "server display" gdb-display-char
909 " " gdb-full-expression "\n") 894 " " gdb-full-expression "\n")
910 'ignore))))) 895 'ignore)))))
911 896
912 (defun gdb-insert-field () 897 (defun gdb-insert-field ()
918 (setq buffer-read-only nil) 903 (setq buffer-read-only nil)
919 (if (string-equal gdb-annotation-arg "\*") (insert "\*")) 904 (if (string-equal gdb-annotation-arg "\*") (insert "\*"))
920 (while (<= num gdb-nesting-level) 905 (while (<= num gdb-nesting-level)
921 (insert "\t") 906 (insert "\t")
922 (setq num (+ num 1))) 907 (setq num (+ num 1)))
923 (insert-buffer-substring (gdb-get-instance-buffer 908 (insert-buffer-substring (gdb-get-buffer
924 'gdb-partial-output-buffer) 909 'gdb-partial-output-buffer)
925 start end) 910 start end)
926 (put-text-property (- (point) (- end start)) (- (point) 1) 911 (put-text-property (- (point) (- end start)) (- (point) 1)
927 'mouse-face 'highlight) 912 'mouse-face 'highlight)
928 (put-text-property (- (point) (- end start)) (- (point) 1) 913 (put-text-property (- (point) (- end start)) (- (point) 1)
1055 (insert 1040 (insert
1056 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n")))) 1041 (concat "\n Slice : " array-slice "\n\nIndex\tValues\n\n"))))
1057 (setq buffer-read-only t)) 1042 (setq buffer-read-only t))
1058 1043
1059 (defun gud-gdba-marker-filter (string) 1044 (defun gud-gdba-marker-filter (string)
1060 "A gud marker filter for gdb. Handle a burst of output from a gdb instance. 1045 "A gud marker filter for gdb. Handle a burst of output from GDB."
1061 It must return output (if any) to be insterted in the gdb buffer."
1062 (save-match-data 1046 (save-match-data
1063 (let ( 1047 (let (
1064 ;; Recall the left over burst from last time 1048 ;; Recall the left over burst from last time
1065 (burst (concat (gdb-instance-burst) string)) 1049 (burst (concat (gdb-get-burst) string))
1066 ;; Start accumulating output for the GUD buffer 1050 ;; Start accumulating output for the GUD buffer
1067 (output "")) 1051 (output ""))
1068 1052
1069 ;; Process all the complete markers in this chunk. 1053 ;; Process all the complete markers in this chunk.
1070 (while (string-match "\n\032\032\\(.*\\)\n" burst) 1054 (while (string-match "\n\032\032\\(.*\\)\n" burst)
1102 burst) 1086 burst)
1103 (progn 1087 (progn
1104 ;; Everything before the potential marker start can be output. 1088 ;; Everything before the potential marker start can be output.
1105 (setq output 1089 (setq output
1106 (gdb-concat-output output 1090 (gdb-concat-output output
1107 (substring burst 0 (match-beginning 0)))) 1091 (substring burst 0 (match-beginning 0))))
1108 1092
1109 ;; Everything after, we save, to combine with later input. 1093 ;; Everything after, we save, to combine with later input.
1110 (setq burst (substring burst (match-beginning 0)))) 1094 (setq burst (substring burst (match-beginning 0))))
1111 1095
1112 ;; In case we know the burst contains no partial annotations: 1096 ;; In case we know the burst contains no partial annotations:
1113 (progn 1097 (progn
1114 (setq output (gdb-concat-output output burst)) 1098 (setq output (gdb-concat-output output burst))
1115 (setq burst ""))) 1099 (setq burst "")))
1116 1100
1117 ;; Save the remaining burst for the next call to this function. 1101 ;; Save the remaining burst for the next call to this function.
1118 (set-gdb-instance-burst burst) 1102 (gdb-set-burst burst)
1119 output))) 1103 output)))
1120 1104
1121 (defun gdb-concat-output (so-far new) 1105 (defun gdb-concat-output (so-far new)
1122 (let ((sink (gdb-instance-output-sink ))) 1106 (let ((sink (gdb-get-output-sink )))
1123 (cond 1107 (cond
1124 ((eq sink 'user) (concat so-far new)) 1108 ((eq sink 'user) (concat so-far new))
1125 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far) 1109 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far)
1126 ((eq sink 'emacs) 1110 ((eq sink 'emacs)
1127 (gdb-append-to-partial-output new) 1111 (gdb-append-to-partial-output new)
1132 (t (error "Bogon output sink %S" sink))))) 1116 (t (error "Bogon output sink %S" sink)))))
1133 1117
1134 (defun gdb-append-to-partial-output (string) 1118 (defun gdb-append-to-partial-output (string)
1135 (save-excursion 1119 (save-excursion
1136 (set-buffer 1120 (set-buffer
1137 (gdb-get-create-instance-buffer 'gdb-partial-output-buffer)) 1121 (gdb-get-create-buffer 'gdb-partial-output-buffer))
1138 (goto-char (point-max)) 1122 (goto-char (point-max))
1139 (insert string))) 1123 (insert string)))
1140 1124
1141 (defun gdb-clear-partial-output () 1125 (defun gdb-clear-partial-output ()
1142 (save-excursion 1126 (save-excursion
1143 (set-buffer 1127 (set-buffer
1144 (gdb-get-create-instance-buffer 'gdb-partial-output-buffer)) 1128 (gdb-get-create-buffer 'gdb-partial-output-buffer))
1145 (delete-region (point-min) (point-max)))) 1129 (delete-region (point-min) (point-max))))
1146 1130
1147 (defun gdb-append-to-inferior-io (string) 1131 (defun gdb-append-to-inferior-io (string)
1148 (save-excursion 1132 (save-excursion
1149 (set-buffer 1133 (set-buffer
1150 (gdb-get-create-instance-buffer 'gdb-inferior-io)) 1134 (gdb-get-create-buffer 'gdb-inferior-io))
1151 (goto-char (point-max)) 1135 (goto-char (point-max))
1152 (insert-before-markers string)) 1136 (insert-before-markers string))
1153 (if (not (string-equal string "")) 1137 (if (not (string-equal string ""))
1154 (gdb-display-buffer 1138 (gdb-display-buffer
1155 (gdb-get-create-instance-buffer 'gdb-inferior-io)))) 1139 (gdb-get-create-buffer 'gdb-inferior-io))))
1156 1140
1157 (defun gdb-clear-inferior-io () 1141 (defun gdb-clear-inferior-io ()
1158 (save-excursion 1142 (save-excursion
1159 (set-buffer 1143 (set-buffer
1160 (gdb-get-create-instance-buffer 'gdb-inferior-io)) 1144 (gdb-get-create-buffer 'gdb-inferior-io))
1161 (delete-region (point-min) (point-max)))) 1145 (delete-region (point-min) (point-max))))
1162 1146
1163 1147
1164 ;; One trick is to have a command who's output is always available in 1148 ;; One trick is to have a command who's output is always available in a buffer
1165 ;; a buffer of it's own, and is always up to date. We build several 1149 ;; of it's own, and is always up to date. We build several buffers of this
1166 ;; buffers of this type. 1150 ;; type.
1167 ;; 1151 ;;
1168 ;; There are two aspects to this: gdb has to tell us when the output 1152 ;; There are two aspects to this: gdb has to tell us when the output for that
1169 ;; for that command might have changed, and we have to be able to run 1153 ;; command might have changed, and we have to be able to run the command
1170 ;; the command behind the user's back. 1154 ;; behind the user's back.
1171 ;; 1155 ;;
1172 ;; The idle input queue and the output phasing associated with 1156 ;; The idle input queue and the output phasing associated with the variable
1173 ;; the instance variable `(gdb-instance-output-sink)' help 1157 ;; gdb-output-sink help us to run commands behind the user's back.
1174 ;; us to run commands behind the user's back.
1175 ;; 1158 ;;
1176 ;; Below is the code for specificly managing buffers of output from one 1159 ;; Below is the code for specificly managing buffers of output from one
1177 ;; command. 1160 ;; command.
1178 ;; 1161 ;;
1179 1162
1189 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command 1172 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command
1190 output-handler) 1173 output-handler)
1191 `(defun ,name (&optional ignored) 1174 `(defun ,name (&optional ignored)
1192 (if (and (,demand-predicate) 1175 (if (and (,demand-predicate)
1193 (not (member ',name 1176 (not (member ',name
1194 (gdb-instance-pending-triggers)))) 1177 (gdb-get-pending-triggers))))
1195 (progn 1178 (progn
1196 (gdb-instance-enqueue-idle-input 1179 (gdb-enqueue-idle-input
1197 (list ,gdb-command ',output-handler)) 1180 (list ,gdb-command ',output-handler))
1198 (set-gdb-instance-pending-triggers 1181 (gdb-set-pending-triggers
1199 (cons ',name 1182 (cons ',name
1200 (gdb-instance-pending-triggers))))))) 1183 (gdb-get-pending-triggers)))))))
1201 1184
1202 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun) 1185 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun)
1203 `(defun ,name () 1186 `(defun ,name ()
1204 (set-gdb-instance-pending-triggers 1187 (gdb-set-pending-triggers
1205 (delq ',trigger 1188 (delq ',trigger
1206 (gdb-instance-pending-triggers))) 1189 (gdb-get-pending-triggers)))
1207 (let ((buf (gdb-get-instance-buffer ',buf-key))) 1190 (let ((buf (gdb-get-buffer ',buf-key)))
1208 (and buf 1191 (and buf
1209 (save-excursion 1192 (save-excursion
1210 (set-buffer buf) 1193 (set-buffer buf)
1211 (let ((p (point)) 1194 (let ((p (point))
1212 (buffer-read-only nil)) 1195 (buffer-read-only nil))
1213 (delete-region (point-min) (point-max)) 1196 (delete-region (point-min) (point-max))
1214 (insert-buffer-substring (gdb-get-create-instance-buffer 1197 (insert-buffer-substring (gdb-get-create-buffer
1215 'gdb-partial-output-buffer)) 1198 'gdb-partial-output-buffer))
1216 (goto-char p))))) 1199 (goto-char p)))))
1217 ;; put customisation here 1200 ;; put customisation here
1218 (,custom-defun))) 1201 (,custom-defun)))
1219 1202
1220 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command 1203 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command
1221 output-handler-name custom-defun) 1204 output-handler-name custom-defun)
1222 `(progn 1205 `(progn
1223 (def-gdb-auto-update-trigger ,trigger-name 1206 (def-gdb-auto-update-trigger ,trigger-name
1224 ;; The demand predicate: 1207 ;; The demand predicate:
1225 (lambda () (gdb-get-instance-buffer ',buffer-key)) 1208 (lambda () (gdb-get-buffer ',buffer-key))
1226 ,gdb-command 1209 ,gdb-command
1227 ,output-handler-name) 1210 ,output-handler-name)
1228 (def-gdb-auto-update-handler ,output-handler-name 1211 (def-gdb-auto-update-handler ,output-handler-name
1229 ,trigger-name ,buffer-key ,custom-defun))) 1212 ,trigger-name ,buffer-key ,custom-defun)))
1230 1213
1233 ;; Breakpoint buffers 1216 ;; Breakpoint buffers
1234 ;; 1217 ;;
1235 ;; These display the output of `info breakpoints'. 1218 ;; These display the output of `info breakpoints'.
1236 ;; 1219 ;;
1237 1220
1238 (gdb-set-instance-buffer-rules 'gdb-breakpoints-buffer 1221 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1239 'gdb-breakpoints-buffer-name 1222 'gdb-breakpoints-buffer-name
1240 'gdb-breakpoints-mode) 1223 'gdb-breakpoints-mode)
1241 1224
1242 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer 1225 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1243 ;; This defines the auto update rule for buffers of type 1226 ;; This defines the auto update rule for buffers of type
1244 ;; `gdb-breakpoints-buffer'. 1227 ;; `gdb-breakpoints-buffer'.
1245 ;; 1228 ;;
1252 1235
1253 ;; This also defines a function to be the handler for the output 1236 ;; This also defines a function to be the handler for the output
1254 ;; from the command above. That function will copy the output into 1237 ;; from the command above. That function will copy the output into
1255 ;; the appropriately typed buffer. That function will be called: 1238 ;; the appropriately typed buffer. That function will be called:
1256 gdb-info-breakpoints-handler 1239 gdb-info-breakpoints-handler
1257 ;; buffer specific functions 1240 ;; buffer specific functions
1258 gdb-info-breakpoints-custom) 1241 gdb-info-breakpoints-custom)
1259 1242
1260 (defvar gdb-cdir nil "Compilation directory.") 1243 (defvar gdb-cdir nil "Compilation directory.")
1261 (defvar breakpoint-enabled-icon) 1244 (defvar breakpoint-enabled-icon)
1262 (defvar breakpoint-disabled-icon) 1245 (defvar breakpoint-disabled-icon)
1276 (remove-images (point-min) (point-max)) 1259 (remove-images (point-min) (point-max))
1277 (remove-strings (point-min) (point-max)))) 1260 (remove-strings (point-min) (point-max))))
1278 (setq buffers (cdr buffers))))) 1261 (setq buffers (cdr buffers)))))
1279 1262
1280 (save-excursion 1263 (save-excursion
1281 (set-buffer (gdb-get-instance-buffer 'gdb-breakpoints-buffer)) 1264 (set-buffer (gdb-get-buffer 'gdb-breakpoints-buffer))
1282 (save-excursion 1265 (save-excursion
1283 (goto-char (point-min)) 1266 (goto-char (point-min))
1284 (while (< (point) (- (point-max) 1)) 1267 (while (< (point) (- (point-max) 1))
1285 (forward-line 1) 1268 (forward-line 1)
1286 (if (looking-at "[^\t].*breakpoint") 1269 (if (looking-at "[^\t].*breakpoint")
1333 'left-margin))))))))))) 1316 'left-margin)))))))))))
1334 (end-of-line)))))) 1317 (end-of-line))))))
1335 1318
1336 (defun gdb-breakpoints-buffer-name () 1319 (defun gdb-breakpoints-buffer-name ()
1337 (with-current-buffer gud-comint-buffer 1320 (with-current-buffer gud-comint-buffer
1338 (concat "*breakpoints of " (gdb-instance-target-string) "*"))) 1321 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1339 1322
1340 (defun gdb-display-breakpoints-buffer () 1323 (defun gdb-display-breakpoints-buffer ()
1341 (interactive) 1324 (interactive)
1342 (gdb-display-buffer 1325 (gdb-display-buffer
1343 (gdb-get-create-instance-buffer 'gdb-breakpoints-buffer))) 1326 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1344 1327
1345 (defun gdb-frame-breakpoints-buffer () 1328 (defun gdb-frame-breakpoints-buffer ()
1346 (interactive) 1329 (interactive)
1347 (switch-to-buffer-other-frame 1330 (switch-to-buffer-other-frame
1348 (gdb-get-create-instance-buffer 'gdb-breakpoints-buffer))) 1331 (gdb-get-create-buffer 'gdb-breakpoints-buffer)))
1349 1332
1350 (defvar gdb-breakpoints-mode-map 1333 (defvar gdb-breakpoints-mode-map
1351 (let ((map (make-sparse-keymap)) 1334 (let ((map (make-sparse-keymap))
1352 (menu (make-sparse-keymap "Breakpoints"))) 1335 (menu (make-sparse-keymap "Breakpoints")))
1353 (define-key menu [toggle] '("Toggle" . gdb-toggle-bp-this-line)) 1336 (define-key menu [toggle] '("Toggle" . gdb-toggle-bp-this-line))
1370 (use-local-map gdb-breakpoints-mode-map) 1353 (use-local-map gdb-breakpoints-mode-map)
1371 (setq buffer-read-only t) 1354 (setq buffer-read-only t)
1372 (gdb-invalidate-breakpoints)) 1355 (gdb-invalidate-breakpoints))
1373 1356
1374 (defun gdb-toggle-bp-this-line () 1357 (defun gdb-toggle-bp-this-line ()
1375 "Enable/disable the breakpoint of the current line." 1358 "Enable/disable the breakpoint of the current line."
1376 (interactive) 1359 (interactive)
1377 (save-excursion 1360 (save-excursion
1378 (beginning-of-line 1) 1361 (beginning-of-line 1)
1379 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) 1362 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1380 (error "Not recognized as break/watchpoint line") 1363 (error "Not recognized as break/watchpoint line")
1381 (gdb-instance-enqueue-input 1364 (gdb-enqueue-input
1382 (list 1365 (list
1383 (concat 1366 (concat
1384 (if (eq ?y (char-after (match-beginning 2))) 1367 (if (eq ?y (char-after (match-beginning 2)))
1385 "server disable " 1368 "server disable "
1386 "server enable ") 1369 "server enable ")
1387 (match-string 1) 1370 (match-string 1)
1388 "\n") 1371 "\n")
1389 'ignore))))) 1372 'ignore)))))
1390 1373
1391 (defun gdb-delete-bp-this-line () 1374 (defun gdb-delete-bp-this-line ()
1392 "Delete the breakpoint of the current line." 1375 "Delete the breakpoint of the current line."
1393 (interactive) 1376 (interactive)
1394 (beginning-of-line 1) 1377 (beginning-of-line 1)
1395 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) 1378 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)"))
1396 (error "Not recognized as break/watchpoint line") 1379 (error "Not recognized as break/watchpoint line")
1397 (gdb-instance-enqueue-input 1380 (gdb-enqueue-input
1398 (list (concat "server delete " (match-string 1) "\n") 'ignore)))) 1381 (list (concat "server delete " (match-string 1) "\n") 'ignore))))
1399 1382
1400 (defvar gdb-source-window nil) 1383 (defvar gdb-source-window nil)
1401 1384
1402 (defun gdb-goto-bp-this-line () 1385 (defun gdb-goto-bp-this-line ()
1403 "Display the file in the source buffer at the specified breakpoint." 1386 "Display the file in the source buffer at the specified breakpoint."
1422 ;; (from the command `where'). 1405 ;; (from the command `where').
1423 ;; 1406 ;;
1424 ;; Alas, if your stack is deep, they are costly. 1407 ;; Alas, if your stack is deep, they are costly.
1425 ;; 1408 ;;
1426 1409
1427 (gdb-set-instance-buffer-rules 'gdb-stack-buffer 1410 (gdb-set-buffer-rules 'gdb-stack-buffer
1428 'gdb-stack-buffer-name 1411 'gdb-stack-buffer-name
1429 'gdb-frames-mode) 1412 'gdb-frames-mode)
1430 1413
1431 (def-gdb-auto-updated-buffer gdb-stack-buffer 1414 (def-gdb-auto-updated-buffer gdb-stack-buffer
1432 gdb-invalidate-frames 1415 gdb-invalidate-frames
1433 "server where\n" 1416 "server where\n"
1434 gdb-info-frames-handler 1417 gdb-info-frames-handler
1435 gdb-info-frames-custom) 1418 gdb-info-frames-custom)
1436 1419
1437 (defun gdb-info-frames-custom () 1420 (defun gdb-info-frames-custom ()
1438 (save-excursion 1421 (save-excursion
1439 (set-buffer (gdb-get-instance-buffer 'gdb-stack-buffer)) 1422 (set-buffer (gdb-get-buffer 'gdb-stack-buffer))
1440 (let ((buffer-read-only nil)) 1423 (let ((buffer-read-only nil))
1441 (goto-char (point-min)) 1424 (goto-char (point-min))
1442 (looking-at "\\S-*\\s-*\\(\\S-*\\)") 1425 (looking-at "\\S-*\\s-*\\(\\S-*\\)")
1443 (setq gdb-current-frame (match-string 1)) 1426 (setq gdb-current-frame (match-string 1))
1444 (while (< (point) (point-max)) 1427 (while (< (point) (point-max))
1448 (forward-line 1))))) 1431 (forward-line 1)))))
1449 1432
1450 (defun gdb-stack-buffer-name () 1433 (defun gdb-stack-buffer-name ()
1451 (with-current-buffer gud-comint-buffer 1434 (with-current-buffer gud-comint-buffer
1452 (concat "*stack frames of " 1435 (concat "*stack frames of "
1453 (gdb-instance-target-string) "*"))) 1436 (gdb-get-target-string) "*")))
1454 1437
1455 (defun gdb-display-stack-buffer () 1438 (defun gdb-display-stack-buffer ()
1456 (interactive) 1439 (interactive)
1457 (gdb-display-buffer 1440 (gdb-display-buffer
1458 (gdb-get-create-instance-buffer 'gdb-stack-buffer))) 1441 (gdb-get-create-buffer 'gdb-stack-buffer)))
1459 1442
1460 (defun gdb-frame-stack-buffer () 1443 (defun gdb-frame-stack-buffer ()
1461 (interactive) 1444 (interactive)
1462 (switch-to-buffer-other-frame 1445 (switch-to-buffer-other-frame
1463 (gdb-get-create-instance-buffer 'gdb-stack-buffer))) 1446 (gdb-get-create-buffer 'gdb-stack-buffer)))
1464 1447
1465 (defvar gdb-frames-mode-map 1448 (defvar gdb-frames-mode-map
1466 (let ((map (make-sparse-keymap))) 1449 (let ((map (make-sparse-keymap)))
1467 (suppress-keymap map) 1450 (suppress-keymap map)
1468 (define-key map [mouse-2] 'gdb-frames-mouse-select) 1451 (define-key map [mouse-2] 'gdb-frames-mouse-select)
1483 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t)) 1466 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t))
1484 (n (or (and pos (string-to-int (match-string 1))) 0))) 1467 (n (or (and pos (string-to-int (match-string 1))) 0)))
1485 n))) 1468 n)))
1486 1469
1487 (defun gdb-frames-mouse-select (e) 1470 (defun gdb-frames-mouse-select (e)
1488 "Make the selected frame become the current frame and 1471 "Make the selected frame become the current frame and
1489 display the source in the source buffer." 1472 display the source in the source buffer."
1490 (interactive "e") 1473 (interactive "e")
1491 (let (selection) 1474 (let (selection)
1492 (save-excursion 1475 (save-excursion
1493 (set-buffer (window-buffer (posn-window (event-end e)))) 1476 (set-buffer (window-buffer (posn-window (event-end e))))
1495 (goto-char (posn-point (event-end e))) 1478 (goto-char (posn-point (event-end e)))
1496 (setq selection (gdb-get-frame-number)))) 1479 (setq selection (gdb-get-frame-number))))
1497 (select-window (posn-window (event-end e))) 1480 (select-window (posn-window (event-end e)))
1498 (save-excursion 1481 (save-excursion
1499 (set-buffer gud-comint-buffer) 1482 (set-buffer gud-comint-buffer)
1500 (gdb-instance-enqueue-input 1483 (gdb-enqueue-input
1501 (list (gud-format-command "server frame %p\n" selection) 1484 (list (gud-format-command "server frame %p\n" selection)
1502 'ignore)) 1485 'ignore))
1503 (gud-display-frame)))) 1486 (gud-display-frame))))
1504 1487
1505 1488
1506 ;; 1489 ;;
1507 ;; Registers buffers 1490 ;; Registers buffers
1508 ;; 1491 ;;
1513 gdb-info-registers-handler 1496 gdb-info-registers-handler
1514 gdb-info-registers-custom) 1497 gdb-info-registers-custom)
1515 1498
1516 (defun gdb-info-registers-custom ()) 1499 (defun gdb-info-registers-custom ())
1517 1500
1518 (gdb-set-instance-buffer-rules 'gdb-registers-buffer 1501 (gdb-set-buffer-rules 'gdb-registers-buffer
1519 'gdb-registers-buffer-name 1502 'gdb-registers-buffer-name
1520 'gdb-registers-mode) 1503 'gdb-registers-mode)
1521 1504
1522 (defvar gdb-registers-mode-map 1505 (defvar gdb-registers-mode-map
1523 (let ((map (make-sparse-keymap))) 1506 (let ((map (make-sparse-keymap)))
1524 (suppress-keymap map) 1507 (suppress-keymap map)
1525 map)) 1508 map))
1534 (use-local-map gdb-registers-mode-map) 1517 (use-local-map gdb-registers-mode-map)
1535 (gdb-invalidate-registers)) 1518 (gdb-invalidate-registers))
1536 1519
1537 (defun gdb-registers-buffer-name () 1520 (defun gdb-registers-buffer-name ()
1538 (with-current-buffer gud-comint-buffer 1521 (with-current-buffer gud-comint-buffer
1539 (concat "*registers of " (gdb-instance-target-string) "*"))) 1522 (concat "*registers of " (gdb-get-target-string) "*")))
1540 1523
1541 (defun gdb-display-registers-buffer () 1524 (defun gdb-display-registers-buffer ()
1542 (interactive) 1525 (interactive)
1543 (gdb-display-buffer 1526 (gdb-display-buffer
1544 (gdb-get-create-instance-buffer 'gdb-registers-buffer))) 1527 (gdb-get-create-buffer 'gdb-registers-buffer)))
1545 1528
1546 (defun gdb-frame-registers-buffer () 1529 (defun gdb-frame-registers-buffer ()
1547 (interactive) 1530 (interactive)
1548 (switch-to-buffer-other-frame 1531 (switch-to-buffer-other-frame
1549 (gdb-get-create-instance-buffer 'gdb-registers-buffer))) 1532 (gdb-get-create-buffer 'gdb-registers-buffer)))
1550 1533
1551 ;; 1534 ;;
1552 ;; Locals buffers 1535 ;; Locals buffers
1553 ;; 1536 ;;
1554 1537
1559 gdb-info-locals-custom) 1542 gdb-info-locals-custom)
1560 1543
1561 1544
1562 ;;Abbreviate for arrays and structures. These can be expanded using gud-display 1545 ;;Abbreviate for arrays and structures. These can be expanded using gud-display
1563 (defun gdb-info-locals-handler nil 1546 (defun gdb-info-locals-handler nil
1564 (set-gdb-instance-pending-triggers (delq 'gdb-invalidate-locals 1547 (gdb-set-pending-triggers (delq 'gdb-invalidate-locals
1565 (gdb-instance-pending-triggers))) 1548 (gdb-get-pending-triggers)))
1566 (let ((buf (gdb-get-instance-buffer 'gdb-partial-output-buffer))) 1549 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer)))
1567 (save-excursion 1550 (save-excursion
1568 (set-buffer buf) 1551 (set-buffer buf)
1569 (goto-char (point-min)) 1552 (goto-char (point-min))
1570 (while (re-search-forward "^ .*\n" nil t) 1553 (while (re-search-forward "^ .*\n" nil t)
1571 (replace-match "" nil nil)) 1554 (replace-match "" nil nil))
1573 (while (re-search-forward "{[-0-9, {}\]*\n" nil t) 1556 (while (re-search-forward "{[-0-9, {}\]*\n" nil t)
1574 (replace-match "(array);\n" nil nil)) 1557 (replace-match "(array);\n" nil nil))
1575 (goto-char (point-min)) 1558 (goto-char (point-min))
1576 (while (re-search-forward "{.*=.*\n" nil t) 1559 (while (re-search-forward "{.*=.*\n" nil t)
1577 (replace-match "(structure);\n" nil nil)))) 1560 (replace-match "(structure);\n" nil nil))))
1578 (let ((buf (gdb-get-instance-buffer 'gdb-locals-buffer))) 1561 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
1579 (and buf (save-excursion 1562 (and buf (save-excursion
1580 (set-buffer buf) 1563 (set-buffer buf)
1581 (let ((p (point)) 1564 (let ((p (point))
1582 (buffer-read-only nil)) 1565 (buffer-read-only nil))
1583 (delete-region (point-min) (point-max)) 1566 (delete-region (point-min) (point-max))
1584 (insert-buffer-substring (gdb-get-create-instance-buffer 1567 (insert-buffer-substring (gdb-get-create-buffer
1585 'gdb-partial-output-buffer)) 1568 'gdb-partial-output-buffer))
1586 (goto-char p))))) 1569 (goto-char p)))))
1587 (run-hooks 'gdb-info-locals-hook)) 1570 (run-hooks 'gdb-info-locals-hook))
1588 1571
1589 (defun gdb-info-locals-custom () 1572 (defun gdb-info-locals-custom ()
1590 nil) 1573 nil)
1591 1574
1592 (gdb-set-instance-buffer-rules 'gdb-locals-buffer 1575 (gdb-set-buffer-rules 'gdb-locals-buffer
1593 'gdb-locals-buffer-name 1576 'gdb-locals-buffer-name
1594 'gdb-locals-mode) 1577 'gdb-locals-mode)
1595 1578
1596 (defvar gdb-locals-mode-map 1579 (defvar gdb-locals-mode-map
1597 (let ((map (make-sparse-keymap))) 1580 (let ((map (make-sparse-keymap)))
1598 (suppress-keymap map) 1581 (suppress-keymap map)
1599 map)) 1582 map))
1608 (use-local-map gdb-locals-mode-map) 1591 (use-local-map gdb-locals-mode-map)
1609 (gdb-invalidate-locals)) 1592 (gdb-invalidate-locals))
1610 1593
1611 (defun gdb-locals-buffer-name () 1594 (defun gdb-locals-buffer-name ()
1612 (with-current-buffer gud-comint-buffer 1595 (with-current-buffer gud-comint-buffer
1613 (concat "*locals of " (gdb-instance-target-string) "*"))) 1596 (concat "*locals of " (gdb-get-target-string) "*")))
1614 1597
1615 (defun gdb-display-locals-buffer () 1598 (defun gdb-display-locals-buffer ()
1616 (interactive) 1599 (interactive)
1617 (gdb-display-buffer 1600 (gdb-display-buffer
1618 (gdb-get-create-instance-buffer 'gdb-locals-buffer))) 1601 (gdb-get-create-buffer 'gdb-locals-buffer)))
1619 1602
1620 (defun gdb-frame-locals-buffer () 1603 (defun gdb-frame-locals-buffer ()
1621 (interactive) 1604 (interactive)
1622 (switch-to-buffer-other-frame 1605 (switch-to-buffer-other-frame
1623 (gdb-get-create-instance-buffer 'gdb-locals-buffer))) 1606 (gdb-get-create-buffer 'gdb-locals-buffer)))
1624 ;; 1607 ;;
1625 ;; Display expression buffers (just allow one to start with) 1608 ;; Display expression buffers (just allow one to start with)
1626 ;; 1609 ;;
1627 (gdb-set-instance-buffer-rules 'gdb-display-buffer 1610 (gdb-set-buffer-rules 'gdb-display-buffer
1628 'gdb-display-buffer-name 1611 'gdb-display-buffer-name
1629 'gdb-display-mode) 1612 'gdb-display-mode)
1630 1613
1631 (def-gdb-auto-updated-buffer gdb-display-buffer 1614 (def-gdb-auto-updated-buffer gdb-display-buffer
1632 ;; `gdb-display-buffer'. 1615 ;; `gdb-display-buffer'.
1633 gdb-invalidate-display 1616 gdb-invalidate-display
1634 "server info display\n" 1617 "server info display\n"
1663 (use-local-map gdb-display-mode-map) 1646 (use-local-map gdb-display-mode-map)
1664 (gdb-invalidate-display)) 1647 (gdb-invalidate-display))
1665 1648
1666 (defun gdb-display-buffer-name () 1649 (defun gdb-display-buffer-name ()
1667 (with-current-buffer gud-comint-buffer 1650 (with-current-buffer gud-comint-buffer
1668 (concat "*Displayed expressions of " (gdb-instance-target-string) "*"))) 1651 (concat "*Displayed expressions of " (gdb-get-target-string) "*")))
1669 1652
1670 (defun gdb-display-display-buffer () 1653 (defun gdb-display-display-buffer ()
1671 (interactive) 1654 (interactive)
1672 (gdb-display-buffer 1655 (gdb-display-buffer
1673 (gdb-get-create-instance-buffer 'gdb-display-buffer))) 1656 (gdb-get-create-buffer 'gdb-display-buffer)))
1674 1657
1675 (defun gdb-frame-display-buffer () 1658 (defun gdb-frame-display-buffer ()
1676 (interactive) 1659 (interactive)
1677 (switch-to-buffer-other-frame 1660 (switch-to-buffer-other-frame
1678 (gdb-get-create-instance-buffer 'gdb-display-buffer))) 1661 (gdb-get-create-buffer 'gdb-display-buffer)))
1679 1662
1680 (defun gdb-toggle-disp-this-line () 1663 (defun gdb-toggle-disp-this-line ()
1681 "Enable/disable the displayed expression of the current line." 1664 "Enable/disable the displayed expression of the current line."
1682 (interactive) 1665 (interactive)
1683 (save-excursion 1666 (save-excursion
1684 (beginning-of-line 1) 1667 (beginning-of-line 1)
1685 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) 1668 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1686 (error "No expression on this line") 1669 (error "No expression on this line")
1687 (gdb-instance-enqueue-input 1670 (gdb-enqueue-input
1688 (list 1671 (list
1689 (concat 1672 (concat
1690 (if (eq ?y (char-after (match-beginning 2))) 1673 (if (eq ?y (char-after (match-beginning 2)))
1691 "server disable display " 1674 "server disable display "
1692 "server enable display ") 1675 "server enable display ")
1693 (match-string 1) 1676 (match-string 1)
1694 "\n") 1677 "\n")
1695 'ignore))))) 1678 'ignore)))))
1696 1679
1697 (defun gdb-delete-disp-this-line () 1680 (defun gdb-delete-disp-this-line ()
1698 "Delete the displayed expression of the current line." 1681 "Delete the displayed expression of the current line."
1699 (interactive) 1682 (interactive)
1700 (save-excursion 1683 (save-excursion
1701 (set-buffer 1684 (set-buffer
1702 (gdb-get-instance-buffer 'gdb-display-buffer)) 1685 (gdb-get-buffer 'gdb-display-buffer))
1703 (beginning-of-line 1) 1686 (beginning-of-line 1)
1704 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)")) 1687 (if (not (looking-at "\\([0-9]+\\): \\([ny]\\)"))
1705 (error "No expression on this line") 1688 (error "No expression on this line")
1706 (let ((number (match-string 1))) 1689 (let ((number (match-string 1)))
1707 (gdb-instance-enqueue-input 1690 (gdb-enqueue-input
1708 (list (concat "server delete display " number "\n") 1691 (list (concat "server delete display " number "\n")
1709 'ignore)) 1692 'ignore))
1710 (if (not (display-graphic-p)) 1693 (if (not (display-graphic-p))
1711 (kill-buffer (get-buffer (concat "*display " number "*"))) 1694 (kill-buffer (get-buffer (concat "*display " number "*")))
1712 (catch 'frame-found 1695 (catch 'frame-found
1778 (answer nil)) 1761 (answer nil))
1779 (unwind-protect 1762 (unwind-protect
1780 (progn 1763 (progn
1781 (walk-windows 1764 (walk-windows
1782 '(lambda (win) 1765 '(lambda (win)
1783 (if (gdb-protected-buffer-p (window-buffer win)) 1766 (if (or (eq gud-comint-buffer (window-buffer win))
1767 (eq gdb-source-window win))
1784 (set-window-dedicated-p win t)))) 1768 (set-window-dedicated-p win t))))
1785 (setq answer (get-buffer-window buf)) 1769 (setq answer (get-buffer-window buf))
1786 (if (not answer) 1770 (if (not answer)
1787 (let ((window (get-lru-window))) 1771 (let ((window (get-lru-window)))
1788 (if window 1772 (if window
1790 (set-window-buffer window buf) 1774 (set-window-buffer window buf)
1791 (setq answer window)) 1775 (setq answer window))
1792 (setq must-split t))))) 1776 (setq must-split t)))))
1793 (walk-windows 1777 (walk-windows
1794 '(lambda (win) 1778 '(lambda (win)
1795 (if (gdb-protected-buffer-p (window-buffer win)) 1779 (if (or (eq gud-comint-buffer (window-buffer win))
1780 (eq gdb-source-window win))
1796 (set-window-dedicated-p win nil))))) 1781 (set-window-dedicated-p win nil)))))
1797 (if must-split 1782 (if must-split
1798 (let* ((largest (get-largest-window)) 1783 (let* ((largest (get-largest-window))
1799 (cur-size (window-height largest)) 1784 (cur-size (window-height largest))
1800 (new-size (and size (< size cur-size) (- cur-size size)))) 1785 (new-size (and size (< size cur-size) (- cur-size size))))
1809 ;;; Shared keymap initialization: 1794 ;;; Shared keymap initialization:
1810 1795
1811 (defun gdb-display-gdb-buffer () 1796 (defun gdb-display-gdb-buffer ()
1812 (interactive) 1797 (interactive)
1813 (gdb-display-buffer 1798 (gdb-display-buffer
1814 (gdb-get-create-instance-buffer 'gdba))) 1799 (gdb-get-create-buffer 'gdba)))
1815 1800
1816 (let ((menu (make-sparse-keymap "GDB-Windows"))) 1801 (let ((menu (make-sparse-keymap "GDB-Windows")))
1817 (define-key gud-menu-map [displays] 1802 (define-key gud-menu-map [displays]
1818 `(menu-item "GDB-Windows" ,menu :visible (eq gud-minor-mode 'gdba))) 1803 `(menu-item "GDB-Windows" ,menu :visible (eq gud-minor-mode 'gdba)))
1819 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer)) 1804 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
1825 (define-key menu [assembler] '("Assembler" . gdb-display-assembler-buffer))) 1810 (define-key menu [assembler] '("Assembler" . gdb-display-assembler-buffer)))
1826 1811
1827 (defun gdb-frame-gdb-buffer () 1812 (defun gdb-frame-gdb-buffer ()
1828 (interactive) 1813 (interactive)
1829 (switch-to-buffer-other-frame 1814 (switch-to-buffer-other-frame
1830 (gdb-get-create-instance-buffer 'gdba))) 1815 (gdb-get-create-buffer 'gdba)))
1831 1816
1832 (let ((menu (make-sparse-keymap "GDB-Frames"))) 1817 (let ((menu (make-sparse-keymap "GDB-Frames")))
1833 (define-key gud-menu-map [frames] 1818 (define-key gud-menu-map [frames]
1834 `(menu-item "GDB-Frames" ,menu :visible (eq gud-minor-mode 'gdba))) 1819 `(menu-item "GDB-Frames" ,menu :visible (eq gud-minor-mode 'gdba)))
1835 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer)) 1820 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
1914 \"+ +\", 1899 \"+ +\",
1915 \"++ ++\", 1900 \"++ ++\",
1916 \"+++ +++\", 1901 \"+++ +++\",
1917 \"+++++ +++++\" 1902 \"+++++ +++++\"
1918 };" 1903 };"
1919 "XPM file used for breakpoint icon.") 1904 "XPM file used for breakpoint icon.")
1920 1905
1921 (defvar breakpoint-enabled-icon 1906 (defvar breakpoint-enabled-icon
1922 (find-image `((:type xpm :data ,breakpoint-xpm-data))) 1907 (find-image `((:type xpm :data ,breakpoint-xpm-data)))
1923 "Icon for enabled breakpoint in display margin") 1908 "Icon for enabled breakpoint in display margin")
1924 (defvar breakpoint-disabled-icon 1909 (defvar breakpoint-disabled-icon
1925 (find-image `((:type xpm :data ,breakpoint-xpm-data 1910 (find-image `((:type xpm :data ,breakpoint-xpm-data
1926 :conversion laplace))) 1911 :conversion laplace)))
1927 "Icon for disabled breakpoint in display margin") 1912 "Icon for disabled breakpoint in display margin")
1928 1913
1929 (defun gdb-quit () 1914 (defun gdb-quit ()
1930 "Kill the GUD and instance buffers and reset variables. 1915 "Kill the GUD interaction and gdb buffers and reset variables.
1931 Use this command to exit a debugging session cleanly and reset 1916 Use this command to exit a debugging session cleanly and reset
1932 things like the toolbar and margin in the source buffers." 1917 things like the toolbar and margin in the source buffers."
1933 (interactive) 1918 (interactive)
1934 (let ((buffers (buffer-list))) 1919 (let ((buffers (buffer-list)))
1935 (save-excursion 1920 (save-excursion
1971 (other-window 1)) 1956 (other-window 1))
1972 (delete-other-windows) 1957 (delete-other-windows)
1973 (if gdb-many-windows 1958 (if gdb-many-windows
1974 (gdb-setup-windows) 1959 (gdb-setup-windows)
1975 (gdb-display-breakpoints-buffer) 1960 (gdb-display-breakpoints-buffer)
1976 (gdb-display-display-buffer)
1977 (gdb-display-stack-buffer) 1961 (gdb-display-stack-buffer)
1978 (delete-other-windows) 1962 (delete-other-windows)
1979 (split-window) 1963 (split-window)
1980 (other-window 1) 1964 (other-window 1)
1981 (switch-to-buffer (gud-find-file gdb-main-file)) 1965 (switch-to-buffer (gud-find-file gdb-main-file))
1982 (other-window 1) 1966 (setq gdb-source-window (get-buffer-window (current-buffer))))
1983 (setq gdb-source-window (get-buffer-window (current-buffer)))))) 1967 (other-window 1)))
1984 1968
1985 ;;from put-image 1969 ;;from put-image
1986 (defun put-string (putstring pos &optional string area) 1970 (defun put-string (putstring pos &optional string area)
1987 "Put string PUTSTRING in front of POS in the current buffer. 1971 "Put string PUTSTRING in front of POS in the current buffer.
1988 PUTSTRING is displayed by putting an overlay into the current buffer with a 1972 PUTSTRING is displayed by putting an overlay into the current buffer with a
2079 " 1 -T X")))))) 2063 " 1 -T X"))))))
2080 2064
2081 (defun gdb-delete-display () 2065 (defun gdb-delete-display ()
2082 "Delete displayed expression and its frame." 2066 "Delete displayed expression and its frame."
2083 (interactive) 2067 (interactive)
2084 (gdb-instance-enqueue-input 2068 (gdb-enqueue-input
2085 (list (concat "server delete display " gdb-display-number "\n") 2069 (list (concat "server delete display " gdb-display-number "\n")
2086 'ignore)) 2070 'ignore))
2087 (kill-buffer nil) 2071 (kill-buffer nil)
2088 (delete-frame)) 2072 (delete-frame))
2089 2073
2096 (concat "server disassemble " gdb-main-or-pc "\n") 2080 (concat "server disassemble " gdb-main-or-pc "\n")
2097 gdb-assembler-handler 2081 gdb-assembler-handler
2098 gdb-assembler-custom) 2082 gdb-assembler-custom)
2099 2083
2100 (defun gdb-assembler-custom () 2084 (defun gdb-assembler-custom ()
2101 (let ((buffer (gdb-get-instance-buffer 'gdb-assembler-buffer)) 2085 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer))
2102 (gdb-arrow-position) (address) (flag)) 2086 (gdb-arrow-position) (address) (flag))
2103 (if gdb-current-address 2087 (if gdb-current-address
2104 (progn 2088 (progn
2105 (save-excursion 2089 (save-excursion
2106 (set-buffer buffer) 2090 (set-buffer buffer)
2115 (set-buffer buffer) 2099 (set-buffer buffer)
2116 (if (display-graphic-p) 2100 (if (display-graphic-p)
2117 (remove-images (point-min) (point-max)) 2101 (remove-images (point-min) (point-max))
2118 (remove-strings (point-min) (point-max)))) 2102 (remove-strings (point-min) (point-max))))
2119 (save-excursion 2103 (save-excursion
2120 (set-buffer (gdb-get-instance-buffer 'gdb-breakpoints-buffer)) 2104 (set-buffer (gdb-get-buffer 'gdb-breakpoints-buffer))
2121 (goto-char (point-min)) 2105 (goto-char (point-min))
2122 (while (< (point) (- (point-max) 1)) 2106 (while (< (point) (- (point-max) 1))
2123 (forward-line 1) 2107 (forward-line 1)
2124 (if (looking-at "[^\t].*breakpoint") 2108 (if (looking-at "[^\t].*breakpoint")
2125 (progn 2109 (progn
2150 (put-string "b" (point) "disabled" 2134 (put-string "b" (point) "disabled"
2151 'left-margin)))))))))) 2135 'left-margin))))))))))
2152 (if gdb-current-address 2136 (if gdb-current-address
2153 (set-window-point (get-buffer-window buffer) gdb-arrow-position)))) 2137 (set-window-point (get-buffer-window buffer) gdb-arrow-position))))
2154 2138
2155 (gdb-set-instance-buffer-rules 'gdb-assembler-buffer 2139 (gdb-set-buffer-rules 'gdb-assembler-buffer
2156 'gdb-assembler-buffer-name 2140 'gdb-assembler-buffer-name
2157 'gdb-assembler-mode) 2141 'gdb-assembler-mode)
2158 2142
2159 (defvar gdb-assembler-mode-map 2143 (defvar gdb-assembler-mode-map
2160 (let ((map (make-sparse-keymap))) 2144 (let ((map (make-sparse-keymap)))
2161 (suppress-keymap map) 2145 (suppress-keymap map)
2162 map)) 2146 map))
2173 (gdb-invalidate-assembler) 2157 (gdb-invalidate-assembler)
2174 (gdb-invalidate-breakpoints)) 2158 (gdb-invalidate-breakpoints))
2175 2159
2176 (defun gdb-assembler-buffer-name () 2160 (defun gdb-assembler-buffer-name ()
2177 (with-current-buffer gud-comint-buffer 2161 (with-current-buffer gud-comint-buffer
2178 (concat "*Machine Code " (gdb-instance-target-string) "*"))) 2162 (concat "*Machine Code " (gdb-get-target-string) "*")))
2179 2163
2180 (defun gdb-display-assembler-buffer () 2164 (defun gdb-display-assembler-buffer ()
2181 (interactive) 2165 (interactive)
2182 (gdb-display-buffer 2166 (gdb-display-buffer
2183 (gdb-get-create-instance-buffer 'gdb-assembler-buffer))) 2167 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2184 2168
2185 (defun gdb-frame-assembler-buffer () 2169 (defun gdb-frame-assembler-buffer ()
2186 (interactive) 2170 (interactive)
2187 (switch-to-buffer-other-frame 2171 (switch-to-buffer-other-frame
2188 (gdb-get-create-instance-buffer 'gdb-assembler-buffer))) 2172 (gdb-get-create-buffer 'gdb-assembler-buffer)))
2189 2173
2190 (defun gdb-invalidate-frame-and-assembler (&optional ignored) 2174 (defun gdb-invalidate-frame-and-assembler (&optional ignored)
2191 (gdb-invalidate-frames) 2175 (gdb-invalidate-frames)
2192 (gdb-invalidate-assembler)) 2176 (gdb-invalidate-assembler))
2193 2177
2198 (defvar gdb-prev-main-or-pc nil) 2182 (defvar gdb-prev-main-or-pc nil)
2199 2183
2200 ;; modified because if gdb-main-or-pc has changed value a new command 2184 ;; modified because if gdb-main-or-pc has changed value a new command
2201 ;; must be enqueued to update the buffer with the new output 2185 ;; must be enqueued to update the buffer with the new output
2202 (defun gdb-invalidate-assembler (&optional ignored) 2186 (defun gdb-invalidate-assembler (&optional ignored)
2203 (if (and (gdb-get-instance-buffer 'gdb-assembler-buffer) 2187 (if (and (gdb-get-buffer 'gdb-assembler-buffer)
2204 (or (not (member 'gdb-invalidate-assembler 2188 (or (not (member 'gdb-invalidate-assembler
2205 (gdb-instance-pending-triggers))) 2189 (gdb-get-pending-triggers)))
2206 (not (string-equal gdb-main-or-pc gdb-prev-main-or-pc)))) 2190 (not (string-equal gdb-main-or-pc gdb-prev-main-or-pc))))
2207 (progn 2191 (progn
2208 2192
2209 ;; take previous disassemble command off the queue 2193 ;; take previous disassemble command off the queue
2210 (save-excursion 2194 (save-excursion
2214 (setq item (car queue)) 2198 (setq item (car queue))
2215 (if (equal (cdr item) '(gdb-assembler-handler)) 2199 (if (equal (cdr item) '(gdb-assembler-handler))
2216 (delete item gdb-idle-input-queue)) 2200 (delete item gdb-idle-input-queue))
2217 (setq queue (cdr queue))))) 2201 (setq queue (cdr queue)))))
2218 2202
2219 (gdb-instance-enqueue-idle-input 2203 (gdb-enqueue-idle-input
2220 (list (concat "server disassemble " gdb-main-or-pc "\n") 2204 (list (concat "server disassemble " gdb-main-or-pc "\n")
2221 'gdb-assembler-handler)) 2205 'gdb-assembler-handler))
2222 (set-gdb-instance-pending-triggers 2206 (gdb-set-pending-triggers
2223 (cons 'gdb-invalidate-assembler 2207 (cons 'gdb-invalidate-assembler
2224 (gdb-instance-pending-triggers))) 2208 (gdb-get-pending-triggers)))
2225 (setq gdb-prev-main-or-pc gdb-main-or-pc)))) 2209 (setq gdb-prev-main-or-pc gdb-main-or-pc))))
2226 2210
2227 (provide 'gdb-ui) 2211 (provide 'gdb-ui)
2228 2212
2229 ;;; gdb-ui.el ends here 2213 ;;; gdb-ui.el ends here