annotate lisp/utils/find-gc.el @ 172:a38aed19690b

Added tag r20-3b12 for changeset 929b76928fce
author cvs
date Mon, 13 Aug 2007 09:47:55 +0200
parents 0293115a14e9
children
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 ;;; find-gc.el --- detect functions that call the garbage collector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: maint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
23 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; #### before this is really usable, it should be rewritten to call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Makefile to compile the files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Produce in unsafe-list the set of all functions that may invoke GC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; This expects the Emacs sources to live in emacs-source-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; It creates a temporary working directory /tmp/esrc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Set this to point to your XEmacs source directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (setq emacs-source-directory "/net/prosper/opt/xemacs/editor/src")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Set this to the include directories neeed for compilation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (setq include-directives "-I/net/prosper/opt/xemacs/editor/src -I/usr/dt/include -I/net/prosper/opt/SUNWmotif/include -I/net/prosper/opt/xemacs/editor/import/xpm/include -I/net/prosper/opt/xemacs/editor/import/include -I/usr/demo/SOUND/include -I/usr/openwin/include -I/usr/openwin/include/desktop -I/usr/openwin/include/desktop -I/net/prosper/opt/xemacs/editor/src/../lwlib -g -v -DNeedFunctionPrototypes -xildoff -I/usr/dt/include -I/net/prosper/opt/SUNWmotif/include -I/net/prosper/opt/xemacs/editor/import/xpm/include -I/net/prosper/opt/xemacs/editor/import/include -I/usr/demo/SOUND/include -I/usr/demo/SOUND/include")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; Set this to the source files you want to check.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (setq source-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 "EmacsFrame.c" "EmacsManager.c" "EmacsShell.c" "abbrev.c" "alloc.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "blocktype.c" "buffer.c" "bytecode.c" "callint.c" "callproc.c" "casefiddle.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 "casetab.c" "cm.c" "cmds.c" "data.c" "debug.c" "device-stream.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 "device-tty.c" "device-x.c" "device.c" "dired.c" "doc.c" "doprnt.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "dynarr.c""editfns.c" "elhash.c" "emacs.c" "eval.c" "event-Xt.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "event-stream.c" "event-tty.c" "events.c" "extents.c" "faces.c" "fileio.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "filelock.c" "filemode.c" "floatfns.c" "fns.c" "font-lock.c" "frame-tty.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 "frame-x.c" "frame.c" "getloadavg.c" "glyphs.c" "gmalloc.c" "hash.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 "indent.c" "insdel.c" "intl.c" "keyboard.c" "keymap.c" "lastfile.c" "lread.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 "lstream.c" "macros.c" "marker.c" "md5.c" "menubar-x.c" "menubar.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "minibuf.c" "objects-x.c" "objects.c" "opaque.c" "print.c" "process.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "pure.c" "redisplay-output.c" "redisplay-tty.c" "redisplay-x.c" "redisplay.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 "regex.c" "scrollbar.c" "search.c" "sound.c" "specifier.c" "sunplay.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "sunpro.c" "symbols.c" "syntax.c" "sysdep.c" "terminfo.c" "toolbar-x.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "toolbar.c" "tooltalk.c" "undo.c" "unexsol2.c" "vm-limit.c" "window.c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "xgccache.c" "xselect.c"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defun find-gc-unsafe ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (trace-call-tree nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (trace-use-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (find-unsafe-funcs 'Fgarbage_collect)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (setq unsafe-list (sort unsafe-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (function (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (string-lessp (car x) (car y))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (princ (format "%s\n" unsafe-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (setq unsafe-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (find-unsafe-funcs 'Fgarbage_collect_1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq unsafe-list (sort unsafe-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (function (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (string-lessp (car x) (car y))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (princ (format "%s\n" unsafe-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;; This does a depth-first search to find all functions that can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;; ultimately call the function "target". The result is an a-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; in unsafe-list; the cars are the unsafe functions, and the cdrs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; are (one of) the unsafe functions that these functions directly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun find-unsafe-funcs (target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq unsafe-list (list (list target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (trace-unsafe target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defun trace-unsafe (func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let ((used (assq func subrs-used)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (or used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (error "No subrs-used for %s" (car unsafe-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (while (setq used (cdr used))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (or (assq (car used) unsafe-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (memq (car used) noreturn-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (setq unsafe-list (cons (cons (car used) func) unsafe-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (trace-unsafe (car used)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;;; Functions on this list are safe, even if they appear to be able
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;; to call the target.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq noreturn-list '( signal_error error Fthrow wrong_type_argument ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;; This produces an a-list of functions in subrs-called. The cdr of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;; each entry is a list of functions which the function in car calls.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defun trace-call-tree (&optional already-setup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (or already-setup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (princ (format "Setting up directories...\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; Gee, wouldn't a built-in "system" function be handy here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (call-process "sh" nil nil nil "-c" "rm -rf /tmp/esrc")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (call-process "sh" nil nil nil "-c" "mkdir /tmp/esrc")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (call-process "sh" nil nil nil "-c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (format "ln -s %s/*.[ch] /tmp/esrc"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 emacs-source-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (set-buffer (get-buffer-create "*Trace Call Tree*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq subrs-called nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (let ((case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (files source-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 name entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (while files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (princ (format "Compiling %s...\n" (car files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (call-process "sh" nil nil nil "-c"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (format "cd /tmp/esrc; gcc -dr -c %s /tmp/esrc/%s -o /dev/null"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 include-directives (car files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (insert-file-contents (concat "/tmp/esrc/" (car files) ".rtl"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (while (re-search-forward ";; Function \\|(call_insn " nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (if (= (char-after (- (point) 3)) ?o)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (looking-at "[a-zA-Z0-9_]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (setq name (intern (buffer-substring (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (princ (format "%s : %s\n" (car files) name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq entry (list name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 subrs-called (cons entry subrs-called)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (if (looking-at ".*\n?.*\"\\([A-Za-z0-9_]+\\)\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq name (intern (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (match-end 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (or (memq name (cdr entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setcdr entry (cons name (cdr entry))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;;(delete-file (concat "/tmp/esrc/" (car files) ".rtl"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq files (cdr files))))))
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 ;;; This produces an inverted a-list in subrs-used. The cdr of each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;; entry is a list of functions that call the function in car.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defun trace-use-tree ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq subrs-used (mapcar 'list (mapcar 'car subrs-called)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (let ((ptr subrs-called)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 p2 found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (while ptr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq p2 (car ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (while (setq p2 (cdr p2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (setq found (assq (car p2) subrs-used))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setcdr found (cons (car (car ptr)) (cdr found)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq ptr (cdr ptr)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;; find-gc.el ends here