Document reserved keys
[emacs.git] / src / .gdbinit
blobcc06b2e11cef23bdce2900f415b264166254cc8c
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 = $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 = $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 ? $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)
823 document xcompiled
824 Print $ as a compiled function pointer.
825 This command assumes that $ is an Emacs Lisp compiled value.
828 define xwindow
829   xgetptr $
830   print (struct window *) $ptr
831   set $window = (struct window *) $ptr
832   printf "%dx%d+%d+%d\n", $window->total_cols, $window->total_lines, $window->left_col, $window->top_line
834 document xwindow
835 Print $ as a window pointer, assuming it is an Emacs Lisp window value.
836 Print the window's position as "WIDTHxHEIGHT+LEFT+TOP".
839 define xwinconfig
840   xgetptr $
841   print (struct save_window_data *) $ptr
843 document xwinconfig
844 Print $ as a window configuration pointer.
845 This command assumes that $ is an Emacs Lisp window configuration value.
848 define xsubr
849   xgetptr $
850   print (struct Lisp_Subr *) $ptr
851   output *$
852   echo \n
854 document xsubr
855 Print the address of the subr which the Lisp_Object $ points to.
858 define xchartable
859   xgetptr $
860   print (struct Lisp_Char_Table *) $ptr
861   printf "Purpose: "
862   xprintsym $->purpose
863   printf "  %d extra slots", ($->header.size & 0x1ff) - 68
864   echo \n
866 document xchartable
867 Print the address of the char-table $, and its purpose.
868 This command assumes that $ is an Emacs Lisp char-table value.
871 define xsubchartable
872   xgetptr $
873   print (struct Lisp_Sub_Char_Table *) $ptr
874   set $subchartab = (struct Lisp_Sub_Char_Table *) $ptr
875   printf "Depth: %d, Min char: %d (0x%x)\n", $subchartab->depth, $subchartab->min_char, $subchartab->min_char
877 document xsubchartable
878 Print the address of the sub-char-table $, its depth and min-char.
879 This command assumes that $ is an Emacs Lisp sub-char-table value.
882 define xboolvector
883   xgetptr $
884   print (struct Lisp_Bool_Vector *) $ptr
885   output ($->size > 256) ? 0 : ($->data[0])@(($->size + BOOL_VECTOR_BITS_PER_CHAR - 1)/ BOOL_VECTOR_BITS_PER_CHAR)
886   echo \n
888 document xboolvector
889 Print the contents and address of the bool-vector $.
890 This command assumes that $ is an Emacs Lisp bool-vector value.
893 define xbuffer
894   xgetptr $
895   print (struct buffer *) $ptr
896   xgetptr $->name_
897   output ((struct Lisp_String *) $ptr)->u.s.data
898   echo \n
900 document xbuffer
901 Set $ as a buffer pointer and the name of the buffer.
902 This command assumes $ is an Emacs Lisp buffer value.
905 define xhashtable
906   xgetptr $
907   print (struct Lisp_Hash_Table *) $ptr
909 document xhashtable
910 Set $ as a hash table pointer.
911 This command assumes that $ is an Emacs Lisp hash table value.
914 define xcons
915   xgetptr $
916   print (struct Lisp_Cons *) $ptr
917   output/x *$
918   echo \n
920 document xcons
921 Print the contents of $ as an Emacs Lisp cons.
924 define nextcons
925   p $.u.cdr
926   xcons
928 document nextcons
929 Print the contents of the next cell in a list.
930 This command assumes that the last thing you printed was a cons cell contents
931 (type struct Lisp_Cons) or a pointer to one.
933 define xcar
934   xgetptr $
935   xgettype $
936   print/x ($type == Lisp_Cons ? ((struct Lisp_Cons *) $ptr)->u.s.car : 0)
938 document xcar
939 Assume that $ is an Emacs Lisp pair and print its car.
942 define xcdr
943   xgetptr $
944   xgettype $
945   print/x ($type == Lisp_Cons ? ((struct Lisp_Cons *) $ptr)->u.s.u.cdr : 0)
947 document xcdr
948 Assume that $ is an Emacs Lisp pair and print its cdr.
951 define xlist
952   xgetptr $
953   set $cons = (struct Lisp_Cons *) $ptr
954   xgetptr Qnil
955   set $nil = $ptr
956   set $i = 0
957   while $cons != $nil && $i < 10
958     p/x $cons->u.s.car
959     xpr
960     xgetptr $cons->u.s.u.cdr
961     set $cons = (struct Lisp_Cons *) $ptr
962     set $i = $i + 1
963     printf "---\n"
964   end
965   if $cons == $nil
966     printf "nil\n"
967   else
968     printf "...\n"
969     p $ptr
970   end
972 document xlist
973 Print $ assuming it is a list.
976 define xfloat
977   xgetptr $
978   print ((struct Lisp_Float *) $ptr)->u.data
980 document xfloat
981 Print $ assuming it is a lisp floating-point number.
984 define xscrollbar
985   xgetptr $
986   print (struct scrollbar *) $ptr
987 output *$
988 echo \n
990 document xscrollbar
991 Print $ as a scrollbar pointer.
994 define xpr
995   xtype
996   if $type == Lisp_Int0 || $type == Lisp_Int1
997     xint
998   end
999   if $type == Lisp_Symbol
1000     xsymbol
1001   end
1002   if $type == Lisp_String
1003     xstring
1004   end
1005   if $type == Lisp_Cons
1006     xcons
1007   end
1008   if $type == Lisp_Float
1009     xfloat
1010   end
1011   if $type == Lisp_Misc
1012     set $misc = (enum Lisp_Misc_Type) (((struct Lisp_Free *) $ptr)->type)
1013     if $misc == Lisp_Misc_Free
1014       xmiscfree
1015     end
1016     if $misc == Lisp_Misc_Marker
1017       xmarker
1018     end
1019     if $misc == Lisp_Misc_Overlay
1020       xoverlay
1021     end
1022 #    if $misc == Lisp_Misc_Save_Value
1023 #      xsavevalue
1024 #    end
1025   end
1026   if $type == Lisp_Vectorlike
1027     set $size = ((struct Lisp_Vector *) $ptr)->header.size
1028     if ($size & PSEUDOVECTOR_FLAG)
1029       set $vec = (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS)
1030       if $vec == PVEC_NORMAL_VECTOR
1031         xvector
1032       end
1033       if $vec == PVEC_PROCESS
1034         xprocess
1035       end
1036       if $vec == PVEC_FRAME
1037         xframe
1038       end
1039       if $vec == PVEC_COMPILED
1040         xcompiled
1041       end
1042       if $vec == PVEC_WINDOW
1043         xwindow
1044       end
1045       if $vec == PVEC_WINDOW_CONFIGURATION
1046         xwinconfig
1047       end
1048       if $vec == PVEC_SUBR
1049         xsubr
1050       end
1051       if $vec == PVEC_CHAR_TABLE
1052         xchartable
1053       end
1054       if $vec == PVEC_BOOL_VECTOR
1055         xboolvector
1056       end
1057       if $vec == PVEC_BUFFER
1058         xbuffer
1059       end
1060       if $vec == PVEC_HASH_TABLE
1061         xhashtable
1062       end
1063     else
1064       xvector
1065     end
1066   end
1068 document xpr
1069 Print $ as a lisp object of any type.
1072 define xprintstr
1073   set $data = (char *) $arg0->u.s.data
1074   set $strsize = ($arg0->u.s.size_byte < 0) ? ($arg0->u.s.size & ~ARRAY_MARK_FLAG) : $arg0->u.s.size_byte
1075   # GDB doesn't like zero repetition counts
1076   if $strsize == 0
1077     output ""
1078   else
1079     output ($arg0->u.s.size > 1000) ? 0 : ($data[0])@($strsize)
1080   end
1083 define xprintsym
1084   xsymname $arg0
1085   xgetptr $symname
1086   set $sym_name = (struct Lisp_String *) $ptr
1087   xprintstr $sym_name
1089 document xprintsym
1090   Print argument as a symbol.
1093 define xcoding
1094   set $tmp = (struct Lisp_Hash_Table *) (Vcoding_system_hash_table & VALMASK)
1095   set $tmp = (struct Lisp_Vector *) ($tmp->key_and_value & VALMASK)
1096   set $name = $tmp->contents[$arg0 * 2]
1097   print $name
1098   pr
1099   print $tmp->contents[$arg0 * 2 + 1]
1100   pr
1102 document xcoding
1103   Print the name and attributes of coding system that has ID (argument).
1106 define xcharset
1107   set $tmp = (struct Lisp_Hash_Table *) (Vcharset_hash_table & VALMASK)
1108   set $tmp = (struct Lisp_Vector *) ($tmp->key_and_value & VALMASK)
1109   p $tmp->contents[charset_table[$arg0].hash_index * 2]
1110   pr
1112 document xcharset
1113   Print the name of charset that has ID (argument).
1116 define xfontset
1117   xgetptr $
1118   set $tbl = (struct Lisp_Char_Table *) $ptr
1119   print $tbl
1120   xgetint $tbl->extras[0]
1121   printf " ID:%d", $int
1122   xgettype $tbl->extras[1]
1123   xgetptr $tbl->extras[1]
1124   if $type == Lisp_String
1125     set $ptr = (struct Lisp_String *) $ptr
1126     printf " Name:"
1127     xprintstr $ptr
1128   else
1129     xgetptr $tbl->extras[2]
1130     set $ptr = (struct Lisp_Char_Table *) $ptr
1131     xgetptr $ptr->extras[1]
1132     set $ptr = (struct Lisp_String *) $ptr
1133     printf " Realized from:"
1134     xprintstr $ptr
1135   end
1136   echo \n
1139 define xfont
1140   xgetptr $
1141   set $size = (((struct Lisp_Vector *) $ptr)->header.size & 0x1FF)
1142   if $size == FONT_SPEC_MAX
1143     print (struct font_spec *) $ptr
1144   else
1145     if $size == FONT_ENTITY_MAX
1146       print (struct font_entity *) $ptr
1147     else
1148       print (struct font *) $ptr
1149     end
1150   end
1152 document xfont
1153 Print $ assuming it is a list font (font-spec, font-entity, or font-object).
1156 define xbacktrace
1157   set $bt = backtrace_top ()
1158   while backtrace_p ($bt)
1159     set $fun = backtrace_function ($bt)
1160     xgettype $fun
1161     if $type == Lisp_Symbol
1162       xprintsym $fun
1163       printf " (0x%x)\n", backtrace_args ($bt)
1164     else
1165       xgetptr $fun
1166       printf "0x%x ", $ptr
1167       if $type == Lisp_Vectorlike
1168         xgetptr $fun
1169         set $size = ((struct Lisp_Vector *) $ptr)->header.size
1170         if ($size & PSEUDOVECTOR_FLAG)
1171           output (enum pvec_type) (($size & PVEC_TYPE_MASK) >> PSEUDOVECTOR_AREA_BITS)
1172         else
1173           output $size & ~ARRAY_MARK_FLAG
1174         end
1175       else
1176         printf "Lisp type %d", $type
1177       end
1178       echo \n
1179     end
1180     set $bt = backtrace_next ($bt)
1181   end
1183 document xbacktrace
1184   Print a backtrace of Lisp function calls from backtrace_list.
1185   Set a breakpoint at Fsignal and call this to see from where
1186   an error was signaled.
1189 define xprintbytestr
1190   set $data = (char *) $arg0->data
1191   set $bstrsize = ($arg0->size_byte < 0) ? ($arg0->size & ~ARRAY_MARK_FLAG) : $arg0->size_byte
1192   printf "Bytecode: "
1193   if $bstrsize > 0
1194     output/u ($arg0->size > 1000) ? 0 : ($data[0])@($bvsize)
1195   else
1196     printf ""
1197   end
1199 document xprintbytestr
1200   Print a string of byte code.
1203 define xwhichsymbols
1204   set $output_debug = print_output_debug_flag
1205   set print_output_debug_flag = 0
1206   call safe_debug_print (which_symbols ($arg0, $arg1))
1207   set print_output_debug_flag = $output_debug
1209 document xwhichsymbols
1210   Print symbols which references a given lisp object
1211   either as its symbol value or symbol function.
1212   Call with two arguments: the lisp object and the
1213   maximum number of symbols referencing it to produce.
1216 # Show Lisp backtrace after normal backtrace.
1217 define hookpost-backtrace
1218   set $bt = backtrace_top ()
1219   if backtrace_p ($bt)
1220     echo \n
1221     echo Lisp Backtrace:\n
1222     xbacktrace
1223   end
1226 # Flush display (X only)
1227 define ff
1228   set x_flush (0)
1230 document ff
1231 Flush pending X window display updates to screen.
1232 Works only when an inferior emacs is executing.
1236 set print pretty on
1237 set print sevenbit-strings
1239 show environment DISPLAY
1240 show environment TERM
1242 # When debugging, it is handy to be able to "return" from
1243 # terminate_due_to_signal when an assertion failure is non-fatal.
1244 break terminate_due_to_signal
1246 # x_error_quitter is defined only on X.  But window-system is set up
1247 # only at run time, during Emacs startup, so we need to defer setting
1248 # the breakpoint.  init_sys_modes is the first function called on
1249 # every platform after init_display, where window-system is set.
1250 tbreak init_sys_modes
1251 commands
1252   silent
1253   xsymname globals.f_Vinitial_window_system
1254   xgetptr $symname
1255   set $tem = (struct Lisp_String *) $ptr
1256   set $tem = (char *) $tem->u.s.data
1257   # If we are running in synchronous mode, we want a chance to look
1258   # around before Emacs exits.  Perhaps we should put the break
1259   # somewhere else instead...
1260   if $tem[0] == 'x' && $tem[1] == '\0'
1261     break x_error_quitter
1262   end
1263   continue
1267 # Put the Python code at the end of .gdbinit so that if GDB does not
1268 # support Python, GDB will do all the above initializations before
1269 # reporting an error.
1271 python
1273 # Omit pretty-printing in older (pre-7.3) GDBs that lack it.
1274 if hasattr(gdb, 'printing'):
1276   class Emacs_Pretty_Printers (gdb.printing.RegexpCollectionPrettyPrinter):
1277     """A collection of pretty-printers.  This is like GDB's
1278        RegexpCollectionPrettyPrinter except when printing Lisp_Object."""
1279     def __call__ (self, val):
1280       """Look up the pretty-printer for the provided value."""
1281       type = val.type.unqualified ()
1282       typename = type.tag or type.name
1283       basic_type = gdb.types.get_basic_type (type)
1284       basic_typename = basic_type.tag or basic_type.name
1285       for printer in self.subprinters:
1286         if (printer.enabled
1287             and ((printer.regexp == '^Lisp_Object$'
1288                   and typename == 'Lisp_Object')
1289                  or (basic_typename
1290                      and printer.compiled_re.search (basic_typename)))):
1291           return printer.gen_printer (val)
1292       return None
1294   class Lisp_Object_Printer:
1295     "A printer for Lisp_Object values."
1296     def __init__ (self, val):
1297       self.val = val
1299     def to_string (self):
1300       "Yield a string that can be fed back into GDB."
1302       # This implementation should work regardless of C compiler, and
1303       # it should not attempt to run any code in the inferior.
1305       # If the macros EMACS_INT_WIDTH and USE_LSB_TAG are not in the
1306       # symbol table, guess reasonable defaults.
1307       sym = gdb.lookup_symbol ("EMACS_INT_WIDTH")[0]
1308       if sym:
1309         EMACS_INT_WIDTH = int (sym.value ())
1310       else:
1311         sym = gdb.lookup_symbol ("EMACS_INT")[0]
1312         EMACS_INT_WIDTH = 8 * sym.type.sizeof
1313       sym = gdb.lookup_symbol ("USE_LSB_TAG")[0]
1314       if sym:
1315         USE_LSB_TAG = int (sym.value ())
1316       else:
1317         USE_LSB_TAG = 1
1319       GCTYPEBITS = 3
1320       VALBITS = EMACS_INT_WIDTH - GCTYPEBITS
1321       Lisp_Int0 = 2
1322       Lisp_Int1 = 6 if USE_LSB_TAG else 3
1324       # Unpack the Lisp value from its containing structure, if necessary.
1325       val = self.val
1326       basic_type = gdb.types.get_basic_type (val.type)
1327       if (basic_type.code == gdb.TYPE_CODE_STRUCT
1328           and gdb.types.has_field (basic_type, "i")):
1329         val = val["i"]
1331       # For nil, yield "XIL(0)", which is easier to read than "XIL(0x0)".
1332       if not val:
1333         return "XIL(0)"
1335       # Extract the integer representation of the value and its Lisp type.
1336       ival = int(val)
1337       itype = ival >> (0 if USE_LSB_TAG else VALBITS)
1338       itype = itype & ((1 << GCTYPEBITS) - 1)
1340       # For a Lisp integer N, yield "make_number(N)".
1341       if itype == Lisp_Int0 or itype == Lisp_Int1:
1342         if USE_LSB_TAG:
1343           ival = ival >> (GCTYPEBITS - 1)
1344         elif (ival >> VALBITS) & 1:
1345           ival = ival | (-1 << VALBITS)
1346         else:
1347           ival = ival & ((1 << VALBITS) - 1)
1348         return "make_number(%d)" % ival
1350       # For non-integers other than nil yield "XIL(N)", where N is a C integer.
1351       # This helps humans distinguish Lisp_Object values from ordinary
1352       # integers even when Lisp_Object is an integer.
1353       # Perhaps some day the pretty-printing could be fancier.
1354       # Prefer the unsigned representation to negative values, converting
1355       # by hand as val.cast(gdb.lookup_type("EMACS_UINT") does not work in
1356       # GDB 7.12.1; see <http://patchwork.sourceware.org/patch/11557/>.
1357       if ival < 0:
1358         ival = ival + (1 << EMACS_INT_WIDTH)
1359       return "XIL(0x%x)" % ival
1361   def build_pretty_printer ():
1362     pp = Emacs_Pretty_Printers ("Emacs")
1363     pp.add_printer ('Lisp_Object', '^Lisp_Object$', Lisp_Object_Printer)
1364     return pp
1366   gdb.printing.register_pretty_printer (gdb.current_objfile (),
1367                                         build_pretty_printer (), True)
1370 # GDB mishandles indentation with leading tabs when feeding it to Python.
1371 # Local Variables:
1372 # indent-tabs-mode: nil
1373 # End: