1 ;;; gdb-mi.el --- User Interface for running GDB
3 ;; Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
5 ;; Author: Nick Roberts <nickrob@gnu.org>
7 ;; Keywords: unix, tools
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This file was written by by Nick Roberts following the general design
27 ;; used in gdb-ui.el for Emacs 22.1 - 23.1. It is currently being developed
28 ;; by Dmitry Dzhus <dima@sphinx.net.ru> as part of the Google Summer
29 ;; of Code 2009 Project "Emacs GDB/MI migration".
33 ;; This mode acts as a graphical user interface to GDB. You can interact with
34 ;; GDB through the GUD buffer in the usual way, but there are also further
35 ;; buffers which control the execution and describe the state of your program.
36 ;; It separates the input/output of your program from that of GDB and displays
37 ;; expressions and their current values in their own buffers. It also uses
38 ;; features of Emacs 21 such as the fringe/display margin for breakpoints, and
39 ;; the toolbar (see the GDB Graphical Interface section in the Emacs info
42 ;; M-x gdb will start the debugger.
44 ;; This file uses GDB/MI as the primary interface to GDB. It is still under
45 ;; development and is part of a process to migrate Emacs from annotations (as
46 ;; used in gdb-ui.el) to GDB/MI. It runs gdb with GDB/MI (-interp=mi) and
47 ;; access CLI using "-interpreter-exec console cli-command". This code works
48 ;; without gdb-ui.el and uses MI tokens instead of queues. Eventually MI
49 ;; should be asynchronous.
51 ;; This mode will PARTLY WORK WITH RECENT GDB RELEASES (status in modeline
52 ;; doesn't update properly when execution commands are issued from GUD buffer)
53 ;; and WORKS BEST when GDB runs asynchronously: maint set linux-async on.
55 ;; You need development version of GDB 7.0 for the thread buffer to work.
57 ;; This file replaces gdb-ui.el and is for development with GDB. Use the
58 ;; release branch of Emacs 22 for the latest version of gdb-ui.el.
62 ;; If you are using Emacs and GDB on Windows you will need to flush the buffer
63 ;; explicitly in your program if you want timely display of I/O in Emacs.
64 ;; Alternatively you can make the output stream unbuffered, for example, by
68 ;; setvbuf (stdout, (char *) NULL, _IONBF, 0);
71 ;; and compiling with -DUNBUFFERED while debugging.
73 ;; If you are using Cygwin GDB and find that the source is not being displayed
74 ;; in Emacs when you step through it, possible solutions are to:
76 ;; 1) Use Cygwin X Windows and Cygwin Emacs.
77 ;; (Since 22.1 Emacs builds under Cygwin.)
78 ;; 2) Use MinGW GDB instead.
79 ;; 3) Use cygwin-mount.el
83 ;; GDB in Emacs on Mac OSX works best with FSF GDB as Apple have made
84 ;; some changes to the version that they include as part of Mac OSX.
85 ;; This requires GDB version 7.0 or later (estimated release date Aug 2009)
86 ;; as earlier versions don not compile on Mac OSX.
90 ;; 1) Stack buffer doesn't parse MI output if you stop in a routine without
91 ;; line information, e.g., a routine in libc (just a TODO item).
94 ;; 2) Watch windows to work with threads.
95 ;; 3) Use treebuffer.el instead of the speedbar for watch-expressions?
96 ;; 4) Mark breakpoint locations on scroll-bar of source buffer?
104 (defvar tool-bar-map
)
105 (defvar speedbar-initial-expansion-list-name
)
107 (defvar gdb-pc-address nil
"Initialization for Assembler buffer.
108 Set to \"main\" at start if `gdb-show-main' is t.")
109 (defvar gdb-memory-address
"main")
110 (defvar gdb-memory-last-address nil
111 "Last successfully accessed memory address.")
112 (defvar gdb-memory-next-page nil
113 "Address of next memory page for program memory buffer.")
114 (defvar gdb-memory-prev-page nil
115 "Address of previous memory page for program memory buffer.")
117 (defvar gdb-selected-frame nil
)
118 (defvar gdb-selected-file nil
)
119 (defvar gdb-selected-line nil
)
120 (defvar gdb-frame-number nil
)
121 (defvar gdb-current-language nil
)
122 (defvar gdb-var-list nil
123 "List of variables in watch window.
124 Each element has the form (VARNUM EXPRESSION NUMCHILD TYPE VALUE STATUS) where
125 STATUS is nil (unchanged), `changed' or `out-of-scope'.")
126 (defvar gdb-main-file nil
"Source file from which program execution begins.")
127 (defvar gdb-overlay-arrow-position nil
)
128 (defvar gdb-stack-position nil
)
129 (defvar gdb-breakpoints-list nil
130 "List of breakpoints.
132 `gdb-get-field' is used to access breakpoints data stored in this
133 variable. Each element contains the same fields as \"body\"
134 member of \"-break-info\".")
135 (defvar gdb-location-alist nil
136 "Alist of breakpoint numbers and full filenames. Only used for files that
138 (defvar gdb-active-process nil
139 "GUD tooltips display variable values when t, and macro definitions otherwise.")
140 (defvar gdb-error
"Non-nil when GDB is reporting an error.")
141 (defvar gdb-macro-info nil
142 "Non-nil if GDB knows that the inferior includes preprocessor macro info.")
143 (defvar gdb-register-names nil
"List of register names.")
144 (defvar gdb-changed-registers nil
145 "List of changed register numbers (strings).")
146 (defvar gdb-buffer-fringe-width nil
)
147 (defvar gdb-last-command nil
)
148 (defvar gdb-prompt-name nil
)
149 (defvar gdb-token-number
0)
150 (defvar gdb-handler-alist
'())
151 (defvar gdb-handler-number nil
)
152 (defvar gdb-source-file-list nil
153 "List of source files for the current executable.")
154 (defvar gdb-first-done-or-error t
)
155 (defvar gdb-source-window nil
)
156 (defvar gdb-inferior-status nil
)
157 (defvar gdb-continuation nil
)
158 (defvar gdb-filter-output nil
159 "Message to be shown in GUD console.
161 This variable is updated in `gdb-done-or-error' and returned by
162 `gud-gdbmi-marker-filter'.")
164 (defvar gdb-buffer-type nil
165 "One of the symbols bound in `gdb-buffer-rules'.")
166 (make-variable-buffer-local 'gdb-buffer-type
)
168 (defvar gdb-output-sink
'nil
169 "The disposition of the output of the current gdb command.
170 Possible values are these symbols:
172 `user' -- gdb output should be copied to the GUD buffer
175 `emacs' -- output should be collected in the partial-output-buffer
176 for subsequent processing by a command. This is the
177 disposition of output generated by commands that
178 gdb mode sends to gdb on its own behalf.")
180 (defvar gdb-pending-triggers
'()
181 "A list of trigger functions that have run later than their output handlers.")
183 (defcustom gdb-debug-log-max
128
184 "Maximum size of `gdb-debug-log'. If nil, size is unlimited."
186 :type
'(choice (integer :tag
"Number of elements")
187 (const :tag
"Unlimited" nil
))
190 (defvar gdb-debug-log nil
191 "List of commands sent to and replies received from GDB.
192 Most recent commands are listed first. This list stores only the last
193 `gdb-debug-log-max' values. This variable is used to debug GDB-MI.")
196 (defcustom gdb-enable-debug nil
197 "Non-nil means record the process input and output in `gdb-debug-log'."
202 (defcustom gdb-cpp-define-alist-program
"gcc -E -dM -"
203 "Shell command for generating a list of defined macros in a source file.
204 This list is used to display the #define directive associated
205 with an identifier as a tooltip. It works in a debug session with
206 GDB, when `gud-tooltip-mode' is t.
208 Set `gdb-cpp-define-alist-flags' for any include paths or
214 (defcustom gdb-cpp-define-alist-flags
""
215 "Preprocessor flags for `gdb-cpp-define-alist-program'."
220 (defcustom gdb-create-source-file-list t
221 "Non-nil means create a list of files from which the executable was built.
222 Set this to nil if the GUD buffer displays \"initializing...\" in the mode
223 line for a long time when starting, possibly because your executable was
224 built from a large number of files. This allows quicker initialization
225 but means that these files are not automatically enabled for debugging,
226 e.g., you won't be able to click in the fringe to set a breakpoint until
227 execution has already stopped there."
232 (defcustom gdb-show-main nil
233 "Non-nil means display source file containing the main routine at startup.
234 Also display the main routine in the disassembly buffer if present."
239 ; Note: This mode requires a separate buffer for inferior IO.
240 (defconst gdb-use-separate-io-buffer t
)
242 (defun gdb-force-mode-line-update (status)
243 (let ((buffer gud-comint-buffer
))
244 (if (and buffer
(buffer-name buffer
))
245 (with-current-buffer buffer
246 (setq mode-line-process
248 (process-status (get-buffer-process buffer
)) status
))
249 ;; Force mode line redisplay soon.
250 (force-mode-line-update)))))
252 (defun gdb-enable-debug (arg)
253 "Toggle logging of transaction between Emacs and Gdb.
254 The log is stored in `gdb-debug-log' as an alist with elements
255 whose cons is send, send-item or recv and whose cdr is the string
256 being transferred. This list may grow up to a size of
257 `gdb-debug-log-max' after which the oldest element (at the end of
258 the list) is deleted every time a new one is added (at the front)."
260 (setq gdb-enable-debug
262 (not gdb-enable-debug
)
263 (> (prefix-numeric-value arg
) 0)))
264 (message (format "Logging of transaction %sabled"
265 (if gdb-enable-debug
"en" "dis"))))
267 (defun gdb-find-watch-expression ()
268 (let* ((var (nth (- (line-number-at-pos (point)) 2) gdb-var-list
))
269 (varnum (car var
)) expr array
)
270 (string-match "\\(var[0-9]+\\)\\.\\(.*\\)" varnum
)
271 (let ((var1 (assoc (match-string 1 varnum
) gdb-var-list
)) var2 varnumlet
272 (component-list (split-string (match-string 2 varnum
) "\\." t
)))
273 (setq expr
(nth 1 var1
))
274 (setq varnumlet
(car var1
))
275 (dolist (component component-list
)
276 (setq var2
(assoc varnumlet gdb-var-list
))
277 (setq expr
(concat expr
278 (if (string-match ".*\\[[0-9]+\\]$" (nth 3 var2
))
279 (concat "[" component
"]")
280 (concat "." component
))))
281 (setq varnumlet
(concat varnumlet
"." component
)))
284 (defvar gdb-locals-font-lock-keywords
287 ( "\\(^\\(\\sw\\|[_.]\\)+\\)\t+\\(\\(\\sw\\|[_.]\\)+\\)"
288 (1 font-lock-variable-name-face
)
289 (3 font-lock-type-face
))
291 "Font lock keywords used in `gdb-local-mode'.")
294 (defun gdb (command-line)
295 "Run gdb on program FILE in buffer *gud-FILE*.
296 The directory containing FILE becomes the initial working directory
297 and source-file directory for your debugger.
299 If `gdb-many-windows' is nil (the default value) then gdb just
300 pops up the GUD buffer unless `gdb-show-main' is t. In this case
301 it starts with two windows: one displaying the GUD buffer and the
302 other with the source file with the main routine of the inferior.
304 If `gdb-many-windows' is t, regardless of the value of
305 `gdb-show-main', the layout below will appear unless
306 `gdb-use-separate-io-buffer' is nil when the source buffer
307 occupies the full width of the frame. Keybindings are shown in
310 Watch expressions appear in the speedbar/slowbar.
312 The following commands help control operation :
314 `gdb-many-windows' - Toggle the number of windows gdb uses.
315 `gdb-restore-windows' - To restore the window layout.
317 See Info node `(emacs)GDB Graphical Interface' for a more
318 detailed description of this mode.
321 +----------------------------------------------------------------------+
323 +-----------------------------------+----------------------------------+
324 | GUD buffer (I/O of GDB) | Locals buffer |
328 +-----------------------------------+----------------------------------+
329 | Source buffer | I/O buffer (of debugged program) |
337 +-----------------------------------+----------------------------------+
338 | Stack buffer | Breakpoints buffer |
339 | RET gdb-frames-select | SPC gdb-toggle-breakpoint |
340 | | RET gdb-goto-breakpoint |
341 | | D gdb-delete-breakpoint |
342 +-----------------------------------+----------------------------------+"
344 (interactive (list (gud-query-cmdline 'gdb
)))
346 (when (and gud-comint-buffer
347 (buffer-name gud-comint-buffer
)
348 (get-buffer-process gud-comint-buffer
)
349 (with-current-buffer gud-comint-buffer
(eq gud-minor-mode
'gdba
)))
350 (gdb-restore-windows)
352 "Multiple debugging requires restarting in text command mode"))
354 (gud-common-init command-line nil
'gud-gdbmi-marker-filter
)
355 (set (make-local-variable 'gud-minor-mode
) 'gdbmi
)
356 (setq comint-input-sender
'gdb-send
)
358 (gud-def gud-tbreak
"tbreak %f:%l" "\C-t"
359 "Set temporary breakpoint at current line.")
361 (progn (gud-call "tbreak %f:%l") (gud-call "jump %f:%l"))
362 "\C-j" "Set execution address to current line.")
364 (gud-def gud-up
"up %p" "<" "Up N stack frames (numeric arg).")
365 (gud-def gud-down
"down %p" ">" "Down N stack frames (numeric arg).")
366 (gud-def gud-print
"print %e" "\C-p" "Evaluate C expression at point.")
367 (gud-def gud-pstar
"print* %e" nil
368 "Evaluate C dereferenced pointer expression at point.")
370 (gud-def gud-step
"-exec-step %p" "\C-s"
371 "Step one source line with display.")
372 (gud-def gud-stepi
"-exec-step-instruction %p" "\C-i"
373 "Step one instruction with display.")
374 (gud-def gud-next
"-exec-next %p" "\C-n"
375 "Step one line (skip functions).")
376 (gud-def gud-nexti
"nexti %p" nil
377 "Step one instruction (skip functions).")
378 (gud-def gud-cont
"-exec-continue" "\C-r"
379 "Continue with display.")
380 (gud-def gud-finish
"-exec-finish" "\C-f"
381 "Finish executing current function.")
382 (gud-def gud-run
"-exec-run" nil
"Runn the program.")
384 (local-set-key "\C-i" 'gud-gdb-complete-command
)
385 (setq gdb-first-prompt t
)
386 (setq gud-running nil
)
388 (run-hooks 'gdb-mode-hook
))
391 (gud-def gud-break
(if (not (string-equal mode-name
"Disassembly"))
392 (gud-call "break %f:%l" arg
)
396 (gud-call "break *%a" arg
)))
397 "\C-b" "Set breakpoint at current line or address.")
399 (gud-def gud-remove
(if (not (string-equal mode-name
"Disassembly"))
400 (gud-call "clear %f:%l" arg
)
404 (gud-call "clear *%a" arg
)))
405 "\C-d" "Remove breakpoint at current line or address.")
407 (gud-def gud-until
(if (not (string-equal mode-name
"Disassembly"))
408 (gud-call "-exec-until %f:%l" arg
)
412 (gud-call "-exec-until *%a" arg
)))
413 "\C-u" "Continue to current line or address.")
416 gud-go
(gud-call (if gdb-active-process
"-exec-continue" "-exec-run") arg
)
417 nil
"Start or continue execution.")
419 ;; For debugging Emacs only.
423 "pp1 " (if (eq (buffer-local-value
424 'major-mode
(window-buffer)) 'speedbar-mode
)
425 (gdb-find-watch-expression) "%e")) arg
)
426 nil
"Print the Emacs s-expression.")
428 (define-key gud-minor-mode-map
[left-margin mouse-1
]
429 'gdb-mouse-set-clear-breakpoint
)
430 (define-key gud-minor-mode-map
[left-fringe mouse-1
]
431 'gdb-mouse-set-clear-breakpoint
)
432 (define-key gud-minor-mode-map
[left-margin C-mouse-1
]
433 'gdb-mouse-toggle-breakpoint-margin
)
434 (define-key gud-minor-mode-map
[left-fringe C-mouse-1
]
435 'gdb-mouse-toggle-breakpoint-fringe
)
437 (define-key gud-minor-mode-map
[left-margin drag-mouse-1
]
439 (define-key gud-minor-mode-map
[left-fringe drag-mouse-1
]
441 (define-key gud-minor-mode-map
[left-margin mouse-3
]
443 (define-key gud-minor-mode-map
[left-fringe mouse-3
]
446 (define-key gud-minor-mode-map
[left-margin C-drag-mouse-1
]
448 (define-key gud-minor-mode-map
[left-fringe C-drag-mouse-1
]
450 (define-key gud-minor-mode-map
[left-fringe C-mouse-3
]
452 (define-key gud-minor-mode-map
[left-margin C-mouse-3
]
456 (setq gdb-pc-address
(if gdb-show-main
"main" nil
))
457 (setq gdb-selected-frame nil
460 gdb-pending-triggers nil
461 gdb-output-sink
'user
462 gdb-location-alist nil
463 gdb-source-file-list nil
466 gdb-handler-alist
'()
467 gdb-handler-number nil
469 gdb-first-done-or-error t
470 gdb-buffer-fringe-width
(car (window-fringes))
472 gdb-source-window nil
473 gdb-inferior-status nil
474 gdb-continuation nil
)
476 (setq gdb-buffer-type
'gdbmi
)
478 (gdb-force-mode-line-update
479 (propertize "initializing..." 'face font-lock-variable-name-face
))
481 (when gdb-use-separate-io-buffer
482 (gdb-get-buffer-create 'gdb-inferior-io
)
483 (gdb-clear-inferior-io)
484 (set-process-filter (get-process "gdb-inferior") 'gdb-inferior-filter
)
486 ;; Needs GDB 6.4 onwards
487 (list (concat "-inferior-tty-set "
488 (process-tty-name (get-process "gdb-inferior")) "\n")
490 (if (eq window-system
'w32
)
491 (gdb-input (list "-gdb-set new-console off\n" 'ignore
)))
492 (gdb-input (list "-gdb-set height 0\n" 'ignore
))
493 ;; find source file and compilation directory here
495 ; Needs GDB 6.2 onwards.
496 (list "-file-list-exec-source-files\n" 'gdb-get-source-file-list
))
497 (if gdb-create-source-file-list
499 ; Needs GDB 6.0 onwards.
500 (list "-file-list-exec-source-file\n" 'gdb-get-source-file
)))
502 (list "-data-list-register-names\n" 'gdb-get-register-names
))
504 (list "-gdb-show prompt\n" 'gdb-get-prompt
)))
506 (defvar gdb-define-alist nil
"Alist of #define directives for GUD tooltips.")
508 (defun gdb-create-define-alist ()
509 "Create an alist of #define directives for GUD tooltips."
510 (let* ((file (buffer-file-name))
512 (with-output-to-string
513 (with-current-buffer standard-output
516 ;; call-process doesn't work with remote file names.
517 (not (file-remote-p default-directory
))
518 (call-process shell-file-name file
519 (list t nil
) nil
"-c"
520 (concat gdb-cpp-define-alist-program
" "
521 gdb-cpp-define-alist-flags
))))))
522 (define-list (split-string output
"\n" t
))
524 (setq gdb-define-alist nil
)
525 (dolist (define define-list
)
526 (setq name
(nth 1 (split-string define
"[( ]")))
527 (push (cons name define
) gdb-define-alist
))))
529 (declare-function tooltip-show
"tooltip" (text &optional use-echo-area
))
530 (defvar tooltip-use-echo-area
)
532 (defun gdb-tooltip-print (expr)
534 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer
)
535 (goto-char (point-min))
537 (if (search-forward "=" nil t
)
538 (concat expr
(buffer-substring (- (point) 2) (point-max)))
540 ;; remove newline for gud-tooltip-echo-area
541 (substring string
0 (- (length string
) 1))))
542 (or gud-tooltip-echo-area tooltip-use-echo-area
543 (not (display-graphic-p)))))
545 ;; If expr is a macro for a function don't print because of possible dangerous
546 ;; side-effects. Also printing a function within a tooltip generates an
547 ;; unexpected starting annotation (phase error).
548 (defun gdb-tooltip-print-1 (expr)
549 (with-current-buffer (gdb-get-buffer 'gdb-partial-output-buffer
)
550 (goto-char (point-min))
551 (if (search-forward "expands to: " nil t
)
552 (unless (looking-at "\\S-+.*(.*).*")
554 (list (concat "print " expr
"\n")
555 `(lambda () (gdb-tooltip-print ,expr
))))))))
557 (defun gdb-init-buffer ()
558 (set (make-local-variable 'gud-minor-mode
) 'gdbmi
)
559 (set (make-local-variable 'tool-bar-map
) gud-tool-bar-map
)
560 (when gud-tooltip-mode
561 (make-local-variable 'gdb-define-alist
)
562 (gdb-create-define-alist)
563 (add-hook 'after-save-hook
'gdb-create-define-alist nil t
)))
565 (defmacro gdb-if-arrow
(arrow-position &rest body
)
567 (let ((buffer (marker-buffer ,arrow-position
)) (line))
568 (if (equal buffer
(window-buffer (posn-window end
)))
569 (with-current-buffer buffer
570 (when (or (equal start end
)
571 (equal (posn-point start
)
572 (marker-position ,arrow-position
)))
575 (defun gdb-mouse-until (event)
576 "Continue running until a source line past the current line.
577 The destination source line can be selected either by clicking
578 with mouse-3 on the fringe/margin or dragging the arrow
579 with mouse-1 (default bindings)."
581 (let ((start (event-start event
))
582 (end (event-end event
)))
583 (gdb-if-arrow gud-overlay-arrow-position
584 (setq line
(line-number-at-pos (posn-point end
)))
585 (gud-call (concat "until " (number-to-string line
))))
586 (gdb-if-arrow gdb-overlay-arrow-position
588 (goto-line (line-number-at-pos (posn-point end
)))
590 (gud-call (concat "until *%a"))))))
592 (defun gdb-mouse-jump (event)
593 "Set execution address/line.
594 The destination source line can be selected either by clicking with C-mouse-3
595 on the fringe/margin or dragging the arrow with C-mouse-1 (default bindings).
596 Unlike `gdb-mouse-until' the destination address can be before the current
597 line, and no execution takes place."
599 (let ((start (event-start event
))
600 (end (event-end event
)))
601 (gdb-if-arrow gud-overlay-arrow-position
602 (setq line
(line-number-at-pos (posn-point end
)))
604 (gud-call (concat "tbreak " (number-to-string line
)))
605 (gud-call (concat "jump " (number-to-string line
)))))
606 (gdb-if-arrow gdb-overlay-arrow-position
608 (goto-line (line-number-at-pos (posn-point end
)))
611 (gud-call (concat "tbreak *%a"))
612 (gud-call (concat "jump *%a")))))))
614 (defcustom gdb-show-changed-values t
615 "If non-nil change the face of out of scope variables and changed values.
616 Out of scope variables are suppressed with `shadow' face.
617 Changed values are highlighted with the face `font-lock-warning-face'."
622 (defcustom gdb-max-children
40
623 "Maximum number of children before expansion requires confirmation."
628 (defcustom gdb-delete-out-of-scope t
629 "If non-nil delete watch expressions automatically when they go out of scope."
634 (defcustom gdb-speedbar-auto-raise nil
635 "If non-nil raise speedbar every time display of watch expressions is\
641 (defcustom gdb-use-colon-colon-notation nil
642 "If non-nil use FUN::VAR format to display variables in the speedbar."
647 (defun gdb-speedbar-auto-raise (arg)
648 "Toggle automatic raising of the speedbar for watch expressions.
649 With prefix argument ARG, automatically raise speedbar if ARG is
650 positive, otherwise don't automatically raise it."
652 (setq gdb-speedbar-auto-raise
654 (not gdb-speedbar-auto-raise
)
655 (> (prefix-numeric-value arg
) 0)))
656 (message (format "Auto raising %sabled"
657 (if gdb-speedbar-auto-raise
"en" "dis"))))
659 (define-key gud-minor-mode-map
"\C-c\C-w" 'gud-watch
)
660 (define-key global-map
(concat gud-key-prefix
"\C-w") 'gud-watch
)
662 (declare-function tooltip-identifier-from-point
"tooltip" (point))
664 (defun gud-watch (&optional arg event
)
665 "Watch expression at point.
666 With arg, enter name of variable to be watched in the minibuffer."
667 (interactive (list current-prefix-arg last-input-event
))
668 (let ((minor-mode (buffer-local-value 'gud-minor-mode gud-comint-buffer
)))
669 (if (eq minor-mode
'gdbmi
)
671 (if event
(posn-set-point (event-end event
)))
673 (save-selected-window
676 (completing-read "Name of variable: "
677 'gud-gdb-complete-command
)
678 (if (and transient-mark-mode mark-active
)
679 (buffer-substring (region-beginning) (region-end))
680 (concat (if (eq major-mode
'gdb-registers-mode
) "$")
681 (tooltip-identifier-from-point (point)))))))
682 (set-text-properties 0 (length expr
) nil expr
)
684 (list (concat"-var-create - * " expr
"\n")
685 `(lambda () (gdb-var-create-handler ,expr
)))))))
686 (message "gud-watch is a no-op in this mode."))))
688 (defconst gdb-var-create-regexp
689 "name=\"\\(.*?\\)\",.*numchild=\"\\(.*?\\)\",\\(?:.*value=\\(\".*\"\\),\\)?.*type=\"\\(.*?\\)\"")
691 (defun gdb-var-create-handler (expr)
692 (goto-char (point-min))
693 (if (re-search-forward gdb-var-create-regexp nil t
)
696 (if (and (string-equal gdb-current-language
"c")
697 gdb-use-colon-colon-notation gdb-selected-frame
)
698 (setq expr
(concat gdb-selected-frame
"::" expr
))
702 (if (match-string 3) (read (match-string 3)))
704 (push var gdb-var-list
)
706 (unless (string-equal
707 speedbar-initial-expansion-list-name
"GUD")
708 (speedbar-change-initial-expansion-list "GUD"))
711 (concat "-var-evaluate-expression " (car var
) "\n")
712 `(lambda () (gdb-var-evaluate-expression-handler
714 (message-box "No symbol \"%s\" in current context." expr
)))
716 (defun gdb-speedbar-update ()
717 (when (and (boundp 'speedbar-frame
) (frame-live-p speedbar-frame
)
718 (not (member 'gdb-speedbar-timer gdb-pending-triggers
)))
719 ;; Dummy command to update speedbar even when idle.
720 (gdb-input (list "-environment-pwd\n" 'gdb-speedbar-timer-fn
))
721 ;; Keep gdb-pending-triggers non-nil till end.
722 (push 'gdb-speedbar-timer gdb-pending-triggers
)))
724 (defun gdb-speedbar-timer-fn ()
725 (if gdb-speedbar-auto-raise
726 (raise-frame speedbar-frame
))
727 (setq gdb-pending-triggers
728 (delq 'gdb-speedbar-timer gdb-pending-triggers
))
731 (defun gdb-var-evaluate-expression-handler (varnum changed
)
732 (goto-char (point-min))
733 (re-search-forward ".*value=\\(\".*\"\\)" nil t
)
734 (let ((var (assoc varnum gdb-var-list
)))
736 (if changed
(setcar (nthcdr 5 var
) 'changed
))
737 (setcar (nthcdr 4 var
) (read (match-string 1)))))
738 (gdb-speedbar-update))
740 ; Uses "-var-list-children --all-values". Needs GDB 6.1 onwards.
741 (defun gdb-var-list-children (varnum)
743 (list (concat "-var-update " varnum
"\n") 'ignore
))
745 (list (concat "-var-list-children --all-values "
747 `(lambda () (gdb-var-list-children-handler ,varnum
)))))
749 (defconst gdb-var-list-children-regexp
750 "child={.*?name=\"\\(.+?\\)\".*?,exp=\"\\(.+?\\)\".*?,\
751 numchild=\"\\(.+?\\)\".*?,value=\\(\".*?\"\\).*?,type=\"\\(.+?\\)\".*?}")
753 (defun gdb-var-list-children-handler (varnum)
754 (goto-char (point-min))
755 (let ((var-list nil
))
756 (catch 'child-already-watched
757 (dolist (var gdb-var-list
)
758 (if (string-equal varnum
(car var
))
761 (while (re-search-forward gdb-var-list-children-regexp nil t
)
762 (let ((varchild (list (match-string 1)
766 (read (match-string 4))
768 (if (assoc (car varchild
) gdb-var-list
)
769 (throw 'child-already-watched nil
))
770 (push varchild var-list
))))
771 (push var var-list
)))
772 (setq gdb-var-list
(nreverse var-list
))))
773 (gdb-speedbar-update))
775 (defun gdb-var-set-format (format)
776 "Set the output format for a variable displayed in the speedbar."
777 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
780 (list (concat "-var-set-format " varnum
" " format
"\n") 'ignore
))
783 (defun gdb-var-delete-1 (varnum)
785 (list (concat "-var-delete " varnum
"\n") 'ignore
))
786 (setq gdb-var-list
(delq var gdb-var-list
))
787 (dolist (varchild gdb-var-list
)
788 (if (string-match (concat (car var
) "\\.") (car varchild
))
789 (setq gdb-var-list
(delq varchild gdb-var-list
)))))
791 (defun gdb-var-delete ()
792 "Delete watch expression at point from the speedbar."
794 (let ((text (speedbar-line-text)))
795 (string-match "\\(\\S-+\\)" text
)
796 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
798 (if (string-match "\\." (car var
))
799 (message-box "Can only delete a root expression")
800 (gdb-var-delete-1 varnum
)))))
802 (defun gdb-var-delete-children (varnum)
803 "Delete children of variable object at point from the speedbar."
805 (list (concat "-var-delete -c " varnum
"\n") 'ignore
)))
807 (defun gdb-edit-value (text token indent
)
808 "Assign a value to a variable displayed in the speedbar."
809 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list
))
810 (varnum (car var
)) (value))
811 (setq value
(read-string "New value: "))
813 (list (concat "-var-assign " varnum
" " value
"\n")
814 `(lambda () (gdb-edit-value-handler ,value
))))))
816 (defconst gdb-error-regexp
"\\^error,msg=\\(\".+\"\\)")
818 (defun gdb-edit-value-handler (value)
819 (goto-char (point-min))
820 (if (re-search-forward gdb-error-regexp nil t
)
821 (message-box "Invalid number or expression (%s)" value
)))
823 ; Uses "-var-update --all-values". Needs GDB 6.4 onwards.
824 (defun gdb-var-update ()
825 (if (not (member 'gdb-var-update gdb-pending-triggers
))
827 (list "-var-update --all-values *\n" 'gdb-var-update-handler
)))
828 (push 'gdb-var-update gdb-pending-triggers
))
830 (defconst gdb-var-update-regexp
831 "{.*?name=\"\\(.*?\\)\".*?,\\(?:value=\\(\".*?\"\\),\\)?.*?\
832 in_scope=\"\\(.*?\\)\".*?}")
834 (defun gdb-var-update-handler ()
835 (dolist (var gdb-var-list
)
836 (setcar (nthcdr 5 var
) nil
))
837 (goto-char (point-min))
838 (while (re-search-forward gdb-var-update-regexp nil t
)
839 (let* ((varnum (match-string 1))
840 (var (assoc varnum gdb-var-list
)))
842 (let ((match (match-string 3)))
843 (cond ((string-equal match
"false")
844 (if gdb-delete-out-of-scope
845 (gdb-var-delete-1 varnum
)
846 (setcar (nthcdr 5 var
) 'out-of-scope
)))
847 ((string-equal match
"true")
848 (setcar (nthcdr 5 var
) 'changed
)
849 (setcar (nthcdr 4 var
)
850 (read (match-string 2))))
851 ((string-equal match
"invalid")
852 (gdb-var-delete-1 varnum
)))))))
853 (setq gdb-pending-triggers
854 (delq 'gdb-var-update gdb-pending-triggers
))
855 (gdb-speedbar-update))
857 (defun gdb-speedbar-expand-node (text token indent
)
858 "Expand the node the user clicked on.
859 TEXT is the text of the button we clicked on, a + or - item.
860 TOKEN is data related to this node.
861 INDENT is the current indentation depth."
862 (cond ((string-match "+" text
) ;expand this node
863 (let* ((var (assoc token gdb-var-list
))
864 (expr (nth 1 var
)) (children (nth 2 var
)))
865 (if (or (<= (string-to-number children
) gdb-max-children
)
867 (format "%s has %s children. Continue? " expr children
)))
868 (gdb-var-list-children token
))))
869 ((string-match "-" text
) ;contract this node
870 (dolist (var gdb-var-list
)
871 (if (string-match (concat token
"\\.") (car var
))
872 (setq gdb-var-list
(delq var gdb-var-list
))))
873 (gdb-var-delete-children token
)
874 (speedbar-change-expand-button-char ?
+)
875 (speedbar-delete-subblock indent
))
876 (t (error "Ooops... not sure what to do")))
877 (speedbar-center-buffer-smartly))
879 (defun gdb-get-target-string ()
880 (with-current-buffer gud-comint-buffer
887 ;; Each buffer has a TYPE -- a symbol that identifies the function
888 ;; of that particular buffer.
890 ;; The usual gdb interaction buffer is given the type `gdbmi' and
891 ;; is constructed specially.
893 ;; Others are constructed by gdb-get-buffer-create and
894 ;; named according to the rules set forth in the gdb-buffer-rules-assoc
896 (defvar gdb-buffer-rules-assoc
'())
898 (defun gdb-get-buffer (key)
899 "Return the gdb buffer tagged with type KEY.
900 The key should be one of the cars in `gdb-buffer-rules-assoc'."
902 (gdb-look-for-tagged-buffer key
(buffer-list))))
904 (defun gdb-get-buffer-create (key)
905 "Create a new gdb buffer of the type specified by KEY.
906 The key should be one of the cars in `gdb-buffer-rules-assoc'."
907 (or (gdb-get-buffer key
)
908 (let* ((rules (assoc key gdb-buffer-rules-assoc
))
909 (name (funcall (gdb-rules-name-maker rules
)))
910 (new (get-buffer-create name
)))
911 (with-current-buffer new
913 (if (cdr (cdr rules
))
914 (setq trigger
(funcall (car (cdr (cdr rules
))))))
915 (setq gdb-buffer-type key
)
916 (set (make-local-variable 'gud-minor-mode
)
917 (buffer-local-value 'gud-minor-mode gud-comint-buffer
))
918 (set (make-local-variable 'tool-bar-map
) gud-tool-bar-map
)
919 (if trigger
(funcall trigger
)))
922 (defun gdb-rules-name-maker (rules) (car (cdr rules
)))
924 (defun gdb-look-for-tagged-buffer (key bufs
)
926 (while (and (not retval
) bufs
)
927 (set-buffer (car bufs
))
928 (if (eq gdb-buffer-type key
)
929 (setq retval
(car bufs
)))
930 (setq bufs
(cdr bufs
)))
933 ;; Used to define all gdb-frame-*-buffer functions except
934 ;; `gdb-frame-separate-io-buffer'
935 (defmacro def-gdb-frame-for-buffer
(name buffer
&optional doc
)
936 "Define a function NAME which shows gdb BUFFER in a separate frame.
938 DOC is an optional documentation string."
942 (let ((special-display-regexps (append special-display-regexps
'(".*")))
943 (special-display-frame-alist gdb-frame-parameters
))
944 (display-buffer (gdb-get-buffer-create ,buffer
)))))
946 (defmacro def-gdb-display-buffer
(name buffer
&optional doc
)
947 "Define a function NAME which shows gdb BUFFER.
949 DOC is an optional documentation string."
954 (gdb-get-buffer-create ,buffer
) t
)))
957 ;; This assoc maps buffer type symbols to rules. Each rule is a list of
958 ;; at least one and possible more functions. The functions have these
959 ;; roles in defining a buffer type:
961 ;; NAME - Return a name for this buffer type.
963 ;; The remaining function(s) are optional:
965 ;; MODE - called in a new buffer with no arguments, should establish
966 ;; the proper mode for the buffer.
969 (defun gdb-set-buffer-rules (buffer-type &rest rules
)
970 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc
)))
972 (setcdr binding rules
)
973 (push (cons buffer-type rules
)
974 gdb-buffer-rules-assoc
))))
976 ;; GUD buffers are an exception to the rules
977 (gdb-set-buffer-rules 'gdbmi
'error
)
979 ;; Partial-output buffer : This accumulates output from a command executed on
980 ;; behalf of emacs (rather than the user).
982 (gdb-set-buffer-rules 'gdb-partial-output-buffer
983 'gdb-partial-output-name
)
985 (defun gdb-partial-output-name ()
986 (concat " *partial-output-"
987 (gdb-get-target-string)
991 (gdb-set-buffer-rules 'gdb-inferior-io
992 'gdb-inferior-io-name
993 'gdb-inferior-io-mode
)
995 (defun gdb-inferior-io-name ()
996 (concat "*input/output of "
997 (gdb-get-target-string)
1000 (defun gdb-display-separate-io-buffer ()
1001 "Display IO of debugged program in a separate window."
1003 (if gdb-use-separate-io-buffer
1005 (gdb-get-buffer-create 'gdb-inferior-io
) t
)))
1007 (defconst gdb-frame-parameters
1008 '((height .
14) (width .
80)
1010 (tool-bar-lines . nil
)
1011 (menu-bar-lines . nil
)
1012 (minibuffer . nil
)))
1014 (defun gdb-frame-separate-io-buffer ()
1015 "Display IO of debugged program in a new frame."
1017 (if gdb-use-separate-io-buffer
1018 (let ((special-display-regexps (append special-display-regexps
'(".*")))
1019 (special-display-frame-alist gdb-frame-parameters
))
1020 (display-buffer (gdb-get-buffer-create 'gdb-inferior-io
)))))
1022 (defvar gdb-inferior-io-mode-map
1023 (let ((map (make-sparse-keymap)))
1024 (define-key map
"\C-c\C-c" 'gdb-separate-io-interrupt
)
1025 (define-key map
"\C-c\C-z" 'gdb-separate-io-stop
)
1026 (define-key map
"\C-c\C-\\" 'gdb-separate-io-quit
)
1027 (define-key map
"\C-c\C-d" 'gdb-separate-io-eof
)
1028 (define-key map
"\C-d" 'gdb-separate-io-eof
)
1031 (define-derived-mode gdb-inferior-io-mode comint-mode
"Inferior I/O"
1032 "Major mode for gdb inferior-io."
1033 :syntax-table nil
:abbrev-table nil
1034 ;; We want to use comint because it has various nifty and familiar
1035 ;; features. We don't need a process, but comint wants one, so create
1037 (make-comint-in-buffer
1038 "gdb-inferior" (current-buffer) "sleep" nil
"1000000000"))
1040 (defun gdb-inferior-filter (proc string
)
1041 (unless (string-equal string
"")
1042 (gdb-display-buffer (gdb-get-buffer-create 'gdb-inferior-io
) t
))
1043 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io
)
1044 (insert-before-markers string
)))
1046 (defun gdb-separate-io-interrupt ()
1047 "Interrupt the program being debugged."
1050 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
1052 (defun gdb-separate-io-quit ()
1053 "Send quit signal to the program being debugged."
1056 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
1058 (defun gdb-separate-io-stop ()
1059 "Stop the program being debugged."
1062 (get-buffer-process gud-comint-buffer
) comint-ptyp
))
1064 (defun gdb-separate-io-eof ()
1065 "Send end-of-file to the program being debugged."
1068 (get-buffer-process gud-comint-buffer
)))
1070 (defun gdb-clear-inferior-io ()
1071 (with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io
)
1075 (defconst breakpoint-xpm-data
1077 static char *magick[] = {
1078 /* columns rows colors chars-per-pixel */
1094 "XPM data used for breakpoint icon.")
1096 (defconst breakpoint-enabled-pbm-data
1099 0 0 0 0 1 1 1 1 0 0 0 0
1100 0 0 0 1 1 1 1 1 1 0 0 0
1101 0 0 1 1 1 1 1 1 1 1 0 0
1102 0 1 1 1 1 1 1 1 1 1 1 0
1103 0 1 1 1 1 1 1 1 1 1 1 0
1104 0 1 1 1 1 1 1 1 1 1 1 0
1105 0 1 1 1 1 1 1 1 1 1 1 0
1106 0 0 1 1 1 1 1 1 1 1 0 0
1107 0 0 0 1 1 1 1 1 1 0 0 0
1108 0 0 0 0 1 1 1 1 0 0 0 0"
1109 "PBM data used for enabled breakpoint icon.")
1111 (defconst breakpoint-disabled-pbm-data
1123 0 0 0 1 0 1 0 1 0 0"
1124 "PBM data used for disabled breakpoint icon.")
1126 (defvar breakpoint-enabled-icon nil
1127 "Icon for enabled breakpoint in display margin.")
1129 (defvar breakpoint-disabled-icon nil
1130 "Icon for disabled breakpoint in display margin.")
1132 (declare-function define-fringe-bitmap
"fringe.c"
1133 (bitmap bits
&optional height width align
))
1135 (and (display-images-p)
1136 ;; Bitmap for breakpoint in fringe
1137 (define-fringe-bitmap 'breakpoint
1138 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c")
1139 ;; Bitmap for gud-overlay-arrow in fringe
1140 (define-fringe-bitmap 'hollow-right-triangle
1141 "\xe0\x90\x88\x84\x84\x88\x90\xe0"))
1143 (defface breakpoint-enabled
1147 "Face for enabled breakpoint icon in fringe."
1150 (defface breakpoint-disabled
1151 '((((class color
) (min-colors 88)) :foreground
"grey70")
1152 ;; Ensure that on low-color displays that we end up something visible.
1153 (((class color
) (min-colors 8) (background light
))
1154 :foreground
"black")
1155 (((class color
) (min-colors 8) (background dark
))
1156 :foreground
"white")
1157 (((type tty
) (class mono
))
1159 (t :background
"gray"))
1160 "Face for disabled breakpoint icon in fringe."
1164 (defun gdb-send (proc string
)
1165 "A comint send filter for gdb."
1166 (with-current-buffer gud-comint-buffer
1167 (let ((inhibit-read-only t
))
1168 (remove-text-properties (point-min) (point-max) '(face))))
1169 ;; mimic <RET> key to repeat previous command in GDB
1170 (if (not (string-match "^\\s+$" string
))
1171 (setq gdb-last-command string
)
1172 (if gdb-last-command
(setq string gdb-last-command
)))
1173 (if gdb-enable-debug
1174 (push (cons 'mi-send
(concat string
"\n")) gdb-debug-log
))
1175 (if (string-match "^-" string
)
1178 (setq gdb-first-done-or-error t
)
1179 (process-send-string proc
(concat string
"\n")))
1181 (if (string-match "\\\\$" string
)
1182 (setq gdb-continuation
(concat gdb-continuation string
"\n"))
1183 (setq gdb-first-done-or-error t
)
1184 (process-send-string proc
(concat "-interpreter-exec console \""
1185 gdb-continuation string
"\"\n"))
1186 (setq gdb-continuation nil
))))
1188 (defun gdb-input (item)
1189 (if gdb-enable-debug
(push (cons 'send-item item
) gdb-debug-log
))
1190 (setq gdb-token-number
(1+ gdb-token-number
))
1191 (setcar item
(concat (number-to-string gdb-token-number
) (car item
)))
1192 (push (cons gdb-token-number
(car (cdr item
))) gdb-handler-alist
)
1193 (process-send-string (get-buffer-process gud-comint-buffer
)
1197 (defcustom gud-gdb-command-name
"gdb -i=mi"
1198 "Default command to execute an executable under the GDB debugger."
1203 (setq gud-running nil
)
1204 (setq gdb-output-sink
'user
)
1205 (setq gdb-pending-triggers nil
))
1207 (defun gdb-update ()
1208 "Update buffers showing status of debug session."
1209 (when gdb-first-prompt
1210 (gdb-force-mode-line-update
1211 (propertize "initializing..." 'face font-lock-variable-name-face
))
1213 (setq gdb-first-prompt nil
))
1214 (gdb-get-selected-frame)
1215 (gdb-invalidate-frames)
1216 ;; Regenerate breakpoints buffer in case it has been inadvertantly deleted.
1217 (gdb-get-buffer-create 'gdb-breakpoints-buffer
)
1218 (gdb-invalidate-breakpoints)
1219 (gdb-invalidate-threads)
1220 (gdb-get-changed-registers)
1221 (gdb-invalidate-registers)
1222 (gdb-invalidate-locals)
1223 (gdb-invalidate-disassembly)
1224 (gdb-invalidate-memory)
1225 (when (and (boundp 'speedbar-frame
) (frame-live-p speedbar-frame
))
1226 (dolist (var gdb-var-list
)
1227 (setcar (nthcdr 5 var
) nil
))
1230 ;; GUD displays the selected GDB frame. This might might not be the current
1231 ;; GDB frame (after up, down etc). If no GDB frame is visible but the last
1232 ;; visited breakpoint is, use that window.
1233 (defun gdb-display-source-buffer (buffer)
1234 (let* ((last-window (if gud-last-last-frame
1236 (gud-find-file (car gud-last-last-frame
)))))
1237 (source-window (or last-window
1238 (if (and gdb-source-window
1239 (window-live-p gdb-source-window
))
1240 gdb-source-window
))))
1242 (setq gdb-source-window source-window
)
1243 (set-window-buffer source-window buffer
))
1246 (defun gdb-car< (a b
)
1247 (< (car a
) (car b
)))
1249 (defvar gdbmi-record-list
1250 '((gdb-gdb .
"(gdb) \n")
1251 (gdb-done .
"\\([0-9]*\\)\\^done,?\\(.*?\\)\n")
1252 (gdb-starting .
"\\([0-9]*\\)\\^running\n")
1253 (gdb-error .
"\\([0-9]*\\)\\^error,\\(.*?\\)\n")
1254 (gdb-console .
"~\\(\".*?\"\\)\n")
1255 (gdb-internals .
"&\\(\".*?\"\\)\n")
1256 (gdb-stopped .
"\\*stopped,?\\(.*?\n\\)")
1257 (gdb-running .
"\\*running,\\(.*?\n\\)")
1258 (gdb-thread-created .
"=thread-created,\\(.*?\n\\)")
1259 (gdb-thread-exited .
"=thread-exited,\\(.*?\n\\)")))
1261 (defun gud-gdbmi-marker-filter (string)
1262 "Filter GDB/MI output."
1264 ;; Record transactions if logging is enabled.
1265 (when gdb-enable-debug
1266 (push (cons 'recv string
) gdb-debug-log
)
1267 (if (and gdb-debug-log-max
1268 (> (length gdb-debug-log
) gdb-debug-log-max
))
1269 (setcdr (nthcdr (1- gdb-debug-log-max
) gdb-debug-log
) nil
)))
1271 ;; Recall the left over gud-marker-acc from last time
1272 (setq gud-marker-acc
(concat gud-marker-acc string
))
1274 ;; Start accumulating output for the GUD buffer
1275 (setq gdb-filter-output
"")
1276 (let ((output-record) (output-record-list))
1278 ;; Process all the complete markers in this chunk.
1279 (dolist (gdbmi-record gdbmi-record-list
)
1280 (while (string-match (cdr gdbmi-record
) gud-marker-acc
)
1281 (push (list (match-beginning 0)
1283 (match-string 1 gud-marker-acc
)
1284 (match-string 2 gud-marker-acc
)
1287 (setq gud-marker-acc
1288 (concat (substring gud-marker-acc
0 (match-beginning 0))
1289 ;; Pad with spaces to preserve position.
1290 (make-string (length (match-string 0 gud-marker-acc
)) 32)
1291 (substring gud-marker-acc
(match-end 0))))))
1293 (setq output-record-list
(sort output-record-list
'gdb-car
<))
1295 (dolist (output-record output-record-list
)
1296 (let ((record-type (cadr output-record
))
1297 (arg1 (nth 2 output-record
))
1298 (arg2 (nth 3 output-record
)))
1299 (if (eq record-type
'gdb-error
)
1300 (gdb-done-or-error arg2 arg1
'error
)
1301 (if (eq record-type
'gdb-done
)
1302 (gdb-done-or-error arg2 arg1
'done
)
1303 ;; Suppress "No registers." since GDB 6.8 and earlier duplicates MI
1304 ;; error message on internal stream. Don't print to GUD buffer.
1305 (unless (and (eq record-type
'gdb-internals
)
1306 (string-equal (read arg1
) "No registers.\n"))
1307 (funcall record-type arg1
))))))
1309 (setq gdb-output-sink
'user
)
1311 (string-match "^ *" gud-marker-acc
)
1312 (setq gud-marker-acc
(substring gud-marker-acc
(match-end 0)))
1316 (defun gdb-gdb (output-field))
1317 (defun gdb-thread-created (output-field))
1318 (defun gdb-thread-exited (output-field))
1320 (defun gdb-running (output-field)
1321 (setq gdb-inferior-status
"running")
1322 (gdb-force-mode-line-update
1323 (propertize gdb-inferior-status
'face font-lock-type-face
))
1324 (setq gdb-active-process t
)
1325 (setq gud-running t
))
1327 (defun gdb-starting (output-field)
1328 ;; CLI commands don't emit ^running at the moment so use gdb-running too.
1329 (setq gdb-inferior-status
"running")
1330 (gdb-force-mode-line-update
1331 (propertize gdb-inferior-status
'face font-lock-type-face
))
1332 (setq gdb-active-process t
)
1333 (setq gud-running t
))
1335 ;; -break-insert -t didn't give a reason before gdb 6.9
1336 (defconst gdb-stopped-regexp
1337 "\\(reason=\"\\(.*?\\)\"\\)?\\(\\(,exit-code=.*?\\)*\n\\|.*?,file=\".*?\".*?,fullname=\"\\(.*?\\)\".*?,line=\"\\(.*?\\)\".*?\n\\)")
1339 (defun gdb-stopped (output-field)
1340 (setq gud-running nil
)
1341 (string-match gdb-stopped-regexp output-field
)
1342 (let ((reason (match-string 2 output-field
))
1343 (file (match-string 5 output-field
)))
1345 ;;; Don't set gud-last-frame here as it's currently done in gdb-frame-handler
1346 ;;; because synchronous GDB doesn't give these fields with CLI.
1349 ;;; ;; Extract the frame position from the marker.
1350 ;;; gud-last-frame (cons file
1351 ;;; (string-to-number
1352 ;;; (match-string 6 gud-marker-acc)))))
1354 (setq gdb-inferior-status
(if reason reason
"unknown"))
1355 (gdb-force-mode-line-update
1356 (propertize gdb-inferior-status
'face font-lock-warning-face
))
1357 (if (string-equal reason
"exited-normally")
1358 (setq gdb-active-process nil
)))
1360 (when gdb-first-done-or-error
1361 (setq gdb-filter-output
(concat gdb-filter-output gdb-prompt-name
))
1363 (setq gdb-first-done-or-error nil
)))
1365 ;; Remove the trimmings from log stream containing debugging messages
1366 ;; being produced by GDB's internals, use warning face and send to GUD
1368 (defun gdb-internals (output-field)
1369 (setq gdb-filter-output
1372 (let ((error-message
1373 (read output-field
)))
1375 0 (length error-message
)
1376 'face font-lock-warning-face
1380 ;; Remove the trimmings from the console stream and send to GUD buffer
1381 ;; (frontend MI commands should not print to this stream)
1382 (defun gdb-console (output-field)
1383 (setq gdb-filter-output
1386 (read output-field
))))
1388 (defun gdb-done-or-error (output-field token-number type
)
1389 (if (string-equal token-number
"")
1390 ;; Output from command entered by user
1392 (setq gdb-output-sink
'user
)
1393 (setq token-number nil
)
1394 ;; MI error - send to minibuffer
1395 (when (eq type
'error
)
1396 ;; Skip "msg=" from `output-field'
1397 (message (read (substring output-field
4)))
1398 ;; Don't send to the console twice. (If it is a console error
1399 ;; it is also in the console stream.)
1400 (setq output-field nil
)))
1401 ;; Output from command from frontend.
1402 (setq gdb-output-sink
'emacs
))
1404 (gdb-clear-partial-output)
1405 (when gdb-first-done-or-error
1406 (unless (or token-number gud-running
)
1407 (setq gdb-filter-output
(concat gdb-filter-output gdb-prompt-name
)))
1409 (setq gdb-first-done-or-error nil
))
1411 (setq gdb-filter-output
1412 (gdb-concat-output gdb-filter-output output-field
))
1416 (with-current-buffer
1417 (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1419 (cdr (assoc (string-to-number token-number
) gdb-handler-alist
))))
1420 (setq gdb-handler-alist
1421 (assq-delete-all token-number gdb-handler-alist
)))))
1423 (defun gdb-concat-output (so-far new
)
1424 (let ((sink gdb-output-sink
))
1426 ((eq sink
'user
) (concat so-far new
))
1428 (gdb-append-to-partial-output new
)
1431 (defun gdb-append-to-partial-output (string)
1432 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1433 (goto-char (point-max))
1436 (defun gdb-clear-partial-output ()
1437 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1440 (defun json-partial-output (&optional fix-key
)
1441 "Parse gdb-partial-output-buffer with `json-read'.
1443 If FIX-KEY is non-nil, strip all \"FIX-KEY=\" occurences from
1444 partial output. This is used to get rid of useless keys in lists
1445 in MI messages, e.g.: [key=.., key=..]. -stack-list-frames and
1446 -break-info are examples of MI commands which issue such
1449 Note that GDB/MI output syntax is different from JSON both
1450 cosmetically and (in some cases) structurally, so correct results
1451 are not guaranteed."
1452 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer
)
1453 (goto-char (point-min))
1454 (while (re-search-forward (concat "[\\[,]\\(" fix-key
"=\\)") nil t
)
1455 (replace-match "" nil nil nil
1))
1456 (goto-char (point-min))
1458 ;; Wrap field names in double quotes and replace equal sign with
1460 ;; TODO: This breaks badly with foo= inside constants
1461 (while (re-search-forward "\\([[:alpha:]-_]+\\)=" nil t
)
1462 (replace-match "\"\\1\":" nil nil
))
1463 (goto-char (point-max))
1465 (goto-char (point-min))
1466 (let ((json-array-type 'list
))
1469 (defalias 'gdb-get-field
'bindat-get-field
)
1471 (defun gdb-get-many-fields (struct &rest fields
)
1472 "Return a list of FIELDS values from STRUCT."
1474 (dolist (field fields values
)
1475 (setq values
(append values
(list (gdb-get-field struct field
)))))))
1477 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed.
1478 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the
1481 (defmacro def-gdb-auto-update-trigger
(name demand-predicate gdb-command
1483 `(defun ,name
(&optional ignored
)
1484 (if (and ,demand-predicate
1486 gdb-pending-triggers
)))
1489 (list ,gdb-command
',output-handler
))
1490 (push ',name gdb-pending-triggers
)))))
1492 (defmacro def-gdb-auto-update-handler
(name trigger buf-key custom-defun
)
1493 "Define a handler NAME for TRIGGER acting in BUF-KEY with CUSTOM-DEFUN.
1495 Delete TRIGGER from `gdb-pending-triggers', switch to gdb BUF-KEY
1496 buffer using `gdb-get-buffer', erase it and evalueat
1499 (setq gdb-pending-triggers
1501 gdb-pending-triggers
))
1502 (let ((buf (gdb-get-buffer ',buf-key
)))
1504 (with-current-buffer buf
1505 (let* ((window (get-buffer-window buf
0))
1506 (start (window-start window
))
1507 (p (window-point window
))
1508 (buffer-read-only nil
))
1510 (set-window-start window start
)
1511 (set-window-point window p
)
1512 (,custom-defun
)))))))
1514 (defmacro def-gdb-auto-updated-buffer
(buf-key
1515 trigger-name gdb-command
1516 output-handler-name custom-defun
)
1517 "Define a trigger and its handler for buffers of type BUF-KEY.
1519 TRIGGER-NAME trigger is defined to send GDB-COMMAND if BUF-KEY
1522 OUTPUT-HANDLER-NAME handler uses customization of CUSTOM-DEFUN."
1524 (def-gdb-auto-update-trigger ,trigger-name
1525 ;; The demand predicate:
1526 (gdb-get-buffer ',buf-key
)
1528 ,output-handler-name
)
1529 (def-gdb-auto-update-handler ,output-handler-name
1530 ,trigger-name
,buf-key
,custom-defun
)))
1534 ;; Breakpoint buffer : This displays the output of `-break-list'.
1536 (gdb-set-buffer-rules 'gdb-breakpoints-buffer
1537 'gdb-breakpoints-buffer-name
1538 'gdb-breakpoints-mode
)
1540 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer
1541 gdb-invalidate-breakpoints
"-break-list\n"
1542 gdb-breakpoints-list-handler gdb-breakpoints-list-handler-custom
)
1544 (defun gdb-breakpoints-list-handler-custom ()
1545 (setq gdb-pending-triggers
(delq 'gdb-invalidate-breakpoints
1546 gdb-pending-triggers
))
1547 (let ((breakpoints-list (gdb-get-field
1548 (json-partial-output "bkpt")
1549 'BreakpointTable
'body
)))
1550 (setq gdb-breakpoints-list breakpoints-list
)
1551 (insert "Num\tType\t\tDisp\tEnb\tHits\tAddr What\n")
1552 (dolist (breakpoint breakpoints-list
)
1555 (gdb-get-field breakpoint
'number
) "\t"
1556 (gdb-get-field breakpoint
'type
) "\t"
1557 (gdb-get-field breakpoint
'disp
) "\t"
1558 (let ((flag (gdb-get-field breakpoint
'enabled
)))
1559 (if (string-equal flag
"y")
1560 (propertize "on" 'face font-lock-warning-face
)
1561 (propertize "off" 'face font-lock-type-face
))) "\t"
1562 (gdb-get-field breakpoint
'times
) "\t"
1563 (gdb-get-field breakpoint
'addr
)))
1564 (let ((at (gdb-get-field breakpoint
'at
)))
1569 (propertize (gdb-get-field breakpoint
'func
)
1570 'face font-lock-function-name-face
)))
1571 (gdb-insert-frame-location breakpoint
)))
1573 (t (insert (gdb-get-field breakpoint
'original-location
)))))
1574 (add-text-properties (line-beginning-position)
1576 `(gdb-breakpoint ,breakpoint
1577 mouse-face highlight
1578 help-echo
"mouse-2, RET: visit breakpoint"))
1580 (gdb-place-breakpoints)))
1582 ;; Put breakpoint icons in relevant margins (even those set in the GUD buffer).
1583 (defun gdb-place-breakpoints ()
1584 (let ((flag) (bptno))
1585 ;; Remove all breakpoint-icons in source buffers but not assembler buffer.
1586 (dolist (buffer (buffer-list))
1587 (with-current-buffer buffer
1588 (if (and (eq gud-minor-mode
'gdbmi
)
1589 (not (string-match "\\` ?\\*.+\\*\\'" (buffer-name))))
1590 (gdb-remove-breakpoint-icons (point-min) (point-max)))))
1591 (dolist (breakpoint gdb-breakpoints-list
)
1592 (let ((line (gdb-get-field breakpoint
'line
)))
1594 (let ((file (gdb-get-field breakpoint
'file
))
1595 (flag (gdb-get-field breakpoint
'enabled
))
1596 (bptno (gdb-get-field breakpoint
'number
)))
1597 (unless (file-exists-p file
)
1598 (setq file
(cdr (assoc bptno gdb-location-alist
))))
1600 (not (string-equal file
"File not found")))
1601 (with-current-buffer
1602 (find-file-noselect file
'nowarn
)
1604 ;; Only want one breakpoint icon at each location.
1606 (goto-line (string-to-number line
))
1607 (gdb-put-breakpoint-icon (string-equal flag
"y") bptno
)))
1609 (list (concat "list " file
":1\n")
1612 (list "-file-list-exec-source-file\n"
1613 `(lambda () (gdb-get-location
1614 ,bptno
,line
,flag
)))))))))))
1616 (defvar gdb-source-file-regexp
"fullname=\"\\(.*?\\)\"")
1618 (defun gdb-get-location (bptno line flag
)
1619 "Find the directory containing the relevant source file.
1620 Put in buffer and place breakpoint icon."
1621 (goto-char (point-min))
1622 (catch 'file-not-found
1623 (if (re-search-forward gdb-source-file-regexp nil t
)
1624 (delete (cons bptno
"File not found") gdb-location-alist
)
1625 (push (cons bptno
(match-string 1)) gdb-location-alist
)
1627 (unless (assoc bptno gdb-location-alist
)
1628 (push (cons bptno
"File not found") gdb-location-alist
)
1629 (message-box "Cannot find source file for breakpoint location.
1630 Add directory to search path for source files using the GDB command, dir."))
1631 (throw 'file-not-found nil
))
1632 (with-current-buffer (find-file-noselect (match-string 1))
1634 ;; only want one breakpoint icon at each location
1636 (goto-line (string-to-number line
))
1637 (gdb-put-breakpoint-icon (eq flag ?y
) bptno
)))))
1639 (add-hook 'find-file-hook
'gdb-find-file-hook
)
1641 (defun gdb-find-file-hook ()
1642 "Set up buffer for debugging if file is part of the source code
1643 of the current session."
1644 (if (and (buffer-name gud-comint-buffer
)
1645 ;; in case gud or gdb-ui is just loaded
1647 (eq (buffer-local-value 'gud-minor-mode gud-comint-buffer
)
1649 (if (member buffer-file-name gdb-source-file-list
)
1650 (with-current-buffer (find-buffer-visiting buffer-file-name
)
1651 (gdb-init-buffer)))))
1653 (declare-function gud-remove
"gdb-mi" t t
) ; gud-def
1654 (declare-function gud-break
"gdb-mi" t t
) ; gud-def
1655 (declare-function fringe-bitmaps-at-pos
"fringe.c" (&optional pos window
))
1657 (defun gdb-mouse-set-clear-breakpoint (event)
1658 "Set/clear breakpoint in left fringe/margin at mouse click.
1659 If not in a source or disassembly buffer just set point."
1661 (mouse-minibuffer-check event
)
1662 (let ((posn (event-end event
)))
1663 (with-selected-window (posn-window posn
)
1664 (if (or (buffer-file-name) (eq major-mode
'gdb-disassembly-mode
))
1665 (if (numberp (posn-point posn
))
1667 (goto-char (posn-point posn
))
1668 (if (or (posn-object posn
)
1669 (eq (car (fringe-bitmaps-at-pos (posn-point posn
)))
1673 (posn-set-point posn
))))
1675 (defun gdb-mouse-toggle-breakpoint-margin (event)
1676 "Enable/disable breakpoint in left margin with mouse click."
1678 (mouse-minibuffer-check event
)
1679 (let ((posn (event-end event
)))
1680 (if (numberp (posn-point posn
))
1681 (with-selected-window (posn-window posn
)
1683 (goto-char (posn-point posn
))
1684 (if (posn-object posn
)
1686 (let ((bptno (get-text-property
1687 0 'gdb-bptno
(car (posn-string posn
)))))
1689 (if (get-text-property
1690 0 'gdb-enabled
(car (posn-string posn
)))
1695 (defun gdb-mouse-toggle-breakpoint-fringe (event)
1696 "Enable/disable breakpoint in left fringe with mouse click."
1698 (mouse-minibuffer-check event
)
1699 (let* ((posn (event-end event
))
1700 (pos (posn-point posn
))
1703 (with-selected-window (posn-window posn
)
1705 (set-buffer (window-buffer (selected-window)))
1707 (dolist (overlay (overlays-in pos pos
))
1708 (when (overlay-get overlay
'put-break
)
1709 (setq obj
(overlay-get overlay
'before-string
))))
1713 (if (get-text-property 0 'gdb-enabled obj
)
1716 (get-text-property 0 'gdb-bptno obj
) "\n"))))))))
1718 (defun gdb-breakpoints-buffer-name ()
1719 (with-current-buffer gud-comint-buffer
1720 (concat "*breakpoints of " (gdb-get-target-string) "*")))
1722 (def-gdb-display-buffer
1723 gdb-display-breakpoints-buffer
1724 'gdb-breakpoints-buffer
1725 "Display status of user-settable breakpoints.")
1727 (def-gdb-frame-for-buffer
1728 gdb-frame-breakpoints-buffer
1729 'gdb-breakpoints-buffer
1730 "Display status of user-settable breakpoints in a new frame.")
1732 (defvar gdb-breakpoints-mode-map
1733 (let ((map (make-sparse-keymap))
1734 (menu (make-sparse-keymap "Breakpoints")))
1735 (define-key menu
[quit] '("Quit" . gdb-delete-frame-or-window))
1736 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint))
1737 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint))
1738 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint))
1739 (suppress-keymap map)
1740 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu))
1741 (define-key map " " 'gdb-toggle-breakpoint)
1742 (define-key map "D" 'gdb-delete-breakpoint)
1743 ;; Don't bind "q" to kill-this-buffer as we need it for breakpoint icons.
1744 (define-key map "q" 'gdb-delete-frame-or-window)
1745 (define-key map "\r" 'gdb-goto-breakpoint)
1746 (define-key map [mouse-2] 'gdb-goto-breakpoint)
1747 (define-key map [follow-link] 'mouse-face)
1750 (defun gdb-delete-frame-or-window ()
1751 "Delete frame if there is only one window. Otherwise delete the window."
1753 (if (one-window-p) (delete-frame)
1756 ;;from make-mode-line-mouse-map
1757 (defun gdb-make-header-line-mouse-map (mouse function) "\
1758 Return a keymap with single entry for mouse key MOUSE on the header line.
1759 MOUSE is defined to run function FUNCTION with no args in the buffer
1760 corresponding to the mode line clicked."
1761 (let ((map (make-sparse-keymap)))
1762 (define-key map (vector 'header-line mouse) function)
1763 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
1767 ;; uses "-thread-info". Needs GDB 7.0 onwards.
1770 (defun gdb-jump-to (file line)
1771 (find-file-other-window file)
1774 (define-button-type 'gdb-file-button
1775 'help-echo "Push to jump to source code"
1779 (gdb-jump-to (button-get b 'file)
1780 (button-get b 'line))))
1782 (defun gdb-insert-file-location-button (file line)
1783 "Insert text button which allows jumping to FILE:LINE.
1785 FILE is a full path."
1787 (format "%s:%d" (file-name-nondirectory file) line)
1788 :type 'gdb-file-button
1792 (defun gdb-threads-buffer-name ()
1793 (concat "*threads of " (gdb-get-target-string) "*"))
1795 (def-gdb-display-buffer
1796 gdb-display-threads-buffer
1798 "Display GDB threads.")
1800 (def-gdb-frame-for-buffer
1801 gdb-frame-threads-buffer
1803 "Display GDB threads in a new frame.")
1805 (gdb-set-buffer-rules 'gdb-threads-buffer
1806 'gdb-threads-buffer-name
1809 (def-gdb-auto-updated-buffer gdb-threads-buffer
1810 gdb-invalidate-threads "-thread-info\n"
1811 gdb-thread-list-handler gdb-thread-list-handler-custom)
1814 (defvar gdb-threads-font-lock-keywords
1815 '(("in \\([^ ]+\\) (" (1 font-lock-function-name-face))
1816 (" \\(stopped\\) in " (1 font-lock-warning-face))
1817 ("\\(\\(\\sw\\|[_.]\\)+\\)=" (1 font-lock-variable-name-face)))
1818 "Font lock keywords used in `gdb-threads-mode'.")
1820 (defvar gdb-threads-mode-map
1822 (make-sparse-keymap))
1824 (defun gdb-threads-mode ()
1825 "Major mode for GDB threads.
1827 \\{gdb-threads-mode-map}"
1828 (kill-all-local-variables)
1829 (setq major-mode 'gdb-threads-mode)
1830 (setq mode-name "Threads")
1831 (use-local-map gdb-threads-mode-map)
1832 (setq buffer-read-only t)
1833 (buffer-disable-undo)
1834 (setq header-line-format gdb-breakpoints-header)
1835 (set (make-local-variable 'font-lock-defaults)
1836 '(gdb-threads-font-lock-keywords))
1837 (run-mode-hooks 'gdb-threads-mode-hook)
1838 'gdb-invalidate-threads)
1840 (defun gdb-thread-list-handler-custom ()
1841 (let* ((res (json-partial-output))
1842 (threads-list (gdb-get-field res 'threads)))
1843 (dolist (thread threads-list)
1844 (insert (apply 'format `("%s (%s) %s in %s "
1845 ,@(gdb-get-many-fields thread 'id 'target-id 'state)
1846 ,(gdb-get-field thread 'frame 'func))))
1849 (let ((args (gdb-get-field thread 'frame 'args)))
1851 (insert (apply 'format `("%s=%s" ,@(gdb-get-many-fields arg 'name 'value)))))
1852 (when args (kill-backward-chars 1)))
1854 (gdb-insert-frame-location (gdb-get-field thread 'frame))
1855 (insert (format " at %s\n" (gdb-get-field thread 'frame 'addr))))))
1860 (defcustom gdb-memory-rows 8
1861 "Number of data rows in memory window."
1866 (defcustom gdb-memory-columns 4
1867 "Number of data columns in memory window."
1872 (defcustom gdb-memory-format "x"
1873 "Display format of data items in memory window."
1874 :type '(choice (const :tag "Hexadecimal" "x")
1875 (const :tag "Signed decimal" "d")
1876 (const :tag "Unsigned decimal" "u")
1877 (const :tag "Octal" "o")
1878 (const :tag "Binary" "t"))
1882 (defcustom gdb-memory-unit 4
1883 "Unit size of data items in memory window."
1884 :type '(choice (const :tag "Byte" 1)
1885 (const :tag "Halfword" 2)
1886 (const :tag "Word" 4)
1887 (const :tag "Giant word" 8))
1891 (gdb-set-buffer-rules 'gdb-memory-buffer
1892 'gdb-memory-buffer-name
1895 (def-gdb-auto-updated-buffer gdb-memory-buffer
1896 gdb-invalidate-memory
1897 (format "-data-read-memory %s %s %d %d %d\n"
1903 gdb-read-memory-handler
1904 gdb-read-memory-custom)
1906 (defun gdb-read-memory-custom ()
1907 (let* ((res (json-partial-output))
1908 (err-msg (gdb-get-field res 'msg)))
1910 (let ((memory (gdb-get-field res 'memory)))
1911 (setq gdb-memory-address (gdb-get-field res 'addr))
1912 (setq gdb-memory-next-page (gdb-get-field res 'next-page))
1913 (setq gdb-memory-prev-page (gdb-get-field res 'prev-page))
1914 (setq gdb-memory-last-address gdb-memory-address)
1915 (dolist (row memory)
1916 (insert (concat (gdb-get-field row 'addr) ": "))
1917 (dolist (column (gdb-get-field row 'data))
1918 (insert (concat column "\t")))
1920 ;; Show last page instead of empty buffer when out of bounds
1922 (let ((gdb-memory-address gdb-memory-last-address))
1923 (gdb-invalidate-memory)
1924 (error err-msg))))))
1926 (defvar gdb-memory-mode-map
1927 (let ((map (make-sparse-keymap)))
1928 (suppress-keymap map t)
1929 (define-key map "q" 'kill-this-buffer)
1930 (define-key map "n" 'gdb-memory-show-next-page)
1931 (define-key map "p" 'gdb-memory-show-previous-page)
1932 (define-key map "a" 'gdb-memory-set-address)
1933 (define-key map "t" 'gdb-memory-format-binary)
1934 (define-key map "o" 'gdb-memory-format-octal)
1935 (define-key map "u" 'gdb-memory-format-unsigned)
1936 (define-key map "d" 'gdb-memory-format-signed)
1937 (define-key map "x" 'gdb-memory-format-hexadecimal)
1938 (define-key map "b" 'gdb-memory-unit-byte)
1939 (define-key map "h" 'gdb-memory-unit-halfword)
1940 (define-key map "w" 'gdb-memory-unit-word)
1941 (define-key map "g" 'gdb-memory-unit-giant)
1942 (define-key map "R" 'gdb-memory-set-rows)
1943 (define-key map "C" 'gdb-memory-set-columns)
1946 (defun gdb-memory-set-address-event (event)
1947 "Handle a click on address field in memory buffer header."
1949 (save-selected-window
1950 (select-window (posn-window (event-start event)))
1951 (gdb-memory-set-address)))
1953 ;; Non-event version for use within keymap
1954 (defun gdb-memory-set-address ()
1955 "Set the start memory address."
1957 (let ((arg (read-from-minibuffer "Memory address: ")))
1958 (setq gdb-memory-address arg))
1959 (gdb-invalidate-memory))
1961 (defmacro def-gdb-set-positive-number (name variable echo-string &optional doc)
1962 "Define a function NAME which reads new VAR value from minibuffer."
1963 `(defun ,name (event)
1966 (save-selected-window
1967 (select-window (posn-window (event-start event)))
1968 (let* ((arg (read-from-minibuffer ,echo-string))
1969 (count (string-to-number arg)))
1971 (error "Positive number only")
1972 (customize-set-variable ',variable count)
1973 (gdb-invalidate-memory))))))
1975 (def-gdb-set-positive-number
1979 "Set the number of data rows in memory window.")
1981 (def-gdb-set-positive-number
1982 gdb-memory-set-columns
1985 "Set the number of data columns in memory window.")
1987 (defmacro def-gdb-memory-format (name format doc)
1988 "Define a function NAME to switch memory buffer to use FORMAT.
1990 DOC is an optional documentation string."
1991 `(defun ,name () ,(when doc doc)
1993 (customize-set-variable 'gdb-memory-format ,format)
1994 (gdb-invalidate-memory)))
1996 (def-gdb-memory-format
1997 gdb-memory-format-binary "t"
1998 "Set the display format to binary.")
2000 (def-gdb-memory-format
2001 gdb-memory-format-octal "o"
2002 "Set the display format to octal.")
2004 (def-gdb-memory-format
2005 gdb-memory-format-unsigned "u"
2006 "Set the display format to unsigned decimal.")
2008 (def-gdb-memory-format
2009 gdb-memory-format-signed "d"
2010 "Set the display format to decimal.")
2012 (def-gdb-memory-format
2013 gdb-memory-format-hexadecimal "x"
2014 "Set the display format to hexadecimal.")
2016 (defvar gdb-memory-format-map
2017 (let ((map (make-sparse-keymap)))
2018 (define-key map [header-line down-mouse-3] 'gdb-memory-format-menu-1)
2020 "Keymap to select format in the header line.")
2022 (defvar gdb-memory-format-menu (make-sparse-keymap "Format")
2023 "Menu of display formats in the header line.")
2025 (define-key gdb-memory-format-menu [binary]
2026 '(menu-item "Binary" gdb-memory-format-binary
2027 :button (:radio . (equal gdb-memory-format "t"))))
2028 (define-key gdb-memory-format-menu [octal]
2029 '(menu-item "Octal" gdb-memory-format-octal
2030 :button (:radio . (equal gdb-memory-format "o"))))
2031 (define-key gdb-memory-format-menu [unsigned]
2032 '(menu-item "Unsigned Decimal" gdb-memory-format-unsigned
2033 :button (:radio . (equal gdb-memory-format "u"))))
2034 (define-key gdb-memory-format-menu [signed]
2035 '(menu-item "Signed Decimal" gdb-memory-format-signed
2036 :button (:radio . (equal gdb-memory-format "d"))))
2037 (define-key gdb-memory-format-menu [hexadecimal]
2038 '(menu-item "Hexadecimal" gdb-memory-format-hexadecimal
2039 :button (:radio . (equal gdb-memory-format "x"))))
2041 (defun gdb-memory-format-menu (event)
2043 (x-popup-menu event gdb-memory-format-menu))
2045 (defun gdb-memory-format-menu-1 (event)
2047 (save-selected-window
2048 (select-window (posn-window (event-start event)))
2049 (let* ((selection (gdb-memory-format-menu event))
2050 (binding (and selection (lookup-key gdb-memory-format-menu
2051 (vector (car selection))))))
2052 (if binding (call-interactively binding)))))
2054 (defmacro def-gdb-memory-unit (name unit-size doc)
2055 "Define a function NAME to switch memory unit size to UNIT-SIZE.
2057 DOC is an optional documentation string."
2058 `(defun ,name () ,(when doc doc)
2060 (customize-set-variable 'gdb-memory-unit ,unit-size)
2061 (gdb-invalidate-memory)))
2063 (def-gdb-memory-unit gdb-memory-unit-giant 8
2064 "Set the unit size to giant words (eight bytes).")
2066 (def-gdb-memory-unit gdb-memory-unit-word 4
2067 "Set the unit size to words (four bytes).")
2069 (def-gdb-memory-unit gdb-memory-unit-halfword 2
2070 "Set the unit size to halfwords (two bytes).")
2072 (def-gdb-memory-unit gdb-memory-unit-byte 1
2073 "Set the unit size to bytes.")
2075 (defmacro def-gdb-memory-show-page (name address-var &optional doc)
2076 "Define a function NAME which show new address in memory buffer.
2078 The defined function switches Memory buffer to show address
2079 stored in ADDRESS-VAR variable.
2081 DOC is an optional documentation string."
2085 (let ((gdb-memory-address ,address-var))
2086 (gdb-invalidate-memory))))
2088 (def-gdb-memory-show-page gdb-memory-show-previous-page
2089 gdb-memory-prev-page)
2091 (def-gdb-memory-show-page gdb-memory-show-next-page
2092 gdb-memory-next-page)
2094 (defvar gdb-memory-unit-map
2095 (let ((map (make-sparse-keymap)))
2096 (define-key map [header-line down-mouse-3] 'gdb-memory-unit-menu-1)
2098 "Keymap to select units in the header line.")
2100 (defvar gdb-memory-unit-menu (make-sparse-keymap "Unit")
2101 "Menu of units in the header line.")
2103 (define-key gdb-memory-unit-menu [giantwords]
2104 '(menu-item "Giant words" gdb-memory-unit-giant
2105 :button (:radio . (equal gdb-memory-unit 8))))
2106 (define-key gdb-memory-unit-menu [words]
2107 '(menu-item "Words" gdb-memory-unit-word
2108 :button (:radio . (equal gdb-memory-unit 4))))
2109 (define-key gdb-memory-unit-menu [halfwords]
2110 '(menu-item "Halfwords" gdb-memory-unit-halfword
2111 :button (:radio . (equal gdb-memory-unit 2))))
2112 (define-key gdb-memory-unit-menu [bytes]
2113 '(menu-item "Bytes" gdb-memory-unit-byte
2114 :button (:radio . (equal gdb-memory-unit 1))))
2116 (defun gdb-memory-unit-menu (event)
2118 (x-popup-menu event gdb-memory-unit-menu))
2120 (defun gdb-memory-unit-menu-1 (event)
2122 (save-selected-window
2123 (select-window (posn-window (event-start event)))
2124 (let* ((selection (gdb-memory-unit-menu event))
2125 (binding (and selection (lookup-key gdb-memory-unit-menu
2126 (vector (car selection))))))
2127 (if binding (call-interactively binding)))))
2129 ;;from make-mode-line-mouse-map
2130 (defun gdb-make-header-line-mouse-map (mouse function) "\
2131 Return a keymap with single entry for mouse key MOUSE on the header line.
2132 MOUSE is defined to run function FUNCTION with no args in the buffer
2133 corresponding to the mode line clicked."
2134 (let ((map (make-sparse-keymap)))
2135 (define-key map (vector 'header-line mouse) function)
2136 (define-key map (vector 'header-line 'down-mouse-1) 'ignore)
2139 (defvar gdb-memory-font-lock-keywords
2140 '(;; <__function.name+n>
2141 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>" (1 font-lock-function-name-face))
2143 "Font lock keywords used in `gdb-memory-mode'.")
2145 (defvar gdb-memory-header
2150 'face font-lock-warning-face
2151 'help-echo "mouse-1: decrement address"
2152 'mouse-face 'mode-line-highlight
2153 'local-map (gdb-make-header-line-mouse-map
2155 #'gdb-memory-show-previous-page))
2158 'face font-lock-warning-face
2159 'help-echo "mouse-1: increment address"
2160 'mouse-face 'mode-line-highlight
2161 'local-map (gdb-make-header-line-mouse-map
2163 #'gdb-memory-show-next-page))
2165 (propertize gdb-memory-address
2166 'face font-lock-warning-face
2167 'help-echo "mouse-1: set start address"
2168 'mouse-face 'mode-line-highlight
2169 'local-map (gdb-make-header-line-mouse-map
2171 #'gdb-memory-set-address-event))
2173 (propertize (number-to-string gdb-memory-rows)
2174 'face font-lock-warning-face
2175 'help-echo "mouse-1: set number of columns"
2176 'mouse-face 'mode-line-highlight
2177 'local-map (gdb-make-header-line-mouse-map
2179 #'gdb-memory-set-rows))
2181 (propertize (number-to-string gdb-memory-columns)
2182 'face font-lock-warning-face
2183 'help-echo "mouse-1: set number of columns"
2184 'mouse-face 'mode-line-highlight
2185 'local-map (gdb-make-header-line-mouse-map
2187 #'gdb-memory-set-columns))
2189 (propertize gdb-memory-format
2190 'face font-lock-warning-face
2191 'help-echo "mouse-3: select display format"
2192 'mouse-face 'mode-line-highlight
2193 'local-map gdb-memory-format-map)
2195 (propertize (number-to-string gdb-memory-unit)
2196 'face font-lock-warning-face
2197 'help-echo "mouse-3: select unit size"
2198 'mouse-face 'mode-line-highlight
2199 'local-map gdb-memory-unit-map)))
2200 "Header line used in `gdb-memory-mode'.")
2202 (defun gdb-memory-mode ()
2203 "Major mode for examining memory.
2205 \\{gdb-memory-mode-map}"
2206 (kill-all-local-variables)
2207 (setq major-mode 'gdb-memory-mode)
2208 (setq mode-name "Memory")
2209 (use-local-map gdb-memory-mode-map)
2210 (setq buffer-read-only t)
2211 (setq header-line-format gdb-memory-header)
2212 (set (make-local-variable 'font-lock-defaults)
2213 '(gdb-memory-font-lock-keywords))
2214 (run-mode-hooks 'gdb-memory-mode-hook)
2215 'gdb-invalidate-memory)
2217 (defun gdb-memory-buffer-name ()
2218 (with-current-buffer gud-comint-buffer
2219 (concat "*memory of " (gdb-get-target-string) "*")))
2221 (def-gdb-display-buffer
2222 gdb-display-memory-buffer
2224 "Display memory contents.")
2226 (defun gdb-frame-memory-buffer ()
2227 "Display memory contents in a new frame."
2229 (let* ((special-display-regexps (append special-display-regexps '(".*")))
2230 (special-display-frame-alist
2234 ,@gdb-frame-parameters)))
2235 (display-buffer (gdb-get-buffer-create 'gdb-memory-buffer))))
2238 ;;; Disassembly view
2240 (defun gdb-disassembly-buffer-name ()
2241 (concat "*disassembly of " (gdb-get-target-string) "*"))
2243 (def-gdb-display-buffer
2244 gdb-display-disassembly-buffer
2245 'gdb-disassembly-buffer
2246 "Display disassembly for current stack frame.")
2248 (def-gdb-frame-for-buffer
2249 gdb-frame-disassembly-buffer
2250 'gdb-disassembly-buffer
2251 "Display disassembly in a new frame.")
2253 (gdb-set-buffer-rules 'gdb-disassembly-buffer
2254 'gdb-disassembly-buffer-name
2255 'gdb-disassembly-mode)
2257 (def-gdb-auto-update-trigger gdb-invalidate-disassembly
2258 (gdb-get-buffer-create 'gdb-disassembly-buffer)
2259 (let ((file (or gdb-selected-file gdb-main-file))
2260 (line (or gdb-selected-line 1)))
2262 (format "-data-disassemble -f %s -l %d -n -1 -- 0\n" file line)
2264 gdb-disassembly-handler)
2266 (def-gdb-auto-update-handler
2267 gdb-disassembly-handler
2268 gdb-invalidate-disassembly
2269 gdb-disassembly-buffer
2270 gdb-disassembly-handler-custom)
2272 (defvar gdb-disassembly-font-lock-keywords
2273 '(;; <__function.name+n>
2274 ("<\\(\\(\\sw\\|[_.]\\)+\\)\\(\\+[0-9]+\\)?>"
2275 (1 font-lock-function-name-face))
2276 ;; 0xNNNNNNNN <__function.name+n>: opcode
2277 ("^0x[0-9a-f]+ \\(<\\(\\(\\sw\\|[_.]\\)+\\)\\+[0-9]+>\\)?:[ \t]+\\(\\sw+\\)"
2278 (4 font-lock-keyword-face))
2279 ;; %register(at least i386)
2280 ("%\\sw+" . font-lock-variable-name-face)
2281 ("^\\(Dump of assembler code for function\\) \\(.+\\):"
2282 (1 font-lock-comment-face)
2283 (2 font-lock-function-name-face))
2284 ("^\\(End of assembler dump\\.\\)" . font-lock-comment-face))
2285 "Font lock keywords used in `gdb-disassembly-mode'.")
2287 (defvar gdb-disassembly-mode-map
2289 (make-sparse-keymap))
2291 (defun gdb-disassembly-mode ()
2292 "Major mode for GDB disassembly information.
2294 \\{gdb-disassembly-mode-map}"
2295 (kill-all-local-variables)
2296 (setq major-mode 'gdb-disassembly-mode)
2297 (setq mode-name "Disassembly")
2298 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position)
2299 (setq fringes-outside-margins t)
2300 (setq gdb-overlay-arrow-position (make-marker))
2301 (use-local-map gdb-disassembly-mode-map)
2302 (setq buffer-read-only t)
2303 (buffer-disable-undo)
2304 (set (make-local-variable 'font-lock-defaults)
2305 '(gdb-disassembly-font-lock-keywords))
2306 (run-mode-hooks 'gdb-disassembly-mode-hook)
2307 'gdb-invalidate-disassembly)
2309 (defun gdb-disassembly-handler-custom ()
2310 (let* ((res (json-partial-output))
2311 (instructions (gdb-get-field res 'asm_insns)))
2312 (dolist (instr instructions)
2313 ;; Put overlay arrow
2314 (when (string-equal (gdb-get-field instr 'address)
2317 (setq fringe-indicator-alist
2318 (if (string-equal gdb-frame-number "0")
2320 '((overlay-arrow . hollow-right-triangle))))
2321 (set-marker gdb-overlay-arrow-position (point))))
2322 (insert (apply 'format `("%s <%s+%s>:\t%s\n"
2323 ,@(gdb-get-many-fields instr 'address 'func-name 'offset 'inst))))))
2324 (gdb-disassembly-place-breakpoints))
2326 (defun gdb-disassembly-place-breakpoints ()
2327 (dolist (breakpoint gdb-breakpoints-list)
2328 (let ((bptno (gdb-get-field breakpoint 'number))
2329 (flag (gdb-get-field breakpoint 'enabled))
2330 (address (gdb-get-field breakpoint 'addr)))
2332 (goto-char (point-min))
2333 (if (re-search-forward (concat "^" address) nil t)
2334 (gdb-put-breakpoint-icon (string-equal flag "y") bptno))))))
2337 ;;; Breakpoints view
2338 (defvar gdb-breakpoints-header
2339 `(,(propertize "Breakpoints"
2340 'help-echo "mouse-1: select"
2341 'mouse-face 'mode-line-highlight
2344 (gdb-make-header-line-mouse-map
2346 (lambda (event) (interactive "e")
2347 (save-selected-window
2348 (select-window (posn-window (event-start event)))
2349 (set-window-dedicated-p (selected-window) nil)
2351 (gdb-get-buffer-create 'gdb-breakpoints-buffer))
2352 (set-window-dedicated-p (selected-window) t)))))
2354 ,(propertize "Threads"
2355 'help-echo "mouse-1: select"
2356 'mouse-face 'mode-line-highlight
2359 (gdb-make-header-line-mouse-map
2361 ;; TODO: same code few lines above
2362 (lambda (event) (interactive "e")
2363 (save-selected-window
2364 (select-window (posn-window (event-start event)))
2365 (set-window-dedicated-p (selected-window) nil)
2367 (gdb-get-buffer-create 'gdb-threads-buffer))
2368 (set-window-dedicated-p (selected-window) t)))
2371 (defun gdb-breakpoints-mode ()
2372 "Major mode for gdb breakpoints.
2374 \\{gdb-breakpoints-mode-map}"
2375 (kill-all-local-variables)
2376 (setq major-mode 'gdb-breakpoints-mode)
2377 (setq mode-name "Breakpoints")
2378 (use-local-map gdb-breakpoints-mode-map)
2379 (setq buffer-read-only t)
2380 (buffer-disable-undo)
2381 (setq header-line-format gdb-breakpoints-header)
2382 (run-mode-hooks 'gdb-breakpoints-mode-hook)
2383 'gdb-invalidate-breakpoints)
2385 (defun gdb-toggle-breakpoint ()
2386 "Enable/disable breakpoint at current line of breakpoints buffer."
2389 (let ((breakpoint (get-text-property (point) 'gdb-breakpoint)))
2392 (concat (if (string-equal "y" (gdb-get-field breakpoint 'enabled))
2395 (gdb-get-field breakpoint 'number)))
2396 (error "Not recognized as break/watchpoint line")))))
2398 (defun gdb-delete-breakpoint ()
2399 "Delete the breakpoint at current line of breakpoints buffer."
2401 (let ((breakpoint (get-text-property (point) 'gdb-breakpoint)))
2403 (gud-basic-call (concat "-break-delete " (gdb-get-field breakpoint 'number)))
2404 (error "Not recognized as break/watchpoint line"))))
2406 (defun gdb-goto-breakpoint (&optional event)
2407 "Go to the location of breakpoint at current line of
2408 breakpoints buffer."
2409 (interactive (list last-input-event))
2410 (if event (posn-set-point (event-end event)))
2411 ;; Hack to stop gdb-goto-breakpoint displaying in GUD buffer.
2412 (let ((window (get-buffer-window gud-comint-buffer)))
2413 (if window (save-selected-window (select-window window))))
2414 (let ((breakpoint (get-text-property (point) 'gdb-breakpoint)))
2416 (let ((bptno (gdb-get-field breakpoint 'number))
2417 (file (gdb-get-field breakpoint 'file))
2418 (line (gdb-get-field breakpoint 'line)))
2419 (save-selected-window
2420 (let* ((buffer (find-file-noselect
2421 (if (file-exists-p file) file
2422 (cdr (assoc bptno gdb-location-alist)))))
2423 (window (or (gdb-display-source-buffer buffer)
2424 (display-buffer buffer))))
2425 (setq gdb-source-window window)
2426 (with-current-buffer buffer
2427 (goto-line (string-to-number line))
2428 (set-window-point window (point))))))
2429 (error "Not recognized as break/watchpoint line"))))
2432 ;; Frames buffer. This displays a perpetually correct bactrack trace.
2434 (gdb-set-buffer-rules 'gdb-stack-buffer
2435 'gdb-stack-buffer-name
2438 (def-gdb-auto-update-trigger gdb-invalidate-frames
2439 (gdb-get-buffer 'gdb-stack-buffer)
2440 "-stack-list-frames\n"
2441 gdb-stack-list-frames-handler)
2443 (defun gdb-insert-frame-location (frame)
2444 "Insert \"of file:line\" button or library name for structure FRAME.
2446 FRAME must have either \"file\" and \"line\" members or \"from\"
2448 (let ((file (gdb-get-field frame 'fullname))
2449 (line (gdb-get-field frame 'line))
2450 (from (gdb-get-field frame 'from)))
2452 ;; Filename with line number
2454 (gdb-insert-file-location-button
2455 file (string-to-number line)))
2457 (from (insert (format " of %s" from))))))
2459 (defun gdb-stack-list-frames-handler ()
2460 (setq gdb-pending-triggers (delq 'gdb-invalidate-frames
2461 gdb-pending-triggers))
2462 (with-current-buffer (gdb-get-buffer-create 'gdb-partial-output-buffer)
2463 (let* ((res (json-partial-output "frame"))
2464 (stack (gdb-get-field res 'stack))
2465 (buf (gdb-get-buffer 'gdb-stack-buffer)))
2467 (with-current-buffer buf
2468 (let ((buffer-read-only nil))
2470 (dolist (frame (nreverse stack))
2471 (insert (apply 'format `("%s in %s" ,@(gdb-get-many-fields frame 'level 'func))))
2472 (gdb-insert-frame-location frame)
2474 (gdb-stack-list-frames-custom)))))))
2476 (defun gdb-stack-list-frames-custom ()
2477 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer)
2479 (let ((buffer-read-only nil))
2480 (goto-char (point-min))
2482 (while (< (point) (point-max))
2483 (add-text-properties (point-at-bol) (1+ (point-at-bol))
2484 '(mouse-face highlight
2485 help-echo "mouse-2, RET: Select frame"))
2487 (when (and (looking-at "^[0-9]+\\s-+\\S-+\\s-+\\(\\S-+\\)")
2488 (equal (match-string 1) gdb-selected-frame))
2489 (if (> (car (window-fringes)) 0)
2491 (or gdb-stack-position
2492 (setq gdb-stack-position (make-marker)))
2493 (set-marker gdb-stack-position (point)))
2494 (let ((bl (point-at-bol)))
2495 (put-text-property bl (+ bl 4)
2496 'face '(:inverse-video t)))))
2497 (forward-line 1))))))
2499 (defun gdb-stack-buffer-name ()
2500 (with-current-buffer gud-comint-buffer
2501 (concat "*stack frames of " (gdb-get-target-string) "*")))
2503 (def-gdb-display-buffer
2504 gdb-display-stack-buffer
2506 "Display backtrace of current stack.")
2508 (def-gdb-frame-for-buffer
2509 gdb-frame-stack-buffer
2511 "Display backtrace of current stack in a new frame.")
2513 (defvar gdb-frames-mode-map
2514 (let ((map (make-sparse-keymap)))
2515 (suppress-keymap map)
2516 (define-key map "q" 'kill-this-buffer)
2517 (define-key map "\r" 'gdb-frames-select)
2518 (define-key map [mouse-2] 'gdb-frames-select)
2519 (define-key map [follow-link] 'mouse-face)
2522 (defvar gdb-frames-font-lock-keywords
2523 '(("in \\([^ ]+\\) of " (1 font-lock-function-name-face)))
2524 "Font lock keywords used in `gdb-frames-mode'.")
2526 (defun gdb-frames-mode ()
2527 "Major mode for gdb call stack.
2529 \\{gdb-frames-mode-map}"
2530 (kill-all-local-variables)
2531 (setq major-mode 'gdb-frames-mode)
2532 (setq mode-name "Frames")
2533 (setq gdb-stack-position nil)
2534 (add-to-list 'overlay-arrow-variable-list 'gdb-stack-position)
2535 (setq truncate-lines t) ;; Make it easier to see overlay arrow.
2536 (setq buffer-read-only t)
2537 (buffer-disable-undo)
2538 (use-local-map gdb-frames-mode-map)
2539 (set (make-local-variable 'font-lock-defaults)
2540 '(gdb-frames-font-lock-keywords))
2541 (run-mode-hooks 'gdb-frames-mode-hook)
2542 'gdb-invalidate-frames)
2544 (defun gdb-get-frame-number ()
2547 (let* ((pos (re-search-backward "^\\([0-9]+\\)" nil t))
2548 (n (or (and pos (match-string-no-properties 1)) "0")))
2551 (defun gdb-frames-select (&optional event)
2552 "Select the frame and display the relevant source."
2553 (interactive (list last-input-event))
2554 (if event (posn-set-point (event-end event)))
2555 (gud-basic-call (concat "-stack-select-frame " (gdb-get-frame-number))))
2559 ;; uses "-stack-list-locals --simple-values". Needs GDB 6.1 onwards.
2560 (gdb-set-buffer-rules 'gdb-locals-buffer
2561 'gdb-locals-buffer-name
2564 (def-gdb-auto-update-trigger gdb-invalidate-locals
2565 (gdb-get-buffer 'gdb-locals-buffer)
2566 "-stack-list-locals --simple-values\n"
2567 gdb-stack-list-locals-handler)
2569 (defconst gdb-stack-list-locals-regexp
2570 (concat "name=\"\\(.*?\\)\",type=\"\\(.*?\\)\""))
2572 (defvar gdb-locals-watch-map
2573 (let ((map (make-sparse-keymap)))
2574 (suppress-keymap map)
2575 (define-key map "\r" 'gud-watch)
2576 (define-key map [mouse-2] 'gud-watch)
2578 "Keymap to create watch expression of a complex data type local variable.")
2580 (defvar gdb-edit-locals-map-1
2581 (let ((map (make-sparse-keymap)))
2582 (suppress-keymap map)
2583 (define-key map "\r" 'gdb-edit-locals-value)
2584 (define-key map [mouse-2] 'gdb-edit-locals-value)
2586 "Keymap to edit value of a simple data type local variable.")
2588 (defun gdb-edit-locals-value (&optional event)
2589 "Assign a value to a variable displayed in the locals buffer."
2590 (interactive (list last-input-event))
2592 (if event (posn-set-point (event-end event)))
2594 (let* ((var (current-word))
2595 (value (read-string (format "New value (%s): " var))))
2597 (concat "-gdb-set variable " var " = " value)))))
2599 ;; Dont display values of arrays or structures.
2600 ;; These can be expanded using gud-watch.
2601 (defun gdb-stack-list-locals-handler nil
2602 (setq gdb-pending-triggers (delq 'gdb-invalidate-locals
2603 gdb-pending-triggers))
2604 (let (local locals-list)
2605 (goto-char (point-min))
2606 (while (re-search-forward gdb-stack-list-locals-regexp nil t)
2607 (let ((local (list (match-string 1)
2610 (if (looking-at ",value=\\(\".*\"\\)}")
2611 (setcar (nthcdr 2 local) (read (match-string 1))))
2612 (push local locals-list)))
2613 (let ((buf (gdb-get-buffer 'gdb-locals-buffer)))
2614 (and buf (with-current-buffer buf
2615 (let* ((window (get-buffer-window buf 0))
2616 (start (window-start window))
2617 (p (window-point window))
2618 (buffer-read-only nil) (name) (value))
2620 (dolist (local locals-list)
2621 (setq name (car local))
2622 (setq value (nth 2 local))
2624 (string-match "\\0x" value))
2625 (add-text-properties 0 (length name)
2626 `(mouse-face highlight
2627 help-echo "mouse-2: create watch expression"
2628 local-map ,gdb-locals-watch-map)
2630 (add-text-properties 0 (length value)
2631 `(mouse-face highlight
2632 help-echo "mouse-2: edit value"
2633 local-map ,gdb-edit-locals-map-1)
2636 (concat name "\t" (nth 1 local)
2637 "\t" (nth 2 local) "\n")))
2638 (set-window-start window start)
2639 (set-window-point window p)))))))
2641 (defvar gdb-locals-header
2642 `(,(propertize "Locals"
2643 'help-echo "mouse-1: select"
2644 'mouse-face 'mode-line-highlight
2647 (gdb-make-header-line-mouse-map
2649 (lambda (event) (interactive "e")
2650 (save-selected-window
2651 (select-window (posn-window (event-start event)))
2652 (set-window-dedicated-p (selected-window) nil)
2654 (gdb-get-buffer-create 'gdb-locals-buffer))
2655 (set-window-dedicated-p (selected-window) t)))))
2657 ,(propertize "Registers"
2658 'help-echo "mouse-1: select"
2659 'mouse-face 'mode-line-highlight
2662 (gdb-make-header-line-mouse-map
2664 (lambda (event) (interactive "e")
2665 (save-selected-window
2666 (select-window (posn-window (event-start event)))
2667 (set-window-dedicated-p (selected-window) nil)
2669 (gdb-get-buffer-create 'gdb-registers-buffer))
2670 (set-window-dedicated-p (selected-window) t)))))))
2672 (defvar gdb-locals-mode-map
2673 (let ((map (make-sparse-keymap)))
2674 (suppress-keymap map)
2675 (define-key map "q" 'kill-this-buffer)
2678 (defun gdb-locals-mode ()
2679 "Major mode for gdb locals.
2681 \\{gdb-locals-mode-map}"
2682 (kill-all-local-variables)
2683 (setq major-mode 'gdb-locals-mode)
2684 (setq mode-name (concat "Locals:" gdb-selected-frame))
2685 (setq buffer-read-only t)
2686 (buffer-disable-undo)
2687 (setq header-line-format gdb-locals-header)
2688 (use-local-map gdb-locals-mode-map)
2689 (set (make-local-variable 'font-lock-defaults)
2690 '(gdb-locals-font-lock-keywords))
2691 (run-mode-hooks 'gdb-locals-mode-hook)
2692 'gdb-invalidate-locals)
2694 (defun gdb-locals-buffer-name ()
2695 (with-current-buffer gud-comint-buffer
2696 (concat "*locals of " (gdb-get-target-string) "*")))
2698 (def-gdb-display-buffer
2699 gdb-display-locals-buffer
2701 "Display local variables of current stack and their values.")
2703 (def-gdb-frame-for-buffer
2704 gdb-frame-locals-buffer
2706 "Display local variables of current stack and their values in a new frame.")
2709 ;; Registers buffer.
2711 (gdb-set-buffer-rules 'gdb-registers-buffer
2712 'gdb-registers-buffer-name
2713 'gdb-registers-mode)
2715 (def-gdb-auto-update-trigger gdb-invalidate-registers
2716 (gdb-get-buffer 'gdb-registers-buffer)
2717 "-data-list-register-values x\n"
2718 gdb-data-list-register-values-handler)
2720 (defconst gdb-data-list-register-values-regexp
2721 "number=\"\\(.*?\\)\",value=\"\\(.*?\\)\"")
2723 (defun gdb-data-list-register-values-handler ()
2724 (setq gdb-pending-triggers (delq 'gdb-invalidate-registers
2725 gdb-pending-triggers))
2726 (goto-char (point-min))
2727 (if (re-search-forward gdb-error-regexp nil t)
2730 (setq match (match-string 1))
2731 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2732 (let ((buffer-read-only nil))
2735 (goto-char (point-min))))))
2736 (let ((register-list (reverse gdb-register-names))
2737 (register nil) (register-string nil) (register-values nil))
2738 (goto-char (point-min))
2739 (while (re-search-forward gdb-data-list-register-values-regexp nil t)
2740 (setq register (pop register-list))
2741 (setq register-string (concat register "\t" (match-string 2) "\n"))
2742 (if (member (match-string 1) gdb-changed-registers)
2743 (put-text-property 0 (length register-string)
2744 'face 'font-lock-warning-face
2746 (setq register-values
2747 (concat register-values register-string)))
2748 (let ((buf (gdb-get-buffer 'gdb-registers-buffer)))
2749 (with-current-buffer buf
2750 (let ((p (window-point (get-buffer-window buf 0)))
2751 (buffer-read-only nil))
2753 (insert register-values)
2754 (set-window-point (get-buffer-window buf 0) p))))))
2755 (gdb-data-list-register-values-custom))
2757 (defun gdb-data-list-register-values-custom ()
2758 (with-current-buffer (gdb-get-buffer 'gdb-registers-buffer)
2760 (let ((buffer-read-only nil)
2762 (goto-char (point-min))
2763 (while (< (point) (point-max))
2764 (setq bl (line-beginning-position))
2765 (when (looking-at "^[^\t]+")
2766 (put-text-property bl (match-end 0)
2767 'face font-lock-variable-name-face))
2768 (forward-line 1))))))
2770 (defvar gdb-registers-mode-map
2771 (let ((map (make-sparse-keymap)))
2772 (suppress-keymap map)
2773 (define-key map "q" 'kill-this-buffer)
2776 (defun gdb-registers-mode ()
2777 "Major mode for gdb registers.
2779 \\{gdb-registers-mode-map}"
2780 (kill-all-local-variables)
2781 (setq major-mode 'gdb-registers-mode)
2782 (setq mode-name "Registers")
2783 (setq header-line-format gdb-locals-header)
2784 (setq buffer-read-only t)
2785 (buffer-disable-undo)
2786 (use-local-map gdb-registers-mode-map)
2787 (run-mode-hooks 'gdb-registers-mode-hook)
2788 'gdb-invalidate-registers)
2790 (defun gdb-registers-buffer-name ()
2791 (with-current-buffer gud-comint-buffer
2792 (concat "*registers of " (gdb-get-target-string) "*")))
2794 (def-gdb-display-buffer
2795 gdb-display-registers-buffer
2796 'gdb-registers-buffer
2797 "Display integer register contents.")
2799 (def-gdb-frame-for-buffer
2800 gdb-frame-registers-buffer
2801 'gdb-registers-buffer
2802 "Display integer register contents in a new frame.")
2804 ;; Needs GDB 6.4 onwards (used to fail with no stack).
2805 (defun gdb-get-changed-registers ()
2806 (if (and (gdb-get-buffer 'gdb-registers-buffer)
2807 (not (member 'gdb-get-changed-registers gdb-pending-triggers)))
2811 "-data-list-changed-registers\n"
2812 'gdb-get-changed-registers-handler))
2813 (push 'gdb-get-changed-registers gdb-pending-triggers))))
2815 (defconst gdb-data-list-register-names-regexp "\"\\(.*?\\)\"")
2817 (defun gdb-get-changed-registers-handler ()
2818 (setq gdb-pending-triggers
2819 (delq 'gdb-get-changed-registers gdb-pending-triggers))
2820 (setq gdb-changed-registers nil)
2821 (goto-char (point-min))
2822 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
2823 (push (match-string 1) gdb-changed-registers)))
2825 (defun gdb-get-register-names ()
2826 "Create a list of register names."
2827 (goto-char (point-min))
2828 (setq gdb-register-names nil)
2829 (while (re-search-forward gdb-data-list-register-names-regexp nil t)
2830 (push (match-string 1) gdb-register-names)))
2833 (defun gdb-get-source-file-list ()
2834 "Create list of source files for current GDB session.
2835 If buffers already exist for any of these files, gud-minor-mode
2837 (goto-char (point-min))
2838 (while (re-search-forward gdb-source-file-regexp nil t)
2839 (push (match-string 1) gdb-source-file-list))
2840 (dolist (buffer (buffer-list))
2841 (with-current-buffer buffer
2842 (when (member buffer-file-name gdb-source-file-list)
2843 (gdb-init-buffer))))
2844 (gdb-force-mode-line-update
2845 (propertize "ready" 'face font-lock-variable-name-face)))
2847 (defun gdb-get-selected-frame ()
2848 (if (not (member 'gdb-get-selected-frame gdb-pending-triggers))
2851 (list "-stack-info-frame\n" 'gdb-frame-handler))
2852 (push 'gdb-get-selected-frame
2853 gdb-pending-triggers))))
2855 (defun gdb-frame-handler ()
2856 (setq gdb-pending-triggers
2857 (delq 'gdb-get-selected-frame gdb-pending-triggers))
2858 (let ((frame (gdb-get-field (json-partial-output) 'frame)))
2860 (setq gdb-frame-number (gdb-get-field frame 'level))
2861 (setq gdb-pc-address (gdb-get-field frame 'addr))
2862 (setq gdb-selected-frame (gdb-get-field frame 'func))
2863 (setq gdb-selected-file (gdb-get-field frame 'fullname))
2864 (let ((line (gdb-get-field frame 'line)))
2865 (setq gdb-selected-line (or (and line (string-to-number line))
2866 nil)) ; don't fail if line is nil
2867 (when line ; obey the current file only if we have line info
2868 (setq gud-last-frame (cons gdb-selected-file gdb-selected-line))
2869 (gud-display-frame)))
2870 (if (gdb-get-buffer 'gdb-locals-buffer)
2871 (with-current-buffer (gdb-get-buffer 'gdb-locals-buffer)
2872 (setq mode-name (concat "Locals:" gdb-selected-frame))))
2873 (if (gdb-get-buffer 'gdb-disassembly-buffer)
2874 (with-current-buffer (gdb-get-buffer 'gdb-disassembly-buffer)
2875 (setq mode-name (concat "Machine:" gdb-selected-frame))))
2876 (if gud-overlay-arrow-position
2877 (let ((buffer (marker-buffer gud-overlay-arrow-position))
2878 (position (marker-position gud-overlay-arrow-position)))
2880 (with-current-buffer buffer
2881 (setq fringe-indicator-alist
2882 (if (string-equal gdb-frame-number "0")
2884 '((overlay-arrow . hollow-right-triangle))))
2885 (setq gud-overlay-arrow-position (make-marker))
2886 (set-marker gud-overlay-arrow-position position)))))
2887 (when gdb-selected-line
2888 (gdb-invalidate-disassembly)))))
2890 (defvar gdb-prompt-name-regexp "value=\"\\(.*?\\)\"")
2892 (defun gdb-get-prompt ()
2893 "Find prompt for GDB session."
2894 (goto-char (point-min))
2895 (setq gdb-prompt-name nil)
2896 (re-search-forward gdb-prompt-name-regexp nil t)
2897 (setq gdb-prompt-name (match-string 1))
2898 ;; Insert first prompt.
2899 (setq gdb-filter-output (concat gdb-filter-output gdb-prompt-name)))
2901 ;;;; Window management
2902 (defun gdb-display-buffer (buf dedicated &optional frame)
2903 (let ((answer (get-buffer-window buf (or frame 0))))
2905 (display-buffer buf nil (or frame 0)) ;Deiconify the frame if necessary.
2906 (let ((window (get-lru-window)))
2907 (if (eq (buffer-local-value 'gud-minor-mode (window-buffer window))
2909 (let* ((largest (get-largest-window))
2910 (cur-size (window-height largest)))
2911 (setq answer (split-window largest))
2912 (set-window-buffer answer buf)
2913 (set-window-dedicated-p answer dedicated)
2915 (set-window-buffer window buf)
2919 ;;; Shared keymap initialization:
2921 (let ((menu (make-sparse-keymap "GDB-Windows")))
2922 (define-key gud-menu-map [displays]
2923 `(menu-item "GDB-Windows" ,menu
2924 :visible (eq gud-minor-mode 'gdbmi)))
2925 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer))
2926 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer))
2927 (define-key menu [memory] '("Memory" . gdb-display-memory-buffer))
2928 (define-key menu [disassembly]
2929 '("Disassembly" . gdb-display-disassembly-buffer))
2930 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer))
2931 (define-key menu [inferior]
2932 '(menu-item "Separate IO" gdb-display-separate-io-buffer
2933 :enable gdb-use-separate-io-buffer))
2934 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer))
2935 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer))
2936 (define-key menu [breakpoints]
2937 '("Breakpoints" . gdb-display-breakpoints-buffer)))
2939 (let ((menu (make-sparse-keymap "GDB-Frames")))
2940 (define-key gud-menu-map [frames]
2941 `(menu-item "GDB-Frames" ,menu
2942 :visible (eq gud-minor-mode 'gdbmi)))
2943 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer))
2944 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer))
2945 (define-key menu [memory] '("Memory" . gdb-frame-memory-buffer))
2946 (define-key menu [disassembly] '("Disassembly" . gdb-frame-disassembly-buffer))
2947 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer))
2948 (define-key menu [inferior]
2949 '(menu-item "Separate IO" gdb-frame-separate-io-buffer
2950 :enable gdb-use-separate-io-buffer))
2951 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer))
2952 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer))
2953 (define-key menu [breakpoints]
2954 '("Breakpoints" . gdb-frame-breakpoints-buffer)))
2956 (let ((menu (make-sparse-keymap "GDB-MI")))
2957 (define-key gud-menu-map [mi]
2958 `(menu-item "GDB-MI" ,menu :visible (eq gud-minor-mode 'gdbmi)))
2959 (define-key menu [gdb-customize]
2960 '(menu-item "Customize" (lambda () (interactive) (customize-group 'gdb))
2961 :help "Customize Gdb Graphical Mode options."))
2962 (define-key menu [gdb-use-separate-io]
2963 '(menu-item "Separate IO" gdb-use-separate-io-buffer
2964 :help "Toggle separate IO for debugged program."
2965 :button (:toggle . gdb-use-separate-io-buffer)))
2966 (define-key menu [gdb-many-windows]
2967 '(menu-item "Display Other Windows" gdb-many-windows
2968 :help "Toggle display of locals, stack and breakpoint information"
2969 :button (:toggle . gdb-many-windows)))
2970 (define-key menu [gdb-restore-windows]
2971 '(menu-item "Restore Window Layout" gdb-restore-windows
2972 :help "Restore standard layout for debug session.")))
2974 (defun gdb-frame-gdb-buffer ()
2975 "Display GUD buffer in a new frame."
2977 (let ((special-display-regexps (append special-display-regexps '(".*")))
2978 (special-display-frame-alist
2979 (remove '(menu-bar-lines) (remove '(tool-bar-lines)
2980 gdb-frame-parameters)))
2981 (same-window-regexps nil))
2982 (display-buffer gud-comint-buffer)))
2984 (defun gdb-display-gdb-buffer ()
2985 "Display GUD buffer."
2987 (let ((same-window-regexps nil))
2988 (select-window (display-buffer gud-comint-buffer nil 0))))
2990 (defun gdb-set-window-buffer (name)
2991 (set-window-buffer (selected-window) (get-buffer name))
2992 (set-window-dedicated-p (selected-window) t))
2994 (defun gdb-setup-windows ()
2995 "Layout the window pattern for `gdb-many-windows'."
2996 (gdb-display-locals-buffer)
2997 (gdb-display-stack-buffer)
2998 (delete-other-windows)
2999 (gdb-display-breakpoints-buffer)
3000 (delete-other-windows)
3002 (pop-to-buffer gud-comint-buffer)
3003 (split-window nil ( / ( * (window-height) 3) 4))
3004 (split-window nil ( / (window-height) 3))
3005 (split-window-horizontally)
3007 (gdb-set-window-buffer (gdb-locals-buffer-name))
3010 (if gud-last-last-frame
3011 (gud-find-file (car gud-last-last-frame))
3013 (gud-find-file gdb-main-file)
3014 ;; Put buffer list in window if we
3015 ;; can't find a source file.
3016 (list-buffers-noselect))))
3017 (setq gdb-source-window (selected-window))
3018 (when gdb-use-separate-io-buffer
3019 (split-window-horizontally)
3021 (gdb-set-window-buffer
3022 (gdb-get-buffer-create 'gdb-inferior-io)))
3024 (gdb-set-window-buffer (gdb-stack-buffer-name))
3025 (split-window-horizontally)
3027 (gdb-set-window-buffer (gdb-breakpoints-buffer-name))
3030 (defcustom gdb-many-windows nil
3031 "If nil just pop up the GUD buffer unless `gdb-show-main' is t.
3032 In this case it starts with two windows: one displaying the GUD
3033 buffer and the other with the source file with the main routine
3034 of the debugged program. Non-nil means display the layout shown for
3040 (defun gdb-many-windows (arg)
3041 "Toggle the number of windows in the basic arrangement.
3042 With arg, display additional buffers iff arg is positive."
3044 (setq gdb-many-windows
3046 (not gdb-many-windows)
3047 (> (prefix-numeric-value arg) 0)))
3048 (message (format "Display of other windows %sabled"
3049 (if gdb-many-windows "en" "dis")))
3050 (if (and gud-comint-buffer
3051 (buffer-name gud-comint-buffer))
3053 (gdb-restore-windows)
3056 (defun gdb-restore-windows ()
3057 "Restore the basic arrangement of windows used by gdb.
3058 This arrangement depends on the value of `gdb-many-windows'."
3060 (pop-to-buffer gud-comint-buffer) ;Select the right window and frame.
3061 (delete-other-windows)
3062 (if gdb-many-windows
3064 (when (or gud-last-last-frame gdb-show-main)
3068 (if gud-last-last-frame
3069 (gud-find-file (car gud-last-last-frame))
3070 (gud-find-file gdb-main-file)))
3071 (setq gdb-source-window (selected-window))
3075 "Exit a debugging session cleanly.
3076 Kills the gdb buffers, and resets variables and the source buffers."
3077 (dolist (buffer (buffer-list))
3078 (unless (eq buffer gud-comint-buffer)
3079 (with-current-buffer buffer
3080 (if (eq gud-minor-mode 'gdbmi)
3081 (if (string-match "\\` ?\\*.+\\*\\'" (buffer-name))
3083 (gdb-remove-breakpoint-icons (point-min) (point-max) t)
3084 (setq gud-minor-mode nil)
3085 (kill-local-variable 'tool-bar-map)
3086 (kill-local-variable 'gdb-define-alist))))))
3087 (setq gdb-overlay-arrow-position nil)
3088 (setq overlay-arrow-variable-list
3089 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))
3090 (setq fringe-indicator-alist '((overlay-arrow . right-triangle)))
3091 (setq gdb-stack-position nil)
3092 (setq overlay-arrow-variable-list
3093 (delq 'gdb-stack-position overlay-arrow-variable-list))
3094 (if (boundp 'speedbar-frame) (speedbar-timer-fn))
3095 (setq gud-running nil)
3096 (setq gdb-active-process nil)
3097 (remove-hook 'after-save-hook 'gdb-create-define-alist t))
3099 (defun gdb-get-source-file ()
3100 "Find the source file where the program starts and display it with related
3101 buffers, if required."
3102 (goto-char (point-min))
3103 (if (re-search-forward gdb-source-file-regexp nil t)
3104 (setq gdb-main-file (match-string 1)))
3105 (if gdb-many-windows
3107 (gdb-get-buffer-create 'gdb-breakpoints-buffer)
3109 (let ((pop-up-windows t))
3110 (display-buffer (gud-find-file gdb-main-file))))))
3113 (defun gdb-put-string (putstring pos &optional dprop &rest sprops)
3114 "Put string PUTSTRING in front of POS in the current buffer.
3115 PUTSTRING is displayed by putting an overlay into the current buffer with a
3116 `before-string' string that has a `display' property whose value is
3118 (let ((string (make-string 1 ?x))
3119 (buffer (current-buffer)))
3120 (setq putstring (copy-sequence putstring))
3121 (let ((overlay (make-overlay pos pos buffer))
3123 (list (list 'margin 'left-margin) putstring))))
3124 (put-text-property 0 1 'display prop string)
3126 (add-text-properties 0 1 sprops string))
3127 (overlay-put overlay 'put-break t)
3128 (overlay-put overlay 'before-string string))))
3130 ;;from remove-images
3131 (defun gdb-remove-strings (start end &optional buffer)
3132 "Remove strings between START and END in BUFFER.
3133 Remove only strings that were put in BUFFER with calls to `gdb-put-string'.
3134 BUFFER nil or omitted means use the current buffer."
3136 (setq buffer (current-buffer)))
3137 (dolist (overlay (overlays-in start end))
3138 (when (overlay-get overlay 'put-break)
3139 (delete-overlay overlay))))
3141 (defun gdb-put-breakpoint-icon (enabled bptno)
3142 (let ((start (- (line-beginning-position) 1))
3143 (end (+ (line-end-position) 1))
3144 (putstring (if enabled "B" "b"))
3145 (source-window (get-buffer-window (current-buffer) 0)))
3146 (add-text-properties
3147 0 1 '(help-echo "mouse-1: clear bkpt, mouse-3: enable/disable bkpt")
3150 (add-text-properties
3151 0 1 `(gdb-bptno ,bptno gdb-enabled t) putstring)
3152 (add-text-properties
3153 0 1 `(gdb-bptno ,bptno gdb-enabled nil) putstring))
3154 (gdb-remove-breakpoint-icons start end)
3155 (if (display-images-p)
3156 (if (>= (or left-fringe-width
3157 (if source-window (car (window-fringes source-window)))
3158 gdb-buffer-fringe-width) 8)
3161 `(left-fringe breakpoint
3164 'breakpoint-disabled))
3166 'gdb-enabled enabled)
3167 (when (< left-margin-width 2)
3168 (save-current-buffer
3169 (setq left-margin-width 2)
3173 left-margin-width right-margin-width))))
3176 (or breakpoint-enabled-icon
3177 (setq breakpoint-enabled-icon
3178 (find-image `((:type xpm :data
3179 ,breakpoint-xpm-data
3180 :ascent 100 :pointer hand)
3182 ,breakpoint-enabled-pbm-data
3183 :ascent 100 :pointer hand)))))
3184 (or breakpoint-disabled-icon
3185 (setq breakpoint-disabled-icon
3186 (find-image `((:type xpm :data
3187 ,breakpoint-xpm-data
3188 :conversion disabled
3189 :ascent 100 :pointer hand)
3191 ,breakpoint-disabled-pbm-data
3192 :ascent 100 :pointer hand))))))
3196 (when (< left-margin-width 2)
3197 (save-current-buffer
3198 (setq left-margin-width 2)
3199 (let ((window (get-buffer-window (current-buffer) 0)))
3202 window left-margin-width right-margin-width)))))
3204 (propertize putstring
3205 'face (if enabled 'breakpoint-enabled 'breakpoint-disabled))
3208 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin)
3209 (gdb-remove-strings start end)
3210 (if (display-images-p)
3211 (remove-images start end))
3213 (setq left-margin-width 0)
3214 (let ((window (get-buffer-window (current-buffer) 0)))
3217 window left-margin-width right-margin-width)))))
3221 ;; arch-tag: 1b41ea2b-f364-4cec-8f35-e02e4fe01912
3222 ;;; gdb-mi.el ends here