* lisp/emacs-lisp/package.el: New quickstart feature
[emacs.git] / src / .gdbinit
blobeb4d57a5fbbd15ed2242c96dc56c300a006411b6
1 # Copyright (C) 1992-1998, 2000-2018 Free Software Foundation, Inc.
3 # This file is part of GNU Emacs.
5 # GNU Emacs is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3, or (at your option)
8 # any later version.
10 # GNU Emacs is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
18 # Force loading of symbols, enough to give us VALBITS etc.
19 set $dummy = main + 8
20 # With some compilers, we need this to give us struct Lisp_Symbol etc.:
21 set $dummy = Fmake_symbol + 8
23 # Find lwlib source files too.
24 dir ../lwlib
25 #dir /gd/gnu/lesstif-0.89.9/lib/Xm
27 # Don't enter GDB when user types C-g to quit.
28 # This has one unfortunate effect: you can't type C-c
29 # at the GDB to stop Emacs, when using X.
30 # However, C-z works just as well in that case.
31 handle 2 noprint pass
33 # Make it work like SIGINT normally does.
34 handle SIGTSTP nopass
36 # Pass on user signals
37 handle SIGUSR1 noprint pass
38 handle SIGUSR2 noprint pass
40 # Don't pass SIGALRM to Emacs.  This makes problems when
41 # debugging.
42 handle SIGALRM ignore
44 # Use $bugfix so that the value isn't a constant.
45 # Using a constant runs into GDB bugs sometimes.
46 define xgetptr
47   if (CHECK_LISP_OBJECT_TYPE)
48     set $bugfix = $arg0.i
49   else
50     set $bugfix = $arg0
51   end
52   set $ptr = (EMACS_INT) $bugfix & VALMASK
53 end
55 define xgetint
56   if (CHECK_LISP_OBJECT_TYPE)
57     set $bugfix = $arg0.i
58   else
59     set $bugfix = $arg0
60   end
61   set $int = (EMACS_INT) $bugfix << (USE_LSB_TAG ? 0 : INTTYPEBITS) >> INTTYPEBITS
62 end
64 define xgettype
65   if (CHECK_LISP_OBJECT_TYPE)
66     set $bugfix = $arg0.i
67   else
68     set $bugfix = $arg0
69   end
70   set $type = (enum Lisp_Type) (USE_LSB_TAG ? (EMACS_INT) $bugfix & (1 << GCTYPEBITS) - 1 : (EMACS_UINT) $bugfix >> VALBITS)
71 end
73 define xgetsym
74   xgetptr $arg0
75   set $ptr = ((struct Lisp_Symbol *) ((char *)lispsym + $ptr))
76 end
78 # Access the name of a symbol
79 define xsymname
80   xgetsym $arg0
81   set $symname = $ptr->u.s.name
82 end
84 # Set up something to print out s-expressions.
85 # We save and restore print_output_debug_flag to prevent the w32 port
86 # from calling OutputDebugString, which causes GDB to display each
87 # character twice (yuk!).
88 define pr
89   pp $
90 end
91 document pr
92 Print the emacs s-expression which is $.
93 Works only when an inferior emacs is executing.
94 end
96 # Print out s-expressions
97 define pp
98   set $tmp = $arg0
99   set $output_debug = print_output_debug_flag
100   set print_output_debug_flag = 0
101   call safe_debug_print ($tmp)
102   set print_output_debug_flag = $output_debug
104 document pp
105 Print the argument as an emacs s-expression
106 Works only when an inferior emacs is executing.
109 # Print value of lisp variable
110 define pv
111   set $tmp = "$arg0"
112   set $output_debug = print_output_debug_flag
113   set print_output_debug_flag = 0
114   call safe_debug_print (find_symbol_value (intern ($tmp)))
115   set print_output_debug_flag = $output_debug
117 document pv
118 Print the value of the lisp variable given as argument.
119 Works only when an inferior emacs is executing.
122 # Print out current buffer point and boundaries
123 define ppt
124   set $b = current_buffer
125   set $t = $b->text
126   printf "BUF PT: %d", $b->pt
127   if ($b->pt != $b->pt_byte)
128     printf "[%d]", $b->pt_byte
129   end
130   printf " of 1..%d", $t->z
131   if ($t->z != $t->z_byte)
132     printf "[%d]", $t->z_byte
133   end
134   if ($b->begv != 1 || $b->zv != $t->z)
135     printf " NARROW=%d..%d", $b->begv, $b->zv
136     if ($b->begv != $b->begv_byte || $b->zv != $b->zv_byte)
137       printf " [%d..%d]", $b->begv_byte, $b->zv_byte
138     end
139   end
140   printf " GAP: %d", $t->gpt
141   if ($t->gpt != $t->gpt_byte)
142     printf "[%d]", $t->gpt_byte
143   end
144   printf " SZ=%d\n", $t->gap_size
146 document ppt
147 Print current buffer's point and boundaries.
148 Prints values of point, beg, end, narrow, and gap for current buffer.
151 define pitmethod
152   set $itmethod = $arg0
153   # output $itmethod
154   if ($itmethod == 0)
155     printf "GET_FROM_BUFFER"
156   end
157   if ($itmethod == 1)
158     printf "GET_FROM_DISPLAY_VECTOR"
159   end
160   if ($itmethod == 2)
161     printf "GET_FROM_STRING"
162   end
163   if ($itmethod == 3)
164     printf "GET_FROM_C_STRING"
165   end
166   if ($itmethod == 4)
167     printf "GET_FROM_IMAGE"
168   end
169   if ($itmethod == 5)
170     printf "GET_FROM_STRETCH"
171   end
172   if ($itmethod < 0 || $itmethod > 5)
173     output $itmethod
174   end
176 document pitmethod
177 Pretty print it->method given as first arg
180 # Print out iterator given as first arg
181 define pitx
182   set $it = $arg0
183   printf "cur=%d", $it->current.pos.charpos
184   if ($it->current.pos.charpos != $it->current.pos.bytepos)
185     printf "[%d]", $it->current.pos.bytepos
186   end
187   printf " pos=%d", $it->position.charpos
188   if ($it->position.charpos != $it->position.bytepos)
189     printf "[%d]", $it->position.bytepos
190   end
191   printf " start=%d", $it->start.pos.charpos
192   if ($it->start.pos.charpos != $it->start.pos.bytepos)
193     printf "[%d]", $it->start.pos.bytepos
194   end
195   printf " end=%d", $it->end_charpos
196   printf " stop=%d", $it->stop_charpos
197   printf " face=%d", $it->face_id
198   if ($it->multibyte_p)
199     printf " MB"
200   end
201   if ($it->header_line_p)
202     printf " HL"
203   end
204   if ($it->n_overlay_strings > 0)
205     printf " nov=%d", $it->n_overlay_strings
206   end
207   if ($it->sp != 0)
208     printf " sp=%d", $it->sp
209   end
210   # IT_CHARACTER
211   if ($it->what == 0)
212     if ($it->len == 1 && $it->c >= ' ' && it->c < 255)
213       printf " ch='%c'", $it->c
214     else
215       printf " ch=[%d,%d]", $it->c, $it->len
216     end
217   else
218     printf " "
219     # output $it->what
220     if ($it->what == 0)
221       printf "IT_CHARACTER"
222     end
223     if ($it->what == 1)
224       printf "IT_COMPOSITION"
225     end
226     if ($it->what == 2)
227       printf "IT_IMAGE"
228     end
229     if ($it->what == 3)
230       printf "IT_STRETCH"
231     end
232     if ($it->what == 4)
233       printf "IT_EOB"
234     end
235     if ($it->what == 5)
236       printf "IT_TRUNCATION"
237     end
238     if ($it->what == 6)
239       printf "IT_CONTINUATION"
240     end
241     if ($it->what < 0 || $it->what > 6)
242       output $it->what
243     end
244   end
245   if ($it->method != 0)
246     # !GET_FROM_BUFFER
247     printf " next="
248     pitmethod $it->method
249     if ($it->method == 2)
250       # GET_FROM_STRING
251       printf "[%d]", $it->current.string_pos.charpos
252     end
253     if ($it->method == 4)
254       # GET_FROM_IMAGE
255       printf "[%d]", $it->image_id
256     end
257   end
258   printf "\n"
259   if ($it->bidi_p)
260     printf "BIDI: base_stop=%d prev_stop=%d level=%d\n", $it->base_level_stop, $it->prev_stop, $it->bidi_it.resolved_level
261   end
262   if ($it->region_beg_charpos >= 0)
263     printf "reg=%d-%d ", $it->region_beg_charpos, $it->region_end_charpos
264   end
265   printf "vpos=%d hpos=%d", $it->vpos, $it->hpos,
266   printf " y=%d lvy=%d", $it->current_y, $it->last_visible_y
267   printf " x=%d vx=%d-%d", $it->current_x, $it->first_visible_x, $it->last_visible_x
268   printf " w=%d", $it->pixel_width
269   printf " a+d=%d+%d=%d", $it->ascent, $it->descent, $it->ascent+$it->descent
270   printf " max=%d+%d=%d", $it->max_ascent, $it->max_descent, $it->max_ascent+$it->max_descent
271   printf "\n"
272   set $i = 0
273   while ($i < $it->sp && $i < 4)
274     set $e = $it->stack[$i]
275     printf "stack[%d]: ", $i
276     pitmethod $e.method
277     printf "[%d]", $e.position.charpos
278     printf "\n"
279     set $i = $i + 1
280   end
282 document pitx
283 Pretty print a display iterator.
284 Take one arg, an iterator object or pointer.
287 define pit
288   pitx it
290 document pit
291 Pretty print the display iterator it.
294 define prowx
295   set $row = $arg0
296   printf "y=%d x=%d pwid=%d", $row->y, $row->x, $row->pixel_width
297   printf " a+d=%d+%d=%d", $row->ascent, $row->height-$row->ascent, $row->height
298   printf " phys=%d+%d=%d", $row->phys_ascent, $row->phys_height-$row->phys_ascent, $row->phys_height
299   printf " vis=%d\n", $row->visible_height
300   printf "used=(LMargin=%d,Text=%d,RMargin=%d) Hash=%d\n", $row->used[0], $row->used[1], $row->used[2], $row->hash
301   printf "start=%d end=%d", $row->start.pos.charpos, $row->end.pos.charpos
302   if ($row->enabled_p)
303     printf " ENA"
304   end
305   if ($row->displays_text_p)
306     printf " DISP"
307   end
308   if ($row->mode_line_p)
309     printf " MODEL"
310   end
311   if ($row->continued_p)
312     printf " CONT"
313   end
314   if ($row-> truncated_on_left_p)
315     printf " TRUNC:L"
316   end
317   if ($row-> truncated_on_right_p)
318     printf " TRUNC:R"
319   end
320   if ($row->starts_in_middle_of_char_p)
321     printf " STARTMID"
322   end
323   if ($row->ends_in_middle_of_char_p)
324     printf " ENDMID"
325   end
326   if ($row->ends_in_newline_from_string_p)
327     printf " ENDNLFS"
328   end
329   if ($row->ends_at_zv_p)
330     printf " ENDZV"
331   end
332   if ($row->overlapped_p)
333     printf " OLAPD"
334   end
335   if ($row->overlapping_p)
336     printf " OLAPNG"
337   end
338   printf "\n"
340 document prowx
341 Pretty print information about glyph_row.
342 Takes one argument, a row object or pointer.
345 define prow
346   prowx row
348 document prow
349 Pretty print information about glyph_row in row.
353 define pcursorx
354   set $cp = $arg0
355   printf "y=%d x=%d vpos=%d hpos=%d", $cp.y, $cp.x, $cp.vpos, $cp.hpos
357 document pcursorx
358 Pretty print a window cursor.
361 define pcursor
362   printf "output: "
363   pcursorx output_cursor
364   printf "\n"
366 document pcursor
367 Pretty print the output_cursor.
370 define pwinx
371   set $w = $arg0
372   if ($w->mini != 0)
373     printf "Mini "
374   end
375   printf "Window %d ", $w->sequence_number
376   xgetptr $w->contents
377   set $tem = (struct buffer *) $ptr
378   xgetptr $tem->name_
379   printf "%s", ((struct Lisp_String *) $ptr)->u.s.data
380   printf "\n"
381   xgetptr $w->start
382   set $tem = (struct Lisp_Marker *) $ptr
383   printf "start=%d end:", $tem->charpos
384   if ($w->window_end_valid != 0)
385     printf "pos=%d", $w->window_end_pos
386     printf " vpos=%d", $w->window_end_vpos
387   else
388     printf "invalid"
389   end
390   printf " vscroll=%d", $w->vscroll
391   if ($w->force_start != 0)
392     printf " FORCE_START"
393   end
394   if ($w->must_be_updated_p)
395     printf " MUST_UPD"
396   end
397   printf "\n"
398   printf "cursor: "
399   pcursorx $w->cursor
400   printf "  phys: "
401   pcursorx $w->phys_cursor
402   if ($w->phys_cursor_on_p)
403     printf " ON"
404   else
405     printf " OFF"
406   end
407   printf " blk="
408   if ($w->last_cursor_off_p != $w->cursor_off_p)
409     if ($w->last_cursor_off_p)
410       printf "ON->"
411     else
412       printf "OFF->"
413     end
414   end
415   if ($w->cursor_off_p)
416     printf "ON"
417   else
418     printf "OFF"
419   end
420   printf "\n"
422 document pwinx
423 Pretty print a window structure.
424 Takes one argument, a pointer to a window structure.
427 define pwin
428   pwinx w
430 document pwin
431 Pretty print window structure w.
434 define pbiditype
435   if ($arg0 == 0)
436     printf "UNDEF"
437   end
438   if ($arg0 == 1)
439     printf "L"
440   end
441   if ($arg0 == 2)
442     printf "R"
443   end
444   if ($arg0 == 3)
445     printf "EN"
446   end
447   if ($arg0 == 4)
448     printf "AN"
449   end
450   if ($arg0 == 5)
451     printf "BN"
452   end
453   if ($arg0 == 6)
454     printf "B"
455   end
456   if ($arg0 < 0 || $arg0 > 6)
457     printf "%d??", $arg0
458   end
460 document pbiditype
461 Print textual description of bidi type given as first argument.
464 define pgx
465   set $g = $arg0
466   # CHAR_GLYPH
467   if ($g.type == 0)
468     if ($g.u.ch >= ' ' && $g.u.ch < 127)
469       printf "CHAR[%c]", $g.u.ch
470     else
471       printf "CHAR[0x%x]", $g.u.ch
472     end
473   end
474   # COMPOSITE_GLYPH
475   if ($g.type == 1)
476     printf "COMP[%d (%d..%d)]", $g.u.cmp.id, $g.slice.cmp.from, $g.slice.cmp.to
477   end
478   # GLYPHLESS_GLYPH
479   if ($g.type == 2)
480     printf "G-LESS["
481     if ($g.u.glyphless.method == 0)
482       printf "THIN;0x%x]", $g.u.glyphless.ch
483     end
484     if ($g.u.glyphless.method == 1)
485       printf "EMPTY;0x%x]", $g.u.glyphless.ch
486     end
487     if ($g.u.glyphless.method == 2)
488       printf "ACRO;0x%x]", $g.u.glyphless.ch
489     end
490     if ($g.u.glyphless.method == 3)
491       printf "HEX;0x%x]", $g.u.glyphless.ch
492     end
493   end
494   # IMAGE_GLYPH
495   if ($g.type == 3)
496     printf "IMAGE[%d]", $g.u.img_id
497   end
498   # STRETCH_GLYPH
499   if ($g.type == 4)
500     printf "STRETCH[%d+%d]", $g.u.stretch.height, $g.u.stretch.ascent
501   end
502   xgettype ($g.object)
503   if ($type == Lisp_String)
504     xgetptr $g.object
505     printf " str=0x%x[%d]", ((struct Lisp_String *)$ptr)->u.s.data, $g.charpos
506   else
507     printf " pos=%d", $g.charpos
508   end
509   # For characters, print their resolved level and bidi type
510   if ($g.type == 0 || $g.type == 2)
511     printf " blev=%d,btyp=", $g.resolved_level
512     pbiditype $g.bidi_type
513   end
514   printf " w=%d a+d=%d+%d", $g.pixel_width, $g.ascent, $g.descent
515   # If not DEFAULT_FACE_ID
516   if ($g.face_id != 0)
517     printf " face=%d", $g.face_id
518   end
519   if ($g.voffset)
520     printf " vof=%d", $g.voffset
521   end
522   if ($g.multibyte_p)
523     printf " MB"
524   end
525   if ($g.padding_p)
526     printf " PAD"
527   end
528   if ($g.glyph_not_available_p)
529     printf " N/A"
530   end
531   if ($g.overlaps_vertically_p)
532     printf " OVL"
533   end
534   if ($g.avoid_cursor_p)
535     printf " AVOID"
536   end
537   if ($g.left_box_line_p)
538     printf " ["
539   end
540   if ($g.right_box_line_p)
541     printf " ]"
542   end
543   if ($g.slice.img.x || $g.slice.img.y || $g.slice.img.width || $g.slice.img.height)
544     printf " slice=%d,%d,%d,%d" ,$g.slice.img.x, $g.slice.img.y, $g.slice.img.width, $g.slice.img.height
545   end
546   printf "\n"
548 document pgx
549 Pretty print a glyph structure.
550 Takes one argument, a pointer to a glyph structure.
553 define pg
554   set $pgidx = 0
555   pgx glyph
557 document pg
558 Pretty print glyph structure glyph.
561 define pgi
562   set $pgidx = $arg0
563   pgx (&glyph[$pgidx])
565 document pgi
566 Pretty print glyph structure glyph[I].
567 Takes one argument, an integer I.
570 define pgn
571   set $pgidx = $pgidx + 1
572   pgx (&glyph[$pgidx])
574 document pgn
575 Pretty print next glyph structure.
578 define pgrowx
579   set $row = $arg0
580   set $area = 0
581   set $xofs = $row->x
582   while ($area < 3)
583     set $used = $row->used[$area]
584     if ($used > 0)
585       set $gl0 = $row->glyphs[$area]
586       set $pgidx = 0
587       printf "%s: %d glyphs\n", ($area == 0 ? "LEFT" : $area == 2 ? "RIGHT" : "TEXT"), $used
588       while ($pgidx < $used)
589         printf "%3d %4d: ", $pgidx, $xofs
590         pgx $gl0[$pgidx]
591         set $xofs = $xofs + $gl0[$pgidx]->pixel_width
592         set $pgidx = $pgidx + 1
593       end
594     end
595     set $area = $area + 1
596   end
598 document pgrowx
599 Pretty print all glyphs in a row structure.
600 Takes one argument, a pointer to a row structure.
603 define pgrow
604   pgrowx row
606 document pgrow
607 Pretty print all glyphs in row structure row.
610 define pgrowit
611   pgrowx it->glyph_row
613 document pgrowit
614 Pretty print all glyphs in it->glyph_row.
617 define prowlims
618   printf "edges=(%d,%d),enb=%d,r2l=%d,cont=%d,trunc=(%d,%d),at_zv=%d\n", $arg0->minpos.charpos, $arg0->maxpos.charpos, $arg0->enabled_p, $arg0->reversed_p, $arg0->continued_p, $arg0->truncated_on_left_p, $arg0->truncated_on_right_p, $arg0->ends_at_zv_p
620 document prowlims
621 Print important attributes of a glyph_row structure.
622 Takes one argument, a pointer to a glyph_row structure.
625 define pmtxrows
626   set $mtx = $arg0
627   set $gl = $mtx->rows
628   set $glend = $mtx->rows + $mtx->nrows - 1
629   set $i = 0
630   while ($gl < $glend)
631     printf "%d: ", $i
632     prowlims $gl
633     set $gl = $gl + 1
634     set $i = $i + 1
635   end
637 document pmtxrows
638 Print data about glyph rows in a glyph matrix.
639 Takes one argument, a pointer to a glyph_matrix structure.
642 define xtype
643   xgettype $
644   output $type
645   echo \n
646   if $type == Lisp_Misc
647     xmisctype
648   else
649     if $type == Lisp_Vectorlike
650       xvectype
651     end
652   end
654 document xtype
655 Print the type of $, assuming it is an Emacs Lisp value.
656 If the first type printed is Lisp_Vector or Lisp_Misc,
657 a second line gives the more precise type.
660 define pvectype
661   set $size = ((struct Lisp_Vector *) $arg0)->header.size
662   if ($size & PSEUDOVECTOR_FLAG)
663     output (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS)
664   else
665     output PVEC_NORMAL_VECTOR
666   end
667   echo \n
669 document pvectype
670 Print the subtype of vectorlike object.
671 Takes one argument, a pointer to an object.
674 define xvectype
675   xgetptr $
676   pvectype $ptr
678 document xvectype
679 Print the subtype of vectorlike object.
680 This command assumes that $ is a Lisp_Object.
683 define pvecsize
684   set $size = ((struct Lisp_Vector *) $arg0)->header.size
685   if ($size & PSEUDOVECTOR_FLAG)
686     output ($size & PSEUDOVECTOR_SIZE_MASK)
687     echo \n
688     output (($size & PSEUDOVECTOR_REST_MASK) >> PSEUDOVECTOR_SIZE_BITS)
689   else
690     output ($size & ~ARRAY_MARK_FLAG)
691   end
692   echo \n
694 document pvecsize
695 Print the size of vectorlike object.
696 Takes one argument, a pointer to an object.
699 define xvecsize
700   xgetptr $
701   pvecsize $ptr
703 document xvecsize
704 Print the size of $
705 This command assumes that $ is a Lisp_Object.
708 define xmisctype
709   xgetptr $
710   output (enum Lisp_Misc_Type) (((struct Lisp_Free *) $ptr)->type)
711   echo \n
713 document xmisctype
714 Assume that $ is some misc type and print its specific type.
717 define xint
718   xgetint $
719   print $int
721 document xint
722 Print $ as an Emacs Lisp integer.  This gets the sign right.
725 define xptr
726   xgetptr $
727   print (void *) $ptr
729 document xptr
730 Print the pointer portion of an Emacs Lisp value in $.
733 define xmarker
734   xgetptr $
735   print (struct Lisp_Marker *) $ptr
737 document xmarker
738 Print $ as a marker pointer.
739 This command assumes that $ is an Emacs Lisp marker value.
742 define xoverlay
743   xgetptr $
744   print (struct Lisp_Overlay *) $ptr
746 document xoverlay
747 Print $ as a overlay pointer.
748 This command assumes that $ is an Emacs Lisp overlay value.
751 define xmiscfree
752   xgetptr $
753   print (struct Lisp_Free *) $ptr
755 document xmiscfree
756 Print $ as a misc free-cell pointer.
757 This command assumes that $ is an Emacs Lisp Misc value.
760 define xsymbol
761   set $sym = $
762   xgetsym $sym
763   print (struct Lisp_Symbol *) $ptr
764   xprintsym $sym
765   echo \n
767 document xsymbol
768 Print the name and address of the symbol $.
769 This command assumes that $ is an Emacs Lisp symbol value.
772 define xstring
773   xgetptr $
774   print (struct Lisp_String *) $ptr
775   xprintstr $
776   echo \n
778 document xstring
779 Print the contents and address of the string $.
780 This command assumes that $ is an Emacs Lisp string value.
783 define xvector
784   xgetptr $
785   print (struct Lisp_Vector *) $ptr
786   output ($->header.size > 50) ? 0 : ($->contents[0])@($->header.size & ~ARRAY_MARK_FLAG)
787 echo \n
789 document xvector
790 Print the contents and address of the vector $.
791 This command assumes that $ is an Emacs Lisp vector value.
794 define xprocess
795   xgetptr $
796   print (struct Lisp_Process *) $ptr
797   output *$
798   echo \n
800 document xprocess
801 Print the address of the struct Lisp_process to which $ points.
802 This command assumes that $ is a Lisp_Object.
805 define xframe
806   xgetptr $
807   print (struct frame *) $ptr
808   xgetptr $->name
809   set $ptr = (struct Lisp_String *) $ptr
810   xprintstr $ptr
811   echo \n
813 document xframe
814 Print $ as a frame pointer.
815 This command assumes $ is an Emacs Lisp frame value.
818 define xcompiled
819   xgetptr $
820   print (struct Lisp_Vector *) $ptr
821   output ($->contents[0])@($->header.size & 0xff)
822   echo \n
824 document xcompiled
825 Print $ as a compiled function pointer.
826 This command assumes that $ is an Emacs Lisp compiled value.
829 define xwindow
830   xgetptr $
831   print (struct window *) $ptr
832   set $window = (struct window *) $ptr
833   printf "%dx%d+%d+%d\n", $window->total_cols, $window->total_lines, $window->left_col, $window->top_line
835 document xwindow
836 Print $ as a window pointer, assuming it is an Emacs Lisp window value.
837 Print the window's position as "WIDTHxHEIGHT+LEFT+TOP".
840 define xwinconfig
841   xgetptr $
842   print (struct save_window_data *) $ptr
844 document xwinconfig
845 Print $ as a window configuration pointer.
846 This command assumes that $ is an Emacs Lisp window configuration value.
849 define xsubr
850   xgetptr $
851   print (struct Lisp_Subr *) $ptr
852   output *$
853   echo \n
855 document xsubr
856 Print the address of the subr which the Lisp_Object $ points to.
859 define xchartable
860   xgetptr $
861   print (struct Lisp_Char_Table *) $ptr
862   printf "Purpose: "
863   xprintsym $->purpose
864   printf "  %d extra slots", ($->header.size & 0x1ff) - 68
865   echo \n
867 document xchartable
868 Print the address of the char-table $, and its purpose.
869 This command assumes that $ is an Emacs Lisp char-table value.
872 define xsubchartable
873   xgetptr $
874   print (struct Lisp_Sub_Char_Table *) $ptr
875   set $subchartab = (struct Lisp_Sub_Char_Table *) $ptr
876   printf "Depth: %d, Min char: %d (0x%x)\n", $subchartab->depth, $subchartab->min_char, $subchartab->min_char
878 document xsubchartable
879 Print the address of the sub-char-table $, its depth and min-char.
880 This command assumes that $ is an Emacs Lisp sub-char-table value.
883 define xboolvector
884   xgetptr $
885   print (struct Lisp_Bool_Vector *) $ptr
886   output ($->size > 256) ? 0 : ($->data[0])@(($->size + BOOL_VECTOR_BITS_PER_CHAR - 1)/ BOOL_VECTOR_BITS_PER_CHAR)
887   echo \n
889 document xboolvector
890 Print the contents and address of the bool-vector $.
891 This command assumes that $ is an Emacs Lisp bool-vector value.
894 define xbuffer
895   xgetptr $
896   print (struct buffer *) $ptr
897   xgetptr $->name_
898   output ((struct Lisp_String *) $ptr)->u.s.data
899   echo \n
901 document xbuffer
902 Set $ as a buffer pointer and the name of the buffer.
903 This command assumes $ is an Emacs Lisp buffer value.
906 define xhashtable
907   xgetptr $
908   print (struct Lisp_Hash_Table *) $ptr
910 document xhashtable
911 Set $ as a hash table pointer.
912 This command assumes that $ is an Emacs Lisp hash table value.
915 define xcons
916   xgetptr $
917   print (struct Lisp_Cons *) $ptr
918   output/x *$
919   echo \n
921 document xcons
922 Print the contents of $ as an Emacs Lisp cons.
925 define nextcons
926   p $.u.cdr
927   xcons
929 document nextcons
930 Print the contents of the next cell in a list.
931 This command assumes that the last thing you printed was a cons cell contents
932 (type struct Lisp_Cons) or a pointer to one.
934 define xcar
935   xgetptr $
936   xgettype $
937   print/x ($type == Lisp_Cons ? ((struct Lisp_Cons *) $ptr)->u.s.car : 0)
939 document xcar
940 Assume that $ is an Emacs Lisp pair and print its car.
943 define xcdr
944   xgetptr $
945   xgettype $
946   print/x ($type == Lisp_Cons ? ((struct Lisp_Cons *) $ptr)->u.s.u.cdr : 0)
948 document xcdr
949 Assume that $ is an Emacs Lisp pair and print its cdr.
952 define xlist
953   xgetptr $
954   set $cons = (struct Lisp_Cons *) $ptr
955   xgetptr Qnil
956   set $nil = $ptr
957   set $i = 0
958   while $cons != $nil && $i < 10
959     p/x $cons->u.s.car
960     xpr
961     xgetptr $cons->u.s.u.cdr
962     set $cons = (struct Lisp_Cons *) $ptr
963     set $i = $i + 1
964     printf "---\n"
965   end
966   if $cons == $nil
967     printf "nil\n"
968   else
969     printf "...\n"
970     p $ptr
971   end
973 document xlist
974 Print $ assuming it is a list.
977 define xfloat
978   xgetptr $
979   print ((struct Lisp_Float *) $ptr)->u.data
981 document xfloat
982 Print $ assuming it is a lisp floating-point number.
985 define xscrollbar
986   xgetptr $
987   print (struct scrollbar *) $ptr
988 output *$
989 echo \n
991 document xscrollbar
992 Print $ as a scrollbar pointer.
995 define xpr
996   xtype
997   if $type == Lisp_Int0 || $type == Lisp_Int1
998     xint
999   end
1000   if $type == Lisp_Symbol
1001     xsymbol
1002   end
1003   if $type == Lisp_String
1004     xstring
1005   end
1006   if $type == Lisp_Cons
1007     xcons
1008   end
1009   if $type == Lisp_Float
1010     xfloat
1011   end
1012   if $type == Lisp_Misc
1013     set $misc = (enum Lisp_Misc_Type) (((struct Lisp_Free *) $ptr)->type)
1014     if $misc == Lisp_Misc_Free
1015       xmiscfree
1016     end
1017     if $misc == Lisp_Misc_Marker
1018       xmarker
1019     end
1020     if $misc == Lisp_Misc_Overlay
1021       xoverlay
1022     end
1023 #    if $misc == Lisp_Misc_Save_Value
1024 #      xsavevalue
1025 #    end
1026   end
1027   if $type == Lisp_Vectorlike
1028     set $size = ((struct Lisp_Vector *) $ptr)->header.size
1029     if ($size & PSEUDOVECTOR_FLAG)
1030       set $vec = (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS)
1031       if $vec == PVEC_NORMAL_VECTOR
1032         xvector
1033       end
1034       if $vec == PVEC_PROCESS
1035         xprocess
1036       end
1037       if $vec == PVEC_FRAME
1038         xframe
1039       end
1040       if $vec == PVEC_COMPILED
1041         xcompiled
1042       end
1043       if $vec == PVEC_WINDOW
1044         xwindow
1045       end
1046       if $vec == PVEC_WINDOW_CONFIGURATION
1047         xwinconfig
1048       end
1049       if $vec == PVEC_SUBR
1050         xsubr
1051       end
1052       if $vec == PVEC_CHAR_TABLE
1053         xchartable
1054       end
1055       if $vec == PVEC_BOOL_VECTOR
1056         xboolvector
1057       end
1058       if $vec == PVEC_BUFFER
1059         xbuffer
1060       end
1061       if $vec == PVEC_HASH_TABLE
1062         xhashtable
1063       end
1064     else
1065       xvector
1066     end
1067   end
1069 document xpr
1070 Print $ as a lisp object of any type.
1073 define xprintstr
1074   set $data = (char *) $arg0->u.s.data
1075   set $strsize = ($arg0->u.s.size_byte < 0) ? ($arg0->u.s.size & ~ARRAY_MARK_FLAG) : $arg0->u.s.size_byte
1076   # GDB doesn't like zero repetition counts
1077   if $strsize == 0
1078     output ""
1079   else
1080     output ($arg0->u.s.size > 1000) ? 0 : ($data[0])@($strsize)
1081   end
1084 define xprintsym
1085   xsymname $arg0
1086   xgetptr $symname
1087   set $sym_name = (struct Lisp_String *) $ptr
1088   xprintstr $sym_name
1090 document xprintsym
1091   Print argument as a symbol.
1094 define xcoding
1095   set $tmp = (struct Lisp_Hash_Table *) (Vcoding_system_hash_table & VALMASK)
1096   set $tmp = (struct Lisp_Vector *) ($tmp->key_and_value & VALMASK)
1097   set $name = $tmp->contents[$arg0 * 2]
1098   print $name
1099   pr
1100   print $tmp->contents[$arg0 * 2 + 1]
1101   pr
1103 document xcoding
1104   Print the name and attributes of coding system that has ID (argument).
1107 define xcharset
1108   set $tmp = (struct Lisp_Hash_Table *) (Vcharset_hash_table & VALMASK)
1109   set $tmp = (struct Lisp_Vector *) ($tmp->key_and_value & VALMASK)
1110   p $tmp->contents[charset_table[$arg0].hash_index * 2]
1111   pr
1113 document xcharset
1114   Print the name of charset that has ID (argument).
1117 define xfontset
1118   xgetptr $
1119   set $tbl = (struct Lisp_Char_Table *) $ptr
1120   print $tbl
1121   xgetint $tbl->extras[0]
1122   printf " ID:%d", $int
1123   xgettype $tbl->extras[1]
1124   xgetptr $tbl->extras[1]
1125   if $type == Lisp_String
1126     set $ptr = (struct Lisp_String *) $ptr
1127     printf " Name:"
1128     xprintstr $ptr
1129   else
1130     xgetptr $tbl->extras[2]
1131     set $ptr = (struct Lisp_Char_Table *) $ptr
1132     xgetptr $ptr->extras[1]
1133     set $ptr = (struct Lisp_String *) $ptr
1134     printf " Realized from:"
1135     xprintstr $ptr
1136   end
1137   echo \n
1140 define xfont
1141   xgetptr $
1142   set $size = (((struct Lisp_Vector *) $ptr)->header.size & 0x1FF)
1143   if $size == FONT_SPEC_MAX
1144     print (struct font_spec *) $ptr
1145   else
1146     if $size == FONT_ENTITY_MAX
1147       print (struct font_entity *) $ptr
1148     else
1149       print (struct font *) $ptr
1150     end
1151   end
1153 document xfont
1154 Print $ assuming it is a list font (font-spec, font-entity, or font-object).
1157 define xbacktrace
1158   set $bt = backtrace_top ()
1159   while backtrace_p ($bt)
1160     set $fun = backtrace_function ($bt)
1161     xgettype $fun
1162     if $type == Lisp_Symbol
1163       xprintsym $fun
1164       printf " (0x%x)\n", backtrace_args ($bt)
1165     else
1166       xgetptr $fun
1167       printf "0x%x ", $ptr
1168       if $type == Lisp_Vectorlike
1169         xgetptr $fun
1170         set $size = ((struct Lisp_Vector *) $ptr)->header.size
1171         if ($size & PSEUDOVECTOR_FLAG)
1172           output (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS)
1173         else
1174           output $size & ~ARRAY_MARK_FLAG
1175         end
1176       else
1177         printf "Lisp type %d", $type
1178       end
1179       echo \n
1180     end
1181     set $bt = backtrace_next ($bt)
1182   end
1184 document xbacktrace
1185   Print a backtrace of Lisp function calls from backtrace_list.
1186   Set a breakpoint at Fsignal and call this to see from where
1187   an error was signaled.
1190 define xprintbytestr
1191   set $data = (char *) $arg0->data
1192   set $bstrsize = ($arg0->size_byte < 0) ? ($arg0->size & ~ARRAY_MARK_FLAG) : $arg0->size_byte
1193   printf "Bytecode: "
1194   if $bstrsize > 0
1195     output/u ($arg0->size > 1000) ? 0 : ($data[0])@($bvsize)
1196   else
1197     printf ""
1198   end
1200 document xprintbytestr
1201   Print a string of byte code.
1204 define xwhichsymbols
1205   set $output_debug = print_output_debug_flag
1206   set print_output_debug_flag = 0
1207   call safe_debug_print (which_symbols ($arg0, $arg1))
1208   set print_output_debug_flag = $output_debug
1210 document xwhichsymbols
1211   Print symbols which references a given lisp object
1212   either as its symbol value or symbol function.
1213   Call with two arguments: the lisp object and the
1214   maximum number of symbols referencing it to produce.
1217 # Show Lisp backtrace after normal backtrace.
1218 define hookpost-backtrace
1219   set $bt = backtrace_top ()
1220   if backtrace_p ($bt)
1221     echo \n
1222     echo Lisp Backtrace:\n
1223     xbacktrace
1224   end
1227 # Flush display (X only)
1228 define ff
1229   set x_flush (0)
1231 document ff
1232 Flush pending X window display updates to screen.
1233 Works only when an inferior emacs is executing.
1237 set print pretty on
1238 set print sevenbit-strings
1240 show environment DISPLAY
1241 show environment TERM
1243 # When debugging, it is handy to be able to "return" from
1244 # terminate_due_to_signal when an assertion failure is non-fatal.
1245 break terminate_due_to_signal
1247 # x_error_quitter is defined only on X.  But window-system is set up
1248 # only at run time, during Emacs startup, so we need to defer setting
1249 # the breakpoint.  init_sys_modes is the first function called on
1250 # every platform after init_display, where window-system is set.
1251 tbreak init_sys_modes
1252 commands
1253   silent
1254   xsymname globals.f_Vinitial_window_system
1255   xgetptr $symname
1256   set $tem = (struct Lisp_String *) $ptr
1257   set $tem = (char *) $tem->u.s.data
1258   # If we are running in synchronous mode, we want a chance to look
1259   # around before Emacs exits.  Perhaps we should put the break
1260   # somewhere else instead...
1261   if $tem[0] == 'x' && $tem[1] == '\0'
1262     break x_error_quitter
1263   end
1264   continue
1268 # Put the Python code at the end of .gdbinit so that if GDB does not
1269 # support Python, GDB will do all the above initializations before
1270 # reporting an error.
1272 python
1274 # Python 3 compatibility.
1275 try:
1276   long
1277 except:
1278   long = int
1280 # Omit pretty-printing in older (pre-7.3) GDBs that lack it.
1281 if hasattr(gdb, 'printing'):
1283   class Emacs_Pretty_Printers (gdb.printing.RegexpCollectionPrettyPrinter):
1284     """A collection of pretty-printers.  This is like GDB's
1285        RegexpCollectionPrettyPrinter except when printing Lisp_Object."""
1286     def __call__ (self, val):
1287       """Look up the pretty-printer for the provided value."""
1288       type = val.type.unqualified ()
1289       typename = type.tag or type.name
1290       basic_type = gdb.types.get_basic_type (type)
1291       basic_typename = basic_type.tag or basic_type.name
1292       for printer in self.subprinters:
1293         if (printer.enabled
1294             and ((printer.regexp == '^Lisp_Object$'
1295                   and typename == 'Lisp_Object')
1296                  or (basic_typename
1297                      and printer.compiled_re.search (basic_typename)))):
1298           return printer.gen_printer (val)
1299       return None
1301   class Lisp_Object_Printer:
1302     "A printer for Lisp_Object values."
1303     def __init__ (self, val):
1304       self.val = val
1306     def to_string (self):
1307       "Yield a string that can be fed back into GDB."
1309       # This implementation should work regardless of C compiler, and
1310       # it should not attempt to run any code in the inferior.
1312       # If the macros EMACS_INT_WIDTH and USE_LSB_TAG are not in the
1313       # symbol table, guess reasonable defaults.
1314       sym = gdb.lookup_symbol ("EMACS_INT_WIDTH")[0]
1315       if sym:
1316         EMACS_INT_WIDTH = long (sym.value ())
1317       else:
1318         sym = gdb.lookup_symbol ("EMACS_INT")[0]
1319         EMACS_INT_WIDTH = 8 * sym.type.sizeof
1320       sym = gdb.lookup_symbol ("USE_LSB_TAG")[0]
1321       if sym:
1322         USE_LSB_TAG = long (sym.value ())
1323       else:
1324         USE_LSB_TAG = 1
1326       GCTYPEBITS = 3
1327       VALBITS = EMACS_INT_WIDTH - GCTYPEBITS
1328       Lisp_Int0 = 2
1329       Lisp_Int1 = 6 if USE_LSB_TAG else 3
1331       val = self.val
1332       basic_type = gdb.types.get_basic_type (val.type)
1334       # Unpack VAL from its containing structure, if necessary.
1335       if (basic_type.code == gdb.TYPE_CODE_STRUCT
1336           and gdb.types.has_field (basic_type, "i")):
1337         val = val["i"]
1339       # Convert VAL to a Python integer.  Convert by hand, as this is
1340       # simpler and works regardless of whether VAL is a pointer or
1341       # integer.  Also, val.cast (gdb.lookup.type ("EMACS_UINT"))
1342       # would have problems with GDB 7.12.1; see
1343       # <http://patchwork.sourceware.org/patch/11557/>.
1344       ival = long (val)
1346       # For nil, yield "XIL(0)", which is easier to read than "XIL(0x0)".
1347       if not ival:
1348         return "XIL(0)"
1350       # Extract the integer representation of the value and its Lisp type.
1351       itype = ival >> (0 if USE_LSB_TAG else VALBITS)
1352       itype = itype & ((1 << GCTYPEBITS) - 1)
1354       # For a Lisp integer N, yield "make_number(N)".
1355       if itype == Lisp_Int0 or itype == Lisp_Int1:
1356         if USE_LSB_TAG:
1357           ival = ival >> (GCTYPEBITS - 1)
1358         elif (ival >> VALBITS) & 1:
1359           ival = ival | (-1 << VALBITS)
1360         else:
1361           ival = ival & ((1 << VALBITS) - 1)
1362         return "make_number(%d)" % ival
1364       # For non-integers other than nil yield "XIL(N)", where N is a C integer.
1365       # This helps humans distinguish Lisp_Object values from ordinary
1366       # integers even when Lisp_Object is an integer.
1367       # Perhaps some day the pretty-printing could be fancier.
1368       # Prefer the unsigned representation to negative values, converting
1369       # by hand as val.cast does not work in GDB 7.12.1 as noted above.
1370       if ival < 0:
1371         ival = ival + (1 << EMACS_INT_WIDTH)
1372       return "XIL(0x%x)" % ival
1374   def build_pretty_printer ():
1375     pp = Emacs_Pretty_Printers ("Emacs")
1376     pp.add_printer ('Lisp_Object', '^Lisp_Object$', Lisp_Object_Printer)
1377     return pp
1379   gdb.printing.register_pretty_printer (gdb.current_objfile (),
1380                                         build_pretty_printer (), True)
1383 # GDB mishandles indentation with leading tabs when feeding it to Python.
1384 # Local Variables:
1385 # indent-tabs-mode: nil
1386 # End: