annotate lisp/comint/gdb.el @ 72:b9518feda344 r20-0b31

Import from CVS: tag r20-0b31
author cvs
date Mon, 13 Aug 2007 09:03:46 +0200
parents 131b0175ea99
children c7528f8e288d
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defun gdb-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Major mode for interacting with an inferior Gdb process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 The following commands are available:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 \\{gdb-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 \\[gdb-display-frame] displays in the other window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 the last line referred to in the gdb buffer. See also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 \\[gdb-display-mode].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 \\[gdb-step],\\[gdb-next], and \\[gdb-nexti] in the gdb window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 call gdb to step,next or nexti and then update the other window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 with the current file and position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 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
233 at, by doing \\[gdb-break].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 Many commands are inherited from comint mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 Additionally we have:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 \\[gdb-display-frame] display frames file in other window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 \\[gdb-step] advance one line in program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 \\[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
242 C-x SPACE sets break point at current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (comint-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (use-local-map gdb-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (set-syntax-table c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (make-local-variable 'gdb-last-frame-displayed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (make-local-variable 'gdb-last-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (make-local-variable 'gdb-delete-prompt-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (make-local-variable 'gdb-display-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (make-local-variable' gdb-filter-accumulator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (setq gdb-last-frame nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 gdb-delete-prompt-marker nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 gdb-filter-accumulator nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 gdb-display-mode t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 major-mode 'gdb-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 mode-name "Inferior GDB"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 comint-prompt-regexp gdb-prompt-pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 gdb-last-frame-displayed-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (set (make-local-variable 'shell-dirtrackp) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;(make-local-variable 'gdb-arrow-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (and (extentp gdb-arrow-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (delete-extent gdb-arrow-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (setq gdb-arrow-extent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; XEmacs change:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (make-local-hook 'kill-buffer-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (add-hook 'kill-buffer-hook 'gdb-delete-arrow-extent nil t)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 22
diff changeset
268 (setq comint-input-sentinel 'shell-directory-tracker)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (run-hooks 'gdb-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (defun gdb-delete-arrow-extent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (if gdb-arrow-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (delete-extent gdb-arrow-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setq gdb-arrow-extent nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (defvar current-gdb-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (defvar gdb-command-name "gdb"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 "Pathname for executing gdb.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (defun gdb (path &optional corefile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 "Run gdb on program FILE in buffer *gdb-FILE*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 The directory containing FILE becomes the initial working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 and source-file directory for GDB. If you wish to change this, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 the GDB commands `cd DIR' and `directory'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (interactive "FRun gdb on file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq path (file-truename (expand-file-name path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (let ((file (file-name-nondirectory path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (switch-to-buffer (concat "*gdb-" file "*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (setq default-directory (file-name-directory path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (or (bolp) (newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (insert "Current directory is " default-directory "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (apply 'make-comint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (concat "gdb-" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (substitute-in-file-name gdb-command-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 "-fullname"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 "-cd" default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (and corefile (list corefile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (set-process-filter (get-buffer-process (current-buffer)) 'gdb-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (set-process-sentinel (get-buffer-process (current-buffer)) 'gdb-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; XEmacs change: turn on gdb mode after setting up the proc filters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;; for the benefit of shell-font.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (gdb-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (gdb-set-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;;;####autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defun gdb-with-core (file corefile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 "Debug a program using a corefile."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (interactive "fProgram to debug: \nfCore file to use: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (gdb file corefile))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defun gdb-set-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (cond ((eq major-mode 'gdb-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq current-gdb-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (if (featurep 'eos-toolbar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (set-specifier default-toolbar (cons (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 gdb-toolbar))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ;; This function is responsible for inserting output from GDB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;; into the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ;; Aside from inserting the text, it notices and deletes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; each filename-and-line-number;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; that GDB prints to identify the selected frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; It records the filename and line number, and maybe displays that file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (defun gdb-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (save-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (if gdb-filter-accumulator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (gdb-filter-accumulate-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 proc (concat gdb-filter-accumulator string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (gdb-filter-scan-input proc string)))))
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-filter-accumulate-marker (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (setq gdb-filter-accumulator nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (if (> (length string) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (= (aref string 1) ?\032)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (let ((end (string-match "\n" string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (if end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (let* ((first-colon (string-match ":" string 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (second-colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (string-match ":" string (1+ first-colon))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (setq gdb-last-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (cons (substring string 2 first-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (substring string (1+ first-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 second-colon)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq gdb-last-frame-displayed-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (gdb-filter-scan-input proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (substring string (1+ end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq gdb-filter-accumulator string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (gdb-filter-insert proc "\032")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (gdb-filter-scan-input proc (substring string 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (setq gdb-filter-accumulator 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-scan-input (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (if (equal string "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (setq gdb-filter-accumulator nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (let ((start (string-match "\032" string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (if start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (progn (gdb-filter-insert proc (substring string 0 start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (gdb-filter-accumulate-marker proc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (substring string start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (gdb-filter-insert proc string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (defun gdb-filter-insert (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (let ((moving (= (point) (process-mark proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (output-after-point (< (point) (process-mark proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; Insert the text, moving the process-marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (insert-before-markers string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (set-marker (process-mark proc) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (gdb-maybe-delete-prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ;; Check for a filename-and-line number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (gdb-display-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; Don't display the specified file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;; unless (1) point is at or after the position where output appears
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; and (2) this buffer is on the screen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (or output-after-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (not (get-buffer-window (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;; Display a file only when a new filename-and-line-number appears.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (if moving (goto-char (process-mark proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (let (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if (and (should-use-dialog-box-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (setq s (or (string-match " (y or n) *\\'" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (string-match " (yes or no) *\\'" string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (gdb-mouse-prompt-hack (substring string 0 s) (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defun gdb-mouse-prompt-hack (prompt buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (popup-dialog-box
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (list prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (vector "Yes" (list 'gdb-mouse-prompt-hack-answer 't buffer) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (vector "No" (list 'gdb-mouse-prompt-hack-answer 'nil buffer) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (vector "Cancel" (list 'gdb-mouse-prompt-hack-answer 'nil buffer) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun gdb-mouse-prompt-hack-answer (answer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (let ((b (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (goto-char (process-mark (get-buffer-process buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (insert (if answer "yes" "no"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (comint-send-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (set-buffer b))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defun gdb-sentinel (proc msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (cond ((null (buffer-name (process-buffer proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;; buffer killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Stop displaying an arrow in a source file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;(setq overlay-arrow-position nil) -- done by kill-buffer-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (set-process-buffer proc nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ((memq (process-status proc) '(signal exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;; Stop displaying an arrow in a source file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (gdb-delete-arrow-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ;; Fix the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq modeline-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (concat ": gdb " (symbol-name (process-status proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let* ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; save-excursion isn't the right thing if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;; process-buffer is current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ;; Write something in *compilation* and hack its mode line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ;; Force mode line redisplay soon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (insert ?\n mode-name " " msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (insert ?\n mode-name " " msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; If buffer and mode line will show that the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; is dead, we can delete it now. Otherwise it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; will stay around until M-x list-processes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (delete-process proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;; Restore old buffer, but don't restore old point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;; if obuf is the gdb buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (set-buffer obuf))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (defun gdb-refresh (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 "Fix up a possibly garbled display, and redraw the arrow."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (recenter arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (gdb-display-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (defun gdb-display-frame (&optional nodisplay noauto)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 "Find, obey and delete the last filename-and-line marker from GDB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 The marker looks like \\032\\032FILENAME:LINE:CHARPOS\\n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 Obeying it means displaying in another window the specified file and line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (gdb-set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (and gdb-last-frame (not nodisplay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 gdb-display-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (or (not gdb-last-frame-displayed-p) (not noauto))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (progn (gdb-display-line (car gdb-last-frame) (cdr gdb-last-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (setq gdb-last-frame-displayed-p t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; 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
474 ;; and that its line LINE is visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; Put the overlay-arrow on the line LINE in that buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (defun gdb-display-line (true-file line &optional select-method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; FILE to display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; LINE number to highlight and make visible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; SELECT-METHOD 'source, 'debugger, or 'none. (default is 'debugger)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (and (null select-method) (setq select-method 'debugger))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (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
483 (pop-up-windows t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (source-buffer (find-file-noselect true-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (source-window (display-buffer source-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (debugger-window (get-buffer-window current-gdb-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (extent gdb-arrow-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; XEmacs change: make sure we find a window displaying the source file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; even if we are already sitting in it when a breakpoint is hit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;; Otherwise the t argument to display-buffer will prevent it from being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;; displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (cond ((eq select-method 'debugger)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 ;; might not already be displayed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (setq debugger-window (display-buffer current-gdb-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (select-window debugger-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ((eq select-method 'source)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (select-window source-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (and extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (not (eq (extent-object extent) source-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq extent (delete-extent extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (or extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (setq extent (make-extent 1 1 source-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (set-extent-face extent 'gdb-arrow-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (set-extent-begin-glyph extent gdb-arrow-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (set-extent-begin-glyph-layout extent 'whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (set-extent-priority extent 2000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (setq gdb-arrow-extent extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (save-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (set-buffer source-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (goto-line line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (set-window-point source-window (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (setq pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (set-extent-endpoints extent pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (run-hook-with-args 'gdb-arrow-extent-hooks extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (cond ((or (< pos (point-min)) (> pos (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (goto-char pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;; Added by Stig. It caused lots of problems for several users
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; and since its purpose is unclear it is getting commented out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;;(and debugger-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; (set-window-point debugger-window pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (defun gdb-call (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 "Invoke gdb COMMAND displaying source in other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; Record info on the last prompt in the buffer and its position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;; This is used in gdb-maybe-delete-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;; to prevent multiple prompts from accumulating.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (goto-char (process-mark (get-buffer-process current-gdb-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (let ((pt (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (setq gdb-delete-prompt-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (if (= (point) pt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (list (point-marker) (- pt (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (buffer-substring (point) pt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (gdb-set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (process-send-string (get-buffer-process current-gdb-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (concat command "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defun gdb-maybe-delete-prompt ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (if gdb-delete-prompt-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;; Get the string that we used as the prompt before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (let ((prompt (nth 2 gdb-delete-prompt-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (length (nth 1 gdb-delete-prompt-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;; Position after it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (goto-char (+ (car gdb-delete-prompt-marker) length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; Delete any duplicates of it which follow right after.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (while (and (<= (+ (point) length) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (string= prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (buffer-substring (point) (+ (point) length))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (delete-region (point) (+ (point) length)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; If that didn't take us to where output is arriving,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; we have encountered something other than a prompt,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 ;; so stop trying to delete any more prompts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (if (not (= (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (process-mark (get-buffer-process current-gdb-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (set-marker (car gdb-delete-prompt-marker) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (setq gdb-delete-prompt-marker nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (defun gdb-break (temp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 "Set GDB breakpoint at this source line. With ARG set temporary breakpoint."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (let* ((file-name (file-name-nondirectory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (line (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (1+ (count-lines 1 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (cmd (concat (if temp "tbreak " "break ") file-name ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (int-to-string line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (set-buffer current-gdb-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (goto-char (process-mark (get-buffer-process current-gdb-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (insert cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (comint-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;;(process-send-string (get-buffer-process current-gdb-buffer) cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (defun gdb-clear ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 "Set GDB breakpoint at this source line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (let* ((file-name (file-name-nondirectory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (line (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (1+ (count-lines 1 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (cmd (concat "clear " file-name ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (int-to-string line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (set-buffer current-gdb-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (goto-char (process-mark (get-buffer-process current-gdb-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (delete-region (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (insert cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (comint-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ;;(process-send-string (get-buffer-process current-gdb-buffer) cmd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (defun gdb-read-address()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 "Return a string containing the core-address found in the buffer at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (let ((pt (point)) found begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (setq found (if (search-backward "0x" (- pt 7) t)(point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (cond (found (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (buffer-substring found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (progn (re-search-forward "[^0-9a-f]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (t (setq begin (progn (re-search-backward "[^0-9]") (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (re-search-forward "[^0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (buffer-substring begin (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (defvar gdb-commands nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 "List of strings or functions used by send-gdb-command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 It is for customization by you.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defun send-gdb-command (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 "This command reads the number where the cursor is positioned. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 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
633 selects the ARG'th member COMMAND of the list gdb-print-command. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 COMMAND is a string, (format COMMAND ADDR) is inserted, otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (funcall COMMAND ADDR) is inserted. eg. \"p (rtx)%s->fld[0].rtint\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 is a possible string to be a member of gdb-commands. "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (let (comm addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (if arg (setq comm (nth arg gdb-commands)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (setq addr (gdb-read-address))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (if (eq (current-buffer) current-gdb-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (set-mark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (cond (comm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (setq comm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (stringp comm) (format comm addr) (funcall comm addr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (t (setq comm addr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (switch-to-buffer current-gdb-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (insert comm)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 22
diff changeset
653 (defun gdb-control-c-subjob ()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 22
diff changeset
654 "Send a Control-C to the subprocess."
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 22
diff changeset
655 (interactive)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 22
diff changeset
656 (process-send-string (get-buffer-process (current-buffer))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 22
diff changeset
657 "\C-c"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (defun gdb-toolbar-break ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (message (car gdb-last-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (set-buffer (find-file-noselect (car gdb-last-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (gdb-break nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (defun gdb-toolbar-clear ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (message (car gdb-last-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (set-buffer (find-file-noselect (car gdb-last-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (gdb-clear)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (provide 'gdb)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
674
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
675 ;;; gdb.el ends here