annotate lisp/comint/gdb.el @ 171:929b76928fce r20-3b12

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