Mercurial > emacs
annotate lisp/emacs-lisp/find-gc.el @ 65953:0f60854c0845
(gud-last-speedbar-buffer): Remove.
(gud-install-speedbar-variables): Add GUD to speedbar "Displays"
list.
(gud-expansion-speedbar-buttons): New function.
(gud-speedbar-buttons): Check for gud-comint-buffer.
author | Nick Roberts <nickrob@snap.net.nz> |
---|---|
date | Sun, 09 Oct 2005 20:22:43 +0000 |
parents | 5b1a238fcbb4 |
children | 067115a6e738 2d92f5c9d6ae |
rev | line source |
---|---|
39027 | 1 ;;; find-gc.el --- detect functions that call the garbage collector |
2 | |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64403
diff
changeset
|
3 ;; Copyright (C) 1992, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
39027 | 4 |
5 ;; Maintainer: FSF | |
6 | |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
22 ;; Boston, MA 02110-1301, USA. | |
39027 | 23 |
24 ;;; Commentary: | |
25 | |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
26 ;; Produce in find-gc-unsafe-list the set of all functions that may invoke GC. |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
27 ;; This expects the Emacs sources to live in find-gc-source-directory. |
39027 | 28 ;; It creates a temporary working directory /tmp/esrc. |
29 | |
30 ;;; Code: | |
31 | |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
32 (defvar find-gc-unsafe-list nil |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
33 "The list of unsafe functions is placed here by `find-gc-unsafe'.") |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
34 |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
35 (defvar find-gc-source-directory) |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
36 |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
37 (defvar find-gc-subrs-callers nil |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
38 "Alist of users of subrs, from GC testing. |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
39 Each entry has the form (FUNCTION . FUNCTIONS-THAT-CALL-IT).") |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
40 |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
41 (defvar find-gc-subrs-called nil |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
42 "Alist of subrs called, in GC testing. |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
43 Each entry has the form (FUNCTION . FUNCTIONS-IT-CALLS).") |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
44 |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
45 |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
46 ;;; Functions on this list are safe, even if they appear to be able |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
47 ;;; to call the target. |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
48 |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
49 (defvar find-gc-noreturn-list '(Fsignal Fthrow wrong_type_argument)) |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
50 |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
51 ;;; This was originally generated directory-files, but there were |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
52 ;;; too many files there that were not actually compiled. The |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
53 ;;; list below was created for a HP-UX 7.0 system. |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
54 |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
55 (defvar find-gc-source-files |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
56 '("dispnew.c" "scroll.c" "xdisp.c" "window.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
57 "term.c" "cm.c" "emacs.c" "keyboard.c" "macros.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
58 "keymap.c" "sysdep.c" "buffer.c" "filelock.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
59 "insdel.c" "marker.c" "minibuf.c" "fileio.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
60 "dired.c" "filemode.c" "cmds.c" "casefiddle.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
61 "indent.c" "search.c" "regex.c" "undo.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
62 "alloc.c" "data.c" "doc.c" "editfns.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
63 "callint.c" "eval.c" "fns.c" "print.c" "lread.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
64 "abbrev.c" "syntax.c" "unexec.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
65 "bytecode.c" "process.c" "callproc.c" "doprnt.c" |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
66 "x11term.c" "x11fns.c")) |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
67 |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
68 |
39027 | 69 (defun find-gc-unsafe () |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
70 "Return a list of unsafe functions--that is, which can call GC. |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
71 Also store it in `find-gc-unsafe'." |
39027 | 72 (trace-call-tree nil) |
73 (trace-use-tree) | |
74 (find-unsafe-funcs 'Fgarbage_collect) | |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
75 (setq find-gc-unsafe-list |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
76 (sort find-gc-unsafe-list |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
77 (function (lambda (x y) |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
78 (string-lessp (car x) (car y)))))) |
39027 | 79 ) |
80 | |
81 ;;; This does a depth-first search to find all functions that can | |
82 ;;; ultimately call the function "target". The result is an a-list | |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
83 ;;; in find-gc-unsafe-list; the cars are the unsafe functions, and the cdrs |
39027 | 84 ;;; are (one of) the unsafe functions that these functions directly |
85 ;;; call. | |
86 | |
87 (defun find-unsafe-funcs (target) | |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
88 (setq find-gc-unsafe-list (list (list target))) |
39027 | 89 (trace-unsafe target) |
90 ) | |
91 | |
92 (defun trace-unsafe (func) | |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
93 (let ((used (assq func find-gc-subrs-callers))) |
39027 | 94 (or used |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
95 (error "No find-gc-subrs-callers for %s" (car find-gc-unsafe-list))) |
39027 | 96 (while (setq used (cdr used)) |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
97 (or (assq (car used) find-gc-unsafe-list) |
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
98 (memq (car used) find-gc-noreturn-list) |
39027 | 99 (progn |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
100 (push (cons (car used) func) find-gc-unsafe-list) |
39027 | 101 (trace-unsafe (car used)))))) |
102 ) | |
103 | |
104 | |
105 | |
106 | |
107 (defun trace-call-tree (&optional already-setup) | |
108 (message "Setting up directories...") | |
109 (or already-setup | |
110 (progn | |
111 ;; Gee, wouldn't a built-in "system" function be handy here. | |
112 (call-process "csh" nil nil nil "-c" "rm -rf /tmp/esrc") | |
113 (call-process "csh" nil nil nil "-c" "mkdir /tmp/esrc") | |
114 (call-process "csh" nil nil nil "-c" | |
115 (format "ln -s %s/*.[ch] /tmp/esrc" | |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
116 find-gc-source-directory)))) |
39027 | 117 (save-excursion |
118 (set-buffer (get-buffer-create "*Trace Call Tree*")) | |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
119 (setq find-gc-subrs-called nil) |
39027 | 120 (let ((case-fold-search nil) |
64380
ce8784010c3c
(find-gc-unsafe-list, find-gc-source-directory, find-gc-subrs-used)
Richard M. Stallman <rms@gnu.org>
parents:
64085
diff
changeset
|
121 (files find-gc-source-files) |
39027 | 122 name entry) |
123 (while files | |
124 (message "Compiling %s..." (car files)) | |
125 (call-process "csh" nil nil nil "-c" | |
126 (format "gcc -dr -c /tmp/esrc/%s -o /dev/null" | |
127 (car files))) | |
128 (erase-buffer) | |
129 (insert-file-contents (concat "/tmp/esrc/" (car files) ".rtl")) | |
130 (while (re-search-forward ";; Function \\|(call_insn " nil t) | |
131 (if (= (char-after (- (point) 3)) ?o) | |
132 (progn | |
133 (looking-at "[a-zA-Z0-9_]+") | |
134 (setq name (intern (buffer-substring (match-beginning 0) | |
135 (match-end 0)))) | |
136 (message "%s : %s" (car files) name) | |
137 (setq entry (list name) | |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
138 find-gc-subrs-called (cons entry find-gc-subrs-called))) |
39027 | 139 (if (looking-at ".*\n?.*\"\\([A-Za-z0-9_]+\\)\"") |
140 (progn | |
141 (setq name (intern (buffer-substring (match-beginning 1) | |
142 (match-end 1)))) | |
143 (or (memq name (cdr entry)) | |
144 (setcdr entry (cons name (cdr entry)))))))) | |
145 (delete-file (concat "/tmp/esrc/" (car files) ".rtl")) | |
146 (setq files (cdr files))))) | |
147 ) | |
148 | |
149 | |
150 (defun trace-use-tree () | |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
151 (setq find-gc-subrs-callers (mapcar 'list (mapcar 'car find-gc-subrs-called))) |
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
152 (let ((ptr find-gc-subrs-called) |
39027 | 153 p2 found) |
154 (while ptr | |
155 (setq p2 (car ptr)) | |
156 (while (setq p2 (cdr p2)) | |
64403
db69241fec2b
(find-gc-subrs-callers): Renamed from find-gc-subrs-used.
Richard M. Stallman <rms@gnu.org>
parents:
64380
diff
changeset
|
157 (if (setq found (assq (car p2) find-gc-subrs-callers)) |
39027 | 158 (setcdr found (cons (car (car ptr)) (cdr found))))) |
159 (setq ptr (cdr ptr)))) | |
160 ) | |
161 | |
162 (provide 'find-gc) | |
163 | |
52401 | 164 ;;; arch-tag: 4a26a538-a008-40d9-a1ef-23bb6dbecef4 |
39027 | 165 ;;; find-gc.el ends here |