xref: /386bsd/usr/local/lib/emacs/19.25/etc/DEBUG (revision a2142627)
1Debugging GNU Emacs
2Copyright (c) 1985 Richard M. Stallman.
3
4   Permission is granted to anyone to make or distribute verbatim copies
5   of this document as received, in any medium, provided that the
6   copyright notice and permission notice are preserved,
7   and that the distributor grants the recipient permission
8   for further redistribution as permitted by this notice.
9
10   Permission is granted to distribute modified versions
11   of this document, or of portions of it,
12   under the above conditions, provided also that they
13   carry prominent notices stating who last changed them.
14
15On 4.2 you will probably find that dbx does not work for
16debugging GNU Emacs.  For one thing, dbx does not keep the
17inferior process's terminal modes separate from its own.
18For another, dbx does not put the inferior in a separate
19process group, which makes trouble when an inferior uses
20interrupt input, which GNU Emacs must do on 4.2.
21
22dbx has also been observed to have other problems,
23such as getting incorrect values for register variables
24in stack frames other than the innermost one.
25
26The Emacs distribution now contains GDB, the new source-level
27debugger for the GNU system.  GDB works for debugging Emacs.
28GDB currently runs on vaxes under 4.2 and on Sun 2 and Sun 3
29systems.
30
31
32** Some useful techniques
33
34`Fsignal' is a very useful place to stop in.
35All Lisp errors go through there.
36
37It is useful, when debugging, to have a guaranteed way
38to return to the debugger at any time.  If you are using
39interrupt-driven input, which is the default, then Emacs is using
40RAW mode and the only way you can do it is to store
41the code for some character into the variable stop_character:
42
43    set stop_character = 29
44
45makes Control-] (decimal code 29) the stop character.
46Typing Control-] will cause immediate stop.  You cannot
47use the set command until the inferior process has been started.
48Put a breakpoint early in `main', or suspend the Emacs,
49to get an opportunity to do the set command.
50
51If you are using cbreak input (see the Lisp function set-input-mode),
52then typing Control-g will cause a SIGINT, which will return control
53to the debugger immediately unless you have done
54
55    ignore 3  (in dbx)
56or  handle 3 nostop noprint  (in gdb)
57
58You will note that most of GNU Emacs is written to avoid
59declaring a local variable in an inner block, even in
60cases where using one would be the cleanest thing to do.
61This is because dbx cannot access any of the variables
62in a function which has even one variable defined in an
63inner block.  A few functions in GNU Emacs do have variables
64in inner blocks, only because I wrote them before realizing
65that dbx had this problem and never rewrote them to avoid it.
66
67I believe that GDB does not have such a problem.
68
69
70** If GDB does not run and your debuggers can't load Emacs.
71
72On some systems, no debugger can load Emacs with a symbol table,
73perhaps because they all have fixed limits on the number of symbols
74and Emacs exceeds the limits.  Here is a method that can be used
75in such an extremity.  Do
76
77    nm -n temacs > nmout
78    strip temacs
79    adb temacs
80    0xd:i
81    0xe:i
82    14:i
83    17:i
84    :r -l loadup   (or whatever)
85
86It is necessary to refer to the file `nmout' to convert
87numeric addresses into symbols and vice versa.
88
89It is useful to be running under a window system.
90Then, if Emacs becomes hopelessly wedged, you can create
91another window to do kill -9 in.  kill -ILL is often
92useful too, since that may make Emacs dump core or return
93to adb.
94
95
96** Debugging incorrect screen updating.
97
98To debug Emacs problems that update the screen wrong, it is useful
99to have a record of what input you typed and what Emacs sent to the
100screen.  To make these records, do
101
102(open-dribble-file "~/.dribble")
103(open-termscript "~/.termscript")
104
105The dribble file contains all characters read by Emacs from the
106terminal, and the termscript file contains all characters it sent to
107the terminal.  The use of the directory `~/' prevents interference
108with any other user.
109
110If you have irreproducible display problems, put those two expressions
111in your ~/.emacs file.  When the problem happens, exit the Emacs that
112you were running, kill it, and rename the two files.  Then you can start
113another Emacs without clobbering those files, and use it to examine them.
114