Initial git import
[sxemacs] / src / gdbinit
1 # -*- ksh -*-
2 # Copyright (C) 1998 Free Software Foundation, Inc.
3
4 # This file is part of SXEmacs
5
6 # SXEmacs is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # SXEmacs is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 # Author: Martin Buchholz
20
21 # Some useful commands for debugging emacs with gdb 4.16 or better.
22 #
23 # Since this file is called `.gdbinit', it will be read by gdb
24 # automatically when gdb is run in the build directory, which is where
25 # developers usually debug their SXEmacs.  You can also source this
26 # file from your ~/.gdbinit, if you like.
27 #
28 # Configure SXEmacs with --debug, and compile with -g.
29 #
30 # See also the question of the SXEmacs FAQ, titled
31 # "How to Debug a SXEmacs problem with a debugger".
32
33 # Some functions defined here require a running process, but most
34 # don't.  Considerable effort has been expended to this end.
35
36 # See the dbg_ C support code in src/alloc.c that allows the functions
37 # defined in this file to work correctly.
38
39 set print union off
40 set print pretty off
41
42 set $Lisp_Type_Int = -2
43
44 define decode_object
45   set $obj = (unsigned long) $arg0
46   if $obj & 1
47   # It's an int
48     set $val = $obj >> 1
49     set $type = $Lisp_Type_Int
50   else
51     set $type = $obj & dbg_typemask
52     if $type == Lisp_Type_Char
53       set $val = ($obj & dbg_valmask) >> dbg_gctypebits
54     else
55       # It's a record pointer
56       set $val = $obj
57     end
58   end
59
60   if $type == Lisp_Type_Record
61     set $lheader = ((struct lrecord_header *) $val)
62     set $lrecord_type = ($lheader->type)
63     set $imp = ((struct lrecord_implementation *) lrecord_implementations_table[(int) $lrecord_type])
64   else
65     set $lrecord_type = -1
66     set $lheader = -1
67     set $imp = -1
68   end
69 end
70
71 document decode_object
72 Usage: decode_object lisp_object
73 Extract implementation information from a Lisp Object.
74 Defines variables $val, $type and $imp.
75 end
76
77 define xint
78 decode_object $arg0
79 print ((long) $val)
80 end
81
82 define xtype
83   decode_object $arg0
84   if $type == $Lisp_Type_Int
85     echo int\n
86   else
87   if $type == Lisp_Type_Char
88     echo char\n
89   else
90     printf "record type: %s\n", $imp->name
91   end
92   end
93 end
94
95 document xtype
96 Usage: xtype lisp_object
97 Print the Lisp type of a lisp object.
98 end
99
100 define lisp-shadows
101   run -batch -vanilla -f list-load-path-shadows
102 end
103
104 document lisp-shadows
105 Usage: lisp-shadows
106 Run SXEmacs to check for lisp shadows
107 end
108
109 define environment-to-run-temacs
110   unset env EMACSLOADPATH
111   set env EMACSBOOTSTRAPLOADPATH=@abs_top_srcdir@/lisp/
112   set env EMACSBOOTSTRAPMODULEPATH=@abs_top_srcdir@/modules/
113 end
114
115 define run-temacs
116   environment-to-run-temacs
117   run -nd -batch -l @abs_top_srcdir@/lisp/loadup.el run-temacs -q
118 end
119
120 document run-temacs
121 Usage: run-temacs
122 Run temacs interactively, like SXEmacs.
123 Use this with debugging tools (like purify) that cannot deal with dumping,
124 or when temacs builds successfully, but SXEmacs does not.
125 end
126
127 define check-sxemacs
128   run -batch -l @abs_top_srcdir@/tests/automated/test-harness.el -f batch-test-emacs @abs_top_srcdir@/tests/automated
129 end
130
131 document check-sxemacs
132 Usage: check-sxemacs
133 Run the test suite.  Equivalent to 'make check'.
134 end
135
136 define check-temacs
137   environment-to-run-temacs
138   run -nd -batch -l @abs_top_srcdir@/lisp/loadup.el run-temacs -q -batch -l @abs_top_srcdir@/tests/automated/test-harness.el -f batch-test-emacs @abs_top_srcdir@/tests/automated
139 end
140
141 document check-temacs
142 Usage: check-temacs
143 Run the test suite on temacs.  Equivalent to 'make check-temacs'.
144 Use this with debugging tools (like purify) that cannot deal with dumping,
145 or when temacs builds successfully, but SXEmacs does not.
146 end
147
148 define update-elc
149   environment-to-run-temacs
150   run -nd -batch -l @abs_top_srcdir@/lisp/update-elc.el
151 end
152
153 document update-elc
154 Usage: update-elc
155 Run the core lisp byte compilation part of the build procedure.
156 Use when debugging temacs, not SXEmacs!
157 Use this when temacs builds successfully, but SXEmacs does not.
158 end
159
160 define dmp
161   environment-to-run-temacs
162   run -nd -batch -l @abs_top_srcdir@/lisp/loadup.el dump
163 end
164
165 document dmp
166 Usage: dmp
167 Run the dumping part of the build procedure.
168 Use when debugging temacs, not SXEmacs!
169 Use this when temacs builds successfully, but SXEmacs does not.
170 end
171
172 define ldp
173   printf "%s", "Lisp => "
174   call debug_print($arg0)
175 end
176
177 document ldp
178 Usage: ldp lisp_object
179 Print a Lisp Object value using the Lisp printer.
180 Requires a running SXEmacs process.
181 end
182
183 define lbt
184 call debug_backtrace()
185 end
186
187 document lbt
188 Usage: lbt
189 Print the current Lisp stack trace.
190 Requires a running SXEmacs process.
191 end
192
193
194 define leval
195 ldp Feval(Fcar(Fread_from_string(build_string($arg0),Qnil,Qnil)))
196 end
197
198 document leval
199 Usage: leval "SEXP"
200 Eval a lisp expression.
201 Requires a running SXEmacs process.
202
203 Example:
204 (gdb) leval "(+ 1 2)"
205 Lisp ==> 3
206 end
207
208
209 define wtype
210 print $arg0->core.widget_class->core_class.class_name
211 end
212
213 define xtname
214 print XrmQuarkToString(((Object)($arg0))->object.xrm_name)
215 end
216
217 # GDB's command language makes you want to ...
218
219 # define ptype
220 #   set $type_ptr = ($arg0 *) $val
221 #   print $type_ptr
222 #   print *$type_ptr
223 # end
224
225 define pstructtype
226   set $type_ptr = (struct $arg0 *) $val
227   print $type_ptr
228   print *$type_ptr
229 end
230
231 define pobj
232   decode_object $arg0
233   if $type == $Lisp_Type_Int
234     printf "Integer: %d\n", $val
235   else
236   if $type == Lisp_Type_Char
237     if $val > 32 && $val < 128
238       printf "Char: %c\n", $val
239     else
240       printf "Char: %d\n", $val
241     end
242   else
243   if $lrecord_type == lrecord_type_string
244     ptype Lisp_String
245   else
246   if $lrecord_type == lrecord_type_cons
247     ptype Lisp_Cons
248   else
249   if $lrecord_type == lrecord_type_symbol
250     ptype Lisp_Symbol
251     printf "Symbol name: %s\n", $type_ptr->name->data
252   else
253   if $lrecord_type == lrecord_type_vector
254     ptype Lisp_Vector
255     printf "Vector of length %d\n", $type_ptr->size
256     #print *($type_ptr->data) @ $type_ptr->size
257   else
258   if $lrecord_type == lrecord_type_bit_vector
259     ptype Lisp_Bit_Vector
260   else
261   if $lrecord_type == lrecord_type_buffer
262     pstructtype buffer
263   else
264   if $lrecord_type == lrecord_type_char_table
265     ptype Lisp_Char_Table
266   else
267   if $lrecord_type == lrecord_type_char_table_entry
268     ptype Lisp_Char_Table_Entry
269   else
270   if $lrecord_type == lrecord_type_charset
271     ptype Lisp_Charset
272   else
273   if $lrecord_type == lrecord_type_coding_system
274     ptype Lisp_Coding_System
275   else
276   if $lrecord_type == lrecord_type_color_instance
277     ptype Lisp_Color_Instance
278   else
279   if $lrecord_type == lrecord_type_command_builder
280     ptype command_builder
281   else
282   if $lrecord_type == lrecord_type_compiled_function
283     ptype Lisp_Compiled_Function
284   else
285   if $lrecord_type == lrecord_type_console
286     pstructtype console
287   else
288   if $lrecord_type == lrecord_type_database
289     ptype Lisp_Database
290   else
291   if $lrecord_type == lrecord_type_device
292     pstructtype device
293   else
294   if $lrecord_type == lrecord_type_event
295     ptype Lisp_Event
296   else
297   if $lrecord_type == lrecord_type_extent
298     pstructtype extent
299   else
300   if $lrecord_type == lrecord_type_extent_auxiliary
301     pstructtype extent_auxiliary
302   else
303   if $lrecord_type == lrecord_type_extent_info
304     pstructtype extent_info
305   else
306   if $lrecord_type == lrecord_type_face
307     ptype Lisp_Face
308   else
309   if $lrecord_type == lrecord_type_float
310     ptype Lisp_Float
311   else
312   if $lrecord_type == lrecord_type_font_instance
313     ptype Lisp_Font_Instance
314   else
315   if $lrecord_type == lrecord_type_frame
316     pstructtype frame
317   else
318   if $lrecord_type == lrecord_type_glyph
319     ptype Lisp_Glyph
320   else
321   if $lrecord_type == lrecord_type_gui_item
322     ptype Lisp_Gui_Item
323   else
324   if $lrecord_type == lrecord_type_hash_table
325     ptype Lisp_Hash_Table
326   else
327   if $lrecord_type == lrecord_type_image_instance
328     ptype Lisp_Image_Instance
329   else
330   if $lrecord_type == lrecord_type_keymap
331     ptype Lisp_Keymap
332   else
333   if $lrecord_type == lrecord_type_lcrecord_list
334     pstructtype lcrecord_list
335   else
336   if $lrecord_type == lrecord_type_ldap
337     ptype Lisp_LDAP
338   else
339   if $lrecord_type == lrecord_type_lstream
340     pstructtype lstream
341   else
342   if $lrecord_type == lrecord_type_marker
343     ptype Lisp_Marker
344   else
345   if $lrecord_type == lrecord_type_opaque
346     ptype Lisp_Opaque
347   else
348   if $lrecord_type == lrecord_type_opaque_ptr
349     ptype Lisp_Opaque_Ptr
350   else
351   if $lrecord_type == lrecord_type_popup_data
352     ptype popup_data
353   else
354   if $lrecord_type == lrecord_type_process
355     ptype Lisp_Process
356   else
357   if $lrecord_type == lrecord_type_range_table
358     ptype Lisp_Range_Table
359   else
360   if $lrecord_type == lrecord_type_specifier
361     ptype Lisp_Specifier
362   else
363   if $lrecord_type == lrecord_type_subr
364     ptype Lisp_Subr
365   else
366   if $lrecord_type == lrecord_type_symbol_value_buffer_local
367     pstructtype symbol_value_buffer_local
368   else
369   if $lrecord_type == lrecord_type_symbol_value_forward
370     pstructtype symbol_value_forward
371   else
372   if $lrecord_type == lrecord_type_symbol_value_lisp_magic
373     pstructtype symbol_value_lisp_magic
374   else
375   if $lrecord_type == lrecord_type_symbol_value_varalias
376     pstructtype symbol_value_varalias
377   else
378   if $lrecord_type == lrecord_type_timeout
379     ptype Lisp_Timeout
380   else
381   if $lrecord_type == lrecord_type_toolbar_button
382     pstructtype toolbar_button
383   else
384   if $lrecord_type == lrecord_type_tooltalk_message
385     ptype Lisp_Tooltalk_Message
386   else
387   if $lrecord_type == lrecord_type_tooltalk_pattern
388     ptype Lisp_Tooltalk_Pattern
389   else
390   if $lrecord_type == lrecord_type_weak_list
391     pstructtype weak_list
392   else
393   if $lrecord_type == lrecord_type_window
394     pstructtype window
395   else
396   if $lrecord_type == lrecord_type_window_configuration
397     pstructtype window_config
398   else
399     echo Unknown Lisp Object type\n
400     print $arg0
401   # Barf, gag, retch
402   end
403   end
404   end
405   end
406   end
407   end
408   end
409   end
410   end
411   end
412   end
413   end
414   end
415   end
416   end
417   end
418   end
419   # Repeat after me... gdb sux, gdb sux, gdb sux...
420   end
421   end
422   end
423   end
424   end
425   end
426   end
427   end
428   end
429   end
430   end
431   end
432   end
433   end
434   end
435   end
436   end
437   end
438   # Are we having fun yet??
439   end
440   end
441   end
442   end
443   end
444   end
445   end
446   end
447   end
448   end
449   end
450   end
451   end
452   end
453   end
454   end
455   end
456   end
457 end
458
459 document pobj
460 Usage: pobj lisp_object
461 Print the internal C representation of a Lisp Object.
462 end
463
464 # -------------------------------------------------------------
465 # functions to test the debugging support itself.
466 # If you change this file, make sure the following still work...
467 # -------------------------------------------------------------
468 define test_xtype
469   printf "Vemacs_major_version: "
470   xtype Vemacs_major_version
471   printf "Vhelp_char: "
472   xtype Vhelp_char
473   printf "Qnil: "
474   xtype Qnil
475   printf "Qunbound: "
476   xtype Qunbound
477   printf "Vobarray: "
478   xtype Vobarray
479   printf "Vall_weak_lists: "
480   xtype Vall_weak_lists
481   printf "Vsxemacs_codename: "
482   xtype Vsxemacs_codename
483 end
484
485 define test_pobj
486   printf "Vemacs_major_version: "
487   pobj Vemacs_major_version
488   printf "Vhelp_char: "
489   pobj Vhelp_char
490   printf "Qnil: "
491   pobj Qnil
492   printf "Qunbound: "
493   pobj Qunbound
494   printf "Vobarray: "
495   pobj Vobarray
496   printf "Vall_weak_lists: "
497   pobj Vall_weak_lists
498   printf "Vsxemacs_codename: "
499   pobj Vsxemacs_codename
500 end
501