Skip to content

Commit bc44b8a

Browse files
committed
2.0 compilation (WIP)
1 parent 9dc01e2 commit bc44b8a

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

ext/ruby_debug/extconf.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
2626
end and
2727
have_header("vm_core.h") and have_header("iseq.h") and have_header("insns.inc") and
2828
have_header("insns_info.inc") and have_header("eval_intern.h")
29-
if checking_for(checking_message("if rb_iseq_compile_with_option was added an argument filepath")) do
30-
try_compile(<<SRC)
31-
#include <ruby.h>
32-
#include "vm_core.h"
33-
extern VALUE rb_iseq_new_main(NODE *node, VALUE filename, VALUE filepath);
34-
SRC
35-
end
36-
$defs << '-DRB_ISEQ_COMPILE_5ARGS'
37-
end
29+
have_func("rb_iseq_new_main", "vm_core.h")
30+
have_func("rb_iseq_compile_on_base", "vm_core.h")
31+
have_struct_member("rb_iseq_t", "location", "vm_core.h") or have_struct_member("rb_iseq_t", "filename", "vm_core.h")
32+
have_struct_member("rb_iseq_t", "line_info_size", "vm_core.h") or have_struct_member("rb_iseq_t", "insn_info_size", "vm_core.h")
33+
have_struct_member("rb_control_frame_t", "ep", "vm_core.h") or
34+
have_struct_member("rb_control_frame_t", "dfp", "vm_core.h")
35+
have_struct_member("rb_control_frame_t", "bp", "vm_core.h")
36+
true
3837
}
3938

39+
$defs << "-O0"
40+
4041
dir_config("ruby")
4142
if !Debugger::RubyCoreSource.create_makefile_with_core(hdrs, "ruby_debug")
4243
STDERR.print("Makefile creation failed\n")

ext/ruby_debug/ruby_debug.c

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
int rb_vm_get_sourceline(const rb_control_frame_t *cfp); /* from vm.c */
2424
/* from iseq.c */
25-
#ifdef RB_ISEQ_COMPILE_5ARGS
25+
#ifdef HAVE_RB_ISEQ_COMPILE_ON_BASE
26+
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt);
27+
#elif RB_ISEQ_COMPILE_5ARGS
2628
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt);
2729
#else
2830
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE line, VALUE opt);
@@ -502,7 +504,11 @@ save_call_frame(rb_event_flag_t _event, debug_context_t *debug_context, VALUE se
502504
debug_frame->arg_ary = Qnil;
503505
debug_frame->argc = GET_THREAD()->cfp->iseq->argc;
504506
debug_frame->info.runtime.cfp = GET_THREAD()->cfp;
507+
#if VM_DEBUG_BP_CHECK
508+
debug_frame->info.runtime.bp_check = GET_THREAD()->cfp->bp_check;
509+
#else
505510
debug_frame->info.runtime.bp = GET_THREAD()->cfp->bp;
511+
#endif
506512
debug_frame->info.runtime.block_iseq = GET_THREAD()->cfp->block_iseq;
507513
debug_frame->info.runtime.block_pc = NULL;
508514
debug_frame->info.runtime.last_pc = GET_THREAD()->cfp->pc;
@@ -705,7 +711,10 @@ create_catch_table(debug_context_t *debug_context, unsigned long cont)
705711
GET_THREAD()->parse_in_eval++;
706712
GET_THREAD()->mild_compile_error++;
707713
/* compiling with option Qfalse (no options) prevents debug hook calls during this catch routine */
708-
#ifdef RB_ISEQ_COMPILE_5ARGS
714+
#ifdef HAVE_RB_ISEQ_COMPILE_ON_BASE
715+
catch_table->iseq = rb_iseq_compile_with_option(
716+
rb_str_new_cstr("begin\nend"), rb_str_new_cstr("(exception catcher)"), Qnil, INT2FIX(1), NULL, Qfalse);
717+
#elif RB_ISEQ_COMPILE_5ARGS
709718
catch_table->iseq = rb_iseq_compile_with_option(
710719
rb_str_new_cstr("begin\nend"), rb_str_new_cstr("(exception catcher)"), Qnil, INT2FIX(1), Qfalse);
711720
#else
@@ -724,6 +733,7 @@ create_catch_table(debug_context_t *debug_context, unsigned long cont)
724733
return(catch_table);
725734
}
726735

736+
#ifdef RUBY_EVENT_VM
727737
static int
728738
set_thread_event_flag_i(st_data_t key, st_data_t val, st_data_t flag)
729739
{
@@ -734,6 +744,7 @@ set_thread_event_flag_i(st_data_t key, st_data_t val, st_data_t flag)
734744

735745
return(ST_CONTINUE);
736746
}
747+
#endif
737748

738749
static void
739750
debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE klass)
@@ -758,8 +769,9 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
758769
mid = iseq->defined_method_id;
759770
klass = iseq->klass;
760771
}
761-
772+
#ifdef ID_ALLOCATOR
762773
if (mid == ID_ALLOCATOR) return;
774+
#endif
763775

764776
/* return if thread is marked as 'ignored'.
765777
debugger's threads are marked this way
@@ -806,13 +818,19 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
806818
debug_context->old_iseq_catch = NULL;
807819
}
808820

821+
#ifdef RUBY_EVENT_VM
809822
/* make sure all threads have event flag set so we'll get its events */
810823
st_foreach(thread->vm->living_threads, set_thread_event_flag_i, 0);
824+
#endif
811825

