1 set startup-with-shell off
5 set $color_highlite = 0
11 set $color_type = "\033[31m"
14 set $color_highlite = "\033[36m"
17 set $color_end = "\033[m"
19 if ruby_dummy_gdb_enums.special_consts
23 # set prompt \033[36m(gdb)\033[m\040
27 if (VALUE)($arg0) & RUBY_FIXNUM_FLAG
28 printf "FIXNUM: %ld\n", (long)($arg0) >> 1
30 if ((VALUE)($arg0) & ~(~(VALUE)0<<RUBY_SPECIAL_SHIFT)) == RUBY_SYMBOL_FLAG
31 set $id = (($arg0) >> RUBY_SPECIAL_SHIFT)
32 printf "%sSYMBOL%s: ", $color_type, $color_end
35 if ($arg0) == RUBY_Qfalse
38 if ($arg0) == RUBY_Qtrue
41 if ($arg0) == RUBY_Qnil
44 if ($arg0) == RUBY_Qundef
47 if (VALUE)($arg0) & RUBY_IMMEDIATE_MASK
48 if ((VALUE)($arg0) & RUBY_FLONUM_MASK) == RUBY_FLONUM_FLAG
49 printf "%sFLONUM%s: %g\n", $color_type, $color_end, (double)rb_float_value($arg0)
54 set $flags = ((struct RBasic*)($arg0))->flags
55 if ($flags & RUBY_FL_PROMOTED) == RUBY_FL_PROMOTED
58 if ($flags & RUBY_T_MASK) == RUBY_T_NONE
59 printf "%sT_NONE%s: ", $color_type, $color_end
60 print (struct RBasic *)($arg0)
62 if ($flags & RUBY_T_MASK) == RUBY_T_NIL
63 printf "%sT_NIL%s: ", $color_type, $color_end
64 print (struct RBasic *)($arg0)
66 if ($flags & RUBY_T_MASK) == RUBY_T_OBJECT
67 printf "%sT_OBJECT%s: ", $color_type, $color_end
68 print ((struct RObject *)($arg0))->basic
69 if ($flags & ROBJECT_EMBED)
70 print/x *((VALUE*)((struct RObject*)($arg0))->as.ary) @ (ROBJECT_EMBED_LEN_MAX+0)
72 print (((struct RObject *)($arg0))->as.heap)
73 if (((struct RObject*)($arg0))->as.heap.numiv) > 0
74 print/x *(((struct RObject*)($arg0))->as.heap.ivptr) @ (((struct RObject*)($arg0))->as.heap.numiv)
78 if ($flags & RUBY_T_MASK) == RUBY_T_CLASS
79 printf "%sT_CLASS%s%s: ", $color_type, ($flags & RUBY_FL_SINGLETON) ? "*" : "", $color_end
82 if ($flags & RUBY_T_MASK) == RUBY_T_ICLASS
83 printf "%sT_ICLASS%s: ", $color_type, $color_end
86 if ($flags & RUBY_T_MASK) == RUBY_T_MODULE
87 printf "%sT_MODULE%s: ", $color_type, $color_end
90 if ($flags & RUBY_T_MASK) == RUBY_T_FLOAT
91 printf "%sT_FLOAT%s: %.16g ", $color_type, $color_end, (((struct RFloat*)($arg0))->float_value)
92 print (struct RFloat *)($arg0)
94 if ($flags & RUBY_T_MASK) == RUBY_T_STRING
95 printf "%sT_STRING%s: ", $color_type, $color_end
96 rp_string $arg0 $flags
98 if ($flags & RUBY_T_MASK) == RUBY_T_REGEXP
99 set $regsrc = ((struct RRegexp*)($arg0))->src
100 set $rsflags = ((struct RBasic*)$regsrc)->flags
101 printf "%sT_REGEXP%s: ", $color_type, $color_end
102 set $len = ($rsflags & RUBY_FL_USER1) ? \
103 ((struct RString*)$regsrc)->as.heap.len : \
104 (($rsflags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2)
105 set print address off
106 output *(char *)(($rsflags & RUBY_FL_USER1) ? \
107 ((struct RString*)$regsrc)->as.heap.ptr : \
108 ((struct RString*)$regsrc)->as.ary) @ $len
110 printf " len:%ld ", $len
111 if $flags & RUBY_FL_USER6
114 if $flags & RUBY_FL_USER5
117 if $flags & RUBY_FL_USER4
120 printf "encoding:%d ", ($flags & RUBY_ENCODING_MASK) >> RUBY_ENCODING_SHIFT
121 print (struct RRegexp *)($arg0)
123 if ($flags & RUBY_T_MASK) == RUBY_T_ARRAY
124 if ($flags & RUBY_FL_USER1)
125 set $len = (($flags & (RUBY_FL_USER3|RUBY_FL_USER4)) >> (RUBY_FL_USHIFT+3))
126 printf "%sT_ARRAY%s: len=%ld ", $color_type, $color_end, $len
131 print/x *((VALUE*)((struct RArray*)($arg0))->as.ary) @ $len
135 set $len = ((struct RArray*)($arg0))->as.heap.len
136 printf "%sT_ARRAY%s: len=%ld ", $color_type, $color_end, $len
137 if ($flags & RUBY_FL_USER2)
138 printf "(shared) shared="
139 output/x ((struct RArray*)($arg0))->as.heap.aux.shared_root
142 printf "(ownership) capa=%ld ", ((struct RArray*)($arg0))->as.heap.aux.capa
147 print/x *((VALUE*)((struct RArray*)($arg0))->as.heap.ptr) @ $len
151 print (struct RArray *)($arg0)
153 if ($flags & RUBY_T_MASK) == RUBY_T_FIXNUM
154 printf "%sT_FIXNUM%s: ", $color_type, $color_end
155 print (struct RBasic *)($arg0)
157 if ($flags & RUBY_T_MASK) == RUBY_T_HASH
158 printf "%sT_HASH%s: ", $color_type, $color_end,
159 if (((struct RHash *)($arg0))->basic.flags & RHASH_ST_TABLE_FLAG)
160 printf "st len=%ld ", ((struct RHash *)($arg0))->as.st->num_entries
162 printf "li len=%ld bound=%ld ", \
163 ((((struct RHash *)($arg0))->basic.flags & RHASH_AR_TABLE_SIZE_MASK) >> RHASH_AR_TABLE_SIZE_SHIFT), \
164 ((((struct RHash *)($arg0))->basic.flags & RHASH_AR_TABLE_BOUND_MASK) >> RHASH_AR_TABLE_BOUND_SHIFT)
166 print (struct RHash *)($arg0)
168 if ($flags & RUBY_T_MASK) == RUBY_T_STRUCT
169 set $len = (($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) ? \
170 ($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) >> (RUBY_FL_USHIFT+1) : \
171 ((struct RStruct *)($arg0))->as.heap.len)
172 printf "%sT_STRUCT%s: len=%ld ", $color_type, $color_end, $len
173 print (struct RStruct *)($arg0)
174 output/x *(($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) ? \
175 ((struct RStruct *)($arg0))->as.ary : \
176 ((struct RStruct *)($arg0))->as.heap.ptr) @ $len
178 if ($flags & RUBY_T_MASK) == RUBY_T_BIGNUM
181 if ($flags & RUBY_T_MASK) == RUBY_T_RATIONAL
182 printf "%sT_RATIONAL%s: ", $color_type, $color_end
183 print (struct RRational *)($arg0)
185 if ($flags & RUBY_T_MASK) == RUBY_T_COMPLEX
186 printf "%sT_COMPLEX%s: ", $color_type, $color_end
187 print (struct RComplex *)($arg0)
189 if ($flags & RUBY_T_MASK) == RUBY_T_FILE
190 printf "%sT_FILE%s: ", $color_type, $color_end
191 print (struct RFile *)($arg0)
192 output *((struct RFile *)($arg0))->fptr
195 if ($flags & RUBY_T_MASK) == RUBY_T_TRUE
196 printf "%sT_TRUE%s: ", $color_type, $color_end
197 print (struct RBasic *)($arg0)
199 if ($flags & RUBY_T_MASK) == RUBY_T_FALSE
200 printf "%sT_FALSE%s: ", $color_type, $color_end
201 print (struct RBasic *)($arg0)
203 if ($flags & RUBY_T_MASK) == RUBY_T_DATA
204 if ((struct RTypedData *)($arg0))->typed_flag == 1
205 printf "%sT_DATA%s(%s): ", $color_type, $color_end, ((struct RTypedData *)($arg0))->type->wrap_struct_name
206 print (struct RTypedData *)($arg0)
208 printf "%sT_DATA%s: ", $color_type, $color_end
209 print (struct RData *)($arg0)
212 if ($flags & RUBY_T_MASK) == RUBY_T_MATCH
213 printf "%sT_MATCH%s: ", $color_type, $color_end
214 print (struct RMatch *)($arg0)
216 if ($flags & RUBY_T_MASK) == RUBY_T_SYMBOL
217 printf "%sT_SYMBOL%s: ", $color_type, $color_end
218 print (struct RSymbol *)($arg0)
219 set $id_type = ((struct RSymbol *)($arg0))->id & RUBY_ID_SCOPE_MASK
220 if $id_type == RUBY_ID_LOCAL
223 if $id_type == RUBY_ID_INSTANCE
226 if $id_type == RUBY_ID_GLOBAL
229 if $id_type == RUBY_ID_ATTRSET
232 if $id_type == RUBY_ID_CONST
235 if $id_type == RUBY_ID_CLASS
245 set $id_fstr = ((struct RSymbol *)($arg0))->fstr
248 if ($flags & RUBY_T_MASK) == RUBY_T_UNDEF
249 printf "%sT_UNDEF%s: ", $color_type, $color_end
250 print (struct RBasic *)($arg0)
252 if ($flags & RUBY_T_MASK) == RUBY_T_IMEMO
253 printf "%sT_IMEMO%s(", $color_type, $color_end
254 output (enum imemo_type)(($flags>>RUBY_FL_USHIFT)&RUBY_IMEMO_MASK)
258 if ($flags & RUBY_T_MASK) == RUBY_T_NODE
259 printf "%sT_NODE%s(", $color_type, $color_end
260 output (enum node_type)(($flags&RUBY_NODE_TYPEMASK)>>RUBY_NODE_TYPESHIFT)
262 print *(NODE *)($arg0)
264 if ($flags & RUBY_T_MASK) == RUBY_T_ZOMBIE
265 printf "%sT_ZOMBIE%s: ", $color_type, $color_end
266 print (struct RData *)($arg0)
268 if ($flags & RUBY_T_MASK) == RUBY_T_MOVED
269 printf "%sT_MOVED%s: ", $color_type, $color_end
270 print *(struct RMoved *)$arg0
272 printf "%sunknown%s: ", $color_type, $color_end
273 print (struct RBasic *)($arg0)
310 Print a Ruby's VALUE.
315 if $id == '!' || $id == '+' || $id == '-' || $id == '*' || $id == '/' || $id == '%' || $id == '<' || $id == '>' || $id == '`'
316 printf "(:%c)\n", $id
381 if $id <= tLAST_OP_ID
384 set $id_type = $id & RUBY_ID_SCOPE_MASK
385 if $id_type == RUBY_ID_LOCAL
388 if $id_type == RUBY_ID_INSTANCE
391 if $id_type == RUBY_ID_GLOBAL
394 if $id_type == RUBY_ID_ATTRSET
397 if $id_type == RUBY_ID_CONST
400 if $id_type == RUBY_ID_CLASS
411 printf "(%ld): ", $id
442 set $flags = ((struct RBasic*)($arg0))->flags
443 set $len = ($flags & RUBY_FL_USER1) ? \
444 ((struct RString*)($arg0))->as.heap.len : \
445 (($flags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2)
447 output *(char *)(($flags & RUBY_FL_USER1) ? \
448 ((struct RString*)($arg0))->as.heap.ptr : \
449 ((struct RString*)($arg0))->as.ary) @ $len
456 set $flags = ((struct RBasic*)($arg0))->flags
457 set $len = ($flags & RUBY_FL_USER1) ? \
458 ((struct RString*)($arg0))->as.heap.len : \
459 (($flags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2)
461 printf "%s", *(char *)(($flags & RUBY_FL_USER1) ? \
462 ((struct RString*)($arg0))->as.heap.ptr : \
463 ((struct RString*)($arg0))->as.ary) @ $len
469 printf " bytesize:%ld ", $len
470 if !($flags & RUBY_FL_USER1)
473 if ($flags & RUBY_FL_USER2)
476 if ($flags & RUBY_FL_USER3)
480 printf "encoding:%d ", ($flags & RUBY_ENCODING_MASK) >> RUBY_ENCODING_SHIFT
481 if ($flags & RUBY_ENC_CODERANGE_MASK) == 0
482 printf "coderange:unknown "
484 if ($flags & RUBY_ENC_CODERANGE_MASK) == RUBY_ENC_CODERANGE_7BIT
485 printf "coderange:7bit "
487 if ($flags & RUBY_ENC_CODERANGE_MASK) == RUBY_ENC_CODERANGE_VALID
488 printf "coderange:valid "
490 printf "coderange:broken "
494 print (struct RString *)($arg0)
497 Print the content of a String.
501 set $flags = ((struct RBignum*)($arg0))->basic.flags
502 set $len = (($flags & RUBY_FL_USER2) ? \
503 ($flags & (RUBY_FL_USER5|RUBY_FL_USER4|RUBY_FL_USER3)) >> (RUBY_FL_USHIFT+3) : \
504 ((struct RBignum*)($arg0))->as.heap.len)
505 printf "%sT_BIGNUM%s: sign=%d len=%ld ", $color_type, $color_end, \
506 (($flags & RUBY_FL_USER1) != 0), $len
507 if $flags & RUBY_FL_USER2
510 print (struct RBignum *)($arg0)
511 set $ptr = (($flags & RUBY_FL_USER2) ? \
512 ((struct RBignum*)($arg0))->as.ary : \
513 ((struct RBignum*)($arg0))->as.heap.digits)
515 printf "0x%x", $ptr[$len]
518 set $val = $ptr[$len]
519 set $w = sizeof($ptr[0])
542 Print the content of a Bignum.
546 printf "(struct RClass *) %p", (void*)$arg0
547 if ((struct RClass *)($arg0))->ptr.origin_ != $arg0
548 printf " -> %p", ((struct RClass *)($arg0))->ptr.origin_
552 print/x *(struct RClass *)($arg0)
553 print *((struct RClass *)($arg0))->ptr
556 Print the content of a Class/Module.
560 set $flags = (enum imemo_type)((((struct RBasic *)($arg0))->flags >> RUBY_FL_USHIFT) & RUBY_IMEMO_MASK)
561 if $flags == imemo_cref
562 printf "(rb_cref_t *) %p\n", (void*)$arg0
563 print *(rb_cref_t *)$arg0
565 if $flags == imemo_svar
566 printf "(struct vm_svar *) %p\n", (void*)$arg0
567 print *(struct vm_svar *)$arg0
569 if $flags == imemo_throw_data
570 printf "(struct vm_throw_data *) %p\n", (void*)$arg0
571 print *(struct vm_throw_data *)$arg0
573 if $flags == imemo_ifunc
574 printf "(struct vm_ifunc *) %p\n", (void*)$arg0
575 print *(struct vm_ifunc *)$arg0
577 if $flags == imemo_memo
578 printf "(struct MEMO *) %p\n", (void*)$arg0
579 print *(struct MEMO *)$arg0
581 if $flags == imemo_ment
582 printf "(rb_method_entry_t *) %p\n", (void*)$arg0
583 print *(rb_method_entry_t *)$arg0
585 if $flags == imemo_iseq
586 printf "(rb_iseq_t *) %p\n", (void*)$arg0
587 print *(rb_iseq_t *)$arg0
589 printf "(struct RIMemo *) %p\n", (void*)$arg0
590 print *(struct RIMemo *)$arg0
600 Print the content of a memo
604 print (enum node_type)((((NODE*)($arg0))->flags&RUBY_NODE_TYPEMASK)>>RUBY_NODE_TYPESHIFT)
607 Print a Ruby' node type.
611 print ((NODE*)($arg0))->nd_file
614 Print the source file name of a node.
618 print ((unsigned int)((((NODE*)($arg0))->flags>>RUBY_NODE_LSHIFT)&RUBY_NODE_LMASK))
621 Print the source line number of a node.
624 # Print members of ruby node.
627 printf "%su1.node%s: ", $color_highlite, $color_end
632 printf "%su2.argc%s: ", $color_highlite, $color_end
637 printf "%su3.node%s: ", $color_highlite, $color_end
643 printf "%su1.node%s: ", $color_highlite, $color_end
648 printf "%su2.node%s: ", $color_highlite, $color_end
653 printf "%su3.node%s: ", $color_highlite, $color_end
659 printf "%su3.value%s: ", $color_highlite, $color_end
665 printf "%su2.node%s: ", $color_highlite, $color_end
670 printf "%su3.node%s: ", $color_highlite, $color_end
676 printf "%su1.node%s: ", $color_highlite, $color_end
681 printf "%su2.node%s: ", $color_highlite, $color_end
687 printf "%su1.node%s: ", $color_highlite, $color_end
693 printf "%su3.entry%s: ", $color_highlite, $color_end
698 printf "%su1.id%s: ", $color_highlite, $color_end
703 printf "%su2.id%s: ", $color_highlite, $color_end
708 printf "%su3.value%s: ", $color_highlite, $color_end
713 printf "%su1.tbl%s: ", $color_highlite, $color_end
719 printf "%su1.node%s: ", $color_highlite, $color_end
724 printf "%su2.node%s: ", $color_highlite, $color_end
729 printf "%su3.node%s: ", $color_highlite, $color_end
735 printf "%su2.node%s: ", $color_highlite, $color_end
740 printf "%su3.id%s: ", $color_highlite, $color_end
746 printf "%su1.value%s: ", $color_highlite, $color_end
751 printf "%su2.argc%s: ", $color_highlite, $color_end
756 printf "%su1.node%s: ", $color_highlite, $color_end
762 printf "%su1.node%s: ", $color_highlite, $color_end
767 printf "%su2.id%s: ", $color_highlite, $color_end
772 printf "%su3.node%s: ", $color_highlite, $color_end
777 printf "%su3.node%s: ", $color_highlite, $color_end
783 printf "%su1.id%s: ", $color_highlite, $color_end
788 printf "%su2.id%s: ", $color_highlite, $color_end
794 printf "%su1.id%s: ", $color_highlite, $color_end
799 printf "%su3.node%s: ", $color_highlite, $color_end
805 printf "%su1.id%s: ", $color_highlite, $color_end
810 printf "%su1.value%s: ", $color_highlite, $color_end
816 printf "%su1.node%s: ", $color_highlite, $color_end
821 printf "%su2.node%s: ", $color_highlite, $color_end
826 printf "%su3.state%s: ", $color_highlite, $color_end
831 printf "%su2.value%s: ", $color_highlite, $color_end
837 printf "%su2.argc%s: ", $color_highlite, $color_end
843 printf "%su1.id%s: ", $color_highlite, $color_end
848 printf "%su2.value%s: ", $color_highlite, $color_end
853 set $buf = (struct RString *)rb_str_buf_new(0)
854 call dump_node((VALUE)($buf), rb_str_tmp_new(0), 0, ($arg0))
855 printf "%s\n", $buf->as.heap.ptr
862 define rb_numtable_entry
863 set $rb_numtable_tbl = $arg0
864 set $rb_numtable_id = (st_data_t)$arg1
865 set $rb_numtable_key = 0
866 set $rb_numtable_rec = 0
867 if $rb_numtable_tbl->entries_packed
868 set $rb_numtable_p = $rb_numtable_tbl->as.packed.bins
869 while $rb_numtable_p && $rb_numtable_p < $rb_numtable_tbl->as.packed.bins+$rb_numtable_tbl->num_entries
870 if $rb_numtable_p.k == $rb_numtable_id
871 set $rb_numtable_key = $rb_numtable_p.k
872 set $rb_numtable_rec = $rb_numtable_p.v
873 set $rb_numtable_p = 0
875 set $rb_numtable_p = $rb_numtable_p + 1
879 set $rb_numtable_p = $rb_numtable_tbl->as.big.bins[st_numhash($rb_numtable_id) % $rb_numtable_tbl->num_bins]
881 if $rb_numtable_p->key == $rb_numtable_id
882 set $rb_numtable_key = $rb_numtable_p->key
883 set $rb_numtable_rec = $rb_numtable_p->record
884 set $rb_numtable_p = 0
886 set $rb_numtable_p = $rb_numtable_p->next
894 printf "%sID%s: ", $color_type, $color_end
901 define rb_method_entry
902 set $rb_method_entry_klass = (struct RClass *)$arg0
903 set $rb_method_entry_id = (ID)$arg1
904 set $rb_method_entry_me = (rb_method_entry_t *)0
905 while !$rb_method_entry_me && $rb_method_entry_klass
906 rb_numtable_entry $rb_method_entry_klass->m_tbl_wrapper->tbl $rb_method_entry_id
907 set $rb_method_entry_me = (rb_method_entry_t *)$rb_numtable_rec
908 if !$rb_method_entry_me
909 set $rb_method_entry_klass = (struct RClass *)RCLASS_SUPER($rb_method_entry_klass)
912 if $rb_method_entry_me
913 print *$rb_method_entry_klass
914 print *$rb_method_entry_me
916 echo method not found\n
919 document rb_method_entry
920 Search method entry by class and id
925 set $rb_classname = rb_mod_name($arg0)
926 if $rb_classname != RUBY_Qnil
929 echo anonymous class/module\n
934 set $rb_ancestors_module = $arg0
935 while $rb_ancestors_module
936 rp_class $rb_ancestors_module
937 set $rb_ancestors_module = RCLASS_SUPER($rb_ancestors_module)
940 document rb_ancestors
949 if ruby_dummy_gdb_enums.special_consts
951 if ($arg0)->type == ISEQ_ELEMENT_NONE
954 if ($arg0)->type == ISEQ_ELEMENT_LABEL
955 print *(LABEL*)($arg0)
957 if ($arg0)->type == ISEQ_ELEMENT_INSN
958 print *(INSN*)($arg0)
959 if ((INSN*)($arg0))->insn_id != YARVINSN_jump
961 set $operand_size = ((INSN*)($arg0))->operand_size
962 set $operands = ((INSN*)($arg0))->operands
963 while $i < $operand_size
968 if ($arg0)->type == ISEQ_ELEMENT_ADJUST
969 print *(ADJUST*)($arg0)
974 rb_ps_vm ruby_current_vm_ptr
977 Dump all threads and their callstacks
981 print $ps_vm = (rb_vm_t*)$arg0
982 set $ps_thread_ln = $ps_vm->living_threads.n.next
983 set $ps_thread_ln_last = $ps_vm->living_threads.n.prev
985 set $ps_thread_th = (rb_thread_t *)$ps_thread_ln
986 set $ps_thread = (VALUE)($ps_thread_th->self)
987 rb_ps_thread $ps_thread
988 if $ps_thread_ln == $ps_thread_ln_last
991 set $ps_thread_ln = $ps_thread_ln->next
995 Dump all threads in a (rb_vm_t*) and their callstacks
1000 set $iseq = $cfp->iseq
1001 set $pos = $cfp->pc - $iseq->body->iseq_encoded
1007 set $size = $iseq->body->insns_info.size
1008 set $table = $iseq->body->insns_info.body
1009 set $positions = $iseq->body->insns_info.positions
1010 #printf "size: %d\n", $size
1014 printf "%d", $table[0].line_no
1017 # get_insn_info_linear_search
1019 while $index < $size
1020 #printf "table[%d]: position: %d, line: %d, pos: %d\n", $i, $positions[$i], $table[$i].line_no, $pos
1021 if $positions[$index] > $pos
1024 set $index = $index + 1
1025 if $positions[$index] == $pos
1030 # get_insn_info_succinct_bitvector
1031 set $sd = $iseq->body->insns_info.succ_index_table
1032 set $immediate_table_size = sizeof($sd->imm_part) / sizeof(uint64_t) * 9
1033 if $pos < $immediate_table_size
1036 set $index = ((int)($sd->imm_part[$i] >> ($j * 7))) & 0x7f
1038 set $block_index = ($pos - $immediate_table_size) / 512
1039 set $block = &$sd->succ_part[$block_index]
1040 set $block_bit_index = ($pos - $immediate_table_size) % 512
1041 set $small_block_index = $block_bit_index / 64
1042 set $small_block_popcount = $small_block_index == 0 ? 0 : (((int)($block->small_block_ranks >> (($small_block_index - 1) * 9))) & 0x1ff)
1043 set $x = $block->bits[$small_block_index] << (63 - $block_bit_index % 64)
1044 set $x = ($x & 0x5555555555555555) + ($x >> 1 & 0x5555555555555555)
1045 set $x = ($x & 0x3333333333333333) + ($x >> 2 & 0x3333333333333333)
1046 set $x = ($x & 0x0707070707070707) + ($x >> 4 & 0x0707070707070707)
1047 set $x = ($x & 0x001f001f001f001f) + ($x >> 8 & 0x001f001f001f001f)
1048 set $x = ($x & 0x0000003f0000003f) + ($x >>16 & 0x0000003f0000003f)
1049 set $popcnt = ($x & 0x7f) + ($x >>32 & 0x7f)
1050 set $index = $block->rank + $small_block_popcount + $popcnt
1053 printf "%d", $table[$index-1].line_no
1058 define check_method_entry
1059 set $imemo = (struct RBasic *)$arg0
1060 if $imemo != RUBY_Qfalse
1061 set $type = ($imemo->flags >> 12) & 0x07
1062 if $type == imemo_ment
1063 set $me = (rb_callable_method_entry_t *)$imemo
1065 if $type == imemo_svar
1066 set $imemo = ((struct vm_svar *)$imemo)->cref_or_me
1067 check_method_entry $imemo
1076 if $id > tLAST_OP_ID
1077 set $serial = (rb_id_serial_t)($id >> RUBY_ID_SCOPE_SHIFT)
1079 set $serial = (rb_id_serial_t)$id
1081 if $serial && $serial <= ruby_global_symbols.last_id
1082 set $idx = $serial / ID_ENTRY_UNIT
1083 set $ids = (struct RArray *)ruby_global_symbols.ids
1084 set $flags = $ids->basic.flags
1085 if ($flags & RUBY_FL_USER1)
1086 set $idsptr = $ids->as.ary
1087 set $idslen = (($flags & (RUBY_FL_USER3|RUBY_FL_USER4)) >> (RUBY_FL_USHIFT+3))
1089 set $idsptr = $ids->as.heap.ptr
1090 set $idslen = $ids->as.heap.len
1094 set $ary = (struct RArray *)$idsptr[$idx]
1095 if $ary != RUBY_Qnil
1096 set $flags = $ary->basic.flags
1097 if ($flags & RUBY_FL_USER1)
1098 set $aryptr = $ary->as.ary
1099 set $arylen = (($flags & (RUBY_FL_USER3|RUBY_FL_USER4)) >> (RUBY_FL_USHIFT+3))
1101 set $aryptr = $ary->as.heap.ptr
1102 set $arylen = $ary->as.heap.len
1104 set $result = $aryptr[($serial % ID_ENTRY_UNIT) * ID_ENTRY_SIZE + $t]
1105 if $result != RUBY_Qnil
1106 print_string $result
1115 define print_pathobj
1116 set $flags = ((struct RBasic*)($arg0))->flags
1117 if ($flags & RUBY_T_MASK) == RUBY_T_STRING
1120 if ($flags & RUBY_T_MASK) == RUBY_T_ARRAY
1121 if $flags & RUBY_FL_USER1
1122 set $str = ((struct RArray*)($arg0))->as.ary[0]
1124 set $str = ((struct RArray*)($arg0))->as.heap.ptr[0]
1131 set $ps_thread = (struct RTypedData*)$arg0
1132 set $ps_thread_th = (rb_thread_t*)$ps_thread->data
1133 printf "* #<Thread:%p rb_thread_t:%p native_thread:%p>\n", \
1134 $ps_thread, $ps_thread_th, $ps_thread_th->thread_id
1135 set $cfp = $ps_thread_th->ec->cfp
1136 set $cfpend = (rb_control_frame_t *)($ps_thread_th->ec->vm_stack + $ps_thread_th->ec->vm_stack_size)-1
1137 while $cfp < $cfpend
1139 if !((VALUE)$cfp->iseq & RUBY_IMMEDIATE_MASK) && (((imemo_ifunc << RUBY_FL_USHIFT) | RUBY_T_IMEMO)==$cfp->iseq->flags & ((RUBY_IMEMO_MASK << RUBY_FL_USHIFT) | RUBY_T_MASK))
1140 printf "%d:ifunc ", $cfpend-$cfp
1141 set print symbol-filename on
1142 output/a $cfp->iseq.body
1143 set print symbol-filename off
1147 set $location = $cfp->iseq->body->location
1148 printf "%d:", $cfpend-$cfp
1149 print_pathobj $location.pathobj
1153 print_string $location.label
1156 printf "%d: ???.rb:???:in `???'\n", $cfpend-$cfp
1160 # if VM_FRAME_TYPE($cfp->flag) == VM_FRAME_MAGIC_CFUNC
1162 if ($ep[0] & 0xffff0001) == 0x55550001
1163 #define VM_ENV_FLAG_LOCAL 0x02
1164 #define VM_ENV_PREV_EP(ep) GC_GUARDED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL])
1166 set $env_specval = $ep[-1]
1167 set $env_me_cref = $ep[-2]
1168 while ($env_specval & 0x02) != 0
1169 check_method_entry $env_me_cref
1174 set $env_specval = $ep[-1]
1175 set $env_me_cref = $ep[-2]
1178 check_method_entry $env_me_cref
1180 printf "%d:", $cfpend-$cfp
1181 set print symbol-filename on
1182 output/a $me->def->body.cfunc.func
1183 set print symbol-filename off
1184 set $mid = $me->def->original_id
1189 printf "%d:unknown_frame:???:in `???'\n", $cfpend-$cfp
1196 define rb_count_objects
1197 set $objspace = ruby_current_vm_ptr->objspace
1232 while $i < $objspace->heap_pages.allocated_pages
1233 printf "\rcounting... %d/%d", $i, $objspace->heap_pages.allocated_pages
1234 set $page = $objspace->heap_pages.sorted[$i]
1235 set $p = $page->start
1236 set $pend = $p + $page->total_slots
1238 set $flags = $p->as.basic.flags & 0x1f
1239 eval "set $counts_%02x = $counts_%02x + 1", $flags, $flags
1242 set $total = $total + $page->total_slots
1245 printf "\rTOTAL: %d, FREE: %d\n", $total, $counts_00
1246 printf "T_OBJECT: %d\n", $counts_01
1247 printf "T_CLASS: %d\n", $counts_02
1248 printf "T_MODULE: %d\n", $counts_03
1249 printf "T_FLOAT: %d\n", $counts_04
1250 printf "T_STRING: %d\n", $counts_05
1251 printf "T_REGEXP: %d\n", $counts_06
1252 printf "T_ARRAY: %d\n", $counts_07
1253 printf "T_HASH: %d\n", $counts_08
1254 printf "T_STRUCT: %d\n", $counts_09
1255 printf "T_BIGNUM: %d\n", $counts_0a
1256 printf "T_FILE: %d\n", $counts_0b
1257 printf "T_DATA: %d\n", $counts_0c
1258 printf "T_MATCH: %d\n", $counts_0d
1259 printf "T_COMPLEX: %d\n", $counts_0e
1260 printf "T_RATIONAL: %d\n", $counts_0f
1261 #printf "UNKNOWN_10: %d\n", $counts_10
1262 printf "T_NIL: %d\n", $counts_11
1263 printf "T_TRUE: %d\n", $counts_12
1264 printf "T_FALSE: %d\n", $counts_13
1265 printf "T_SYMBOL: %d\n", $counts_14
1266 printf "T_FIXNUM: %d\n", $counts_15
1267 printf "T_UNDEF: %d\n", $counts_16
1268 #printf "UNKNOWN_17: %d\n", $counts_17
1269 #printf "UNKNOWN_18: %d\n", $counts_18
1270 #printf "UNKNOWN_19: %d\n", $counts_19
1271 printf "T_IMEMO: %d\n", $counts_1a
1272 printf "T_NODE: %d\n", $counts_1b
1273 printf "T_ICLASS: %d\n", $counts_1c
1274 printf "T_ZOMBIE: %d\n", $counts_1d
1275 #printf "UNKNOWN_1E: %d\n", $counts_1e
1276 printf "T_MASK: %d\n", $counts_1f
1278 document rb_count_objects
1279 Counts all objects grouped by type.
1282 # Details: https://bugs.ruby-lang.org/projects/ruby-master/wiki/MachineInstructionsTraceWithGDB
1283 define trace_machine_instructions
1295 call rb_vmdebug_stack_dump_raw_current()
1299 if ((LINK_ELEMENT*)$arg0)->type == ISEQ_ELEMENT_LABEL
1302 if ((LINK_ELEMENT*)$arg0)->type == ISEQ_ELEMENT_INSN
1305 if ((LINK_ELEMENT*)$arg0)->type == ISEQ_ELEMENT_ADJUST
1315 set $str = rb_parser_dump_tree($arg0, 0)
1316 set $flags = ((struct RBasic*)($str))->flags
1317 printf "%s", (char *)(($flags & RUBY_FL_USER1) ? \
1318 ((struct RString*)$str)->as.heap.ptr : \
1319 ((struct RString*)$str)->as.ary)
1323 printf "RUBY_FL_WB_PROTECTED: %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_WB_PROTECTED ? "1" : "0"
1324 printf "RUBY_FL_PROMOTED0 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_PROMOTED0 ? "1" : "0"
1325 printf "RUBY_FL_PROMOTED1 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_PROMOTED1 ? "1" : "0"
1326 printf "RUBY_FL_FINALIZE : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_FINALIZE ? "1" : "0"
1327 printf "RUBY_FL_SHAREABLE : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_SHAREABLE ? "1" : "0"
1328 printf "RUBY_FL_EXIVAR : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_EXIVAR ? "1" : "0"
1329 printf "RUBY_FL_FREEZE : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_FREEZE ? "1" : "0"
1331 printf "RUBY_FL_USER0 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER0 ? "1" : "0"
1332 printf "RUBY_FL_USER1 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER1 ? "1" : "0"
1333 printf "RUBY_FL_USER2 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER2 ? "1" : "0"
1334 printf "RUBY_FL_USER3 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER3 ? "1" : "0"
1335 printf "RUBY_FL_USER4 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER4 ? "1" : "0"
1336 printf "RUBY_FL_USER5 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER5 ? "1" : "0"
1337 printf "RUBY_FL_USER6 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER6 ? "1" : "0"
1338 printf "RUBY_FL_USER7 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER7 ? "1" : "0"
1339 printf "RUBY_FL_USER8 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER8 ? "1" : "0"
1340 printf "RUBY_FL_USER9 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER9 ? "1" : "0"
1341 printf "RUBY_FL_USER10 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER10 ? "1" : "0"
1342 printf "RUBY_FL_USER11 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER11 ? "1" : "0"
1343 printf "RUBY_FL_USER12 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER12 ? "1" : "0"
1344 printf "RUBY_FL_USER13 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER13 ? "1" : "0"
1345 printf "RUBY_FL_USER14 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER14 ? "1" : "0"
1346 printf "RUBY_FL_USER15 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER15 ? "1" : "0"
1347 printf "RUBY_FL_USER16 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER16 ? "1" : "0"
1348 printf "RUBY_FL_USER17 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER17 ? "1" : "0"
1349 printf "RUBY_FL_USER18 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER18 ? "1" : "0"