diff options
Diffstat (limited to '.gdbinit')
| -rw-r--r-- | .gdbinit | 293 |
1 files changed, 159 insertions, 134 deletions
@@ -1,21 +1,7 @@ -define hook-run - set $color_type = 0 - set $color_highlite = 0 - set $color_end = 0 -end - define ruby_gdb_init - if !$color_type - set $color_type = "\033[31m" - end - if !$color_highlite - set $color_highlite = "\033[36m" - end - if !$color_end - set $color_end = "\033[m" - end - if ruby_dummy_gdb_enums.special_consts - end + init-if-undefined $color_type = "\033[31m" + init-if-undefined $color_highlite = "\033[36m" + init-if-undefined $color_end = "\033[m" end # set prompt \033[36m(gdb)\033[m\040 @@ -65,7 +51,7 @@ define rp printf "%sT_OBJECT%s: ", $color_type, $color_end print ((struct RObject *)($arg0))->basic if ($flags & ROBJECT_EMBED) - print/x *((VALUE*)((struct RObject*)($arg0))->as.ary) @ (ROBJECT_EMBED_LEN_MAX+0) + print/x *((VALUE*)((struct RObject*)($arg0))->as.ary) @ (RSHAPE_CAPACITY(rb_obj_shape_id($arg0))) else print (((struct RObject *)($arg0))->as.heap) if (((struct RObject*)($arg0))->as.heap.numiv) > 0 @@ -97,13 +83,11 @@ define rp set $regsrc = ((struct RRegexp*)($arg0))->src set $rsflags = ((struct RBasic*)$regsrc)->flags printf "%sT_REGEXP%s: ", $color_type, $color_end - set $len = ($rsflags & RUBY_FL_USER1) ? \ - ((struct RString*)$regsrc)->as.heap.len : \ - (($rsflags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2) + set $len = ((struct RString*)($arg0))->len set print address off output *(char *)(($rsflags & RUBY_FL_USER1) ? \ - ((struct RString*)$regsrc)->as.heap.ptr : \ - ((struct RString*)$regsrc)->as.ary) @ $len + ((struct RString*)$regsrc)->as.heap.ptr : \ + ((struct RString*)$regsrc)->as.embed.ary) @ $len set print address on printf " len:%ld ", $len if $flags & RUBY_FL_USER6 @@ -124,26 +108,26 @@ define rp printf "%sT_ARRAY%s: len=%ld ", $color_type, $color_end, $len printf "(embed) " if ($len == 0) - printf "{(empty)} " + printf "{(empty)} " else - print/x *((VALUE*)((struct RArray*)($arg0))->as.ary) @ $len - printf " " + print/x *((VALUE*)((struct RArray*)($arg0))->as.ary) @ $len + printf " " end else set $len = ((struct RArray*)($arg0))->as.heap.len printf "%sT_ARRAY%s: len=%ld ", $color_type, $color_end, $len if ($flags & RUBY_FL_USER2) - printf "(shared) shared=" - output/x ((struct RArray*)($arg0))->as.heap.aux.shared - printf " " + printf "(shared) shared=" + output/x ((struct RArray*)($arg0))->as.heap.aux.shared_root + printf " " else - printf "(ownership) capa=%ld ", ((struct RArray*)($arg0))->as.heap.aux.capa + printf "(ownership) capa=%ld ", ((struct RArray*)($arg0))->as.heap.aux.capa end if ($len == 0) - printf "{(empty)} " + printf "{(empty)} " else - print/x *((VALUE*)((struct RArray*)($arg0))->as.heap.ptr) @ $len - printf " " + print/x *((VALUE*)((struct RArray*)($arg0))->as.heap.ptr) @ $len + printf " " end end print (struct RArray *)($arg0) @@ -154,10 +138,16 @@ define rp else if ($flags & RUBY_T_MASK) == RUBY_T_HASH printf "%sT_HASH%s: ", $color_type, $color_end, - if ((struct RHash *)($arg0))->ntbl - printf "len=%ld ", ((struct RHash *)($arg0))->ntbl->num_entries + if (((struct RHash *)($arg0))->basic.flags & RHASH_ST_TABLE_FLAG) + set $st = (struct st_table *)((uintptr_t)($arg0) + sizeof(struct RHash)) + printf "st len=%ld ", $st->num_entries + print $st + else + printf "li len=%ld bound=%ld ", \ + ((((struct RHash *)($arg0))->basic.flags & RHASH_AR_TABLE_SIZE_MASK) >> RHASH_AR_TABLE_SIZE_SHIFT), \ + ((((struct RHash *)($arg0))->basic.flags & RHASH_AR_TABLE_BOUND_MASK) >> RHASH_AR_TABLE_BOUND_SHIFT) + print (struct ar_table_struct *)((uintptr_t)($arg0) + sizeof(struct RHash)) end - print (struct RHash *)($arg0) else if ($flags & RUBY_T_MASK) == RUBY_T_STRUCT set $len = (($flags & (RUBY_FL_USER1|RUBY_FL_USER2)) ? \ @@ -195,12 +185,14 @@ define rp print (struct RBasic *)($arg0) else if ($flags & RUBY_T_MASK) == RUBY_T_DATA - if ((struct RTypedData *)($arg0))->typed_flag == 1 - printf "%sT_DATA%s(%s): ", $color_type, $color_end, ((struct RTypedData *)($arg0))->type->wrap_struct_name - print (struct RTypedData *)($arg0) + set $data = (struct RTypedData *)($arg0) + set $type = (const rb_data_type_t *)($data->type & ~1) + printf "%sT_DATA%s(%s): ", $color_type, $color_end, $type->wrap_struct_name + print *$type + if ($data->type & 1) + print (void *)&$data->data else - printf "%sT_DATA%s: ", $color_type, $color_end - print (struct RData *)($arg0) + print $data end else if ($flags & RUBY_T_MASK) == RUBY_T_MATCH @@ -259,6 +251,10 @@ define rp printf "%sT_ZOMBIE%s: ", $color_type, $color_end print (struct RData *)($arg0) else + if ($flags & RUBY_T_MASK) == RUBY_T_MOVED + printf "%sT_MOVED%s: ", $color_type, $color_end + print *(struct RMoved *)$arg0 + else printf "%sunknown%s: ", $color_type, $color_end print (struct RBasic *)($arg0) end @@ -294,6 +290,7 @@ define rp end end end + end end document rp Print a Ruby's VALUE. @@ -429,13 +426,11 @@ end define output_string set $flags = ((struct RBasic*)($arg0))->flags - set $len = ($flags & RUBY_FL_USER1) ? \ - ((struct RString*)($arg0))->as.heap.len : \ - (($flags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2) + set $len = ((struct RString*)($arg0))->len if $len > 0 output *(char *)(($flags & RUBY_FL_USER1) ? \ - ((struct RString*)($arg0))->as.heap.ptr : \ - ((struct RString*)($arg0))->as.ary) @ $len + ((struct RString*)($arg0))->as.heap.ptr : \ + ((struct RString*)($arg0))->as.embed.ary) @ $len else output "" end @@ -443,13 +438,11 @@ end define print_string set $flags = ((struct RBasic*)($arg0))->flags - set $len = ($flags & RUBY_FL_USER1) ? \ - ((struct RString*)($arg0))->as.heap.len : \ - (($flags & (RUBY_FL_USER2|RUBY_FL_USER3|RUBY_FL_USER4|RUBY_FL_USER5|RUBY_FL_USER6)) >> RUBY_FL_USHIFT+2) + set $len = ((struct RString*)($arg0))->len if $len > 0 printf "%s", *(char *)(($flags & RUBY_FL_USER1) ? \ - ((struct RString*)($arg0))->as.heap.ptr : \ - ((struct RString*)($arg0))->as.ary) @ $len + ((struct RString*)($arg0))->as.heap.ptr : \ + ((struct RString*)($arg0))->as.embed.ary) @ $len end end @@ -532,14 +525,14 @@ document rp_bignum end define rp_class + set $class_and_classext = (struct RClass_and_rb_classext_t *)($arg0) printf "(struct RClass *) %p", (void*)$arg0 - if ((struct RClass *)($arg0))->ptr.origin_ != $arg0 - printf " -> %p", ((struct RClass *)($arg0))->ptr.origin_ + if $class_and_classext->classext->origin_ != (VALUE)$arg0 + printf " -> %p", $class_and_classext->classext->origin_ end printf "\n" rb_classname $arg0 - print/x *(struct RClass *)($arg0) - print *((struct RClass *)($arg0))->ptr + print/x *$class_and_classext end document rp_class Print the content of a Class/Module. @@ -678,11 +671,6 @@ define nd_stts end -define nd_entry - printf "%su3.entry%s: ", $color_highlite, $color_end - p ($arg0).u3.entry -end - define nd_vid printf "%su1.id%s: ", $color_highlite, $color_end p ($arg0).u1.id @@ -698,12 +686,6 @@ define nd_cval rp ($arg0).u3.value end - -define nd_cnt - printf "%su3.cnt%s: ", $color_highlite, $color_end - p ($arg0).u3.cnt -end - define nd_tbl printf "%su1.tbl%s: ", $color_highlite, $color_end p ($arg0).u1.tbl @@ -742,12 +724,6 @@ define nd_lit rp ($arg0).u1.value end - -define nd_frml - printf "%su1.node%s: ", $color_highlite, $color_end - rp ($arg0).u1.node -end - define nd_rest printf "%su2.argc%s: ", $color_highlite, $color_end p ($arg0).u2.argc @@ -774,12 +750,6 @@ define nd_args rp ($arg0).u3.node end - -define nd_noex - printf "%su1.id%s: ", $color_highlite, $color_end - p ($arg0).u1.id -end - define nd_defn printf "%su3.node%s: ", $color_highlite, $color_end rp ($arg0).u3.node @@ -797,17 +767,6 @@ define nd_new end -define nd_cfnc - printf "%su1.cfunc%s: ", $color_highlite, $color_end - p ($arg0).u1.cfunc -end - -define nd_argc - printf "%su2.argc%s: ", $color_highlite, $color_end - p ($arg0).u2.argc -end - - define nd_cname printf "%su1.id%s: ", $color_highlite, $color_end p ($arg0).u1.id @@ -886,22 +845,22 @@ define rb_numtable_entry set $rb_numtable_p = $rb_numtable_tbl->as.packed.bins while $rb_numtable_p && $rb_numtable_p < $rb_numtable_tbl->as.packed.bins+$rb_numtable_tbl->num_entries if $rb_numtable_p.k == $rb_numtable_id - set $rb_numtable_key = $rb_numtable_p.k - set $rb_numtable_rec = $rb_numtable_p.v - set $rb_numtable_p = 0 + set $rb_numtable_key = $rb_numtable_p.k + set $rb_numtable_rec = $rb_numtable_p.v + set $rb_numtable_p = 0 else - set $rb_numtable_p = $rb_numtable_p + 1 + set $rb_numtable_p = $rb_numtable_p + 1 end end else set $rb_numtable_p = $rb_numtable_tbl->as.big.bins[st_numhash($rb_numtable_id) % $rb_numtable_tbl->num_bins] while $rb_numtable_p if $rb_numtable_p->key == $rb_numtable_id - set $rb_numtable_key = $rb_numtable_p->key - set $rb_numtable_rec = $rb_numtable_p->record - set $rb_numtable_p = 0 + set $rb_numtable_key = $rb_numtable_p->key + set $rb_numtable_rec = $rb_numtable_p->record + set $rb_numtable_p = 0 else - set $rb_numtable_p = $rb_numtable_p->next + set $rb_numtable_p = $rb_numtable_p->next end end end @@ -939,10 +898,10 @@ document rb_method_entry end define rb_classname - # up to 128bit int - set $rb_classname = rb_mod_name($arg0) - if $rb_classname != RUBY_Qnil - rp $rb_classname + set $rb_classname = ((struct RClass_and_rb_classext_t*)$arg0)->classext->classpath + if $rb_classname != RUBY_Qfalse + print_string $rb_classname + printf "\n" else echo anonymous class/module\n end @@ -979,7 +938,7 @@ define iseq set $operand_size = ((INSN*)($arg0))->operand_size set $operands = ((INSN*)($arg0))->operands while $i < $operand_size - rp $operands[$i++] + rp $operands[$i++] end end end @@ -997,8 +956,8 @@ end define rb_ps_vm print $ps_vm = (rb_vm_t*)$arg0 - set $ps_thread_ln = $ps_vm->living_threads.n.next - set $ps_thread_ln_last = $ps_vm->living_threads.n.prev + set $ps_thread_ln = $ps_vm->ractor.main_ractor.threads.set.n.next + set $ps_thread_ln_last = $ps_vm->ractor.main_ractor.threads.set.n.prev while 1 set $ps_thread_th = (rb_thread_t *)$ps_thread_ln set $ps_thread = (VALUE)($ps_thread_th->self) @@ -1015,30 +974,61 @@ end define print_lineno set $cfp = $arg0 - set $iseq = $cfp->iseq + set $iseq = rb_get_cfp_iseq($cfp) set $pos = $cfp->pc - $iseq->body->iseq_encoded if $pos != 0 set $pos = $pos - 1 end - set $i = 0 - set $size = $iseq->body->line_info_size - set $table = $iseq->body->line_info_table + set $index = 0 + set $size = $iseq->body->insns_info.size + set $table = $iseq->body->insns_info.body + set $positions = $iseq->body->insns_info.positions #printf "size: %d\n", $size if $size == 0 else - set $i = 1 - while $i < $size - #printf "table[%d]: position: %d, line: %d, pos: %d\n", $i, $table[$i].position, $table[$i].line_no, $pos - if $table[$i].position > $pos - loop_break + if $size == 1 + printf "%d", $table[0].line_no + else + if $positions + # get_insn_info_linear_search + set $index = 1 + while $index < $size + #printf "table[%d]: position: %d, line: %d, pos: %d\n", $i, $positions[$i], $table[$i].line_no, $pos + if $positions[$index] > $pos + loop_break + end + set $index = $index + 1 + if $positions[$index] == $pos + loop_break + end end - set $i = $i + 1 - if $table[$i].position == $pos - loop_break + else + # get_insn_info_succinct_bitvector + set $sd = $iseq->body->insns_info.succ_index_table + set $immediate_table_size = sizeof($sd->imm_part) / sizeof(uint64_t) * 9 + if $pos < $immediate_table_size + set $i = $pos / 9 + set $j = $pos % 9 + set $index = ((int)($sd->imm_part[$i] >> ($j * 7))) & 0x7f + else + set $block_index = ($pos - $immediate_table_size) / 512 + set $block = &$sd->succ_part[$block_index] + set $block_bit_index = ($pos - $immediate_table_size) % 512 + set $small_block_index = $block_bit_index / 64 + set $small_block_popcount = $small_block_index == 0 ? 0 : (((int)($block->small_block_ranks >> (($small_block_index - 1) * 9))) & 0x1ff) + set $x = $block->bits[$small_block_index] << (63 - $block_bit_index % 64) + set $x = ($x & 0x5555555555555555) + ($x >> 1 & 0x5555555555555555) + set $x = ($x & 0x3333333333333333) + ($x >> 2 & 0x3333333333333333) + set $x = ($x & 0x0707070707070707) + ($x >> 4 & 0x0707070707070707) + set $x = ($x & 0x001f001f001f001f) + ($x >> 8 & 0x001f001f001f001f) + set $x = ($x & 0x0000003f0000003f) + ($x >>16 & 0x0000003f0000003f) + set $popcnt = ($x & 0x7f) + ($x >>32 & 0x7f) + set $index = $block->rank + $small_block_popcount + $popcnt end end - printf "%d", $table[$i-1].line_no + printf "%d", $table[$index-1].line_no + end end end @@ -1065,9 +1055,9 @@ define print_id else set $serial = (rb_id_serial_t)$id end - if $serial && $serial <= global_symbols.last_id + if $serial && $serial < ruby_global_symbols.next_id set $idx = $serial / ID_ENTRY_UNIT - set $ids = (struct RArray *)global_symbols.ids + set $ids = (struct RArray *)ruby_global_symbols.ids set $flags = $ids->basic.flags if ($flags & RUBY_FL_USER1) set $idsptr = $ids->as.ary @@ -1088,12 +1078,12 @@ define print_id set $aryptr = $ary->as.heap.ptr set $arylen = $ary->as.heap.len end - set $result = $aryptr[($serial % ID_ENTRY_UNIT) * ID_ENTRY_SIZE + $t] - if $result != RUBY_Qnil + set $result = $aryptr[($serial % ID_ENTRY_UNIT) + $t] + if $result != RUBY_Qnil print_string $result - else - echo undef - end + else + echo undef + end end end end @@ -1110,7 +1100,7 @@ define print_pathobj else set $str = ((struct RArray*)($arg0))->as.heap.ptr[0] end - printf "%s", $str + print_string $str end end @@ -1118,20 +1108,21 @@ define rb_ps_thread set $ps_thread = (struct RTypedData*)$arg0 set $ps_thread_th = (rb_thread_t*)$ps_thread->data printf "* #<Thread:%p rb_thread_t:%p native_thread:%p>\n", \ - $ps_thread, $ps_thread_th, $ps_thread_th->thread_id + $ps_thread, $ps_thread_th, $ps_thread_th->nt set $cfp = $ps_thread_th->ec->cfp set $cfpend = (rb_control_frame_t *)($ps_thread_th->ec->vm_stack + $ps_thread_th->ec->vm_stack_size)-1 while $cfp < $cfpend - if $cfp->iseq - 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)) + if $cfp->_iseq + set $iseq = rb_get_cfp_iseq($cfp) + if !((VALUE)$iseq & RUBY_IMMEDIATE_MASK) && (((imemo_ifunc << RUBY_FL_USHIFT) | RUBY_T_IMEMO)==$iseq->flags & ((RUBY_IMEMO_MASK << RUBY_FL_USHIFT) | RUBY_T_MASK)) printf "%d:ifunc ", $cfpend-$cfp set print symbol-filename on - output/a $cfp->iseq.body + output/a $iseq.body set print symbol-filename off printf "\n" else if $cfp->pc - set $location = $cfp->iseq->body->location + set $location = $iseq->body->location printf "%d:", $cfpend-$cfp print_pathobj $location.pathobj printf ":" @@ -1266,9 +1257,9 @@ document rb_count_objects Counts all objects grouped by type. end -# Details: https://bugs.ruby-lang.org/projects/ruby-trunk/wiki/MachineInstructionsTraceWithGDB +# Details: https://github.com/ruby/ruby/wiki/Machine-Instructions-Trace-with-GDB define trace_machine_instructions - set logging on + set logging enabled set height 0 set width 0 display/i $pc @@ -1303,5 +1294,39 @@ define dump_node set $flags = ((struct RBasic*)($str))->flags printf "%s", (char *)(($flags & RUBY_FL_USER1) ? \ ((struct RString*)$str)->as.heap.ptr : \ - ((struct RString*)$str)->as.ary) -end + ((struct RString*)$str)->as.embed.ary) +end + +define print_flags + printf "RUBY_FL_WB_PROTECTED: %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_WB_PROTECTED ? "1" : "0" + printf "RUBY_FL_PROMOTED : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_PROMOTED ? "1" : "0" + printf "RUBY_FL_FINALIZE : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_FINALIZE ? "1" : "0" + printf "RUBY_FL_SHAREABLE : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_SHAREABLE ? "1" : "0" + printf "RUBY_FL_EXIVAR : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_EXIVAR ? "1" : "0" + printf "RUBY_FL_FREEZE : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_FREEZE ? "1" : "0" + + printf "RUBY_FL_USER0 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER0 ? "1" : "0" + printf "RUBY_FL_USER1 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER1 ? "1" : "0" + printf "RUBY_FL_USER2 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER2 ? "1" : "0" + printf "RUBY_FL_USER3 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER3 ? "1" : "0" + printf "RUBY_FL_USER4 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER4 ? "1" : "0" + printf "RUBY_FL_USER5 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER5 ? "1" : "0" + printf "RUBY_FL_USER6 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER6 ? "1" : "0" + printf "RUBY_FL_USER7 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER7 ? "1" : "0" + printf "RUBY_FL_USER8 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER8 ? "1" : "0" + printf "RUBY_FL_USER9 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER9 ? "1" : "0" + printf "RUBY_FL_USER10 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER10 ? "1" : "0" + printf "RUBY_FL_USER11 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER11 ? "1" : "0" + printf "RUBY_FL_USER12 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER12 ? "1" : "0" + printf "RUBY_FL_USER13 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER13 ? "1" : "0" + printf "RUBY_FL_USER14 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER14 ? "1" : "0" + printf "RUBY_FL_USER15 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER15 ? "1" : "0" + printf "RUBY_FL_USER16 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER16 ? "1" : "0" + printf "RUBY_FL_USER17 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER17 ? "1" : "0" + printf "RUBY_FL_USER18 : %s\n", ((struct RBasic*)($arg0))->flags & RUBY_FL_USER18 ? "1" : "0" +end + +source -s misc/gdb.py + +# Moved from beginning, since it fails on older gdbs +set startup-with-shell off |
