annotate lisp/eterm/tgud.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents 376386a54a3c
children 131b0175ea99
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 ;; Things to look at:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ; (gud-call "") in gud-send-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ; (defvar gud-last-last-frame nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ; term-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; tgud.el --- Grand Unified Debugger mode for gdb, sdb, dbx, or xdb
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; under Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; Version: 1.3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; Keywords: unix, tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; along with GNU Emacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; The ancestral gdb.el was by W. Schelter <wfs@rascal.ics.utexas.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; It was later rewritten by rms. Some ideas were due to Masanobu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Grand Unification (sdb/dbx support) by Eric S. Raymond <esr@thyrsus.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; The overloading code was then rewritten by Barry Warsaw <bwarsaw@cen.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; who also hacked the mode to use comint.el. Shane Hartman <shane@spr.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; added support for xdb (HPUX debugger). Rick Sladkey <jrs@world.std.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; wrote the GDB command completion code. Dave Love <d.love@dl.ac.uk>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; added the IRIX kluge and re-implemented the Mips-ish variant.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; Then hacked by Per Bothner <bothner@cygnus.com> to use term.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (require 'term)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (require 'etags)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; TGUD commands must be visible in C buffers visited by TGUD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defvar tgud-key-prefix "\C-x\C-a"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "Prefix of all TGUD commands valid in C buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (global-set-key (concat tgud-key-prefix "\C-l") 'tgud-refresh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (define-key ctl-x-map " " 'tgud-break) ;; backward compatibility hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; the overloading mechanism
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defun tgud-overload-functions (tgud-overload-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "Overload functions defined in TGUD-OVERLOAD-ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 This association list has elements of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (ORIGINAL-FUNCTION-NAME OVERLOAD-FUNCTION)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (function (lambda (p) (fset (car p) (symbol-function (cdr p)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 tgud-overload-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defun tgud-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (error "TGUD not properly entered"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defun tgud-marker-filter (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (error "TGUD not properly entered"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defun tgud-find-file (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (error "TGUD not properly entered"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; command definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; This macro is used below to define some basic debugger interface commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; Of course you may use `tgud-def' with any other debugger command, including
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; user defined ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; A macro call like (tgud-def FUNC NAME KEY DOC) expands to a form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; which defines FUNC to send the command NAME to the debugger, gives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; it the docstring DOC, and binds that function to KEY in the TGUD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; major mode. The function is also bound in the global keymap with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; TGUD prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defmacro tgud-def (func cmd key &optional doc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Define FUNC to be a command sending STR and bound to KEY, with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 optional doc string DOC. Certain %-escapes in the string arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 are interpreted specially if present. These are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 %f name (without directory) of current source file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 %d directory of current source file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 %l number of current source line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 %e text of the C lvalue or function-call expression surrounding point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 %a text of the hexadecimal address surrounding point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 %p prefix argument to the command (if any) as a number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 The `current' source file is the file of the current buffer (if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 we're in a C file) or the source file current at the last break or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 step (if we're in the TGUD buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 The `current' line is that of the current buffer (if we're in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 source file) or the source line number at the last break or step (if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 we're in the TGUD buffer)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (list 'progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (list 'defun func '(arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (or doc "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 '(interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (list 'tgud-call cmd 'arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (list 'define-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 '(current-local-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (concat "\C-c" key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (list 'quote func)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (if key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (list 'global-set-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (list 'concat 'tgud-key-prefix key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (list 'quote func)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; Used by tgud-refresh, which should cause tgud-display-frame to redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; the last frame, even if it's been called before and term-pending-frame has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; been set to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar tgud-last-last-frame nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; All debugger-specific information is collected here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; Here's how it works, in case you ever need to add a debugger to the mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; Each entry must define the following at startup:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;<name>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; term-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; tgud-<name>-massage-args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; tgud-<name>-marker-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; tgud-<name>-find-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; The job of the massage-args method is to modify the given list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; debugger arguments before running the debugger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; The job of the marker-filter method is to detect file/line markers in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; strings and set the global term-pending-frame to indicate what display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; action (if any) should be triggered by the marker. Note that only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; whatever the method *returns* is displayed in the buffer; thus, you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; can filter the debugger's output, interpreting some and passing on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; The job of the find-file method is to visit and return the buffer indicated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; by the car of tgud-tag-frame. This may be a file name, a tag name, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; something else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; gdb functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;; History of argument lists passed to gdb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defvar tgud-gdb-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (defun tgud-gdb-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (cons "-fullname" (cons file args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; Don't need to do anything, since term-mode does it for us.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; (This is so that you can run 'gdb -fullname' from a shell buffer.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun tgud-gdb-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defun tgud-gdb-find-file (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (find-file-noselect f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defvar gdb-minibuffer-local-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "Keymap for minibuffer prompting of gdb startup command.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (if gdb-minibuffer-local-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (setq gdb-minibuffer-local-map (copy-keymap minibuffer-local-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (define-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 gdb-minibuffer-local-map "\C-i" 'term-dynamic-complete-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defun tgdb (command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "Run gdb on program FILE in buffer *tgud-FILE*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 The directory containing FILE becomes the initial working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 and source-file directory for your debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (list (read-from-minibuffer "Run gdb (like this): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (if (consp tgud-gdb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (car tgud-gdb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "gdb ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 gdb-minibuffer-local-map nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 '(tgud-gdb-history . 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (tgud-overload-functions '((tgud-massage-args . tgud-gdb-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (tgud-marker-filter . tgud-gdb-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (tgud-find-file . tgud-gdb-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (tgud-common-init command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (tgud-def tgud-break "break %f:%l" "\C-b" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (tgud-def tgud-tbreak "tbreak %f:%l" "\C-t" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (tgud-def tgud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (tgud-def tgud-step "step %p" "\C-s" "Step one source line with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (tgud-def tgud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (tgud-def tgud-next "next %p" "\C-n" "Step one line (skip functions).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (tgud-def tgud-cont "cont" "\C-r" "Continue with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (tgud-def tgud-finish "finish" "\C-f" "Finish executing current function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (tgud-def tgud-up "up %p" "<" "Up N stack frames (numeric arg).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (tgud-def tgud-down "down %p" ">" "Down N stack frames (numeric arg).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (tgud-def tgud-print "print %e" "\C-p" "Evaluate C expression at point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (local-set-key "\C-i" 'tgud-gdb-complete-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (setq term-prompt-regexp "^(.*gdb[+]?) *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq paragraph-start term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (run-hooks 'gdb-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;; One of the nice features of GDB is its impressive support for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;; context-sensitive command completion. We preserve that feature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; in the TGUD buffer by using a GDB command designed just for Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;; The completion process filter indicates when it is finished.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (defvar tgud-gdb-complete-in-progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;; Since output may arrive in fragments we accumulate partials strings here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (defvar tgud-gdb-complete-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ;; We need to know how much of the completion to chop off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (defvar tgud-gdb-complete-break)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;; The completion list is constructed by the process filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (defvar tgud-gdb-complete-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defvar tgud-term-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (defun tgud-gdb-complete-command ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "Perform completion on the GDB command preceding point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 This is implemented using the GDB `complete' command which isn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 available with older versions of GDB."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (let* ((end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (command (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (and (looking-at term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (buffer-substring (point) end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 command-word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; Find the word break. This match will always succeed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (string-match "\\(\\`\\| \\)\\([^ ]*\\)\\'" command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq tgud-gdb-complete-break (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 command-word (substring command tgud-gdb-complete-break))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;; Temporarily install our filter function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (tgud-overload-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 '((tgud-marker-filter . tgud-gdb-complete-filter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ;; Issue the command to GDB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (tgud-basic-call (concat "complete " command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq tgud-gdb-complete-in-progress t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 tgud-gdb-complete-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 tgud-gdb-complete-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; Slurp the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (while tgud-gdb-complete-in-progress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (accept-process-output (get-buffer-process tgud-term-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; Restore the old filter function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (tgud-overload-functions '((tgud-marker-filter . tgud-gdb-marker-filter))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; Protect against old versions of GDB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (and tgud-gdb-complete-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (string-match "^Undefined command: \"complete\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (car tgud-gdb-complete-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (error "This version of GDB doesn't support the `complete' command."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; Sort the list like readline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq tgud-gdb-complete-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (sort tgud-gdb-complete-list (function string-lessp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; Remove duplicates.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (let ((first tgud-gdb-complete-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (second (cdr tgud-gdb-complete-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (while second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (string-equal (car first) (car second))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setcdr first (setq second (cdr second)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq first second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 second (cdr second)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; Let term handle the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (term-dynamic-simple-complete command-word tgud-gdb-complete-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; The completion process filter is installed temporarily to slurp the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; output of GDB up to the next prompt and build the completion list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (defun tgud-gdb-complete-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (setq string (concat tgud-gdb-complete-string string))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
288 (while (string-match "\r?\n" string)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq tgud-gdb-complete-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (cons (substring string tgud-gdb-complete-break (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 tgud-gdb-complete-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (setq string (substring string (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if (string-match term-prompt-regexp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (setq tgud-gdb-complete-in-progress nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (setq tgud-gdb-complete-string string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; sdb functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;;; History of argument lists passed to sdb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defvar tgud-sdb-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (defvar tgud-sdb-needs-tags (not (file-exists-p "/var"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 "If nil, we're on a System V Release 4 and don't need the tags hack.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (defvar tgud-sdb-lastfile nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (defun tgud-sdb-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (cons file args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (defun tgud-sdb-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;; System V Release 3.2 uses this format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 ((string-match "\\(^0x\\w* in \\|^\\|\n\\)\\([^:\n]*\\):\\([0-9]*\\):.*\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (substring string (match-beginning 2) (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (substring string (match-beginning 3) (match-end 3))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;; System V Release 4.0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 ((string-match "^\\(BREAKPOINT\\|STEPPED\\) process [0-9]+ function [^ ]+ in \\(.+\\)\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (setq tgud-sdb-lastfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (substring string (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ((and tgud-sdb-lastfile (string-match "^\\([0-9]+\\):" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 tgud-sdb-lastfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (substring string (match-beginning 1) (match-end 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (setq tgud-sdb-lastfile nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defun tgud-sdb-find-file (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (if tgud-sdb-needs-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (find-tag-noselect f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (find-file-noselect f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (defun tsdb (command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 "Run sdb on program FILE in buffer *tgud-FILE*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 The directory containing FILE becomes the initial working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 and source-file directory for your debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (list (read-from-minibuffer "Run sdb (like this): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if (consp tgud-sdb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (car tgud-sdb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 "sdb ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 '(tgud-sdb-history . 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (if (and tgud-sdb-needs-tags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (not (and (boundp 'tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (stringp tags-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (file-exists-p tags-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (error "The sdb support requires a valid tags table to work."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (tgud-overload-functions '((tgud-massage-args . tgud-sdb-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (tgud-marker-filter . tgud-sdb-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (tgud-find-file . tgud-sdb-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (tgud-common-init command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (tgud-def tgud-break "%l b" "\C-b" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (tgud-def tgud-tbreak "%l c" "\C-t" "Set temporary breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (tgud-def tgud-remove "%l d" "\C-d" "Remove breakpoint at current line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (tgud-def tgud-step "s %p" "\C-s" "Step one source line with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (tgud-def tgud-stepi "i %p" "\C-i" "Step one instruction with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (tgud-def tgud-next "S %p" "\C-n" "Step one line (skip functions).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (tgud-def tgud-cont "c" "\C-r" "Continue with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (tgud-def tgud-print "%e/" "\C-p" "Evaluate C expression at point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (setq term-prompt-regexp "\\(^\\|\n\\)\\*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (setq paragraph-start term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (run-hooks 'sdb-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;; dbx functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ;;; History of argument lists passed to dbx.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (defvar tgud-dbx-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (defun tgud-dbx-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (cons file args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (defun tgud-dbx-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if (or (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 "stopped in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 "signal .* in .* at line \\([0-9]*\\) in file \"\\([^\"]*\\)\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (setq term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (substring string (match-beginning 2) (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (substring string (match-beginning 1) (match-end 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; Functions for Mips-style dbx. Given the option `-emacs', documented in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; OSF1, not necessarily elsewhere, it produces markers similar to gdb's.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defvar tgud-mips-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (or (string-match "^mips-[^-]*-ultrix" system-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;; We haven't tested tgud on this system:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (string-match "^mips-[^-]*-riscos" system-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;; It's documented on OSF/1.3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (string-match "^mips-[^-]*-osf1" system-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (string-match "^alpha-[^-]*-osf" system-configuration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "Non-nil to assume the MIPS/OSF dbx conventions (argument `-emacs').")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (defun tgud-mipsdbx-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (cons "-emacs" (cons file args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; This is just like the gdb one except for the regexps since we need to cope
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;; with an optional breakpoint number in [] before the ^Z^Z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (defun tgud-mipsdbx-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (setq tgud-marker-acc (concat tgud-marker-acc string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (let ((output ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ;; Process all the complete markers in this chunk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (while (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;; This is like th gdb marker but with an optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ;; leading break point number like `[1] '
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 "[][ 0-9]*\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 tgud-marker-acc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ;; Extract the frame position from the marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (cons (substring tgud-marker-acc (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (string-to-int (substring tgud-marker-acc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;; Append any text before the marker to the output we're going
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; to return - we don't include the marker in this text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 output (concat output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (substring tgud-marker-acc 0 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; Set the accumulator to the remaining text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 tgud-marker-acc (substring tgud-marker-acc (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;; Does the remaining text look like it might end with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; beginning of another marker? If it does, then keep it in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;; tgud-marker-acc until we receive the rest of it. Since we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;; know the full marker regexp above failed, it's pretty simple to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; test for marker starts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (if (string-match "[][ 0-9]*\032.*\\'" tgud-marker-acc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; Everything before the potential marker start can be output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq output (concat output (substring tgud-marker-acc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; Everything after, we save, to combine with later input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (setq tgud-marker-acc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (substring tgud-marker-acc (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (setq output (concat output tgud-marker-acc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 tgud-marker-acc ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 output)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; The dbx in IRIX is a pain. It doesn't print the file name when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; stopping at a breakpoint (but you do get it from the `up' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; `down' commands...). The only way to extract the information seems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;; to be with a `file' command, although the current line number is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; available in $curline. Thus we have to look for output which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ;; appears to indicate a breakpoint. Then we prod the dbx sub-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; to output the information we want with a combination of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; `printf' and `file' commands as a pseudo marker which we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; recognise next time through the marker-filter. This would be like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; the gdb marker but you can't get the file name without a newline...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; Note that tgud-remove won't work since Irix dbx expects a breakpoint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; number rather than a line number etc. Maybe this could be made to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; work by listing all the breakpoints and picking the one(s) with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; correct line number, but life's too short.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; d.love@dl.ac.uk (Dave Love) can be blamed for this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defvar tgud-irix-p (string-match "^mips-[^-]*-irix" system-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 "Non-nil to assume the interface appropriate for IRIX dbx.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 This works in IRIX 4 and probably IRIX 5.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; (It's been tested in IRIX 4 and the output from dbx on IRIX 5 looks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;; the same.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; this filter is influenced by the xdb one rather than the gdb one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (defun tgud-irixdbx-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (let (result (case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if (or (string-match term-prompt-regexp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (string-match ".*\012" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (setq result (concat tgud-marker-acc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 tgud-marker-acc "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq tgud-marker-acc (concat tgud-marker-acc string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (if result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ;; look for breakpoint or signal indication e.g.:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 ;; [2] Process 1267 (pplot) stopped at [params:338 ,0x400ec0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ;; Process 1281 (pplot) stopped at [params:339 ,0x400ec8]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; Process 1270 (pplot) Floating point exception [._read._read:16 ,0x452188]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 "^\\(\\[[0-9]+] \\)?Process +[0-9]+ ([^)]*) [^[]+\\[[^]\n]*]\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; prod dbx into printing out the line number and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;; name in a form we can grok as below
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (process-send-string (get-buffer-process tgud-term-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 "printf \"\032\032%1d:\",$curline;file\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 ;; look for result of, say, "up" e.g.:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;; .pplot.pplot(0x800) ["src/pplot.f":261, 0x400c7c]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;; (this will also catch one of the lines printed by "where")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ((string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 "^[^ ][^[]*\\[\"\\([^\"]+\\)\":\\([0-9]+\\), [^]]+]\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (let ((file (substring result (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (if (file-exists-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (setq term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 result (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 result (match-beginning 2) (match-end 2)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ((string-match ; kluged-up marker as above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 "\032\032\\([0-9]*\\):\\(.*\\)\n" result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (let ((file (substring result (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (if (file-exists-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (setq term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 result (match-beginning 1) (match-end 1)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (setq result (substring result 0 (match-beginning 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (or result ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (defun tgud-dbx-find-file (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (find-file-noselect f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defun tdbx (command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 "Run dbx on program FILE in buffer *tgud-FILE*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 The directory containing FILE becomes the initial working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 and source-file directory for your debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (list (read-from-minibuffer "Run dbx (like this): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (if (consp tgud-dbx-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (car tgud-dbx-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 "dbx ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 '(tgud-dbx-history . 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (tgud-overload-functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (tgud-mips-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 '((tgud-massage-args . tgud-mipsdbx-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (tgud-marker-filter . tgud-mipsdbx-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (tgud-find-file . tgud-dbx-find-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (tgud-irix-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 '((tgud-massage-args . tgud-dbx-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (tgud-marker-filter . tgud-irixdbx-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (tgud-find-file . tgud-dbx-find-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 '((tgud-massage-args . tgud-dbx-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (tgud-marker-filter . tgud-dbx-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (tgud-find-file . tgud-dbx-find-file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (tgud-common-init command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (tgud-mips-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (tgud-def tgud-break "stop at \"%f\":%l"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 "\C-b" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (tgud-def tgud-finish "return" "\C-f" "Finish executing current function."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (tgud-irix-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (tgud-def tgud-break "stop at \"%d%f\":%l"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 "\C-b" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (tgud-def tgud-finish "return" "\C-f" "Finish executing current function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 ;; Make dbx give out the source location info that we need.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (process-send-string (get-buffer-process tgud-term-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 "printf \"\032\032%1d:\",$curline;file\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (tgud-def tgud-break "file \"%d%f\"\nstop at %l"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 "\C-b" "Set breakpoint at current line.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (tgud-def tgud-remove "clear %l" "\C-d" "Remove breakpoint at current line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (tgud-def tgud-step "step %p" "\C-s" "Step one line with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (tgud-def tgud-stepi "stepi %p" "\C-i" "Step one instruction with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (tgud-def tgud-next "next %p" "\C-n" "Step one line (skip functions).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (tgud-def tgud-cont "cont" "\C-r" "Continue with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (tgud-def tgud-up "up %p" "<" "Up (numeric arg) stack frames.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (tgud-def tgud-down "down %p" ">" "Down (numeric arg) stack frames.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (tgud-def tgud-print "print %e" "\C-p" "Evaluate C expression at point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (setq term-prompt-regexp "^[^)\n]*dbx) *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (setq paragraph-start term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (run-hooks 'dbx-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;;---ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 ;; xdb (HP PARISC debugger) functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;;; History of argument lists passed to xdb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (defvar tgud-xdb-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (defvar tgud-xdb-directories nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 "*A list of directories that xdb should search for source code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 If nil, only source files in the program directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 will be known to xdb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 The file names should be absolute, or relative to the directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 containing the executable being debugged.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (defun tgud-xdb-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (nconc (let ((directories tgud-xdb-directories)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (result nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (while directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (setq result (cons (car directories) (cons "-d" result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (setq directories (cdr directories)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (nreverse (cons file result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (defun tgud-xdb-file-name (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 "Transform a relative pathname to a full pathname in xdb mode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (let ((result nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (if (file-exists-p f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq result (expand-file-name f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (let ((directories tgud-xdb-directories))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (while directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (let ((path (concat (car directories) "/" f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (if (file-exists-p path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (setq result (expand-file-name path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 directories nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (setq directories (cdr directories)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 ;; xdb does not print the lines all at once, so we have to accumulate them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (defun tgud-xdb-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (let (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (if (or (string-match term-prompt-regexp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (string-match ".*\012" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (setq result (concat tgud-marker-acc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 tgud-marker-acc "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (setq tgud-marker-acc (concat tgud-marker-acc string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (if result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (if (or (string-match "\\([^\n \t:]+\\): [^:]+: \\([0-9]+\\):" result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (string-match "[^: \t]+:[ \t]+\\([^:]+\\): [^:]+: \\([0-9]+\\):"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (let ((line (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (substring result (match-beginning 2) (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (file (tgud-xdb-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (substring result (match-beginning 1) (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (setq term-pending-frame (cons file line))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (or result "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (defun tgud-xdb-find-file (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (let ((realf (tgud-xdb-file-name f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (if realf (find-file-noselect realf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defun txdb (command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 "Run xdb on program FILE in buffer *tgud-FILE*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 The directory containing FILE becomes the initial working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 and source-file directory for your debugger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 You can set the variable 'tgud-xdb-directories' to a list of program source
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 directories if your program contains sources from more than one directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (list (read-from-minibuffer "Run xdb (like this): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (if (consp tgud-xdb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (car tgud-xdb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 "xdb ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 '(tgud-xdb-history . 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (tgud-overload-functions '((tgud-massage-args . tgud-xdb-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (tgud-marker-filter . tgud-xdb-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (tgud-find-file . tgud-xdb-find-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (tgud-common-init command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (tgud-def tgud-break "b %f:%l" "\C-b" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (tgud-def tgud-tbreak "b %f:%l\\t" "\C-t"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 "Set temporary breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (tgud-def tgud-remove "db" "\C-d" "Remove breakpoint at current line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (tgud-def tgud-step "s %p" "\C-s" "Step one line with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (tgud-def tgud-next "S %p" "\C-n" "Step one line (skip functions).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (tgud-def tgud-cont "c" "\C-r" "Continue with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (tgud-def tgud-up "up %p" "<" "Up (numeric arg) stack frames.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (tgud-def tgud-down "down %p" ">" "Down (numeric arg) stack frames.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (tgud-def tgud-finish "bu\\t" "\C-f" "Finish executing current function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (tgud-def tgud-print "p %e" "\C-p" "Evaluate C expression at point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (setq term-prompt-regexp "^>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (setq paragraph-start term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (run-hooks 'xdb-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;; perldb functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;;; History of argument lists passed to perldb.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (defvar tgud-perldb-history nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (defun tgud-perldb-massage-args (file args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (cons "-d" (cons file (cons "-emacs" args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 ;; There's no guarantee that Emacs will hand the filter the entire
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ;; marker at once; it could be broken up across several strings. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ;; might even receive a big chunk with several markers in it. If we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;; receive a chunk of text which looks like it might contain the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;; beginning of a marker, we save it here between calls to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;; filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (defvar tgud-perldb-marker-acc "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (defun tgud-perldb-marker-filter (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (setq tgud-marker-acc (concat tgud-marker-acc string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (let ((output ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;; Process all the complete markers in this chunk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (while (string-match "\032\032\\([^:\n]*\\):\\([0-9]*\\):.*\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 tgud-marker-acc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (setq
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ;; Extract the frame position from the marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (cons (substring tgud-marker-acc (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (string-to-int (substring tgud-marker-acc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 ;; Append any text before the marker to the output we're going
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; to return - we don't include the marker in this text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 output (concat output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (substring tgud-marker-acc 0 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;; Set the accumulator to the remaining text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 tgud-marker-acc (substring tgud-marker-acc (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 ;; Does the remaining text look like it might end with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;; beginning of another marker? If it does, then keep it in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 ;; tgud-marker-acc until we receive the rest of it. Since we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ;; know the full marker regexp above failed, it's pretty simple to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; test for marker starts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (if (string-match "\032.*\\'" tgud-marker-acc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;; Everything before the potential marker start can be output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (setq output (concat output (substring tgud-marker-acc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 ;; Everything after, we save, to combine with later input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (setq tgud-marker-acc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (substring tgud-marker-acc (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (setq output (concat output tgud-marker-acc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 tgud-marker-acc ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 output)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (defun tgud-perldb-find-file (f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (find-file-noselect f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (defun tperldb (command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 "Run perldb on program FILE in buffer *tgud-FILE*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 The directory containing FILE becomes the initial working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 and source-file directory for your debugger."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (list (read-from-minibuffer "Run perldb (like this): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (if (consp tgud-perldb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (car tgud-perldb-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 "perl ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 nil nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 '(tgud-perldb-history . 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (tgud-overload-functions '((tgud-massage-args . tgud-perldb-massage-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (tgud-marker-filter . tgud-perldb-marker-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (tgud-find-file . tgud-perldb-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (tgud-common-init command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (tgud-def tgud-break "b %l" "\C-b" "Set breakpoint at current line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (tgud-def tgud-remove "d %l" "\C-d" "Remove breakpoint at current line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (tgud-def tgud-step "s" "\C-s" "Step one source line with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (tgud-def tgud-next "n" "\C-n" "Step one line (skip functions).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (tgud-def tgud-cont "c" "\C-r" "Continue with display.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ; (tgud-def tgud-finish "finish" "\C-f" "Finish executing current function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ; (tgud-def tgud-up "up %p" "<" "Up N stack frames (numeric arg).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ; (tgud-def tgud-down "down %p" ">" "Down N stack frames (numeric arg).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (tgud-def tgud-print "%e" "\C-p" "Evaluate perl expression at point.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (setq term-prompt-regexp "^ DB<[0-9]+> ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (setq paragraph-start term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (run-hooks 'perldb-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 ;; End of debugger-specific information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;;; When we send a command to the debugger via tgud-call, it's annoying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ;;; to see the command and the new prompt inserted into the debugger's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 ;;; buffer; we have other ways of knowing the command has completed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 ;;; If the buffer looks like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ;;; --------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 ;;; (gdb) set args foo bar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 ;;; (gdb) -!-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;;; --------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ;;; (the -!- marks the location of point), and we type `C-x SPC' in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ;;; source file to set a breakpoint, we want the buffer to end up like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ;;; this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;;; --------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;;; (gdb) set args foo bar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;;; Breakpoint 1 at 0x92: file make-docfile.c, line 49.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ;;; (gdb) -!-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 ;;; --------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 ;;; Essentially, the old prompt is deleted, and the command's output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 ;;; and the new prompt take its place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 ;;; Not echoing the command is easy enough; you send it directly using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ;;; process-send-string, and it never enters the buffer. However,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;;; getting rid of the old prompt is trickier; you don't want to do it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ;;; when you send the command, since that will result in an annoying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ;;; flicker as the prompt is deleted, redisplay occurs while Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;;; waits for a response from the debugger, and the new prompt is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ;;; inserted. Instead, we'll wait until we actually get some output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 ;;; from the subprocess before we delete the prompt. If the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;;; produced no output other than a new prompt, that prompt will most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ;;; likely be in the first chunk of output received, so we will delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ;;; the prompt and then replace it with an identical one. If the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;;; command produces output, the prompt is moving anyway, so the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 ;;; flicker won't be annoying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 ;;; So - when we want to delete the prompt upon receipt of the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ;;; chunk of debugger output, we position term-pending-delete-marker at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;;; the start of the prompt; the process filter will notice this, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 ;;; delete all text between it and the process output marker. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 ;;; term-pending-delete-marker points nowhere, we leave the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ;;; prompt alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (defvar term-pending-delete-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (defun tgud-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 "Major mode for interacting with an inferior debugger process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 You start it up with one of the commands M-x gdb, M-x sdb, M-x dbx,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 or M-x xdb. Each entry point finishes by executing a hook; `gdb-mode-hook',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 `sdb-mode-hook', `dbx-mode-hook' or `xdb-mode-hook' respectively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 After startup, the following commands are available in both the TGUD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 interaction buffer and any source buffer TGUD visits due to a breakpoint stop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 or step operation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 \\[tgud-break] sets a breakpoint at the current file and line. In the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 TGUD buffer, the current file and line are those of the last breakpoint or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 step. In a source buffer, they are the buffer's file and current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 \\[tgud-remove] removes breakpoints on the current file and line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 \\[tgud-refresh] displays in the source window the last line referred to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 in the tgud buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 \\[tgud-step], \\[tgud-next], and \\[tgud-stepi] do a step-one-line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 step-one-line (not entering function calls), and step-one-instruction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 and then update the source window with the current file and position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 \\[tgud-cont] continues execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 \\[tgud-print] tries to find the largest C lvalue or function-call expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 around point, and sends it to the debugger for value display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 The above commands are common to all supported debuggers except xdb which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 does not support stepping instructions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 Under gdb, sdb and xdb, \\[tgud-tbreak] behaves exactly like \\[tgud-break],
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 except that the breakpoint is temporary; that is, it is removed when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 execution stops on it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 Under gdb, dbx, and xdb, \\[tgud-up] pops up through an enclosing stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 frame. \\[tgud-down] drops back down through one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 If you are using gdb or xdb, \\[tgud-finish] runs execution to the return from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 the current function and stops.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 All the keystrokes above are accessible in the TGUD buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 with the prefix C-c, and in all buffers through the prefix C-x C-a.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 All pre-defined functions for which the concept make sense repeat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 themselves the appropriate number of times if you give a prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 You may use the `tgud-def' macro in the initialization hook to define other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 Other commands for interacting with the debugger process are inherited from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 term mode, which see."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (term-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (setq major-mode 'tgud-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (setq mode-name "Debugger")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (setq mode-line-process '(":%s"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (use-local-map (copy-keymap term-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (define-key (current-local-map) "\C-m" 'tgud-send-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (define-key (current-local-map) "\C-c\C-l" 'tgud-refresh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (make-local-variable 'term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (run-hooks 'tgud-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (defun tgud-send-input ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (let ((proc (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (if (not proc) (error "Current buffer has no process")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;; If input line is empty, use tgud-call to get prompt deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (if (and (= (point) (process-mark proc)) (= (point) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (tgud-call "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (term-send-input)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 ;; Chop STRING into words separated by SPC or TAB and return a list of them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (defun tgud-chop-words (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (let ((i 0) (beg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (len (length string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (words nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (if (memq (aref string i) '(?\t ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (setq words (cons (substring string beg i) words)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 beg (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (while (and (< beg len) (memq (aref string beg) '(?\t ? )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (setq beg (1+ beg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (setq i (1+ beg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (setq i (1+ i))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (if (< beg len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (setq words (cons (substring string beg) words)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (nreverse words)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ;; Perform initializations common to all debuggers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (defun tgud-common-init (command-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (let* ((words (tgud-chop-words command-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (program (car words))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (file-word (let ((w (cdr words)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (while (and w (= ?- (aref (car w) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (setq w (cdr w)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (car w)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (args (delq file-word (cdr words)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (file (and file-word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (expand-file-name (substitute-in-file-name file-word))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (filepart (and file-word (file-name-nondirectory file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (switch-to-buffer (concat "*tgud-" filepart "*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (and file-word (setq default-directory (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (or (bolp) (newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (insert "Current directory is " default-directory "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (apply 'make-term (concat "tgud-" filepart) program nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (if file-word (tgud-massage-args file args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (tgud-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 ;; Note the insertion about of the line giving the "Current directory"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 ;; is not known about by the terminal emulator, so clear the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;; current-row cache to avoid confusion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (setq term-current-row nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (set-process-filter (get-buffer-process (current-buffer)) 'tgud-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (set-process-sentinel (get-buffer-process (current-buffer)) 'tgud-sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (tgud-set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (defun tgud-set-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (cond ((eq major-mode 'tgud-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (setq tgud-term-buffer (current-buffer)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 ;; These functions are responsible for inserting output from your debugger
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 ;; into the buffer. The hard work is done by the method that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 ;; the value of tgud-marker-filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (defun tgud-filter (proc string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 ;; Here's where the actual buffer insertion is done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (let ((inhibit-quit t)) ;; ???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (term-emulate-terminal proc (tgud-marker-filter string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (defun tgud-sentinel (proc msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (cond ((null (buffer-name (process-buffer proc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 ;; buffer killed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 ;; Stop displaying an arrow in a source file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (setq overlay-arrow-position nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (set-process-buffer proc nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 ((memq (process-status proc) '(signal exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 ;; Stop displaying an arrow in a source file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (setq overlay-arrow-position nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 ;; Fix the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (setq mode-line-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (concat ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (symbol-name (process-status proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (let* ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; save-excursion isn't the right thing if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ;; process-buffer is current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; Write something in *compilation* and hack its mode line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (set-buffer (process-buffer proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ;; Force mode line redisplay soon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (set-buffer-modified-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (insert ?\n mode-name " " msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (insert ?\n mode-name " " msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;; If buffer and mode line will show that the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;; is dead, we can delete it now. Otherwise it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;; will stay around until M-x list-processes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (delete-process proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;; Restore old buffer, but don't restore old point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; if obuf is the tgud buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (set-buffer obuf))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (defun tgud-display-frame ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 "Find and obey the last filename-and-line marker from the debugger.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 Obeying it means displaying in another window the specified file and line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (if term-pending-frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (tgud-set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (term-display-buffer-line (tgud-visit-file (car term-pending-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (cdr term-pending-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (setq term-pending-frame nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ;;; The tgud-call function must do the right thing whether its invoking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;;; keystroke is from the TGUD buffer itself (via major-mode binding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;;; or a C buffer. In the former case, we want to supply data from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 ;;; term-pending-frame. Here's how we do it:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (defun tgud-format-command (str arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (let ((insource (not (eq (current-buffer) tgud-term-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (frame (or term-pending-frame tgud-last-last-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (while (and str (string-match "\\([^%]*\\)%\\([adeflp]\\)" str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (let ((key (string-to-char (substring str (match-beginning 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 subst)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 ((eq key ?f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (setq subst (file-name-nondirectory (if insource
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (car frame)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ((eq key ?d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (setq subst (file-name-directory (if insource
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (car frame)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ((eq key ?l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (setq subst (if insource
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (save-restriction (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (1+ (count-lines 1 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (cdr frame))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 ((eq key ?e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (setq subst (find-c-expr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ((eq key ?a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (setq subst (tgud-read-address)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ((eq key ?p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (setq subst (if arg (int-to-string arg) ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (setq result (concat result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (substring str (match-beginning 1) (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 subst)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (setq str (substring str (match-end 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;; There might be text left in STR when the loop ends.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 (concat result str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (defun tgud-read-address ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 "Return a string containing the core-address found in the buffer at point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (let ((pt (point)) found begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (setq found (if (search-backward "0x" (- pt 7) t) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (found (forward-char 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (buffer-substring found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (progn (re-search-forward "[^0-9a-f]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (t (setq begin (progn (re-search-backward "[^0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (re-search-forward "[^0-9]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (buffer-substring begin (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (defun tgud-call (fmt &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (let ((msg (tgud-format-command fmt arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (message "Command: %s" msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (sit-for 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (tgud-basic-call msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (defun tgud-basic-call (command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 "Invoke the debugger COMMAND displaying source in other window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (tgud-set-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (let ((proc (get-buffer-process tgud-term-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 ;; Arrange for the current prompt to get deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (set-buffer tgud-term-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (goto-char (process-mark proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (if (looking-at term-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (set-marker term-pending-delete-marker (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (term-send-invisible command proc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (defun tgud-refresh (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 "Fix up a possibly garbled display, and redraw the arrow."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (recenter arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (or term-pending-frame (setq term-pending-frame tgud-last-last-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (tgud-display-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ;;; Code for parsing expressions out of C code. The single entry point is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;;; find-c-expr, which tries to return an lvalue expression from around point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 ;;; The rest of this file is a hacked version of gdbsrc.el by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 ;;; Debby Ayers <ayers@asc.slb.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 ;;; Rich Schaefer <schaefer@asc.slb.com> Schlumberger, Austin, Tx.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (defun find-c-expr ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 "Returns the C expr that surrounds point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (let ((p) (expr) (test-expr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (setq p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (setq expr (expr-cur))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (setq test-expr (expr-prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (while (expr-compound test-expr expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (setq expr (cons (car test-expr) (cdr expr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (goto-char (car expr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (setq test-expr (expr-prev)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (setq test-expr (expr-next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (while (expr-compound expr test-expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (setq expr (cons (car expr) (cdr test-expr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (setq test-expr (expr-next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (buffer-substring (car expr) (cdr expr)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (defun expr-cur ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 "Returns the expr that point is in; point is set to beginning of expr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 The expr is represented as a cons cell, where the car specifies the point in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 the current buffer that marks the beginning of the expr and the cdr specifies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 the character after the end of the expr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (let ((p (point)) (begin) (end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (expr-backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (setq begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (expr-forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (if (>= p end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (setq begin p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (goto-char p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (expr-forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (cons begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (defun expr-backward-sexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 "Version of `backward-sexp' that catches errors."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (defun expr-forward-sexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 "Version of `forward-sexp' that catches errors."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (error t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (defun expr-prev ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 "Returns the previous expr, point is set to beginning of that expr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 The expr is represented as a cons cell, where the car specifies the point in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 the current buffer that marks the beginning of the expr and the cdr specifies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 the character after the end of the expr"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (let ((begin) (end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (expr-backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (setq begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (expr-forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (cons begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (defun expr-next ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 "Returns the following expr, point is set to beginning of that expr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 The expr is represented as a cons cell, where the car specifies the point in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 the current buffer that marks the beginning of the expr and the cdr specifies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 the character after the end of the expr."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (let ((begin) (end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (expr-forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (expr-forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (expr-backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (setq begin (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (cons begin end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (defun expr-compound-sep (span-start span-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 "Returns '.' for '->' & '.', returns ' ' for white space,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 returns '?' for other punctuation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (let ((result ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (while (< span-start span-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (setq syntax (char-syntax (char-after span-start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ((= syntax ? ) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ((= syntax ?.) (setq syntax (char-after span-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 ((= syntax ?.) (setq result ?.))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 ((and (= syntax ?-) (= (char-after (+ span-start 1)) ?>))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (setq result ?.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (setq span-start (+ span-start 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (t (setq span-start span-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (setq result ??)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (setq span-start (+ span-start 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (defun expr-compound (first second)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 "Non-nil if concatenating FIRST and SECOND makes a single C token.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 The two exprs are represented as a cons cells, where the car
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 specifies the point in the current buffer that marks the beginning of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 expr and the cdr specifies the character after the end of the expr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 Link exprs of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 Expr -> Expr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 Expr . Expr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 Expr (Expr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 Expr [Expr]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (Expr) Expr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 [Expr] Expr"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (let ((span-start (cdr first))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (span-end (car second))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (setq syntax (expr-compound-sep span-start span-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ((= (car first) (car second)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 ((= (cdr first) (cdr second)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 ((= syntax ?.) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 ((= syntax ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (setq span-start (char-after (- span-start 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (setq span-end (char-after span-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 ((= span-start ?) ) t )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ((= span-start ?] ) t )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ((= span-end ?( ) t )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 ((= span-end ?[ ) t )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (t nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (provide 'tgud)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ;;; tgud.el ends here