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