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