812826
/* remove any frames that are now out of scope */
813827
while(debug_context->stack_size > 0)
814828
{
829+
#if VM_DEBUG_BP_CHECK
830+
if (debug_context->frames[debug_context->stack_size - 1].info.runtime.bp_check <= thread->cfp->bp_check)
831+
#else
815832
if (debug_context->frames[debug_context->stack_size - 1].info.runtime.bp <= thread->cfp->bp)
833+
#endif
816834
break;
817835
debug_context->stack_size--;
818836
}
@@ -988,7 +1006,11 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl
9881006
while(debug_context->stack_size > 0)
9891007
{
9901008
debug_context->stack_size--;
1009+
#if VM_DEBUG_BP_CHECK
1010+
if (debug_context->frames[debug_context->stack_size].info.runtime.bp_check <= GET_THREAD()->cfp->bp_check)
1011+
#else
9911012
if (debug_context->frames[debug_context->stack_size].info.runtime.bp <= GET_THREAD()->cfp->bp)
1013+
#endif
9921014
break;
9931015
}
9941016
CTX_FL_SET(debug_context, CTX_FL_ENABLE_BKPT);
@@ -1932,8 +1954,11 @@ copy_scalar_args(debug_frame_t *debug_frame)
19321954
for (i = 0; i < iseq->argc; i++)
19331955
{
19341956
if (!rb_is_local_id(iseq->local_table[i])) continue; /* skip flip states */
1935-
1957+
#ifdef HAVE_RB_CONTROL_FRAME_T_EP
1958+
val = *(cfp->ep - iseq->local_size + i);
1959+
#else
19361960
val = *(cfp->dfp - iseq->local_size + i);
1961+
#endif
19371962

19381963
if (arg_value_is_small(val))
19391964
rb_ary_push(debug_frame->arg_ary, val);
@@ -1994,7 +2019,11 @@ context_copy_locals(debug_context_t *debug_context, debug_frame_t *debug_frame,
19942019
{
19952020
VALUE str = rb_id2str(iseq->local_table[i]);
19962021
if (str != 0)
2022+
#ifdef HAVE_RB_CONTROL_FRAME_T_EP
2023+
rb_hash_aset(hash, str, *(cfp->ep - iseq->local_size + i));
2024+
#else
19972025
rb_hash_aset(hash, str, *(cfp->dfp - iseq->local_size + i));
2026+
#endif
19982027
}
19992028
}
20002029

@@ -2012,7 +2041,11 @@ context_copy_locals(debug_context_t *debug_context, debug_frame_t *debug_frame,
20122041
{
20132042
VALUE str = rb_id2str(iseq->local_table[i]);
20142043
if (str != 0)
2044+
#ifdef HAVE_RB_CONTROL_FRAME_T_EP
2045+
rb_hash_aset(hash, str, *(block_frame->ep - iseq->local_table_size + i - 1));
2046+
#else
20152047
rb_hash_aset(hash, str, *(block_frame->dfp - iseq->local_table_size + i - 1));
2048+
#endif
20162049
}
20172050
return(hash);
20182051
}
@@ -2479,11 +2512,24 @@ context_jump(VALUE self, VALUE line, VALUE file)
24792512
/* find target frame to jump to */
24802513
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, cfp_end))
24812514
{
2515+
#ifdef HAVE_RB_ISEQ_T_LOCATION
2516+
if ((cfp->iseq != NULL) && (rb_str_cmp(file, cfp->iseq->location.path) == 0))
2517+
#else
24822518
if ((cfp->iseq != NULL) && (rb_str_cmp(file, cfp->iseq->filename) == 0))
2519+
#endif
24832520
{
2521+
#ifdef HAVE_RB_ISEQ_T_LINE_INFO_SIZE
2522+
for (i = 0; i < cfp->iseq->line_info_size; i++)
2523+
#else
24842524
for (i = 0; i < cfp->iseq->insn_info_size; i++)
2525+
#endif
24852526
{
2527+
#ifdef HAVE_RB_ISEQ_T_LINE_INFO_SIZE
2528+
if (cfp->iseq->line_info_table[i].line_no != line)
2529+
#else
24862530
if (cfp->iseq->insn_info_table[i].line_no != line)
2531+
#endif
2532+
24872533
continue;
24882534

24892535
/* hijack the currently running code so that we can change the frame PC */
@@ -2493,8 +2539,13 @@ context_jump(VALUE self, VALUE line, VALUE file)
24932539
cfp_start->pc[1] = (VALUE)do_jump;
24942540

24952541
debug_context->jump_cfp = cfp;
2542+
#ifdef HAVE_RB_ISEQ_T_LINE_INFO_SIZE
2543+
debug_context->jump_pc =
2544+
cfp->iseq->iseq_encoded + cfp->iseq->line_info_table[i].position;
2545+
#else
24962546
debug_context->jump_pc =
24972547
cfp->iseq->iseq_encoded + cfp->iseq->insn_info_table[i].position;
2548+
#endif
24982549

24992550
return(INT2FIX(0)); /* success */
25002551
}

ext/ruby_debug/ruby_debug.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ typedef struct {
4545
union {
4646
struct {
4747
rb_control_frame_t *cfp;
48-
VALUE *bp;
48+
#if VM_DEBUG_BP_CHECK
49+
VALUE *bp_check;
50+
#else
51+
VALUE *bp;
52+
#endif
4953
struct rb_iseq_struct *block_iseq;
5054
VALUE *block_pc;
5155
VALUE *last_pc;

0 commit comments

Comments
 (0)