Mercurial > emacs
annotate lisp/progmodes/gdb-ui.el @ 54736:b94de166de9d
(ethio-sera-being-called-by-w3): New
variable.
(ethio-sera-to-fidel-ethio): Check ethio-sera-being-called-by-w3
instead of sera-being-called-by-w3.
(ethio-fidel-to-sera-buffer): Likewise.
(ethio-find-file): Bind ethio-sera-being-called-by-w3 to t
instead of sera-being-called-by-w3.
(ethio-write-file): Likewise.
| author | Kenichi Handa <handa@m17n.org> |
|---|---|
| date | Mon, 05 Apr 2004 23:27:37 +0000 |
| parents | 7bfccd78beed |
| children | c6ccb7a82f9f |
| rev | line source |
|---|---|
| 54538 | 1 ;;; gdb-ui.el --- User Interface for running GDB |
| 2 | |
| 3 ;; Author: Nick Roberts <nick@nick.uklinux.net> | |
| 4 ;; Maintainer: FSF | |
| 5 ;; Keywords: unix, tools | |
| 6 | |
| 7 ;; Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. | |
| 8 | |
| 9 ;; This file is part of GNU Emacs. | |
| 10 | |
| 11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
| 12 ;; it under the terms of the GNU General Public License as published by | |
| 13 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 14 ;; any later version. | |
| 15 | |
| 16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
| 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 19 ;; GNU General Public License for more details. | |
| 20 | |
| 21 ;; You should have received a copy of the GNU General Public License | |
| 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
| 23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 24 ;; Boston, MA 02111-1307, USA. | |
| 25 | |
| 26 ;;; Commentary: | |
| 27 | |
| 28 ;; This mode acts as a graphical user interface to GDB. You can interact with | |
| 29 ;; GDB through the GUD buffer in the usual way, but there are also further | |
| 30 ;; buffers which control the execution and describe the state of your program. | |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
31 ;; It separates the input/output of your program from that of GDB, if |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
32 ;; required, and displays expressions and their current values in their own |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
33 ;; buffers. It also uses features of Emacs 21 such as the display margin for |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
34 ;; breakpoints, and the toolbar (see the GDB Graphical Interface section in |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
35 ;; the Emacs info manual). |
| 54538 | 36 |
| 37 ;; Start the debugger with M-x gdba. | |
| 38 | |
| 39 ;; This file has evolved from gdba.el from GDB 5.0 written by Tom Lord and Jim | |
| 40 ;; Kingdon and uses GDB's annotation interface. You don't need to know about | |
| 41 ;; annotations to use this mode as a debugger, but if you are interested | |
| 42 ;; developing the mode itself, then see the Annotations section in the GDB | |
| 43 ;; info manual. Some GDB/MI commands are also used through th CLI command | |
| 44 ;; 'interpreter mi <mi-command>'. | |
| 45 ;; | |
| 46 ;; Known Bugs: | |
| 47 ;; | |
| 48 | |
| 49 ;;; Code: | |
| 50 | |
| 51 (require 'gud) | |
| 52 | |
| 53 (defvar gdb-current-address "main" "Initialisation for Assembler buffer.") | |
| 54 (defvar gdb-previous-address nil) | |
| 55 (defvar gdb-previous-frame nil) | |
| 56 (defvar gdb-current-frame "main") | |
| 57 (defvar gdb-current-language nil) | |
| 58 (defvar gdb-view-source t "Non-nil means that source code can be viewed.") | |
| 59 (defvar gdb-selected-view 'source "Code type that user wishes to view.") | |
| 60 (defvar gdb-var-list nil "List of variables in watch window") | |
| 61 (defvar gdb-var-changed nil "Non-nil means that gdb-var-list has changed.") | |
| 62 (defvar gdb-buffer-type nil) | |
| 63 (defvar gdb-overlay-arrow-position nil) | |
| 64 (defvar gdb-variables '() | |
| 65 "A list of variables that are local to the GUD buffer.") | |
| 66 | |
| 67 ;;;###autoload | |
| 68 (defun gdba (command-line) | |
| 69 "Run gdb on program FILE in buffer *gud-FILE*. | |
| 70 The directory containing FILE becomes the initial working directory | |
| 71 and source-file directory for your debugger. | |
| 72 | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
73 If `gdb-many-windows' is nil (the default value) then gdb just |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
74 pops up the GUD buffer unless `gdb-show-main' is t. In this case |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
75 it starts with two windows: one displaying the GUD buffer and the |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
76 other with the source file with the main routine of the debugee. |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
77 |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
78 If `gdb-many-windows' is t the layout below will appear |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
79 regardless of the value of `gdb-show-main'. Keybindings are given |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
80 in relevant buffer. |
| 54538 | 81 |
| 82 --------------------------------------------------------------------- | |
| 83 GDB Toolbar | |
| 84 --------------------------------------------------------------------- | |
| 85 GUD buffer (I/O of GDB) | Locals buffer | |
| 86 | | |
| 87 | | |
| 88 | | |
| 89 --------------------------------------------------------------------- | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
90 Source buffer | Input/Output (of debugee) buffer |
| 54538 | 91 | (comint-mode) |
| 92 | | |
| 93 | | |
| 94 | | |
| 95 | | |
| 96 | | |
| 97 | | |
| 98 --------------------------------------------------------------------- | |
| 99 Stack buffer | Breakpoints buffer | |
| 100 RET gdb-frames-select | SPC gdb-toggle-breakpoint | |
| 101 | RET gdb-goto-breakpoint | |
| 102 | d gdb-delete-breakpoint | |
| 103 --------------------------------------------------------------------- | |
| 104 | |
| 105 All the buffers share the toolbar and source should always display in the same | |
| 106 window e.g after typing g on a breakpoint in the breakpoints buffer. Breakpoint | |
| 107 icons are displayed both by setting a break with gud-break and by typing break | |
| 108 in the GUD buffer. | |
| 109 | |
| 110 This works best (depending on the size of your monitor) using most of the | |
| 111 screen. | |
| 112 | |
| 113 Displayed expressions appear in separate frames. Arrays may be displayed | |
| 114 as slices and visualised using the graph program from plotutils if installed. | |
| 115 Pointers in structures may be followed in a tree-like fashion. | |
| 116 | |
| 117 The following interactive lisp functions help control operation : | |
| 118 | |
| 119 `gdb-many-windows' - Toggle the number of windows gdb uses. | |
| 120 `gdb-restore-windows' - To restore the window layout." | |
| 121 ;; | |
| 122 (interactive (list (gud-query-cmdline 'gdba))) | |
| 123 ;; | |
| 124 ;; Let's start with a basic gud-gdb buffer and then modify it a bit. | |
| 125 (gdb command-line) | |
| 126 (gdb-ann3)) | |
| 127 | |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
128 (defvar gdb-debug-log nil) |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
129 |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
130 (defcustom gdb-enable-debug-log nil |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
131 "Non-nil means record the process input and output in `gdb-debug-log'." |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
132 :type 'boolean |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
133 :group 'gud) |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
134 |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
135 (defcustom gdb-use-inferior-io-buffer nil |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
136 "Non-nil means display output from the inferior in a separate buffer." |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
137 :type 'boolean |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
138 :group 'gud) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
139 |
| 54538 | 140 (defun gdb-ann3 () |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
141 (setq gdb-debug-log nil) |
| 54538 | 142 (set (make-local-variable 'gud-minor-mode) 'gdba) |
| 143 (set (make-local-variable 'gud-marker-filter) 'gud-gdba-marker-filter) | |
| 144 ;; | |
| 145 (gud-def gud-break (if (not (string-equal mode-name "Machine")) | |
| 146 (gud-call "break %f:%l" arg) | |
| 147 (save-excursion | |
| 148 (beginning-of-line) | |
| 149 (forward-char 2) | |
| 150 (gud-call "break *%a" arg))) | |
| 151 "\C-b" "Set breakpoint at current line or address.") | |
| 152 ;; | |
| 153 (gud-def gud-remove (if (not (string-equal mode-name "Machine")) | |
| 154 (gud-call "clear %f:%l" arg) | |
| 155 (save-excursion | |
| 156 (beginning-of-line) | |
| 157 (forward-char 2) | |
| 158 (gud-call "clear *%a" arg))) | |
| 159 "\C-d" "Remove breakpoint at current line or address.") | |
| 160 ;; | |
| 161 (gud-def gud-until (if (not (string-equal mode-name "Machine")) | |
| 162 (gud-call "until %f:%l" arg) | |
| 163 (save-excursion | |
| 164 (beginning-of-line) | |
| 165 (forward-char 2) | |
| 166 (gud-call "until *%a" arg))) | |
| 167 "\C-u" "Continue to current line or address.") | |
| 168 | |
| 169 (define-key gud-minor-mode-map [left-margin mouse-1] | |
| 170 'gdb-mouse-toggle-breakpoint) | |
| 171 (define-key gud-minor-mode-map [left-fringe mouse-1] | |
| 172 'gdb-mouse-toggle-breakpoint) | |
| 173 | |
| 174 (setq comint-input-sender 'gdb-send) | |
| 175 ;; | |
| 176 ;; (re-)initialise | |
| 177 (setq gdb-current-address "main") | |
| 178 (setq gdb-previous-address nil) | |
| 179 (setq gdb-previous-frame nil) | |
| 180 (setq gdb-current-frame "main") | |
| 181 (setq gdb-view-source t) | |
| 182 (setq gdb-selected-view 'source) | |
| 183 (setq gdb-var-list nil) | |
| 184 (setq gdb-var-changed nil) | |
| 185 (setq gdb-first-prompt nil) | |
| 186 ;; | |
| 187 (mapc 'make-local-variable gdb-variables) | |
| 188 (setq gdb-buffer-type 'gdba) | |
| 189 ;; | |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
190 (if gdb-use-inferior-io-buffer (gdb-clear-inferior-io)) |
| 54538 | 191 ;; |
| 192 (if (eq window-system 'w32) | |
| 193 (gdb-enqueue-input (list "set new-console off\n" 'ignore))) | |
| 194 (gdb-enqueue-input (list "set height 0\n" 'ignore)) | |
| 195 ;; find source file and compilation directory here | |
| 196 (gdb-enqueue-input (list "server list main\n" 'ignore)) ; C program | |
| 197 (gdb-enqueue-input (list "server list MAIN__\n" 'ignore)) ; Fortran program | |
| 198 (gdb-enqueue-input (list "server info source\n" 'gdb-source-info)) | |
| 199 ;; | |
| 200 (run-hooks 'gdba-mode-hook)) | |
| 201 | |
| 202 (defcustom gdb-use-colon-colon-notation nil | |
| 203 "Non-nil means use FUNCTION::VARIABLE format to display variables in the | |
| 204 speedbar." | |
| 205 :type 'boolean | |
| 206 :group 'gud) | |
| 207 | |
| 208 (defun gud-watch () | |
| 209 "Watch expression at point." | |
| 210 (interactive) | |
| 211 (require 'tooltip) | |
| 212 (let ((expr (tooltip-identifier-from-point (point)))) | |
| 213 (if (and (string-equal gdb-current-language "c") | |
| 214 gdb-use-colon-colon-notation) | |
| 215 (setq expr (concat gdb-current-frame "::" expr))) | |
| 216 (catch 'already-watched | |
| 217 (dolist (var gdb-var-list) | |
| 218 (if (string-equal expr (car var)) (throw 'already-watched nil))) | |
| 219 (set-text-properties 0 (length expr) nil expr) | |
| 220 (gdb-enqueue-input | |
| 221 (list (concat "server interpreter mi \"-var-create - * " expr "\"\n") | |
| 222 `(lambda () (gdb-var-create-handler ,expr)))))) | |
| 223 (select-window (get-buffer-window gud-comint-buffer))) | |
| 224 | |
| 225 (defconst gdb-var-create-regexp | |
| 226 "name=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\",type=\"\\(.*?\\)\"") | |
| 227 | |
| 228 (defun gdb-var-create-handler (expr) | |
| 229 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 230 (goto-char (point-min)) | |
| 231 (if (re-search-forward gdb-var-create-regexp nil t) | |
| 232 (let ((var (list expr | |
| 233 (match-string 1) | |
| 234 (match-string 2) | |
| 235 (match-string 3) | |
| 236 nil nil))) | |
| 237 (push var gdb-var-list) | |
| 238 (setq speedbar-update-flag t) | |
| 239 (speedbar 1) | |
| 240 (if (equal (nth 2 var) "0") | |
| 241 (gdb-enqueue-input | |
| 242 (list (concat "server interpreter mi \"-var-evaluate-expression " | |
| 243 (nth 1 var) "\"\n") | |
| 244 `(lambda () (gdb-var-evaluate-expression-handler | |
| 245 ,(nth 1 var) nil)))) | |
| 246 (setq gdb-var-changed t))) | |
| 247 (if (re-search-forward "Undefined command" nil t) | |
| 248 (message "Watching expressions requires gdb 6.0 onwards") | |
| 249 (message "No symbol %s in current context." expr))))) | |
| 250 | |
| 251 (defun gdb-var-evaluate-expression-handler (varnum changed) | |
| 252 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 253 (goto-char (point-min)) | |
| 254 (re-search-forward ".*value=\"\\(.*?\\)\"" nil t) | |
| 255 (catch 'var-found | |
| 256 (let ((var-list nil) (num 0)) | |
| 257 (dolist (var gdb-var-list) | |
| 258 (if (string-equal varnum (cadr var)) | |
| 259 (progn | |
| 260 (if changed (setcar (nthcdr 5 var) t)) | |
| 261 (setcar (nthcdr 4 var) (match-string 1)) | |
| 262 (setcar (nthcdr num gdb-var-list) var) | |
| 263 (throw 'var-found nil))) | |
| 264 (setq num (+ num 1)))))) | |
| 265 (setq gdb-var-changed t)) | |
| 266 | |
| 267 (defun gdb-var-list-children (varnum) | |
| 268 (gdb-enqueue-input | |
| 269 (list (concat "server interpreter mi \"-var-list-children " varnum "\"\n") | |
| 270 `(lambda () (gdb-var-list-children-handler ,varnum))))) | |
| 271 | |
| 272 (defconst gdb-var-list-children-regexp | |
| 273 "name=\"\\(.*?\\)\",exp=\"\\(.*?\\)\",numchild=\"\\(.*?\\)\"") | |
| 274 | |
| 275 (defun gdb-var-list-children-handler (varnum) | |
| 276 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 277 (goto-char (point-min)) | |
| 278 (let ((var-list nil)) | |
| 279 (catch 'child-already-watched | |
| 280 (dolist (var gdb-var-list) | |
| 281 (if (string-equal varnum (cadr var)) | |
| 282 (progn | |
| 283 (push var var-list) | |
| 284 (while (re-search-forward gdb-var-list-children-regexp nil t) | |
| 285 (let ((varchild (list (match-string 2) | |
| 286 (match-string 1) | |
| 287 (match-string 3) | |
| 288 nil nil nil))) | |
| 289 (if (looking-at ",type=\"\\(.*?\\)\"") | |
| 290 (setcar (nthcdr 3 varchild) (match-string 1))) | |
| 291 (dolist (var1 gdb-var-list) | |
| 292 (if (string-equal (cadr var1) (cadr varchild)) | |
| 293 (throw 'child-already-watched nil))) | |
| 294 (push varchild var-list) | |
| 295 (if (equal (nth 2 varchild) "0") | |
| 296 (gdb-enqueue-input | |
| 297 (list | |
| 298 (concat | |
| 299 "server interpreter mi \"-var-evaluate-expression " | |
| 300 (nth 1 varchild) "\"\n") | |
| 301 `(lambda () (gdb-var-evaluate-expression-handler | |
| 302 ,(nth 1 varchild) nil)))))))) | |
| 303 (push var var-list))) | |
| 304 (setq gdb-var-list (nreverse var-list)))))) | |
| 305 | |
| 306 (defun gdb-var-update () | |
| 307 (if (not (member 'gdb-var-update (gdb-get-pending-triggers))) | |
| 308 (progn | |
| 309 (gdb-enqueue-input (list "server interpreter mi \"-var-update *\"\n" | |
| 310 'gdb-var-update-handler)) | |
| 311 (gdb-set-pending-triggers (cons 'gdb-var-update | |
| 312 (gdb-get-pending-triggers)))))) | |
| 313 | |
| 314 (defconst gdb-var-update-regexp "name=\"\\(.*?\\)\"") | |
| 315 | |
| 316 (defun gdb-var-update-handler () | |
| 317 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 318 (goto-char (point-min)) | |
| 319 (while (re-search-forward gdb-var-update-regexp nil t) | |
| 320 (let ((varnum (match-string 1))) | |
| 321 (gdb-enqueue-input | |
| 322 (list (concat "server interpreter mi \"-var-evaluate-expression " | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
323 varnum "\"\n") |
| 54538 | 324 `(lambda () (gdb-var-evaluate-expression-handler |
| 325 ,varnum t))))))) | |
| 326 (gdb-set-pending-triggers | |
| 327 (delq 'gdb-var-update (gdb-get-pending-triggers)))) | |
| 328 | |
| 329 (defun gdb-var-delete () | |
| 330 "Delete watched expression from the speedbar." | |
| 331 (interactive) | |
| 332 (if (with-current-buffer gud-comint-buffer (eq gud-minor-mode 'gdba)) | |
| 333 (let ((text (speedbar-line-text))) | |
| 334 (string-match "\\(\\S-+\\)" text) | |
| 335 (let* ((expr (match-string 1 text)) | |
| 336 (var (assoc expr gdb-var-list)) | |
| 337 (varnum (cadr var))) | |
| 338 (unless (string-match "\\." varnum) | |
| 339 (gdb-enqueue-input | |
| 340 (list (concat "server interpreter mi \"-var-delete " | |
| 341 varnum "\"\n") | |
| 342 'ignore)) | |
| 343 (setq gdb-var-list (delq var gdb-var-list)) | |
| 344 (dolist (varchild gdb-var-list) | |
| 345 (if (string-match (concat (nth 1 var) "\\.") (nth 1 varchild)) | |
| 346 (setq gdb-var-list (delq varchild gdb-var-list)))) | |
| 347 (setq gdb-var-changed t)))))) | |
| 348 | |
| 349 (defun gdb-edit-value (text token indent) | |
| 350 "Assign a value to a variable displayed in the speedbar" | |
| 351 (let* ((var (nth (- (count-lines (point-min) (point)) 2) gdb-var-list)) | |
| 352 (varnum (cadr var)) (value)) | |
| 353 (setq value (read-string "New value: ")) | |
| 354 (gdb-enqueue-input | |
| 355 (list (concat "server interpreter mi \"-var-assign " | |
| 356 varnum " " value "\"\n") | |
| 357 'ignore)))) | |
| 358 | |
| 359 (defcustom gdb-show-changed-values t | |
| 360 "Non-nil means use font-lock-warning-face to display values that have | |
| 361 recently changed in the speedbar." | |
| 362 :type 'boolean | |
| 363 :group 'gud) | |
| 364 | |
| 365 (defun gdb-speedbar-expand-node (text token indent) | |
| 366 "Expand the node the user clicked on. | |
| 367 TEXT is the text of the button we clicked on, a + or - item. | |
| 368 TOKEN is data related to this node. | |
| 369 INDENT is the current indentation depth." | |
| 370 (cond ((string-match "+" text) ;expand this node | |
| 371 (gdb-var-list-children token)) | |
| 372 ((string-match "-" text) ;contract this node | |
| 373 (dolist (var gdb-var-list) | |
| 374 (if (string-match (concat token "\\.") (nth 1 var)) | |
| 375 (setq gdb-var-list (delq var gdb-var-list)))) | |
| 376 (setq gdb-var-changed t)))) | |
| 377 | |
| 378 | |
| 379 ;; ====================================================================== | |
| 380 ;; | |
| 381 ;; In this world, there are gdb variables (of unspecified | |
| 382 ;; representation) and buffers associated with those objects. | |
| 383 ;; The list of variables is built up by the expansions of | |
| 384 ;; def-gdb-variable | |
| 385 | |
| 386 (defmacro def-gdb-var (root-symbol &optional default doc) | |
| 387 (let* ((root (symbol-name root-symbol)) | |
| 388 (accessor (intern (concat "gdb-get-" root))) | |
| 389 (setter (intern (concat "gdb-set-" root))) | |
| 390 (name (intern (concat "gdb-" root)))) | |
| 391 `(progn | |
| 392 (defvar ,name ,default ,doc) | |
| 393 (if (not (memq ',name gdb-variables)) | |
| 394 (push ',name gdb-variables)) | |
| 395 (defun ,accessor () | |
| 396 (buffer-local-value ',name gud-comint-buffer)) | |
| 397 (defun ,setter (val) | |
| 398 (with-current-buffer gud-comint-buffer | |
| 399 (setq ,name val)))))) | |
| 400 | |
| 401 (def-gdb-var buffer-type nil | |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
402 "One of the symbols bound in `gdb-buffer-rules'.") |
| 54538 | 403 |
| 404 (def-gdb-var burst "" | |
| 405 "A string of characters from gdb that have not yet been processed.") | |
| 406 | |
| 407 (def-gdb-var input-queue () | |
| 408 "A list of gdb command objects.") | |
| 409 | |
| 410 (def-gdb-var prompting nil | |
| 411 "True when gdb is idle with no pending input.") | |
| 412 | |
| 413 (def-gdb-var output-sink 'user | |
| 414 "The disposition of the output of the current gdb command. | |
| 415 Possible values are these symbols: | |
| 416 | |
| 417 user -- gdb output should be copied to the GUD buffer | |
| 418 for the user to see. | |
| 419 | |
| 420 inferior -- gdb output should be copied to the inferior-io buffer | |
| 421 | |
| 422 pre-emacs -- output should be ignored util the post-prompt | |
| 423 annotation is received. Then the output-sink | |
| 424 becomes:... | |
| 425 emacs -- output should be collected in the partial-output-buffer | |
| 426 for subsequent processing by a command. This is the | |
| 427 disposition of output generated by commands that | |
| 428 gdb mode sends to gdb on its own behalf. | |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
429 post-emacs -- ignore output until the prompt annotation is |
| 54538 | 430 received, then go to USER disposition. |
| 431 ") | |
| 432 | |
| 433 (def-gdb-var current-item nil | |
| 434 "The most recent command item sent to gdb.") | |
| 435 | |
| 436 (def-gdb-var pending-triggers '() | |
| 437 "A list of trigger functions that have run later than their output | |
| 438 handlers.") | |
| 439 | |
| 440 ;; end of gdb variables | |
| 441 | |
| 442 (defun gdb-get-target-string () | |
| 443 (with-current-buffer gud-comint-buffer | |
| 444 gud-target-name)) | |
| 445 | |
| 446 | |
| 447 ;; | |
| 448 ;; gdb buffers. | |
| 449 ;; | |
| 450 ;; Each buffer has a TYPE -- a symbol that identifies the function | |
| 451 ;; of that particular buffer. | |
| 452 ;; | |
| 453 ;; The usual gdb interaction buffer is given the type `gdba' and | |
| 454 ;; is constructed specially. | |
| 455 ;; | |
| 456 ;; Others are constructed by gdb-get-create-buffer and | |
| 457 ;; named according to the rules set forth in the gdb-buffer-rules-assoc | |
| 458 | |
| 459 (defvar gdb-buffer-rules-assoc '()) | |
| 460 | |
| 461 (defun gdb-get-buffer (key) | |
| 462 "Return the gdb buffer tagged with type KEY. | |
| 463 The key should be one of the cars in `gdb-buffer-rules-assoc'." | |
| 464 (save-excursion | |
| 465 (gdb-look-for-tagged-buffer key (buffer-list)))) | |
| 466 | |
| 467 (defun gdb-get-create-buffer (key) | |
| 468 "Create a new gdb buffer of the type specified by KEY. | |
| 469 The key should be one of the cars in `gdb-buffer-rules-assoc'." | |
| 470 (or (gdb-get-buffer key) | |
| 471 (let* ((rules (assoc key gdb-buffer-rules-assoc)) | |
| 472 (name (funcall (gdb-rules-name-maker rules))) | |
| 473 (new (get-buffer-create name))) | |
| 474 (with-current-buffer new | |
| 475 ;; FIXME: This should be set after calling the function, since the | |
| 476 ;; function should run kill-all-local-variables. | |
| 477 (set (make-local-variable 'gdb-buffer-type) key) | |
| 478 (if (cdr (cdr rules)) | |
| 479 (funcall (car (cdr (cdr rules))))) | |
| 480 (set (make-local-variable 'gud-comint-buffer) gud-comint-buffer) | |
| 481 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
| 482 (set (make-local-variable 'tool-bar-map) gud-tool-bar-map) | |
| 483 new)))) | |
| 484 | |
| 485 (defun gdb-rules-name-maker (rules) (car (cdr rules))) | |
| 486 | |
| 487 (defun gdb-look-for-tagged-buffer (key bufs) | |
| 488 (let ((retval nil)) | |
| 489 (while (and (not retval) bufs) | |
| 490 (set-buffer (car bufs)) | |
| 491 (if (eq gdb-buffer-type key) | |
| 492 (setq retval (car bufs))) | |
| 493 (setq bufs (cdr bufs))) | |
| 494 retval)) | |
| 495 | |
| 496 ;; | |
| 497 ;; This assoc maps buffer type symbols to rules. Each rule is a list of | |
| 498 ;; at least one and possible more functions. The functions have these | |
| 499 ;; roles in defining a buffer type: | |
| 500 ;; | |
| 501 ;; NAME - Return a name for this buffer type. | |
| 502 ;; | |
| 503 ;; The remaining function(s) are optional: | |
| 504 ;; | |
| 505 ;; MODE - called in a new buffer with no arguments, should establish | |
| 506 ;; the proper mode for the buffer. | |
| 507 ;; | |
| 508 | |
| 509 (defun gdb-set-buffer-rules (buffer-type &rest rules) | |
| 510 (let ((binding (assoc buffer-type gdb-buffer-rules-assoc))) | |
| 511 (if binding | |
| 512 (setcdr binding rules) | |
| 513 (push (cons buffer-type rules) | |
| 514 gdb-buffer-rules-assoc)))) | |
| 515 | |
| 516 ;; GUD buffers are an exception to the rules | |
| 517 (gdb-set-buffer-rules 'gdba 'error) | |
| 518 | |
| 519 ;; | |
| 520 ;; Partial-output buffer : This accumulates output from a command executed on | |
| 521 ;; behalf of emacs (rather than the user). | |
| 522 ;; | |
| 523 (gdb-set-buffer-rules 'gdb-partial-output-buffer | |
| 524 'gdb-partial-output-name) | |
| 525 | |
| 526 (defun gdb-partial-output-name () | |
| 527 (concat "*partial-output-" | |
| 528 (gdb-get-target-string) | |
| 529 "*")) | |
| 530 | |
| 531 | |
| 532 (gdb-set-buffer-rules 'gdb-inferior-io | |
| 533 'gdb-inferior-io-name | |
| 534 'gdb-inferior-io-mode) | |
| 535 | |
| 536 (defun gdb-inferior-io-name () | |
| 537 (concat "*input/output of " | |
| 538 (gdb-get-target-string) | |
| 539 "*")) | |
| 540 | |
| 541 (defvar gdb-inferior-io-mode-map | |
| 542 (let ((map (make-sparse-keymap))) | |
| 543 (define-key map "\C-c\C-c" 'gdb-inferior-io-interrupt) | |
| 544 (define-key map "\C-c\C-z" 'gdb-inferior-io-stop) | |
| 545 (define-key map "\C-c\C-\\" 'gdb-inferior-io-quit) | |
| 546 (define-key map "\C-c\C-d" 'gdb-inferior-io-eof) | |
| 547 map)) | |
| 548 | |
| 549 (define-derived-mode gdb-inferior-io-mode comint-mode "Debuggee I/O" | |
| 550 "Major mode for gdb inferior-io." | |
| 551 :syntax-table nil :abbrev-table nil | |
| 552 ;; We want to use comint because it has various nifty and familiar | |
| 553 ;; features. We don't need a process, but comint wants one, so create | |
| 554 ;; a dummy one. | |
| 555 (make-comint-in-buffer | |
| 556 (substring (buffer-name) 1 (- (length (buffer-name)) 1)) | |
| 557 (current-buffer) "hexl") | |
| 558 (setq comint-input-sender 'gdb-inferior-io-sender)) | |
| 559 | |
| 560 (defun gdb-inferior-io-sender (proc string) | |
| 561 ;; PROC is the pseudo-process created to satisfy comint. | |
| 562 (with-current-buffer (process-buffer proc) | |
| 563 (setq proc (get-buffer-process gud-comint-buffer)) | |
| 564 (process-send-string proc string) | |
| 565 (process-send-string proc "\n"))) | |
| 566 | |
| 567 (defun gdb-inferior-io-interrupt () | |
| 568 "Interrupt the program being debugged." | |
| 569 (interactive) | |
| 570 (interrupt-process | |
| 571 (get-buffer-process gud-comint-buffer) comint-ptyp)) | |
| 572 | |
| 573 (defun gdb-inferior-io-quit () | |
| 574 "Send quit signal to the program being debugged." | |
| 575 (interactive) | |
| 576 (quit-process | |
| 577 (get-buffer-process gud-comint-buffer) comint-ptyp)) | |
| 578 | |
| 579 (defun gdb-inferior-io-stop () | |
| 580 "Stop the program being debugged." | |
| 581 (interactive) | |
| 582 (stop-process | |
| 583 (get-buffer-process gud-comint-buffer) comint-ptyp)) | |
| 584 | |
| 585 (defun gdb-inferior-io-eof () | |
| 586 "Send end-of-file to the program being debugged." | |
| 587 (interactive) | |
| 588 (process-send-eof | |
| 589 (get-buffer-process gud-comint-buffer))) | |
| 590 | |
| 591 | |
| 592 ;; | |
| 593 ;; gdb communications | |
| 594 ;; | |
| 595 | |
| 596 ;; INPUT: things sent to gdb | |
| 597 ;; | |
| 598 ;; The queues are lists. Each element is either a string (indicating user or | |
| 599 ;; user-like input) or a list of the form: | |
| 600 ;; | |
| 601 ;; (INPUT-STRING HANDLER-FN) | |
| 602 ;; | |
| 603 ;; The handler function will be called from the partial-output buffer when the | |
| 604 ;; command completes. This is the way to write commands which invoke gdb | |
| 605 ;; commands autonomously. | |
| 606 ;; | |
| 607 ;; These lists are consumed tail first. | |
| 608 ;; | |
| 609 | |
| 610 (defun gdb-send (proc string) | |
| 611 "A comint send filter for gdb. | |
| 612 This filter may simply queue output for a later time." | |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
613 (if gud-running |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
614 (process-send-string proc (concat string "\n")) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
615 (gdb-enqueue-input (concat string "\n")))) |
| 54538 | 616 |
| 617 ;; Note: Stuff enqueued here will be sent to the next prompt, even if it | |
| 618 ;; is a query, or other non-top-level prompt. | |
| 619 | |
| 620 (defun gdb-enqueue-input (item) | |
| 621 (if (gdb-get-prompting) | |
| 622 (progn | |
| 623 (gdb-send-item item) | |
| 624 (gdb-set-prompting nil)) | |
| 625 (gdb-set-input-queue | |
| 626 (cons item (gdb-get-input-queue))))) | |
| 627 | |
| 628 (defun gdb-dequeue-input () | |
| 629 (let ((queue (gdb-get-input-queue))) | |
| 630 (and queue | |
| 631 (let ((last (car (last queue)))) | |
| 632 (unless (nbutlast queue) (gdb-set-input-queue '())) | |
| 633 last)))) | |
| 634 | |
| 635 | |
| 636 ;; | |
| 637 ;; output -- things gdb prints to emacs | |
| 638 ;; | |
| 639 ;; GDB output is a stream interrupted by annotations. | |
| 640 ;; Annotations can be recognized by their beginning | |
| 641 ;; with \C-j\C-z\C-z<tag><opt>\C-j | |
| 642 ;; | |
| 643 ;; The tag is a string obeying symbol syntax. | |
| 644 ;; | |
| 645 ;; The optional part `<opt>' can be either the empty string | |
| 646 ;; or a space followed by more data relating to the annotation. | |
| 647 ;; For example, the SOURCE annotation is followed by a filename, | |
| 648 ;; line number and various useless goo. This data must not include | |
| 649 ;; any newlines. | |
| 650 ;; | |
| 651 | |
| 652 (defcustom gud-gdba-command-name "gdb -annotate=3" | |
| 653 "Default command to execute an executable under the GDB-UI debugger." | |
| 654 :type 'string | |
| 655 :group 'gud) | |
| 656 | |
| 657 (defvar gdb-annotation-rules | |
| 658 '(("pre-prompt" gdb-pre-prompt) | |
| 659 ("prompt" gdb-prompt) | |
| 660 ("commands" gdb-subprompt) | |
| 661 ("overload-choice" gdb-subprompt) | |
| 662 ("query" gdb-subprompt) | |
| 663 ("prompt-for-continue" gdb-subprompt) | |
| 664 ("post-prompt" gdb-post-prompt) | |
| 665 ("source" gdb-source) | |
| 666 ("starting" gdb-starting) | |
| 667 ("exited" gdb-stopping) | |
| 668 ("signalled" gdb-stopping) | |
| 669 ("signal" gdb-stopping) | |
| 670 ("breakpoint" gdb-stopping) | |
| 671 ("watchpoint" gdb-stopping) | |
| 672 ("frame-begin" gdb-frame-begin) | |
| 673 ("stopped" gdb-stopped) | |
| 674 ) "An assoc mapping annotation tags to functions which process them.") | |
| 675 | |
| 676 (defconst gdb-source-spec-regexp | |
| 677 "\\(.*\\):\\([0-9]*\\):[0-9]*:[a-z]*:\\(0x[a-f0-9]*\\)") | |
| 678 | |
| 679 ;; Do not use this except as an annotation handler. | |
| 680 (defun gdb-source (args) | |
| 681 (string-match gdb-source-spec-regexp args) | |
| 682 ;; Extract the frame position from the marker. | |
| 683 (setq gud-last-frame | |
| 684 (cons | |
| 685 (match-string 1 args) | |
| 686 (string-to-int (match-string 2 args)))) | |
| 687 (setq gdb-current-address (match-string 3 args)) | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
688 (setq gdb-view-source t) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
689 ;; cover for auto-display output which comes *before* |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
690 ;; stopped annotation |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
691 (if (eq (gdb-get-output-sink) 'inferior) (gdb-set-output-sink 'user))) |
| 54538 | 692 |
| 693 (defun gdb-send-item (item) | |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
694 (if gdb-enable-debug-log (push (cons 'send item) gdb-debug-log)) |
| 54538 | 695 (gdb-set-current-item item) |
| 696 (if (stringp item) | |
| 697 (progn | |
| 698 (gdb-set-output-sink 'user) | |
| 699 (process-send-string (get-buffer-process gud-comint-buffer) item)) | |
| 700 (progn | |
| 701 (gdb-clear-partial-output) | |
| 702 (gdb-set-output-sink 'pre-emacs) | |
| 703 (process-send-string (get-buffer-process gud-comint-buffer) | |
| 704 (car item))))) | |
| 705 | |
| 706 (defun gdb-pre-prompt (ignored) | |
| 707 "An annotation handler for `pre-prompt'. This terminates the collection of | |
| 708 output from a previous command if that happens to be in effect." | |
| 709 (let ((sink (gdb-get-output-sink))) | |
| 710 (cond | |
| 711 ((eq sink 'user) t) | |
| 712 ((eq sink 'emacs) | |
| 713 (gdb-set-output-sink 'post-emacs)) | |
| 714 (t | |
| 715 (gdb-set-output-sink 'user) | |
| 716 (error "Phase error in gdb-pre-prompt (got %s)" sink))))) | |
| 717 | |
| 718 (defun gdb-prompt (ignored) | |
| 719 "An annotation handler for `prompt'. | |
| 720 This sends the next command (if any) to gdb." | |
| 721 (when gdb-first-prompt (gdb-ann3)) | |
| 722 (let ((sink (gdb-get-output-sink))) | |
| 723 (cond | |
| 724 ((eq sink 'user) t) | |
| 725 ((eq sink 'post-emacs) | |
| 726 (gdb-set-output-sink 'user) | |
| 727 (let ((handler | |
| 728 (car (cdr (gdb-get-current-item))))) | |
| 729 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 730 (funcall handler)))) | |
| 731 (t | |
| 732 (gdb-set-output-sink 'user) | |
| 733 (error "Phase error in gdb-prompt (got %s)" sink)))) | |
| 734 (let ((input (gdb-dequeue-input))) | |
| 735 (if input | |
| 736 (gdb-send-item input) | |
| 737 (progn | |
| 738 (gdb-set-prompting t) | |
| 739 (gud-display-frame))))) | |
| 740 | |
| 741 (defun gdb-subprompt (ignored) | |
| 742 "An annotation handler for non-top-level prompts." | |
| 743 (gdb-set-prompting t)) | |
| 744 | |
| 745 (defun gdb-starting (ignored) | |
| 746 "An annotation handler for `starting'. This says that I/O for the | |
| 747 subprocess is now the program being debugged, not GDB." | |
| 748 (let ((sink (gdb-get-output-sink))) | |
| 749 (cond | |
| 750 ((eq sink 'user) | |
| 751 (progn | |
| 752 (setq gud-running t) | |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
753 (if gdb-use-inferior-io-buffer |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
754 (gdb-set-output-sink 'inferior)))) |
| 54538 | 755 (t (error "Unexpected `starting' annotation"))))) |
| 756 | |
| 757 (defun gdb-stopping (ignored) | |
| 758 "An annotation handler for `exited' and other annotations which say that I/O | |
| 759 for the subprocess is now GDB, not the program being debugged." | |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
760 (if gdb-use-inferior-io-buffer |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
761 (let ((sink (gdb-get-output-sink))) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
762 (cond |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
763 ((eq sink 'inferior) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
764 (gdb-set-output-sink 'user)) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
765 (t (error "Unexpected stopping annotation")))))) |
| 54538 | 766 |
| 767 (defun gdb-frame-begin (ignored) | |
| 768 (let ((sink (gdb-get-output-sink))) | |
| 769 (cond | |
| 770 ((eq sink 'inferior) | |
| 771 (gdb-set-output-sink 'user)) | |
| 772 ((eq sink 'user) t) | |
| 773 ((eq sink 'emacs) t) | |
| 774 (t (error "Unexpected frame-begin annotation (%S)" sink))))) | |
| 775 | |
| 776 (defun gdb-stopped (ignored) | |
| 777 "An annotation handler for `stopped'. It is just like gdb-stopping, except | |
| 778 that if we already set the output sink to 'user in gdb-stopping, that is fine." | |
| 779 (setq gud-running nil) | |
| 780 (let ((sink (gdb-get-output-sink))) | |
| 781 (cond | |
| 782 ((eq sink 'inferior) | |
| 783 (gdb-set-output-sink 'user)) | |
| 784 ((eq sink 'user) t) | |
| 785 (t (error "Unexpected stopped annotation"))))) | |
| 786 | |
| 787 (defun gdb-post-prompt (ignored) | |
| 788 "An annotation handler for `post-prompt'. This begins the collection of | |
| 789 output from the current command if that happens to be appropriate." | |
| 790 (if (not (gdb-get-pending-triggers)) | |
| 791 (progn | |
| 792 (gdb-get-current-frame) | |
| 793 (gdb-invalidate-frames) | |
| 794 (gdb-invalidate-breakpoints) | |
| 795 (gdb-invalidate-assembler) | |
| 796 (gdb-invalidate-registers) | |
| 797 (gdb-invalidate-locals) | |
| 798 (gdb-invalidate-threads) | |
|
54617
9049edac1117
(gdb-post-prompt): Fix test.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54616
diff
changeset
|
799 (unless (eq system-type 'darwin) ;Breaks on Darwin's GDB-5.3. |
|
9049edac1117
(gdb-post-prompt): Fix test.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54616
diff
changeset
|
800 ;; FIXME: with GDB-6 on Darwin, this might very well work. |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
801 (dolist (frame (frame-list)) |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
802 (when (string-equal (frame-parameter frame 'name) "Speedbar") |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
803 (setq gdb-var-changed t) ; force update |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
804 (dolist (var gdb-var-list) |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
805 (setcar (nthcdr 5 var) nil)))) |
|
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
806 (gdb-var-update)))) |
| 54538 | 807 (let ((sink (gdb-get-output-sink))) |
| 808 (cond | |
| 809 ((eq sink 'user) t) | |
| 810 ((eq sink 'pre-emacs) | |
| 811 (gdb-set-output-sink 'emacs)) | |
| 812 (t | |
| 813 (gdb-set-output-sink 'user) | |
| 814 (error "Phase error in gdb-post-prompt (got %s)" sink))))) | |
| 815 | |
| 816 (defun gud-gdba-marker-filter (string) | |
| 817 "A gud marker filter for gdb. Handle a burst of output from GDB." | |
|
54616
47c4cb867a84
(gdb-ann3, gdb-send-item)
Nick Roberts <nickrob@snap.net.nz>
parents:
54538
diff
changeset
|
818 (if gdb-enable-debug-log (push (cons 'recv string) gdb-debug-log)) |
| 54538 | 819 ;; Recall the left over gud-marker-acc from last time |
| 820 (setq gud-marker-acc (concat gud-marker-acc string)) | |
| 821 ;; Start accumulating output for the GUD buffer | |
| 822 (let ((output "")) | |
| 823 ;; | |
| 824 ;; Process all the complete markers in this chunk. | |
| 825 (while (string-match "\n\032\032\\(.*\\)\n" gud-marker-acc) | |
| 826 (let ((annotation (match-string 1 gud-marker-acc))) | |
| 827 ;; | |
| 828 ;; Stuff prior to the match is just ordinary output. | |
| 829 ;; It is either concatenated to OUTPUT or directed | |
| 830 ;; elsewhere. | |
| 831 (setq output | |
| 832 (gdb-concat-output | |
| 833 output | |
| 834 (substring gud-marker-acc 0 (match-beginning 0)))) | |
| 835 ;; | |
| 836 ;; Take that stuff off the gud-marker-acc. | |
| 837 (setq gud-marker-acc (substring gud-marker-acc (match-end 0))) | |
| 838 ;; | |
| 839 ;; Parse the tag from the annotation, and maybe its arguments. | |
| 840 (string-match "\\(\\S-*\\) ?\\(.*\\)" annotation) | |
| 841 (let* ((annotation-type (match-string 1 annotation)) | |
| 842 (annotation-arguments (match-string 2 annotation)) | |
| 843 (annotation-rule (assoc annotation-type | |
| 844 gdb-annotation-rules))) | |
| 845 ;; Call the handler for this annotation. | |
| 846 (if annotation-rule | |
| 847 (funcall (car (cdr annotation-rule)) | |
| 848 annotation-arguments) | |
| 849 ;; Else the annotation is not recognized. Ignore it silently, | |
| 850 ;; so that GDB can add new annotations without causing | |
| 851 ;; us to blow up. | |
| 852 )))) | |
| 853 ;; | |
| 854 ;; Does the remaining text end in a partial line? | |
| 855 ;; If it does, then keep part of the gud-marker-acc until we get more. | |
| 856 (if (string-match "\n\\'\\|\n\032\\'\\|\n\032\032.*\\'" | |
| 857 gud-marker-acc) | |
| 858 (progn | |
| 859 ;; Everything before the potential marker start can be output. | |
| 860 (setq output | |
| 861 (gdb-concat-output output | |
| 862 (substring gud-marker-acc 0 | |
| 863 (match-beginning 0)))) | |
| 864 ;; | |
| 865 ;; Everything after, we save, to combine with later input. | |
| 866 (setq gud-marker-acc (substring gud-marker-acc (match-beginning 0)))) | |
| 867 ;; | |
| 868 ;; In case we know the gud-marker-acc contains no partial annotations: | |
| 869 (progn | |
| 870 (setq output (gdb-concat-output output gud-marker-acc)) | |
| 871 (setq gud-marker-acc ""))) | |
| 872 output)) | |
| 873 | |
| 874 (defun gdb-concat-output (so-far new) | |
| 875 (let ((sink (gdb-get-output-sink ))) | |
| 876 (cond | |
| 877 ((eq sink 'user) (concat so-far new)) | |
| 878 ((or (eq sink 'pre-emacs) (eq sink 'post-emacs)) so-far) | |
| 879 ((eq sink 'emacs) | |
| 880 (gdb-append-to-partial-output new) | |
| 881 so-far) | |
| 882 ((eq sink 'inferior) | |
| 883 (gdb-append-to-inferior-io new) | |
| 884 so-far) | |
| 885 (t (error "Bogon output sink %S" sink))))) | |
| 886 | |
| 887 (defun gdb-append-to-partial-output (string) | |
| 888 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 889 (goto-char (point-max)) | |
| 890 (insert string))) | |
| 891 | |
| 892 (defun gdb-clear-partial-output () | |
| 893 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 894 (erase-buffer))) | |
| 895 | |
| 896 (defun gdb-append-to-inferior-io (string) | |
| 897 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io) | |
| 898 (goto-char (point-max)) | |
| 899 (insert-before-markers string)) | |
| 900 (if (not (string-equal string "")) | |
| 901 (gdb-display-buffer (gdb-get-create-buffer 'gdb-inferior-io)))) | |
| 902 | |
| 903 (defun gdb-clear-inferior-io () | |
| 904 (with-current-buffer (gdb-get-create-buffer 'gdb-inferior-io) | |
| 905 (erase-buffer))) | |
| 906 | |
| 907 | |
| 908 ;; One trick is to have a command who's output is always available in a buffer | |
| 909 ;; of it's own, and is always up to date. We build several buffers of this | |
| 910 ;; type. | |
| 911 ;; | |
| 912 ;; There are two aspects to this: gdb has to tell us when the output for that | |
| 913 ;; command might have changed, and we have to be able to run the command | |
| 914 ;; behind the user's back. | |
| 915 ;; | |
| 916 ;; The output phasing associated with the variable gdb-output-sink | |
| 917 ;; help us to run commands behind the user's back. | |
| 918 ;; | |
| 919 ;; Below is the code for specificly managing buffers of output from one | |
| 920 ;; command. | |
| 921 ;; | |
| 922 | |
| 923 ;; The trigger function is suitable for use in the assoc GDB-ANNOTATION-RULES | |
| 924 ;; It adds an input for the command we are tracking. It should be the | |
| 925 ;; annotation rule binding of whatever gdb sends to tell us this command | |
| 926 ;; might have changed it's output. | |
| 927 ;; | |
| 928 ;; NAME is the function name. DEMAND-PREDICATE tests if output is really needed. | |
| 929 ;; GDB-COMMAND is a string of such. OUTPUT-HANDLER is the function bound to the | |
| 930 ;; input in the input queue (see comment about ``gdb communications'' above). | |
| 931 | |
| 932 (defmacro def-gdb-auto-update-trigger (name demand-predicate gdb-command | |
| 933 output-handler) | |
| 934 `(defun ,name (&optional ignored) | |
| 935 (if (and (,demand-predicate) | |
| 936 (not (member ',name | |
| 937 (gdb-get-pending-triggers)))) | |
| 938 (progn | |
| 939 (gdb-enqueue-input | |
| 940 (list ,gdb-command ',output-handler)) | |
| 941 (gdb-set-pending-triggers | |
| 942 (cons ',name | |
| 943 (gdb-get-pending-triggers))))))) | |
| 944 | |
| 945 (defmacro def-gdb-auto-update-handler (name trigger buf-key custom-defun) | |
| 946 `(defun ,name () | |
| 947 (gdb-set-pending-triggers | |
| 948 (delq ',trigger | |
| 949 (gdb-get-pending-triggers))) | |
| 950 (let ((buf (gdb-get-buffer ',buf-key))) | |
| 951 (and buf | |
| 952 (with-current-buffer buf | |
| 953 (let ((p (point)) | |
| 954 (buffer-read-only nil)) | |
| 955 (erase-buffer) | |
| 956 (insert-buffer-substring (gdb-get-create-buffer | |
| 957 'gdb-partial-output-buffer)) | |
| 958 (goto-char p))))) | |
| 959 ;; put customisation here | |
| 960 (,custom-defun))) | |
| 961 | |
| 962 (defmacro def-gdb-auto-updated-buffer (buffer-key trigger-name gdb-command | |
| 963 output-handler-name custom-defun) | |
| 964 `(progn | |
| 965 (def-gdb-auto-update-trigger ,trigger-name | |
| 966 ;; The demand predicate: | |
| 967 (lambda () (gdb-get-buffer ',buffer-key)) | |
| 968 ,gdb-command | |
| 969 ,output-handler-name) | |
| 970 (def-gdb-auto-update-handler ,output-handler-name | |
| 971 ,trigger-name ,buffer-key ,custom-defun))) | |
| 972 | |
| 973 | |
| 974 ;; | |
| 975 ;; Breakpoint buffer : This displays the output of `info breakpoints'. | |
| 976 ;; | |
| 977 (gdb-set-buffer-rules 'gdb-breakpoints-buffer | |
| 978 'gdb-breakpoints-buffer-name | |
| 979 'gdb-breakpoints-mode) | |
| 980 | |
| 981 (def-gdb-auto-updated-buffer gdb-breakpoints-buffer | |
| 982 ;; This defines the auto update rule for buffers of type | |
| 983 ;; `gdb-breakpoints-buffer'. | |
| 984 ;; | |
| 985 ;; It defines a function to serve as the annotation handler that | |
| 986 ;; handles the `foo-invalidated' message. That function is called: | |
| 987 gdb-invalidate-breakpoints | |
| 988 ;; | |
| 989 ;; To update the buffer, this command is sent to gdb. | |
| 990 "server info breakpoints\n" | |
| 991 ;; | |
| 992 ;; This also defines a function to be the handler for the output | |
| 993 ;; from the command above. That function will copy the output into | |
| 994 ;; the appropriately typed buffer. That function will be called: | |
| 995 gdb-info-breakpoints-handler | |
| 996 ;; buffer specific functions | |
| 997 gdb-info-breakpoints-custom) | |
| 998 | |
| 999 (defvar gdb-cdir nil "Compilation directory.") | |
| 1000 | |
| 1001 (defconst breakpoint-xpm-data "/* XPM */ | |
| 1002 static char *magick[] = { | |
| 1003 /* columns rows colors chars-per-pixel */ | |
| 1004 \"10 10 2 1\", | |
| 1005 \" c red\", | |
| 1006 \"+ c None\", | |
| 1007 /* pixels */ | |
| 1008 \"+++ +++\", | |
| 1009 \"++ ++\", | |
| 1010 \"+ +\", | |
| 1011 \" \", | |
| 1012 \" \", | |
| 1013 \" \", | |
| 1014 \" \", | |
| 1015 \"+ +\", | |
| 1016 \"++ ++\", | |
| 1017 \"+++ +++\", | |
| 1018 };" | |
| 1019 "XPM data used for breakpoint icon.") | |
| 1020 | |
| 1021 (defconst breakpoint-enabled-pbm-data | |
| 1022 "P1 | |
| 1023 10 10\", | |
| 1024 0 0 0 0 1 1 1 1 0 0 0 0 | |
| 1025 0 0 0 1 1 1 1 1 1 0 0 0 | |
| 1026 0 0 1 1 1 1 1 1 1 1 0 0 | |
| 1027 0 1 1 1 1 1 1 1 1 1 1 0 | |
| 1028 0 1 1 1 1 1 1 1 1 1 1 0 | |
| 1029 0 1 1 1 1 1 1 1 1 1 1 0 | |
| 1030 0 1 1 1 1 1 1 1 1 1 1 0 | |
| 1031 0 0 1 1 1 1 1 1 1 1 0 0 | |
| 1032 0 0 0 1 1 1 1 1 1 0 0 0 | |
| 1033 0 0 0 0 1 1 1 1 0 0 0 0" | |
| 1034 "PBM data used for enabled breakpoint icon.") | |
| 1035 | |
| 1036 (defconst breakpoint-disabled-pbm-data | |
| 1037 "P1 | |
| 1038 10 10\", | |
| 1039 0 0 1 0 1 0 1 0 0 0 | |
| 1040 0 1 0 1 0 1 0 1 0 0 | |
| 1041 1 0 1 0 1 0 1 0 1 0 | |
| 1042 0 1 0 1 0 1 0 1 0 1 | |
| 1043 1 0 1 0 1 0 1 0 1 0 | |
| 1044 0 1 0 1 0 1 0 1 0 1 | |
| 1045 1 0 1 0 1 0 1 0 1 0 | |
| 1046 0 1 0 1 0 1 0 1 0 1 | |
| 1047 0 0 1 0 1 0 1 0 1 0 | |
| 1048 0 0 0 1 0 1 0 1 0 0" | |
| 1049 "PBM data used for disabled breakpoint icon.") | |
| 1050 | |
| 1051 (defvar breakpoint-enabled-icon nil | |
| 1052 "Icon for enabled breakpoint in display margin") | |
| 1053 | |
| 1054 (defvar breakpoint-disabled-icon nil | |
| 1055 "Icon for disabled breakpoint in display margin") | |
| 1056 | |
| 1057 (defvar breakpoint-bitmap nil | |
| 1058 "Bitmap for breakpoint in fringe") | |
| 1059 | |
| 1060 (defface breakpoint-enabled-bitmap-face | |
| 1061 '((t | |
| 1062 :inherit fringe | |
| 1063 :foreground "red")) | |
| 1064 "Face for enabled breakpoint icon in fringe.") | |
| 1065 | |
| 1066 (defface breakpoint-disabled-bitmap-face | |
| 1067 '((t | |
| 1068 :inherit fringe | |
| 1069 :foreground "grey60")) | |
| 1070 "Face for disabled breakpoint icon in fringe.") | |
| 1071 | |
| 1072 | |
| 1073 ;;-put breakpoint icons in relevant margins (even those set in the GUD buffer) | |
| 1074 (defun gdb-info-breakpoints-custom () | |
| 1075 (let ((flag)(address)) | |
| 1076 ;; | |
| 1077 ;; remove all breakpoint-icons in source buffers but not assembler buffer | |
| 1078 (dolist (buffer (buffer-list)) | |
| 1079 (with-current-buffer buffer | |
| 1080 (if (and (eq gud-minor-mode 'gdba) | |
| 1081 (not (string-match "^\*" (buffer-name)))) | |
| 1082 (gdb-remove-breakpoint-icons (point-min) (point-max))))) | |
| 1083 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer) | |
| 1084 (save-excursion | |
| 1085 (goto-char (point-min)) | |
| 1086 (while (< (point) (- (point-max) 1)) | |
| 1087 (forward-line 1) | |
| 1088 (if (looking-at "[^\t].*breakpoint") | |
| 1089 (progn | |
| 1090 (looking-at "[0-9]*\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)") | |
| 1091 (setq flag (char-after (match-beginning 1))) | |
| 1092 (beginning-of-line) | |
| 1093 (if (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t) | |
| 1094 (progn | |
| 1095 (looking-at "\\(\\S-*\\):\\([0-9]+\\)") | |
| 1096 (let ((line (match-string 2)) (buffer-read-only nil) | |
| 1097 (file (match-string 1))) | |
| 1098 (add-text-properties (point-at-bol) (point-at-eol) | |
| 1099 '(mouse-face highlight | |
| 1100 help-echo "mouse-2, RET: visit breakpoint")) | |
| 1101 (with-current-buffer | |
| 1102 (find-file-noselect | |
| 1103 (if (file-exists-p file) file | |
| 1104 (expand-file-name file gdb-cdir))) | |
| 1105 (save-current-buffer | |
| 1106 (set (make-local-variable 'gud-minor-mode) 'gdba) | |
| 1107 (set (make-local-variable 'tool-bar-map) | |
| 1108 gud-tool-bar-map)) | |
| 1109 ;; only want one breakpoint icon at each location | |
| 1110 (save-excursion | |
| 1111 (goto-line (string-to-number line)) | |
| 1112 (gdb-put-breakpoint-icon (eq flag ?y))))))))) | |
| 1113 (end-of-line))))) | |
| 1114 (if (gdb-get-buffer 'gdb-assembler-buffer) (gdb-assembler-custom))) | |
| 1115 | |
| 1116 (defun gdb-mouse-toggle-breakpoint (event) | |
| 1117 "Toggle breakpoint with mouse click in left margin." | |
| 1118 (interactive "e") | |
| 1119 (mouse-minibuffer-check event) | |
| 1120 (let ((posn (event-end event))) | |
| 1121 (if (numberp (posn-point posn)) | |
| 1122 (with-selected-window (posn-window posn) | |
| 1123 (save-excursion | |
| 1124 (goto-char (posn-point posn)) | |
| 1125 (if (or (posn-object posn) | |
| 1126 (and breakpoint-bitmap | |
| 1127 (eq (car (fringe-bitmaps-at-pos (posn-point posn))) | |
| 1128 breakpoint-bitmap))) | |
| 1129 (gud-remove nil) | |
| 1130 (gud-break nil))))))) | |
| 1131 | |
| 1132 (defun gdb-breakpoints-buffer-name () | |
| 1133 (with-current-buffer gud-comint-buffer | |
| 1134 (concat "*breakpoints of " (gdb-get-target-string) "*"))) | |
| 1135 | |
| 1136 (defun gdb-display-breakpoints-buffer () | |
| 1137 (interactive) | |
| 1138 (gdb-display-buffer | |
| 1139 (gdb-get-create-buffer 'gdb-breakpoints-buffer))) | |
| 1140 | |
| 1141 (defun gdb-frame-breakpoints-buffer () | |
| 1142 (interactive) | |
| 1143 (switch-to-buffer-other-frame | |
| 1144 (gdb-get-create-buffer 'gdb-breakpoints-buffer))) | |
| 1145 | |
| 1146 (defvar gdb-breakpoints-mode-map | |
| 1147 (let ((map (make-sparse-keymap)) | |
| 1148 (menu (make-sparse-keymap "Breakpoints"))) | |
| 1149 (define-key menu [toggle] '("Toggle" . gdb-toggle-breakpoint)) | |
| 1150 (define-key menu [delete] '("Delete" . gdb-delete-breakpoint)) | |
| 1151 (define-key menu [goto] '("Goto" . gdb-goto-breakpoint)) | |
| 1152 | |
| 1153 (suppress-keymap map) | |
| 1154 (define-key map [menu-bar breakpoints] (cons "Breakpoints" menu)) | |
| 1155 (define-key map " " 'gdb-toggle-breakpoint) | |
| 1156 (define-key map "d" 'gdb-delete-breakpoint) | |
| 1157 (define-key map "\r" 'gdb-goto-breakpoint) | |
| 1158 (define-key map [mouse-2] 'gdb-mouse-goto-breakpoint) | |
| 1159 map)) | |
| 1160 | |
| 1161 (defun gdb-breakpoints-mode () | |
| 1162 "Major mode for gdb breakpoints. | |
| 1163 | |
| 1164 \\{gdb-breakpoints-mode-map}" | |
| 1165 (setq major-mode 'gdb-breakpoints-mode) | |
| 1166 (setq mode-name "Breakpoints") | |
| 1167 (use-local-map gdb-breakpoints-mode-map) | |
| 1168 (setq buffer-read-only t) | |
| 1169 (gdb-invalidate-breakpoints)) | |
| 1170 | |
| 1171 (defun gdb-toggle-breakpoint () | |
| 1172 "Enable/disable the breakpoint at current line." | |
| 1173 (interactive) | |
| 1174 (save-excursion | |
| 1175 (beginning-of-line 1) | |
| 1176 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | |
| 1177 (error "Not recognized as break/watchpoint line") | |
| 1178 (gdb-enqueue-input | |
| 1179 (list | |
| 1180 (concat | |
| 1181 (if (eq ?y (char-after (match-beginning 2))) | |
| 1182 "server disable " | |
| 1183 "server enable ") | |
| 1184 (match-string 1) "\n") | |
| 1185 'ignore))))) | |
| 1186 | |
| 1187 (defun gdb-delete-breakpoint () | |
| 1188 "Delete the breakpoint at current line." | |
| 1189 (interactive) | |
| 1190 (beginning-of-line 1) | |
| 1191 (if (not (looking-at "\\([0-9]+\\).*point\\s-*\\S-*\\s-*\\(.\\)")) | |
| 1192 (error "Not recognized as break/watchpoint line") | |
| 1193 (gdb-enqueue-input | |
| 1194 (list (concat "server delete " (match-string 1) "\n") 'ignore)))) | |
| 1195 | |
| 1196 (defvar gdb-source-window nil) | |
| 1197 | |
| 1198 (defun gdb-goto-breakpoint () | |
| 1199 "Display the file in the source buffer at the breakpoint specified on the | |
| 1200 current line." | |
| 1201 (interactive) | |
| 1202 (save-excursion | |
| 1203 (beginning-of-line 1) | |
| 1204 (re-search-forward "in\\s-+\\S-+\\s-+at\\s-+" nil t) | |
| 1205 (looking-at "\\(\\S-*\\):\\([0-9]+\\)")) | |
| 1206 (if (match-string 2) | |
| 1207 (let ((line (match-string 2)) | |
| 1208 (file (match-string 1))) | |
| 1209 (save-selected-window | |
| 1210 (select-window gdb-source-window) | |
| 1211 (switch-to-buffer (find-file-noselect | |
| 1212 (if (file-exists-p file) | |
| 1213 file | |
| 1214 (expand-file-name file gdb-cdir)))) | |
| 1215 (goto-line (string-to-number line)))))) | |
| 1216 | |
| 1217 (defun gdb-mouse-goto-breakpoint (event) | |
| 1218 "Display the file in the source buffer at the selected breakpoint." | |
| 1219 (interactive "e") | |
| 1220 (mouse-set-point event) | |
| 1221 (gdb-goto-breakpoint)) | |
| 1222 | |
| 1223 ;; | |
| 1224 ;; Frames buffer. This displays a perpetually correct bactracktrace | |
| 1225 ;; (from the command `where'). | |
| 1226 ;; | |
| 1227 ;; Alas, if your stack is deep, it is costly. | |
| 1228 ;; | |
| 1229 (gdb-set-buffer-rules 'gdb-stack-buffer | |
| 1230 'gdb-stack-buffer-name | |
| 1231 'gdb-frames-mode) | |
| 1232 | |
| 1233 (def-gdb-auto-updated-buffer gdb-stack-buffer | |
| 1234 gdb-invalidate-frames | |
| 1235 "server where\n" | |
| 1236 gdb-info-frames-handler | |
| 1237 gdb-info-frames-custom) | |
| 1238 | |
| 1239 (defun gdb-info-frames-custom () | |
| 1240 (with-current-buffer (gdb-get-buffer 'gdb-stack-buffer) | |
| 1241 (save-excursion | |
| 1242 (let ((buffer-read-only nil)) | |
| 1243 (goto-char (point-min)) | |
| 1244 (while (< (point) (point-max)) | |
| 1245 (add-text-properties (point-at-bol) (point-at-eol) | |
| 1246 '(mouse-face highlight | |
| 1247 help-echo "mouse-2, RET: Select frame")) | |
| 1248 (beginning-of-line) | |
| 1249 (when (and (or (looking-at "^#[0-9]*\\s-*\\S-* in \\(\\S-*\\)") | |
| 1250 (looking-at "^#[0-9]*\\s-*\\(\\S-*\\)")) | |
| 1251 (equal (match-string 1) gdb-current-frame)) | |
| 1252 (put-text-property (point-at-bol) (point-at-eol) | |
| 1253 'face '(:inverse-video t))) | |
| 1254 (forward-line 1)))))) | |
| 1255 | |
| 1256 (defun gdb-stack-buffer-name () | |
| 1257 (with-current-buffer gud-comint-buffer | |
| 1258 (concat "*stack frames of " (gdb-get-target-string) "*"))) | |
| 1259 | |
| 1260 (defun gdb-display-stack-buffer () | |
| 1261 (interactive) | |
| 1262 (gdb-display-buffer | |
| 1263 (gdb-get-create-buffer 'gdb-stack-buffer))) | |
| 1264 | |
| 1265 (defun gdb-frame-stack-buffer () | |
| 1266 (interactive) | |
| 1267 (switch-to-buffer-other-frame | |
| 1268 (gdb-get-create-buffer 'gdb-stack-buffer))) | |
| 1269 | |
| 1270 (defvar gdb-frames-mode-map | |
| 1271 (let ((map (make-sparse-keymap))) | |
| 1272 (suppress-keymap map) | |
| 1273 (define-key map "\r" 'gdb-frames-select) | |
| 1274 (define-key map [mouse-2] 'gdb-frames-mouse-select) | |
| 1275 map)) | |
| 1276 | |
| 1277 (defun gdb-frames-mode () | |
| 1278 "Major mode for gdb frames. | |
| 1279 | |
| 1280 \\{gdb-frames-mode-map}" | |
| 1281 (setq major-mode 'gdb-frames-mode) | |
| 1282 (setq mode-name "Frames") | |
| 1283 (setq buffer-read-only t) | |
| 1284 (use-local-map gdb-frames-mode-map) | |
| 1285 (font-lock-mode -1) | |
| 1286 (gdb-invalidate-frames)) | |
| 1287 | |
| 1288 (defun gdb-get-frame-number () | |
| 1289 (save-excursion | |
| 1290 (let* ((pos (re-search-backward "^#\\([0-9]*\\)" nil t)) | |
| 1291 (n (or (and pos (match-string-no-properties 1)) "0"))) | |
| 1292 n))) | |
| 1293 | |
| 1294 (defun gdb-frames-select () | |
| 1295 "Make the frame on the current line become the current frame and display the | |
| 1296 source in the source buffer." | |
| 1297 (interactive) | |
| 1298 (gdb-enqueue-input | |
| 1299 (list (concat "server frame " (gdb-get-frame-number) "\n") 'ignore)) | |
| 1300 (gud-display-frame)) | |
| 1301 | |
| 1302 (defun gdb-frames-mouse-select (event) | |
| 1303 "Make the selected frame become the current frame and display the source in | |
| 1304 the source buffer." | |
| 1305 (interactive "e") | |
| 1306 (mouse-set-point event) | |
| 1307 (gdb-frames-select)) | |
| 1308 | |
| 1309 ;; | |
| 1310 ;; Threads buffer. This displays a selectable thread list. | |
| 1311 ;; | |
| 1312 (gdb-set-buffer-rules 'gdb-threads-buffer | |
| 1313 'gdb-threads-buffer-name | |
| 1314 'gdb-threads-mode) | |
| 1315 | |
| 1316 (def-gdb-auto-updated-buffer gdb-threads-buffer | |
| 1317 gdb-invalidate-threads | |
| 1318 "server info threads\n" | |
| 1319 gdb-info-threads-handler | |
| 1320 gdb-info-threads-custom) | |
| 1321 | |
| 1322 (defun gdb-info-threads-custom () | |
| 1323 (with-current-buffer (gdb-get-buffer 'gdb-threads-buffer) | |
| 1324 (let ((buffer-read-only nil)) | |
| 1325 (goto-char (point-min)) | |
| 1326 (while (< (point) (point-max)) | |
| 1327 (add-text-properties (point-at-bol) (point-at-eol) | |
| 1328 '(mouse-face highlight | |
| 1329 help-echo "mouse-2, RET: select thread")) | |
| 1330 (forward-line 1))))) | |
| 1331 | |
| 1332 (defun gdb-threads-buffer-name () | |
| 1333 (with-current-buffer gud-comint-buffer | |
| 1334 (concat "*threads of " (gdb-get-target-string) "*"))) | |
| 1335 | |
| 1336 (defun gdb-display-threads-buffer () | |
| 1337 (interactive) | |
| 1338 (gdb-display-buffer | |
| 1339 (gdb-get-create-buffer 'gdb-threads-buffer))) | |
| 1340 | |
| 1341 (defun gdb-frame-threads-buffer () | |
| 1342 (interactive) | |
| 1343 (switch-to-buffer-other-frame | |
| 1344 (gdb-get-create-buffer 'gdb-threads-buffer))) | |
| 1345 | |
| 1346 (defvar gdb-threads-mode-map | |
| 1347 (let ((map (make-sparse-keymap))) | |
| 1348 (suppress-keymap map) | |
| 1349 (define-key map "\r" 'gdb-threads-select) | |
| 1350 (define-key map [mouse-2] 'gdb-threads-mouse-select) | |
| 1351 map)) | |
| 1352 | |
| 1353 (defun gdb-threads-mode () | |
| 1354 "Major mode for gdb frames. | |
| 1355 | |
| 1356 \\{gdb-frames-mode-map}" | |
| 1357 (setq major-mode 'gdb-threads-mode) | |
| 1358 (setq mode-name "Threads") | |
| 1359 (setq buffer-read-only t) | |
| 1360 (use-local-map gdb-threads-mode-map) | |
| 1361 (gdb-invalidate-threads)) | |
| 1362 | |
| 1363 (defun gdb-get-thread-number () | |
| 1364 (save-excursion | |
| 1365 (re-search-backward "^\\s-*\\([0-9]*\\)" nil t) | |
| 1366 (match-string-no-properties 1))) | |
| 1367 | |
| 1368 (defun gdb-threads-select () | |
| 1369 "Make the thread on the current line become the current thread and display the | |
| 1370 source in the source buffer." | |
| 1371 (interactive) | |
| 1372 (gdb-enqueue-input | |
| 1373 (list (concat "thread " (gdb-get-thread-number) "\n") 'ignore)) | |
| 1374 (gud-display-frame)) | |
| 1375 | |
| 1376 (defun gdb-threads-mouse-select (event) | |
| 1377 "Make the selected frame become the current frame and display the source in | |
| 1378 the source buffer." | |
| 1379 (interactive "e") | |
| 1380 (mouse-set-point event) | |
| 1381 (gdb-threads-select)) | |
| 1382 | |
| 1383 ;; | |
| 1384 ;; Registers buffer. | |
| 1385 ;; | |
| 1386 (gdb-set-buffer-rules 'gdb-registers-buffer | |
| 1387 'gdb-registers-buffer-name | |
| 1388 'gdb-registers-mode) | |
| 1389 | |
| 1390 (def-gdb-auto-updated-buffer gdb-registers-buffer | |
| 1391 gdb-invalidate-registers | |
| 1392 "server info registers\n" | |
| 1393 gdb-info-registers-handler | |
| 1394 gdb-info-registers-custom) | |
| 1395 | |
| 1396 (defun gdb-info-registers-custom ()) | |
| 1397 | |
| 1398 (defvar gdb-registers-mode-map | |
| 1399 (let ((map (make-sparse-keymap))) | |
| 1400 (suppress-keymap map) | |
| 1401 map)) | |
| 1402 | |
| 1403 (defun gdb-registers-mode () | |
| 1404 "Major mode for gdb registers. | |
| 1405 | |
| 1406 \\{gdb-registers-mode-map}" | |
| 1407 (setq major-mode 'gdb-registers-mode) | |
| 1408 (setq mode-name "Registers") | |
| 1409 (setq buffer-read-only t) | |
| 1410 (use-local-map gdb-registers-mode-map) | |
| 1411 (gdb-invalidate-registers)) | |
| 1412 | |
| 1413 (defun gdb-registers-buffer-name () | |
| 1414 (with-current-buffer gud-comint-buffer | |
| 1415 (concat "*registers of " (gdb-get-target-string) "*"))) | |
| 1416 | |
| 1417 (defun gdb-display-registers-buffer () | |
| 1418 (interactive) | |
| 1419 (gdb-display-buffer | |
| 1420 (gdb-get-create-buffer 'gdb-registers-buffer))) | |
| 1421 | |
| 1422 (defun gdb-frame-registers-buffer () | |
| 1423 (interactive) | |
| 1424 (switch-to-buffer-other-frame | |
| 1425 (gdb-get-create-buffer 'gdb-registers-buffer))) | |
| 1426 | |
| 1427 ;; | |
| 1428 ;; Locals buffer. | |
| 1429 ;; | |
| 1430 (gdb-set-buffer-rules 'gdb-locals-buffer | |
| 1431 'gdb-locals-buffer-name | |
| 1432 'gdb-locals-mode) | |
| 1433 | |
| 1434 (def-gdb-auto-updated-buffer gdb-locals-buffer | |
| 1435 gdb-invalidate-locals | |
| 1436 "server info locals\n" | |
| 1437 gdb-info-locals-handler | |
| 1438 gdb-info-locals-custom) | |
| 1439 | |
| 1440 ;; Abbreviate for arrays and structures. | |
| 1441 ;; These can be expanded using gud-display. | |
| 1442 (defun gdb-info-locals-handler nil | |
| 1443 (gdb-set-pending-triggers (delq 'gdb-invalidate-locals | |
| 1444 (gdb-get-pending-triggers))) | |
| 1445 (let ((buf (gdb-get-buffer 'gdb-partial-output-buffer))) | |
| 1446 (with-current-buffer buf | |
| 1447 (goto-char (point-min)) | |
| 1448 (while (re-search-forward "^ .*\n" nil t) | |
| 1449 (replace-match "" nil nil)) | |
| 1450 (goto-char (point-min)) | |
| 1451 (while (re-search-forward "{[-0-9, {}\]*\n" nil t) | |
| 1452 (replace-match "(array);\n" nil nil)) | |
| 1453 (goto-char (point-min)) | |
| 1454 (while (re-search-forward "{.*=.*\n" nil t) | |
| 1455 (replace-match "(structure);\n" nil nil)))) | |
| 1456 (let ((buf (gdb-get-buffer 'gdb-locals-buffer))) | |
| 1457 (and buf (with-current-buffer buf | |
| 1458 (let ((p (point)) | |
| 1459 (buffer-read-only nil)) | |
| 1460 (delete-region (point-min) (point-max)) | |
| 1461 (insert-buffer-substring (gdb-get-create-buffer | |
| 1462 'gdb-partial-output-buffer)) | |
| 1463 (goto-char p))))) | |
| 1464 (run-hooks 'gdb-info-locals-hook)) | |
| 1465 | |
| 1466 (defun gdb-info-locals-custom () | |
| 1467 nil) | |
| 1468 | |
| 1469 (defvar gdb-locals-mode-map | |
| 1470 (let ((map (make-sparse-keymap))) | |
| 1471 (suppress-keymap map) | |
| 1472 map)) | |
| 1473 | |
| 1474 (defun gdb-locals-mode () | |
| 1475 "Major mode for gdb locals. | |
| 1476 | |
| 1477 \\{gdb-locals-mode-map}" | |
| 1478 (setq major-mode 'gdb-locals-mode) | |
| 1479 (setq mode-name "Locals") | |
| 1480 (setq buffer-read-only t) | |
| 1481 (use-local-map gdb-locals-mode-map) | |
| 1482 (gdb-invalidate-locals)) | |
| 1483 | |
| 1484 (defun gdb-locals-buffer-name () | |
| 1485 (with-current-buffer gud-comint-buffer | |
| 1486 (concat "*locals of " (gdb-get-target-string) "*"))) | |
| 1487 | |
| 1488 (defun gdb-display-locals-buffer () | |
| 1489 (interactive) | |
| 1490 (gdb-display-buffer | |
| 1491 (gdb-get-create-buffer 'gdb-locals-buffer))) | |
| 1492 | |
| 1493 (defun gdb-frame-locals-buffer () | |
| 1494 (interactive) | |
| 1495 (switch-to-buffer-other-frame | |
| 1496 (gdb-get-create-buffer 'gdb-locals-buffer))) | |
| 1497 | |
| 1498 | |
| 1499 ;;;; Window management | |
| 1500 | |
| 1501 ;;; The way we abuse the dedicated-p flag is pretty gross, but seems | |
| 1502 ;;; to do the right thing. Seeing as there is no way for Lisp code to | |
| 1503 ;;; get at the use_time field of a window, I'm not sure there exists a | |
| 1504 ;;; more elegant solution without writing C code. | |
| 1505 | |
| 1506 (defun gdb-display-buffer (buf &optional size) | |
| 1507 (let ((must-split nil) | |
| 1508 (answer nil)) | |
| 1509 (unwind-protect | |
| 1510 (progn | |
| 1511 (walk-windows | |
| 1512 #'(lambda (win) | |
| 1513 (if (or (eq gud-comint-buffer (window-buffer win)) | |
| 1514 (eq gdb-source-window win)) | |
| 1515 (set-window-dedicated-p win t)))) | |
| 1516 (setq answer (get-buffer-window buf)) | |
| 1517 (if (not answer) | |
| 1518 (let ((window (get-lru-window))) | |
| 1519 (if window | |
| 1520 (progn | |
| 1521 (set-window-buffer window buf) | |
| 1522 (setq answer window)) | |
| 1523 (setq must-split t))))) | |
| 1524 (walk-windows | |
| 1525 #'(lambda (win) | |
| 1526 (if (or (eq gud-comint-buffer (window-buffer win)) | |
| 1527 (eq gdb-source-window win)) | |
| 1528 (set-window-dedicated-p win nil))))) | |
| 1529 (if must-split | |
| 1530 (let* ((largest (get-largest-window)) | |
| 1531 (cur-size (window-height largest)) | |
| 1532 (new-size (and size (< size cur-size) (- cur-size size)))) | |
| 1533 (setq answer (split-window largest new-size)) | |
| 1534 (set-window-buffer answer buf))) | |
| 1535 answer)) | |
| 1536 | |
| 1537 (defun gdb-display-source-buffer (buffer) | |
| 1538 (if (eq gdb-selected-view 'source) | |
| 1539 (progn | |
| 1540 (if (window-live-p gdb-source-window) | |
| 1541 (set-window-buffer gdb-source-window buffer) | |
| 1542 (gdb-display-buffer buffer) | |
| 1543 (setq gdb-source-window (get-buffer-window buffer))) | |
| 1544 gdb-source-window) | |
| 1545 (if (window-live-p gdb-source-window) | |
| 1546 (set-window-buffer gdb-source-window | |
| 1547 (gdb-get-buffer 'gdb-assembler-buffer)) | |
| 1548 (let ((buf (gdb-get-buffer 'gdb-assembler-buffer))) | |
| 1549 (gdb-display-buffer buf) | |
| 1550 (setq gdb-source-window (get-buffer-window buf)))) | |
| 1551 nil)) | |
| 1552 | |
| 1553 | |
| 1554 ;;; Shared keymap initialization: | |
| 1555 | |
| 1556 (let ((menu (make-sparse-keymap "GDB-Frames"))) | |
| 1557 (define-key gud-menu-map [frames] | |
| 1558 `(menu-item "GDB-Frames" ,menu :visible (eq gud-minor-mode 'gdba))) | |
| 1559 (define-key menu [gdb] '("Gdb" . gdb-frame-gdb-buffer)) | |
| 1560 (define-key menu [locals] '("Locals" . gdb-frame-locals-buffer)) | |
| 1561 (define-key menu [registers] '("Registers" . gdb-frame-registers-buffer)) | |
| 1562 (define-key menu [frames] '("Stack" . gdb-frame-stack-buffer)) | |
| 1563 (define-key menu [breakpoints] '("Breakpoints" . gdb-frame-breakpoints-buffer)) | |
| 1564 (define-key menu [threads] '("Threads" . gdb-frame-threads-buffer)) | |
| 1565 ; (define-key menu [assembler] '("Machine" . gdb-frame-assembler-buffer)) | |
| 1566 ) | |
| 1567 | |
| 1568 (let ((menu (make-sparse-keymap "GDB-Windows"))) | |
| 1569 (define-key gud-menu-map [displays] | |
| 1570 `(menu-item "GDB-Windows" ,menu :visible (eq gud-minor-mode 'gdba))) | |
| 1571 (define-key menu [gdb] '("Gdb" . gdb-display-gdb-buffer)) | |
| 1572 (define-key menu [locals] '("Locals" . gdb-display-locals-buffer)) | |
| 1573 (define-key menu [registers] '("Registers" . gdb-display-registers-buffer)) | |
| 1574 (define-key menu [frames] '("Stack" . gdb-display-stack-buffer)) | |
| 1575 (define-key menu [breakpoints] '("Breakpoints" . gdb-display-breakpoints-buffer)) | |
| 1576 (define-key menu [threads] '("Threads" . gdb-display-threads-buffer)) | |
| 1577 ; (define-key menu [assembler] '("Machine" . gdb-display-assembler-buffer)) | |
| 1578 ) | |
| 1579 | |
| 1580 (let ((menu (make-sparse-keymap "View"))) | |
| 1581 (define-key gud-menu-map [view] | |
| 1582 `(menu-item "View" ,menu :visible (eq gud-minor-mode 'gdba))) | |
| 1583 ; (define-key menu [both] '(menu-item "Both" gdb-view-both | |
| 1584 ; :help "Display both source and assembler" | |
| 1585 ; :button (:radio . (eq gdb-selected-view 'both)))) | |
| 1586 (define-key menu [assembler] '(menu-item "Machine" gdb-view-assembler | |
| 1587 :help "Display assembler only" | |
| 1588 :button (:radio . (eq gdb-selected-view 'assembler)))) | |
| 1589 (define-key menu [source] '(menu-item "Source" gdb-view-source-function | |
| 1590 :help "Display source only" | |
| 1591 :button (:radio . (eq gdb-selected-view 'source))))) | |
| 1592 | |
| 1593 (let ((menu (make-sparse-keymap "GDB-UI"))) | |
| 1594 (define-key gud-menu-map [ui] | |
| 1595 `(menu-item "GDB-UI" ,menu :visible (eq gud-minor-mode 'gdba))) | |
| 1596 (define-key menu [gdb-restore-windows] | |
| 1597 '("Restore window layout" . gdb-restore-windows)) | |
| 1598 (define-key menu [gdb-many-windows] | |
| 1599 (menu-bar-make-toggle gdb-many-windows gdb-many-windows | |
| 1600 "Display other windows" "Many Windows %s" | |
| 1601 "Display locals, stack and breakpoint information"))) | |
| 1602 | |
| 1603 (defun gdb-frame-gdb-buffer () | |
| 1604 (interactive) | |
| 1605 (switch-to-buffer-other-frame | |
| 1606 (gdb-get-create-buffer 'gdba))) | |
| 1607 | |
| 1608 (defun gdb-display-gdb-buffer () | |
| 1609 (interactive) | |
| 1610 (gdb-display-buffer | |
| 1611 (gdb-get-create-buffer 'gdba))) | |
| 1612 | |
| 1613 (defvar gdb-main-file nil "Source file from which program execution begins.") | |
| 1614 | |
| 1615 (defun gdb-view-source-function () | |
| 1616 (interactive) | |
| 1617 (if gdb-view-source | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1618 (if (window-live-p gdb-source-window) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1619 (set-window-buffer gdb-source-window |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1620 (if gud-last-last-frame |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1621 (gud-find-file (car gud-last-last-frame)) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1622 (gud-find-file gdb-main-file))) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1623 (setq gdb-source-window |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1624 (display-buffer |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1625 (if gud-last-last-frame |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1626 (gud-find-file (car gud-last-last-frame)) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1627 (gud-find-file gdb-main-file)))))) |
| 54538 | 1628 (setq gdb-selected-view 'source)) |
| 1629 | |
| 1630 (defun gdb-view-assembler() | |
| 1631 (interactive) | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1632 (if (window-live-p gdb-source-window) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1633 (set-window-buffer gdb-source-window |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1634 (gdb-get-create-buffer 'gdb-assembler-buffer)) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1635 (setq gdb-source-window |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1636 (display-buffer (gdb-get-create-buffer 'gdb-assembler-buffer)))) |
| 54538 | 1637 (setq gdb-selected-view 'assembler)) |
| 1638 | |
| 1639 ;(defun gdb-view-both() | |
| 1640 ;(interactive) | |
| 1641 ;(setq gdb-selected-view 'both)) | |
| 1642 | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1643 (defcustom gdb-show-main nil |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1644 "Nil means don't display source file containing the main routine." |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1645 :type 'boolean |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1646 :group 'gud) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1647 |
| 54538 | 1648 (defun gdb-setup-windows () |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1649 "Layout the window pattern for gdb-many-windows." |
| 54538 | 1650 (gdb-display-locals-buffer) |
| 1651 (gdb-display-stack-buffer) | |
| 1652 (delete-other-windows) | |
| 1653 (gdb-display-breakpoints-buffer) | |
| 1654 (delete-other-windows) | |
| 1655 (switch-to-buffer gud-comint-buffer) | |
| 1656 (split-window nil ( / ( * (window-height) 3) 4)) | |
| 1657 (split-window nil ( / (window-height) 3)) | |
| 1658 (split-window-horizontally) | |
| 1659 (other-window 1) | |
| 1660 (switch-to-buffer (gdb-locals-buffer-name)) | |
| 1661 (other-window 1) | |
| 1662 (switch-to-buffer | |
| 1663 (if (and gdb-view-source | |
| 1664 (eq gdb-selected-view 'source)) | |
| 1665 (if gud-last-last-frame | |
| 1666 (gud-find-file (car gud-last-last-frame)) | |
| 1667 (gud-find-file gdb-main-file)) | |
| 1668 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
| 1669 (setq gdb-source-window (get-buffer-window (current-buffer))) | |
|
54729
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
1670 (when gdb-use-inferior-io-buffer |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
1671 (split-window-horizontally) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
1672 (other-window 1) |
|
7bfccd78beed
(gdb-use-inferior-io-buffer): New option.
Nick Roberts <nickrob@snap.net.nz>
parents:
54668
diff
changeset
|
1673 (switch-to-buffer (gdb-inferior-io-name))) |
| 54538 | 1674 (other-window 1) |
| 1675 (switch-to-buffer (gdb-stack-buffer-name)) | |
| 1676 (split-window-horizontally) | |
| 1677 (other-window 1) | |
| 1678 (switch-to-buffer (gdb-breakpoints-buffer-name)) | |
| 1679 (other-window 1)) | |
| 1680 | |
| 1681 (defcustom gdb-many-windows nil | |
| 1682 "Nil means that gdb starts with just two windows : the GUD and | |
| 1683 the source buffer." | |
| 1684 :type 'boolean | |
| 1685 :group 'gud) | |
| 1686 | |
| 1687 (defun gdb-many-windows (arg) | |
| 1688 "Toggle the number of windows in the basic arrangement." | |
| 1689 (interactive "P") | |
| 1690 (setq gdb-many-windows | |
| 1691 (if (null arg) | |
| 1692 (not gdb-many-windows) | |
| 1693 (> (prefix-numeric-value arg) 0))) | |
| 1694 (gdb-restore-windows)) | |
| 1695 | |
| 1696 (defun gdb-restore-windows () | |
| 1697 "Restore the basic arrangement of windows used by gdba. | |
| 1698 This arrangement depends on the value of `gdb-many-windows'." | |
| 1699 (interactive) | |
| 1700 (if gdb-many-windows | |
| 1701 (progn | |
| 1702 (switch-to-buffer gud-comint-buffer) | |
| 1703 (delete-other-windows) | |
| 1704 (gdb-setup-windows)) | |
| 1705 (switch-to-buffer gud-comint-buffer) | |
| 1706 (delete-other-windows) | |
| 1707 (split-window) | |
| 1708 (other-window 1) | |
| 1709 (switch-to-buffer | |
| 1710 (if (and gdb-view-source | |
| 1711 (eq gdb-selected-view 'source)) | |
| 1712 (if gud-last-last-frame | |
| 1713 (gud-find-file (car gud-last-last-frame)) | |
| 1714 (gud-find-file gdb-main-file)) | |
| 1715 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
| 1716 (setq gdb-source-window (get-buffer-window (current-buffer))) | |
| 1717 (other-window 1))) | |
| 1718 | |
| 1719 (defun gdb-reset () | |
| 1720 "Exit a debugging session cleanly by killing the gdb buffers and resetting | |
| 1721 the source buffers." | |
| 1722 (dolist (buffer (buffer-list)) | |
| 1723 (if (not (eq buffer gud-comint-buffer)) | |
| 1724 (with-current-buffer buffer | |
| 1725 (if (memq gud-minor-mode '(gdba pdb)) | |
| 1726 (if (string-match "^\*.+*$" (buffer-name)) | |
| 1727 (kill-buffer nil) | |
| 1728 (gdb-remove-breakpoint-icons (point-min) (point-max) t) | |
| 1729 (setq gud-minor-mode nil) | |
| 1730 (kill-local-variable 'tool-bar-map) | |
| 1731 (setq gud-running nil)))))) | |
| 1732 (when (markerp gdb-overlay-arrow-position) | |
| 1733 (move-marker gdb-overlay-arrow-position nil) | |
| 1734 (setq gdb-overlay-arrow-position nil)) | |
| 1735 (setq overlay-arrow-variable-list | |
| 1736 (delq 'gdb-overlay-arrow-position overlay-arrow-variable-list))) | |
| 1737 | |
| 1738 (defun gdb-source-info () | |
| 1739 "Find the source file where the program starts and displays it with related | |
| 1740 buffers." | |
| 1741 (goto-char (point-min)) | |
| 1742 (if (search-forward "directory is " nil t) | |
| 1743 (if (looking-at "\\S-*:\\(\\S-*\\)") | |
| 1744 (setq gdb-cdir (match-string 1)) | |
| 1745 (looking-at "\\S-*") | |
| 1746 (setq gdb-cdir (match-string 0)))) | |
| 1747 (if (search-forward "Located in " nil t) | |
| 1748 (if (looking-at "\\S-*") | |
| 1749 (setq gdb-main-file (match-string 0))) | |
| 1750 (setq gdb-view-source nil)) | |
| 1751 (if gdb-many-windows | |
| 1752 (gdb-setup-windows) | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1753 (gdb-get-create-buffer 'gdb-breakpoints-buffer) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1754 (when gdb-show-main |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1755 (switch-to-buffer gud-comint-buffer) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1756 (delete-other-windows) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1757 (split-window) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1758 (other-window 1) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1759 (switch-to-buffer |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1760 (if gdb-view-source |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1761 (gud-find-file gdb-main-file) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1762 (gdb-get-create-buffer 'gdb-assembler-buffer))) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1763 (setq gdb-source-window (get-buffer-window (current-buffer))) |
|
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1764 (other-window 1)))) |
| 54538 | 1765 |
| 1766 ;;from put-image | |
| 1767 (defun gdb-put-string (putstring pos &optional dprop) | |
| 1768 "Put string PUTSTRING in front of POS in the current buffer. | |
| 1769 PUTSTRING is displayed by putting an overlay into the current buffer with a | |
| 1770 `before-string' STRING that has a `display' property whose value is | |
| 1771 PUTSTRING." | |
| 1772 (let ((gdb-string "x") | |
| 1773 (buffer (current-buffer))) | |
| 1774 (let ((overlay (make-overlay pos pos buffer)) | |
| 1775 (prop (or dprop | |
| 1776 (list (list 'margin 'left-margin) putstring)))) | |
| 1777 (put-text-property 0 (length gdb-string) 'display prop gdb-string) | |
| 1778 (overlay-put overlay 'put-break t) | |
| 1779 (overlay-put overlay 'before-string gdb-string)))) | |
| 1780 | |
| 1781 ;;from remove-images | |
| 1782 (defun gdb-remove-strings (start end &optional buffer) | |
| 1783 "Remove strings between START and END in BUFFER. | |
| 1784 Remove only strings that were put in BUFFER with calls to `gdb-put-string'. | |
| 1785 BUFFER nil or omitted means use the current buffer." | |
| 1786 (unless buffer | |
| 1787 (setq buffer (current-buffer))) | |
| 1788 (let ((overlays (overlays-in start end))) | |
| 1789 (while overlays | |
| 1790 (let ((overlay (car overlays))) | |
| 1791 (when (overlay-get overlay 'put-break) | |
| 1792 (delete-overlay overlay))) | |
| 1793 (setq overlays (cdr overlays))))) | |
| 1794 | |
| 1795 (defun gdb-put-breakpoint-icon (enabled) | |
| 1796 (let ((start (progn (beginning-of-line) (- (point) 1))) | |
| 1797 (end (progn (end-of-line) (+ (point) 1)))) | |
| 1798 (gdb-remove-breakpoint-icons start end) | |
| 1799 (if (display-images-p) | |
| 1800 (if (>= (car (window-fringes)) 8) | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1801 (gdb-put-string |
| 54538 | 1802 nil (1+ start) |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1803 `(left-fringe |
| 54538 | 1804 ,(or breakpoint-bitmap |
| 1805 (setq breakpoint-bitmap | |
| 1806 (define-fringe-bitmap | |
| 1807 "\x3c\x7e\xff\xff\xff\xff\x7e\x3c"))) | |
| 1808 ,(if enabled | |
| 1809 'breakpoint-enabled-bitmap-face | |
| 1810 'breakpoint-disabled-bitmap-face))) | |
| 1811 (when (< left-margin-width 2) | |
| 1812 (save-current-buffer | |
| 1813 (setq left-margin-width 2) | |
| 1814 (if (get-buffer-window (current-buffer)) | |
| 1815 (set-window-margins (get-buffer-window | |
| 1816 (current-buffer)) | |
| 1817 left-margin-width | |
| 1818 right-margin-width)))) | |
| 1819 (put-image | |
| 1820 (if enabled | |
| 1821 (or breakpoint-enabled-icon | |
| 1822 (setq breakpoint-enabled-icon | |
|
54668
69a699e79a0d
(gdb-view-source-function, gdb-view-assembler)
Nick Roberts <nickrob@snap.net.nz>
parents:
54617
diff
changeset
|
1823 (find-image `((:type xpm :data |
| 54538 | 1824 ,breakpoint-xpm-data |
| 1825 :ascent 100 :pointer hand) | |
| 1826 (:type pbm :data | |
| 1827 ,breakpoint-enabled-pbm-data | |
| 1828 :ascent 100 :pointer hand))))) | |
| 1829 (or breakpoint-disabled-icon | |
| 1830 (setq breakpoint-disabled-icon | |
| 1831 (find-image `((:type xpm :data | |
| 1832 ,breakpoint-xpm-data | |
| 1833 :conversion disabled | |
| 1834 :ascent 100) | |
| 1835 (:type pbm :data | |
| 1836 ,breakpoint-disabled-pbm-data | |
| 1837 :ascent 100)))))) | |
| 1838 (+ start 1) nil 'left-margin)) | |
| 1839 (when (< left-margin-width 2) | |
| 1840 (save-current-buffer | |
| 1841 (setq left-margin-width 2) | |
| 1842 (if (get-buffer-window (current-buffer)) | |
| 1843 (set-window-margins (get-buffer-window | |
| 1844 (current-buffer)) | |
| 1845 left-margin-width | |
| 1846 right-margin-width)))) | |
| 1847 (gdb-put-string (if enabled "B" "b") (1+ start))))) | |
| 1848 | |
| 1849 (defun gdb-remove-breakpoint-icons (start end &optional remove-margin) | |
| 1850 (gdb-remove-strings start end) | |
| 1851 (if (display-images-p) | |
| 1852 (remove-images start end)) | |
| 1853 (when remove-margin | |
| 1854 (setq left-margin-width 0) | |
| 1855 (if (get-buffer-window (current-buffer)) | |
| 1856 (set-window-margins (get-buffer-window | |
| 1857 (current-buffer)) | |
| 1858 left-margin-width | |
| 1859 right-margin-width)))) | |
| 1860 | |
| 1861 | |
| 1862 ;; | |
| 1863 ;; Assembler buffer. | |
| 1864 ;; | |
| 1865 (gdb-set-buffer-rules 'gdb-assembler-buffer | |
| 1866 'gdb-assembler-buffer-name | |
| 1867 'gdb-assembler-mode) | |
| 1868 | |
| 1869 (def-gdb-auto-updated-buffer gdb-assembler-buffer | |
| 1870 gdb-invalidate-assembler | |
| 1871 (concat "server disassemble " gdb-current-address "\n") | |
| 1872 gdb-assembler-handler | |
| 1873 gdb-assembler-custom) | |
| 1874 | |
| 1875 (defun gdb-assembler-custom () | |
| 1876 (let ((buffer (gdb-get-buffer 'gdb-assembler-buffer)) | |
| 1877 (pos 1) (address) (flag)) | |
| 1878 (with-current-buffer buffer | |
| 1879 (if (not (equal gdb-current-address "main")) | |
| 1880 (progn | |
| 1881 (goto-char (point-min)) | |
| 1882 (if (re-search-forward gdb-current-address nil t) | |
| 1883 (progn | |
| 1884 (setq pos (point)) | |
| 1885 (beginning-of-line) | |
| 1886 (or gdb-overlay-arrow-position | |
| 1887 (setq gdb-overlay-arrow-position (make-marker))) | |
| 1888 (set-marker gdb-overlay-arrow-position | |
| 1889 (point) (current-buffer)))))) | |
| 1890 ;; remove all breakpoint-icons in assembler buffer before updating. | |
| 1891 (gdb-remove-breakpoint-icons (point-min) (point-max))) | |
| 1892 (with-current-buffer (gdb-get-buffer 'gdb-breakpoints-buffer) | |
| 1893 (goto-char (point-min)) | |
| 1894 (while (< (point) (- (point-max) 1)) | |
| 1895 (forward-line 1) | |
| 1896 (if (looking-at "[^\t].*breakpoint") | |
| 1897 (progn | |
| 1898 (looking-at | |
| 1899 "[0-9]*\\s-*\\S-*\\s-*\\S-*\\s-*\\(.\\)\\s-*0x\\(\\S-*\\)") | |
| 1900 (setq flag (char-after (match-beginning 1))) | |
| 1901 (setq address (match-string 2)) | |
| 1902 ;; remove leading 0s from output of info break. | |
| 1903 (if (string-match "^0+\\(.*\\)" address) | |
| 1904 (setq address (match-string 1 address))) | |
| 1905 (with-current-buffer buffer | |
| 1906 (goto-char (point-min)) | |
| 1907 (if (re-search-forward address nil t) | |
| 1908 (gdb-put-breakpoint-icon (eq flag ?y)))))))) | |
| 1909 (if (not (equal gdb-current-address "main")) | |
| 1910 (set-window-point (get-buffer-window buffer) pos)))) | |
| 1911 | |
| 1912 (defvar gdb-assembler-mode-map | |
| 1913 (let ((map (make-sparse-keymap))) | |
| 1914 (suppress-keymap map) | |
| 1915 map)) | |
| 1916 | |
| 1917 (defun gdb-assembler-mode () | |
| 1918 "Major mode for viewing code assembler. | |
| 1919 | |
| 1920 \\{gdb-assembler-mode-map}" | |
| 1921 (setq major-mode 'gdb-assembler-mode) | |
| 1922 (setq mode-name "Machine") | |
| 1923 (setq gdb-overlay-arrow-position nil) | |
| 1924 (add-to-list 'overlay-arrow-variable-list 'gdb-overlay-arrow-position) | |
| 1925 (put 'gdb-overlay-arrow-position 'overlay-arrow-string "=>") | |
| 1926 (setq fringes-outside-margins t) | |
| 1927 (setq buffer-read-only t) | |
| 1928 (use-local-map gdb-assembler-mode-map) | |
| 1929 (gdb-invalidate-assembler)) | |
| 1930 | |
| 1931 (defun gdb-assembler-buffer-name () | |
| 1932 (with-current-buffer gud-comint-buffer | |
| 1933 (concat "*Machine Code " (gdb-get-target-string) "*"))) | |
| 1934 | |
| 1935 (defun gdb-display-assembler-buffer () | |
| 1936 (interactive) | |
| 1937 (gdb-display-buffer | |
| 1938 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
| 1939 | |
| 1940 (defun gdb-frame-assembler-buffer () | |
| 1941 (interactive) | |
| 1942 (switch-to-buffer-other-frame | |
| 1943 (gdb-get-create-buffer 'gdb-assembler-buffer))) | |
| 1944 | |
| 1945 ;; modified because if gdb-current-address has changed value a new command | |
| 1946 ;; must be enqueued to update the buffer with the new output | |
| 1947 (defun gdb-invalidate-assembler (&optional ignored) | |
| 1948 (if (gdb-get-buffer 'gdb-assembler-buffer) | |
| 1949 (progn | |
| 1950 (unless (string-equal gdb-current-frame gdb-previous-frame) | |
| 1951 (if (or (not (member 'gdb-invalidate-assembler | |
| 1952 (gdb-get-pending-triggers))) | |
| 1953 (not (string-equal gdb-current-address | |
| 1954 gdb-previous-address))) | |
| 1955 (progn | |
| 1956 ;; take previous disassemble command off the queue | |
| 1957 (with-current-buffer gud-comint-buffer | |
| 1958 (let ((queue (gdb-get-input-queue)) (item)) | |
| 1959 (dolist (item queue) | |
| 1960 (if (equal (cdr item) '(gdb-assembler-handler)) | |
| 1961 (gdb-set-input-queue | |
| 1962 (delete item (gdb-get-input-queue))))))) | |
| 1963 (gdb-enqueue-input | |
| 1964 (list (concat "server disassemble " gdb-current-address "\n") | |
| 1965 'gdb-assembler-handler)) | |
| 1966 (gdb-set-pending-triggers | |
| 1967 (cons 'gdb-invalidate-assembler | |
| 1968 (gdb-get-pending-triggers))) | |
| 1969 (setq gdb-previous-address gdb-current-address) | |
| 1970 (setq gdb-previous-frame gdb-current-frame))))))) | |
| 1971 | |
| 1972 (defun gdb-get-current-frame () | |
| 1973 (if (not (member 'gdb-get-current-frame (gdb-get-pending-triggers))) | |
| 1974 (progn | |
| 1975 (gdb-enqueue-input | |
| 1976 (list (concat "server info frame\n") 'gdb-frame-handler)) | |
| 1977 (gdb-set-pending-triggers | |
| 1978 (cons 'gdb-get-current-frame | |
| 1979 (gdb-get-pending-triggers)))))) | |
| 1980 | |
| 1981 (defun gdb-frame-handler () | |
| 1982 (gdb-set-pending-triggers | |
| 1983 (delq 'gdb-get-current-frame (gdb-get-pending-triggers))) | |
| 1984 (with-current-buffer (gdb-get-create-buffer 'gdb-partial-output-buffer) | |
| 1985 (goto-char (point-min)) | |
| 1986 (forward-line) | |
| 1987 (if (looking-at ".*=\\s-+0x\\(\\S-*\\)\\s-+in\\s-+\\(\\S-*\\)") | |
| 1988 (progn | |
| 1989 (setq gdb-current-frame (match-string 2)) | |
| 1990 (let ((address (match-string 1))) | |
| 1991 ;; remove leading 0s from output of info frame command. | |
| 1992 (if (string-match "^0+\\(.*\\)" address) | |
| 1993 (setq gdb-current-address | |
| 1994 (concat "0x" (match-string 1 address))) | |
| 1995 (setq gdb-current-address (concat "0x" address)))) | |
| 1996 (if (or (if (not (re-search-forward "(\\S-*:[0-9]*);" nil t)) | |
| 1997 (progn (setq gdb-view-source nil) t)) | |
| 1998 (eq gdb-selected-view 'assembler)) | |
| 1999 (progn | |
| 2000 (set-window-buffer | |
| 2001 gdb-source-window | |
| 2002 (gdb-get-create-buffer 'gdb-assembler-buffer)) | |
| 2003 ;;update with new frame for machine code if necessary | |
| 2004 (gdb-invalidate-assembler)))))) | |
| 2005 (if (re-search-forward " source language \\(\\S-*\\)\." nil t) | |
| 2006 (setq gdb-current-language (match-string 1)))) | |
| 2007 | |
| 2008 (provide 'gdb-ui) | |
| 2009 | |
| 2010 ;;; arch-tag: e9fb00c5-74ef-469f-a088-37384caae352 | |
| 2011 ;;; gdb-ui.el ends here |
