0
|
1 ;;; gdb.el --- run gdb under Emacs
|
|
2
|
|
3 ;; Author: W. Schelter, University of Texas
|
|
4 ;; wfs@rascal.ics.utexas.edu
|
|
5 ;; Rewritten by rms.
|
|
6 ;; Keywords: c, unix, tools, debugging
|
|
7
|
|
8 ;; Some ideas are due to Masanobu.
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
72
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
25 ;; 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: Not in FSF
|
|
28
|
|
29 ;;; Commentary:
|
0
|
30
|
|
31 ;; Description of GDB interface:
|
|
32
|
|
33 ;; A facility is provided for the simultaneous display of the source code
|
|
34 ;; in one window, while using gdb to step through a function in the
|
|
35 ;; other. A small arrow in the source window, indicates the current
|
|
36 ;; line.
|
|
37
|
|
38 ;; Starting up:
|
|
39
|
|
40 ;; In order to use this facility, invoke the command GDB to obtain a
|
|
41 ;; shell window with the appropriate command bindings. You will be asked
|
|
42 ;; for the name of a file to run. Gdb will be invoked on this file, in a
|
|
43 ;; window named *gdb-foo* if the file is foo.
|
|
44
|
|
45 ;; M-s steps by one line, and redisplays the source file and line.
|
|
46
|
|
47 ;; You may easily create additional commands and bindings to interact
|
|
48 ;; with the display. For example to put the gdb command next on \M-n
|
|
49 ;; (def-gdb next "\M-n")
|
|
50
|
|
51 ;; This causes the emacs command gdb-next to be defined, and runs
|
|
52 ;; gdb-display-frame after the command.
|
|
53
|
|
54 ;; gdb-display-frame is the basic display function. It tries to display
|
|
55 ;; in the other window, the file and line corresponding to the current
|
|
56 ;; position in the gdb window. For example after a gdb-step, it would
|
|
57 ;; display the line corresponding to the position for the last step. Or
|
|
58 ;; if you have done a backtrace in the gdb buffer, and move the cursor
|
|
59 ;; into one of the frames, it would display the position corresponding to
|
|
60 ;; that frame.
|
|
61
|
|
62 ;; gdb-display-frame is invoked automatically when a filename-and-line-number
|
|
63 ;; appears in the output.
|
|
64
|
72
|
65 ;;; Code:
|
|
66
|
0
|
67 (require 'comint)
|
|
68 (require 'shell)
|
|
69
|
|
70 (condition-case nil
|
|
71 (if (featurep 'toolbar)
|
|
72 (require 'eos-toolbar "sun-eos-toolbar"))
|
|
73 (error nil))
|
|
74
|
|
75 (defvar gdb-last-frame)
|
|
76 (defvar gdb-delete-prompt-marker)
|
|
77 (defvar gdb-filter-accumulator)
|
|
78 (defvar gdb-last-frame-displayed-p)
|
|
79 (defvar gdb-arrow-extent nil)
|
|
80 (or (fboundp 'make-glyph) (fset 'make-glyph 'identity)) ; work w/ pre beta v12
|
|
81 (defvar gdb-arrow-glyph (make-glyph "=>"))
|
|
82
|
|
83 (make-face 'gdb-arrow-face)
|
|
84 (or (face-differs-from-default-p 'gdb-arrow-face)
|
|
85 ;; Usually has a better default value than highlight does
|
|
86 (copy-face 'isearch 'gdb-arrow-face))
|
|
87
|
|
88 ;; Hooks can side-effect extent arg to change extent properties
|
|
89 (defvar gdb-arrow-extent-hooks '())
|
|
90
|
|
91 (defvar gdb-prompt-pattern "^>\\|^(.*gdb[+]?) *\\|^---Type <return> to.*--- *"
|
|
92 "A regexp to recognize the prompt for gdb or gdb+.")
|
|
93
|
|
94 (defvar gdb-mode-map nil
|
|
95 "Keymap for gdb-mode.")
|
|
96
|
|
97 (defvar gdb-toolbar
|
|
98 '([eos::toolbar-stop-at-icon
|
|
99 gdb-toolbar-break
|
|
100 t
|
|
101 "Stop at selected position"]
|
|
102 [eos::toolbar-stop-in-icon
|
|
103 gdb-toolbar-break
|
|
104 t
|
|
105 "Stop in function whose name is selected"]
|
|
106 [eos::toolbar-clear-at-icon
|
|
107 gdb-toolbar-clear
|
|
108 t
|
|
109 "Clear at selected position"]
|
|
110 [eos::toolbar-evaluate-icon
|
|
111 nil
|
|
112 nil
|
|
113 "Evaluate selected expression; shows in separate XEmacs frame"]
|
|
114 [eos::toolbar-evaluate-star-icon
|
|
115 nil
|
|
116 nil
|
|
117 "Evaluate selected expression as a pointer; shows in separate XEmacs frame"]
|
|
118 [eos::toolbar-run-icon
|
|
119 gdb-run
|
|
120 t
|
|
121 "Run current program"]
|
|
122 [eos::toolbar-cont-icon
|
|
123 gdb-cont
|
|
124 t
|
|
125 "Continue current program"]
|
|
126 [eos::toolbar-step-into-icon
|
|
127 gdb-step
|
|
128 t
|
|
129 "Step into (aka step)"]
|
|
130 [eos::toolbar-step-over-icon
|
|
131 gdb-next
|
|
132 t
|
|
133 "Step over (aka next)"]
|
|
134 [eos::toolbar-up-icon
|
|
135 gdb-up
|
|
136 t
|
|
137 "Stack Up (towards \"cooler\" - less recently visited - frames)"]
|
|
138 [eos::toolbar-down-icon
|
|
139 gdb-down
|
|
140 t
|
|
141 "Stack Down (towards \"warmer\" - more recently visited - frames)"]
|
|
142 [eos::toolbar-fix-icon nil nil "Fix (not available with gdb)"]
|
|
143 [eos::toolbar-build-icon
|
|
144 toolbar-compile
|
|
145 t
|
|
146 "Build (aka make -NYI)"]
|
|
147 ))
|
|
148
|
|
149 (if gdb-mode-map
|
|
150 nil
|
|
151 (setq gdb-mode-map (make-sparse-keymap))
|
|
152 (set-keymap-name gdb-mode-map 'gdb-mode-map)
|
|
153 (set-keymap-parents gdb-mode-map (list comint-mode-map))
|
|
154 (define-key gdb-mode-map "\C-l" 'gdb-refresh)
|
|
155 (define-key gdb-mode-map "\C-c\C-c" 'gdb-control-c-subjob)
|
|
156 (define-key gdb-mode-map "\t" 'comint-dynamic-complete)
|
|
157 (define-key gdb-mode-map "\M-?" 'comint-dynamic-list-completions))
|
|
158
|
|
159 (define-key ctl-x-map " " 'gdb-break)
|
|
160 (define-key ctl-x-map "&" 'send-gdb-command)
|
|
161
|
|
162 ;;Of course you may use `def-gdb' with any other gdb command, including
|
|
163 ;;user defined ones.
|
|
164
|
|
165 (defmacro def-gdb (name key &optional doc &rest forms)
|
|
166 (let* ((fun (intern (format "gdb-%s" name)))
|
|
167 (cstr (list 'if '(not (= 1 arg))
|
|
168 (list 'format "%s %s" name 'arg)
|
|
169 name)))
|
|
170 (list 'progn
|
|
171 (nconc (list 'defun fun '(arg)
|
|
172 (or doc "")
|
|
173 '(interactive "p")
|
|
174 (list 'gdb-call cstr))
|
|
175 forms)
|
|
176 (and key (list 'define-key 'gdb-mode-map key (list 'quote fun))))))
|
|
177
|
|
178 (def-gdb "step" "\M-s" "Step one source line with display"
|
|
179 (gdb-delete-arrow-extent))
|
|
180 (def-gdb "stepi" "\M-i" "Step one instruction with display"
|
|
181 (gdb-delete-arrow-extent))
|
|
182 (def-gdb "finish" "\C-c\C-f" "Finish executing current function"
|
|
183 (gdb-delete-arrow-extent))
|
|
184 (def-gdb "run" nil "Run the current program"
|
|
185 (gdb-delete-arrow-extent))
|
|
186
|
|
187 ;;"next" and "cont" were bound to M-n and M-c in Emacs 18, but these are
|
|
188 ;;poor choices, since M-n is used for history navigation and M-c is
|
|
189 ;;capitalize-word. These are defined without key bindings so that users
|
|
190 ;;may choose their own bindings.
|
|
191 (def-gdb "next" "\C-c\C-n" "Step one source line (skip functions)"
|
|
192 (gdb-delete-arrow-extent))
|
|
193 (def-gdb "cont" "\C-c\M-c" "Proceed with the program"
|
|
194 (gdb-delete-arrow-extent))
|
|
195
|
|
196 (def-gdb "up" "\C-c<" "Go up N stack frames (numeric arg) with display")
|
|
197 (def-gdb "down" "\C-c>" "Go down N stack frames (numeric arg) with display")
|
|
198
|
|
199 (defvar gdb-display-mode nil
|
|
200 "Minor mode for gdb frame display")
|
|
201 (or (assq 'gdb-display-mode minor-mode-alist)
|
|
202 (setq minor-mode-alist
|
|
203 (purecopy
|
|
204 (append minor-mode-alist
|
|
205 '((gdb-display-mode " Frame"))))))
|
|
206
|
|
207 (defun gdb-display-mode (&optional arg)
|
|
208 "Toggle GDB Frame display mode
|
|
209 With arg, turn display mode on if and only if arg is positive.
|
|
210 In the display minor mode, source file are displayed in another
|
|
211 window for repective \\[gdb-display-frame] commands."
|
|
212 (interactive "P")
|
|
213 (setq gdb-display-mode (if (null arg)
|
|
214 (not gdb-display-mode)
|
|
215 (> (prefix-numeric-value arg) 0))))
|
|
216
|
|
217
|
|
218 (defun gdb-mode ()
|
|
219 "Major mode for interacting with an inferior Gdb process.
|
|
220 The following commands are available:
|
|
221
|
|
222 \\{gdb-mode-map}
|
|
223
|
|
224 \\[gdb-display-frame] displays in the other window
|
|
225 the last line referred to in the gdb buffer. See also
|
|
226 \\[gdb-display-mode].
|
|
227
|
|
228 \\[gdb-step],\\[gdb-next], and \\[gdb-nexti] in the gdb window,
|
|
229 call gdb to step,next or nexti and then update the other window
|
|
230 with the current file and position.
|
|
231
|
|
232 If you are in a source file, you may select a point to break
|
|
233 at, by doing \\[gdb-break].
|
|
234
|
|
235 Commands:
|
|
236 Many commands are inherited from comint mode.
|
|
237 Additionally we have:
|
|
238
|
|
239 \\[gdb-display-frame] display frames file in other window
|
|
240 \\[gdb-step] advance one line in program
|
|
241 \\[send-gdb-command] used for special printing of an arg at the current point.
|
|
242 C-x SPACE sets break point at current line."
|
|
243 (interactive)
|
|
244 (comint-mode)
|
|
245 (use-local-map gdb-mode-map)
|
|
246 (set-syntax-table c-mode-syntax-table)
|
|
247 (make-local-variable 'gdb-last-frame-displayed-p)
|
|
248 (make-local-variable 'gdb-last-frame)
|
|
249 (make-local-variable 'gdb-delete-prompt-marker)
|
|
250 (make-local-variable 'gdb-display-mode)
|
|
251 (make-local-variable' gdb-filter-accumulator)
|
|
252 (setq gdb-last-frame nil
|
|
253 gdb-delete-prompt-marker nil
|
|
254 gdb-filter-accumulator nil
|
|
255 gdb-display-mode t
|
|
256 major-mode 'gdb-mode
|
|
257 mode-name "Inferior GDB"
|
|
258 comint-prompt-regexp gdb-prompt-pattern
|
|
259 gdb-last-frame-displayed-p t)
|
|
260 (set (make-local-variable 'shell-dirtrackp) t)
|
|
261 ;;(make-local-variable 'gdb-arrow-extent)
|
|
262 (and (extentp gdb-arrow-extent)
|
|
263 (delete-extent gdb-arrow-extent))
|
|
264 (setq gdb-arrow-extent nil)
|
|
265 ;; XEmacs change:
|
|
266 (make-local-hook 'kill-buffer-hook)
|
|
267 (add-hook 'kill-buffer-hook 'gdb-delete-arrow-extent nil t)
|
70
|
268 (setq comint-input-sentinel 'shell-directory-tracker)
|
0
|
269 (run-hooks 'gdb-mode-hook))
|
|
270
|
|
271 (defun gdb-delete-arrow-extent ()
|
|
272 (let ((inhibit-quit t))
|
|
273 (if gdb-arrow-extent
|
|
274 (delete-extent gdb-arrow-extent))
|
|
275 (setq gdb-arrow-extent nil)))
|
|
276
|
|
277 (defvar current-gdb-buffer nil)
|
|
278
|
|
279 ;;;###autoload
|
|
280 (defvar gdb-command-name "gdb"
|
|
281 "Pathname for executing gdb.")
|
|
282
|
|
283 ;;;###autoload
|
|
284 (defun gdb (path &optional corefile)
|
|
285 "Run gdb on program FILE in buffer *gdb-FILE*.
|
|
286 The directory containing FILE becomes the initial working directory
|
|
287 and source-file directory for GDB. If you wish to change this, use
|
|
288 the GDB commands `cd DIR' and `directory'."
|
|
289 (interactive "FRun gdb on file: ")
|
|
290 (setq path (file-truename (expand-file-name path)))
|
|
291 (let ((file (file-name-nondirectory path)))
|
|
292 (switch-to-buffer (concat "*gdb-" file "*"))
|
|
293 (setq default-directory (file-name-directory path))
|
|
294 (or (bolp) (newline))
|
|
295 (insert "Current directory is " default-directory "\n")
|
|
296 (apply 'make-comint
|
|
297 (concat "gdb-" file)
|
|
298 (substitute-in-file-name gdb-command-name)
|
|
299 nil
|
|
300 "-fullname"
|
|
301 "-cd" default-directory
|
|
302 file
|
|
303 (and corefile (list corefile)))
|
|
304 (set-process-filter (get-buffer-process (current-buffer)) 'gdb-filter)
|
|
305 (set-process-sentinel (get-buffer-process (current-buffer)) 'gdb-sentinel)
|
|
306 ;; XEmacs change: turn on gdb mode after setting up the proc filters
|
|
307 ;; for the benefit of shell-font.el
|
|
308 (gdb-mode)
|
|
309 (gdb-set-buffer)))
|
|
310
|
|
311 ;;;####autoload
|
|
312 (defun gdb-with-core (file corefile)
|
|
313 "Debug a program using a corefile."
|
|
314 (interactive "fProgram to debug: \nfCore file to use: ")
|
|
315 (gdb file corefile))
|
|
316
|
|
317 (defun gdb-set-buffer ()
|
|
318 (cond ((eq major-mode 'gdb-mode)
|
|
319 (setq current-gdb-buffer (current-buffer))
|
|
320 (if (featurep 'eos-toolbar)
|
|
321 (set-specifier default-toolbar (cons (current-buffer)
|
|
322 gdb-toolbar))))))
|
|
323
|
|
324
|
|
325 ;; This function is responsible for inserting output from GDB
|
|
326 ;; into the buffer.
|
|
327 ;; Aside from inserting the text, it notices and deletes
|
|
328 ;; each filename-and-line-number;
|
|
329 ;; that GDB prints to identify the selected frame.
|
|
330 ;; It records the filename and line number, and maybe displays that file.
|
|
331 (defun gdb-filter (proc string)
|
|
332 (let ((inhibit-quit t))
|
|
333 (save-current-buffer
|
|
334 (set-buffer (process-buffer proc))
|
|
335 (if gdb-filter-accumulator
|
|
336 (gdb-filter-accumulate-marker
|
|
337 proc (concat gdb-filter-accumulator string))
|
|
338 (gdb-filter-scan-input proc string)))))
|
|
339
|
|
340 (defun gdb-filter-accumulate-marker (proc string)
|
|
341 (setq gdb-filter-accumulator nil)
|
|
342 (if (> (length string) 1)
|
|
343 (if (= (aref string 1) ?\032)
|
|
344 (let ((end (string-match "\n" string)))
|
|
345 (if end
|
|
346 (progn
|
|
347 (let* ((first-colon (string-match ":" string 2))
|
|
348 (second-colon
|
|
349 (string-match ":" string (1+ first-colon))))
|
|
350 (setq gdb-last-frame
|
|
351 (cons (substring string 2 first-colon)
|
|
352 (string-to-int
|
|
353 (substring string (1+ first-colon)
|
|
354 second-colon)))))
|
|
355 (setq gdb-last-frame-displayed-p nil)
|
|
356 (gdb-filter-scan-input proc
|
|
357 (substring string (1+ end))))
|
|
358 (setq gdb-filter-accumulator string)))
|
|
359 (gdb-filter-insert proc "\032")
|
|
360 (gdb-filter-scan-input proc (substring string 1)))
|
|
361 (setq gdb-filter-accumulator string)))
|
|
362
|
|
363 (defun gdb-filter-scan-input (proc string)
|
|
364 (if (equal string "")
|
|
365 (setq gdb-filter-accumulator nil)
|
|
366 (let ((start (string-match "\032" string)))
|
|
367 (if start
|
|
368 (progn (gdb-filter-insert proc (substring string 0 start))
|
|
369 (gdb-filter-accumulate-marker proc
|
|
370 (substring string start)))
|
|
371 (gdb-filter-insert proc string)))))
|
|
372
|
|
373 (defun gdb-filter-insert (proc string)
|
|
374 (let ((moving (= (point) (process-mark proc)))
|
|
375 (output-after-point (< (point) (process-mark proc))))
|
|
376 (save-excursion
|
|
377 ;; Insert the text, moving the process-marker.
|
|
378 (goto-char (process-mark proc))
|
|
379 (insert-before-markers string)
|
|
380 (set-marker (process-mark proc) (point))
|
|
381 (gdb-maybe-delete-prompt)
|
|
382 ;; Check for a filename-and-line number.
|
|
383 (gdb-display-frame
|
|
384 ;; Don't display the specified file
|
|
385 ;; unless (1) point is at or after the position where output appears
|
|
386 ;; and (2) this buffer is on the screen.
|
|
387 (or output-after-point
|
|
388 (not (get-buffer-window (current-buffer))))
|
|
389 ;; Display a file only when a new filename-and-line-number appears.
|
|
390 t))
|
|
391 (if moving (goto-char (process-mark proc))))
|
|
392
|
|
393 (let (s)
|
|
394 (if (and (should-use-dialog-box-p)
|
|
395 (setq s (or (string-match " (y or n) *\\'" string)
|
|
396 (string-match " (yes or no) *\\'" string))))
|
|
397 (gdb-mouse-prompt-hack (substring string 0 s) (current-buffer))))
|
|
398 )
|
|
399
|
|
400 (defun gdb-mouse-prompt-hack (prompt buffer)
|
|
401 (popup-dialog-box
|
|
402 (list prompt
|
|
403 (vector "Yes" (list 'gdb-mouse-prompt-hack-answer 't buffer) t)
|
|
404 (vector "No" (list 'gdb-mouse-prompt-hack-answer 'nil buffer) t)
|
|
405 nil
|
|
406 (vector "Cancel" (list 'gdb-mouse-prompt-hack-answer 'nil buffer) t)
|
|
407 )))
|
|
408
|
|
409 (defun gdb-mouse-prompt-hack-answer (answer buffer)
|
|
410 (let ((b (current-buffer)))
|
|
411 (unwind-protect
|
|
412 (progn
|
|
413 (set-buffer buffer)
|
|
414 (goto-char (process-mark (get-buffer-process buffer)))
|
|
415 (delete-region (point) (point-max))
|
|
416 (insert (if answer "yes" "no"))
|
|
417 (comint-send-input))
|
|
418 (set-buffer b))))
|
|
419
|
|
420 (defun gdb-sentinel (proc msg)
|
|
421 (cond ((null (buffer-name (process-buffer proc)))
|
|
422 ;; buffer killed
|
|
423 ;; Stop displaying an arrow in a source file.
|
|
424 ;(setq overlay-arrow-position nil) -- done by kill-buffer-hook
|
|
425 (set-process-buffer proc nil))
|
|
426 ((memq (process-status proc) '(signal exit))
|
|
427 ;; Stop displaying an arrow in a source file.
|
|
428 (gdb-delete-arrow-extent)
|
|
429 ;; Fix the mode line.
|
|
430 (setq modeline-process
|
|
431 (concat ": gdb " (symbol-name (process-status proc))))
|
|
432 (let* ((obuf (current-buffer)))
|
|
433 ;; save-excursion isn't the right thing if
|
|
434 ;; process-buffer is current-buffer
|
|
435 (unwind-protect
|
|
436 (progn
|
|
437 ;; Write something in *compilation* and hack its mode line,
|
|
438 (set-buffer (process-buffer proc))
|
|
439 ;; Force mode line redisplay soon
|
|
440 (set-buffer-modified-p (buffer-modified-p))
|
|
441 (if (eobp)
|
|
442 (insert ?\n mode-name " " msg)
|
|
443 (save-excursion
|
|
444 (goto-char (point-max))
|
|
445 (insert ?\n mode-name " " msg)))
|
|
446 ;; If buffer and mode line will show that the process
|
|
447 ;; is dead, we can delete it now. Otherwise it
|
|
448 ;; will stay around until M-x list-processes.
|
|
449 (delete-process proc))
|
|
450 ;; Restore old buffer, but don't restore old point
|
|
451 ;; if obuf is the gdb buffer.
|
|
452 (set-buffer obuf))))))
|
|
453
|
|
454
|
|
455 (defun gdb-refresh (&optional arg)
|
|
456 "Fix up a possibly garbled display, and redraw the arrow."
|
|
457 (interactive "P")
|
|
458 (recenter arg)
|
|
459 (gdb-display-frame))
|
|
460
|
|
461 (defun gdb-display-frame (&optional nodisplay noauto)
|
|
462 "Find, obey and delete the last filename-and-line marker from GDB.
|
|
463 The marker looks like \\032\\032FILENAME:LINE:CHARPOS\\n.
|
|
464 Obeying it means displaying in another window the specified file and line."
|
|
465 (interactive)
|
|
466 (gdb-set-buffer)
|
|
467 (and gdb-last-frame (not nodisplay)
|
|
468 gdb-display-mode
|
|
469 (or (not gdb-last-frame-displayed-p) (not noauto))
|
|
470 (progn (gdb-display-line (car gdb-last-frame) (cdr gdb-last-frame))
|
|
471 (setq gdb-last-frame-displayed-p t))))
|
|
472
|
|
473 ;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
|
|
474 ;; and that its line LINE is visible.
|
|
475 ;; Put the overlay-arrow on the line LINE in that buffer.
|
|
476
|
|
477 (defun gdb-display-line (true-file line &optional select-method)
|
|
478 ;; FILE to display
|
|
479 ;; LINE number to highlight and make visible
|
|
480 ;; SELECT-METHOD 'source, 'debugger, or 'none. (default is 'debugger)
|
|
481 (and (null select-method) (setq select-method 'debugger))
|
|
482 (let* ((pre-display-buffer-function nil) ; screw it, put it all in one screen
|
|
483 (pop-up-windows t)
|
|
484 (source-buffer (find-file-noselect true-file))
|
|
485 (source-window (display-buffer source-buffer))
|
|
486 (debugger-window (get-buffer-window current-gdb-buffer))
|
|
487 (extent gdb-arrow-extent)
|
|
488 pos)
|
|
489 ;; XEmacs change: make sure we find a window displaying the source file
|
|
490 ;; even if we are already sitting in it when a breakpoint is hit.
|
|
491 ;; Otherwise the t argument to display-buffer will prevent it from being
|
|
492 ;; displayed.
|
|
493 (save-excursion
|
|
494 (cond ((eq select-method 'debugger)
|
|
495 ;; might not already be displayed
|
|
496 (setq debugger-window (display-buffer current-gdb-buffer))
|
|
497 (select-window debugger-window))
|
|
498 ((eq select-method 'source)
|
|
499 (select-window source-window))))
|
|
500 (and extent
|
|
501 (not (eq (extent-object extent) source-buffer))
|
|
502 (setq extent (delete-extent extent)))
|
|
503 (or extent
|
|
504 (progn
|
|
505 (setq extent (make-extent 1 1 source-buffer))
|
|
506 (set-extent-face extent 'gdb-arrow-face)
|
|
507 (set-extent-begin-glyph extent gdb-arrow-glyph)
|
|
508 (set-extent-begin-glyph-layout extent 'whitespace)
|
|
509 (set-extent-priority extent 2000)
|
|
510 (setq gdb-arrow-extent extent)))
|
|
511 (save-current-buffer
|
|
512 (set-buffer source-buffer)
|
|
513 (save-restriction
|
|
514 (widen)
|
|
515 (goto-line line)
|
|
516 (set-window-point source-window (point))
|
|
517 (setq pos (point))
|
|
518 (end-of-line)
|
|
519 (set-extent-endpoints extent pos (point))
|
|
520 (run-hook-with-args 'gdb-arrow-extent-hooks extent))
|
|
521 (cond ((or (< pos (point-min)) (> pos (point-max)))
|
|
522 (widen)
|
|
523 (goto-char pos))))
|
|
524 ;; Added by Stig. It caused lots of problems for several users
|
|
525 ;; and since its purpose is unclear it is getting commented out.
|
|
526 ;;(and debugger-window
|
|
527 ;; (set-window-point debugger-window pos))
|
|
528 ))
|
|
529
|
|
530 (defun gdb-call (command)
|
|
531 "Invoke gdb COMMAND displaying source in other window."
|
|
532 (interactive)
|
|
533 (goto-char (point-max))
|
|
534 ;; Record info on the last prompt in the buffer and its position.
|
|
535 ;; This is used in gdb-maybe-delete-prompt
|
|
536 ;; to prevent multiple prompts from accumulating.
|
|
537 (save-excursion
|
|
538 (goto-char (process-mark (get-buffer-process current-gdb-buffer)))
|
|
539 (let ((pt (point)))
|
|
540 (beginning-of-line)
|
|
541 (setq gdb-delete-prompt-marker
|
|
542 (if (= (point) pt)
|
|
543 nil
|
|
544 (list (point-marker) (- pt (point))
|
|
545 (buffer-substring (point) pt))))))
|
|
546 (gdb-set-buffer)
|
|
547 (process-send-string (get-buffer-process current-gdb-buffer)
|
|
548 (concat command "\n")))
|
|
549
|
|
550 (defun gdb-maybe-delete-prompt ()
|
|
551 (if gdb-delete-prompt-marker
|
|
552 ;; Get the string that we used as the prompt before.
|
|
553 (let ((prompt (nth 2 gdb-delete-prompt-marker))
|
|
554 (length (nth 1 gdb-delete-prompt-marker)))
|
|
555 ;; Position after it.
|
|
556 (goto-char (+ (car gdb-delete-prompt-marker) length))
|
|
557 ;; Delete any duplicates of it which follow right after.
|
|
558 (while (and (<= (+ (point) length) (point-max))
|
|
559 (string= prompt
|
|
560 (buffer-substring (point) (+ (point) length))))
|
|
561 (delete-region (point) (+ (point) length)))
|
|
562 ;; If that didn't take us to where output is arriving,
|
|
563 ;; we have encountered something other than a prompt,
|
|
564 ;; so stop trying to delete any more prompts.
|
|
565 (if (not (= (point)
|
|
566 (process-mark (get-buffer-process current-gdb-buffer))))
|
|
567 (progn
|
|
568 (set-marker (car gdb-delete-prompt-marker) nil)
|
|
569 (setq gdb-delete-prompt-marker nil))))))
|
|
570
|
|
571 (defun gdb-break (temp)
|
|
572 "Set GDB breakpoint at this source line. With ARG set temporary breakpoint."
|
|
573 (interactive "P")
|
|
574 (let* ((file-name (file-name-nondirectory buffer-file-name))
|
|
575 (line (save-restriction
|
|
576 (widen)
|
|
577 (beginning-of-line)
|
|
578 (1+ (count-lines 1 (point)))))
|
|
579 (cmd (concat (if temp "tbreak " "break ") file-name ":"
|
|
580 (int-to-string line))))
|
|
581 (set-buffer current-gdb-buffer)
|
|
582 (goto-char (process-mark (get-buffer-process current-gdb-buffer)))
|
|
583 (delete-region (point) (point-max))
|
|
584 (insert cmd)
|
|
585 (comint-send-input)
|
|
586 ;;(process-send-string (get-buffer-process current-gdb-buffer) cmd)
|
|
587 ))
|
|
588
|
|
589 (defun gdb-clear ()
|
|
590 "Set GDB breakpoint at this source line."
|
|
591 (interactive)
|
|
592 (let* ((file-name (file-name-nondirectory buffer-file-name))
|
|
593 (line (save-restriction
|
|
594 (widen)
|
|
595 (beginning-of-line)
|
|
596 (1+ (count-lines 1 (point)))))
|
|
597 (cmd (concat "clear " file-name ":"
|
|
598 (int-to-string line))))
|
|
599 (set-buffer current-gdb-buffer)
|
|
600 (goto-char (process-mark (get-buffer-process current-gdb-buffer)))
|
|
601 (delete-region (point) (point-max))
|
|
602 (insert cmd)
|
|
603 (comint-send-input)
|
|
604 ;;(process-send-string (get-buffer-process current-gdb-buffer) cmd)
|
|
605 ))
|
|
606
|
|
607 (defun gdb-read-address()
|
|
608 "Return a string containing the core-address found in the buffer at point."
|
|
609 (save-excursion
|
|
610 (let ((pt (point)) found begin)
|
|
611 (setq found (if (search-backward "0x" (- pt 7) t)(point)))
|
|
612 (cond (found (forward-char 2)
|
|
613 (buffer-substring found
|
|
614 (progn (re-search-forward "[^0-9a-f]")
|
|
615 (forward-char -1)
|
|
616 (point))))
|
|
617 (t (setq begin (progn (re-search-backward "[^0-9]") (forward-char 1)
|
|
618 (point)))
|
|
619 (forward-char 1)
|
|
620 (re-search-forward "[^0-9]")
|
|
621 (forward-char -1)
|
|
622 (buffer-substring begin (point)))))))
|
|
623
|
|
624
|
|
625 (defvar gdb-commands nil
|
|
626 "List of strings or functions used by send-gdb-command.
|
|
627 It is for customization by you.")
|
|
628
|
|
629 (defun send-gdb-command (arg)
|
|
630
|
|
631 "This command reads the number where the cursor is positioned. It
|
|
632 then inserts this ADDR at the end of the gdb buffer. A numeric arg
|
|
633 selects the ARG'th member COMMAND of the list gdb-print-command. If
|
|
634 COMMAND is a string, (format COMMAND ADDR) is inserted, otherwise
|
|
635 (funcall COMMAND ADDR) is inserted. eg. \"p (rtx)%s->fld[0].rtint\"
|
|
636 is a possible string to be a member of gdb-commands. "
|
|
637
|
|
638
|
|
639 (interactive "P")
|
|
640 (let (comm addr)
|
|
641 (if arg (setq comm (nth arg gdb-commands)))
|
|
642 (setq addr (gdb-read-address))
|
|
643 (if (eq (current-buffer) current-gdb-buffer)
|
|
644 (set-mark (point)))
|
|
645 (cond (comm
|
|
646 (setq comm
|
|
647 (if (stringp comm) (format comm addr) (funcall comm addr))))
|
|
648 (t (setq comm addr)))
|
|
649 (switch-to-buffer current-gdb-buffer)
|
|
650 (goto-char (point-max))
|
|
651 (insert comm)))
|
|
652
|
70
|
653 (defun gdb-control-c-subjob ()
|
|
654 "Send a Control-C to the subprocess."
|
|
655 (interactive)
|
|
656 (process-send-string (get-buffer-process (current-buffer))
|
|
657 "\C-c"))
|
0
|
658
|
|
659 (defun gdb-toolbar-break ()
|
|
660 (interactive)
|
|
661 (save-excursion
|
|
662 (message (car gdb-last-frame))
|
|
663 (set-buffer (find-file-noselect (car gdb-last-frame)))
|
|
664 (gdb-break nil)))
|
|
665
|
|
666 (defun gdb-toolbar-clear ()
|
|
667 (interactive)
|
|
668 (save-excursion
|
|
669 (message (car gdb-last-frame))
|
|
670 (set-buffer (find-file-noselect (car gdb-last-frame)))
|
|
671 (gdb-clear)))
|
|
672
|
|
673 (provide 'gdb)
|
72
|
674
|
|
675 ;;; gdb.el ends here
|