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