From b452500415ee2b73556668e049c4d747433f97ad Mon Sep 17 00:00:00 2001 From: windwiny Date: Tue, 26 Feb 2013 10:47:17 +0800 Subject: [PATCH 1/4] compile compatible to ruby 2.0 --- ext/ruby_debug/extconf.rb | 11 +++++++++-- ruby-debug-base19x.gemspec | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ext/ruby_debug/extconf.rb b/ext/ruby_debug/extconf.rb index 1d05668..d98b149 100644 --- a/ext/ruby_debug/extconf.rb +++ b/ext/ruby_debug/extconf.rb @@ -3,10 +3,10 @@ require 'rbconfig' bindir = RbConfig::CONFIG['bindir'] if bindir =~ %r{(^.*/\.rbenv/versions)/([^/]+)/bin$} - ruby_include = "#{$1}/#{$2}/include/ruby-1.9.1/ruby-#{$2}" + ruby_include = "#{$1}/#{$2}/include/ruby-#{RUBY_VERSION}/ruby-#{$2}" ARGV << "--with-ruby-include=#{ruby_include}" elsif bindir =~ %r{(^.*/\.rvm/rubies)/([^/]+)/bin$} - ruby_include = "#{$1}/#{$2}/include/ruby-1.9.1/#{$2}" + ruby_include = "#{$1}/#{$2}/include/ruby-#{RUBY_VERSION}/#{$2}" ruby_include = "#{ENV['rvm_path']}/src/#{$2}" unless File.exist?(ruby_include) ARGV << "--with-ruby-include=#{ruby_include}" end @@ -37,6 +37,13 @@ } $defs << "-O0" +if RUBY_VERSION >= '2.0.0' + # compile on ruby 2.0 , require debugger-ruby_core_source 1.2.0, add INCLUDE path . + DHP1=Gem::Specification.to_a.find {|x| x.name=='debugger-ruby_core_source' and x.version.to_s >= '1.2.0'}.full_gem_path + DHP="#{DHP1}/lib/debugger/ruby_core_source/ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" + RUBY20MACRO="-DHAVE_RB_ISEQ_COMPILE_ON_BASE -DVM_DEBUG_BP_CHECK -DHAVE_RB_CONTROL_FRAME_T_EP -DHAVE_RB_ISEQ_T_LOCATION -DHAVE_RB_ISEQ_T_LINE_INFO_SIZE " + $defs << " #{RUBY20MACRO} -I#{DHP} " +end dir_config("ruby") if !Debugger::RubyCoreSource.create_makefile_with_core(hdrs, "ruby_debug") diff --git a/ruby-debug-base19x.gemspec b/ruby-debug-base19x.gemspec index e168c50..59bb45c 100644 --- a/ruby-debug-base19x.gemspec +++ b/ruby-debug-base19x.gemspec @@ -41,7 +41,7 @@ EOF spec.required_ruby_version = '>= 1.9' spec.date = Time.now spec.rubyforge_project = 'ruby-debug19' - spec.add_dependency "debugger-ruby_core_source", '~> 1.1.4' + spec.add_dependency "debugger-ruby_core_source", '>= 1.1.4' spec.add_dependency("rake", ">= 0.8.1") # rdoc From e93a4fe461f26db45a078ebdeafcaf592c0b4684 Mon Sep 17 00:00:00 2001 From: windwiny Date: Fri, 1 Mar 2013 16:18:13 +0800 Subject: [PATCH 2/4] fix ruby 2.0.0 error. undefined symbol: ruby_current_thread --- ext/ruby_debug/ruby_debug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ext/ruby_debug/ruby_debug.c b/ext/ruby_debug/ruby_debug.c index 9fee280..7422126 100644 --- a/ext/ruby_debug/ruby_debug.c +++ b/ext/ruby_debug/ruby_debug.c @@ -167,7 +167,9 @@ threadptr_data_type(void) } #define ruby_threadptr_data_type *threadptr_data_type() -#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())) +//#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())) +// FIXME: ruby 2.0.0 Error. undefined symbol: ruby_current_thread +rb_thread_t *ruby_current_thread; static int is_in_locked(VALUE thread_id) @@ -2678,6 +2680,7 @@ Init_ruby_debug() iseq.iseq = &opt_call_c_function; iseq.iseq_size = 1; iseq.iseq_encoded = NULL; + ruby_current_thread = ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())); opt_call_c_function = (VALUE)BIN(opt_call_c_function); rb_iseq_translate_threaded_code(&iseq); From 903561662e61167580c761aae29d04f687ad1f44 Mon Sep 17 00:00:00 2001 From: windwiny Date: Sat, 2 Mar 2013 17:43:15 +0800 Subject: [PATCH 3/4] Fix bug on ruby 2.0.0-p0. On ruby 1.9.3-xxx GET_THREAD is a macro, on ruby 2.0.0-p0 is a function. /vm_core.h Call rb_thread_current() before use GET_THREAD. --- ext/ruby_debug/ruby_debug.c | 59 ++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/ext/ruby_debug/ruby_debug.c b/ext/ruby_debug/ruby_debug.c index 7422126..17cde93 100644 --- a/ext/ruby_debug/ruby_debug.c +++ b/ext/ruby_debug/ruby_debug.c @@ -167,9 +167,21 @@ threadptr_data_type(void) } #define ruby_threadptr_data_type *threadptr_data_type() -//#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())) -// FIXME: ruby 2.0.0 Error. undefined symbol: ruby_current_thread -rb_thread_t *ruby_current_thread; + +// On ruby 1.9.3-xxx GET_THREAD is a macro, on ruby 2.0.0-p0 is a function. /vm_core.h +// CAREFUL: ruby_current_thread, GET_THREAD, rb_thread_set_current_raw +#if GET_THREAD + #define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())) + #define GET_THREAD2 GET_THREAD +#else +#warning "ruby 2.0.0-p0 GET_THREAD is a function." + rb_thread_t *ruby_current_thread; + rb_thread_t *GET_THREAD2(void) + { + ruby_current_thread = ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())); + return GET_THREAD(); + } +#endif static int is_in_locked(VALUE thread_id) @@ -504,16 +516,16 @@ save_call_frame(rb_event_flag_t _event, debug_context_t *debug_context, VALUE se debug_frame->dead = 0; debug_frame->self = self; debug_frame->arg_ary = Qnil; - debug_frame->argc = GET_THREAD()->cfp->iseq->argc; - debug_frame->info.runtime.cfp = GET_THREAD()->cfp; + debug_frame->argc = GET_THREAD2()->cfp->iseq->argc; + debug_frame->info.runtime.cfp = GET_THREAD2()->cfp; #if VM_DEBUG_BP_CHECK - debug_frame->info.runtime.bp_check = GET_THREAD()->cfp->bp_check; + debug_frame->info.runtime.bp_check = GET_THREAD2()->cfp->bp_check; #else - debug_frame->info.runtime.bp = GET_THREAD()->cfp->bp; + debug_frame->info.runtime.bp = GET_THREAD2()->cfp->bp; #endif - debug_frame->info.runtime.block_iseq = GET_THREAD()->cfp->block_iseq; + debug_frame->info.runtime.block_iseq = GET_THREAD2()->cfp->block_iseq; debug_frame->info.runtime.block_pc = NULL; - debug_frame->info.runtime.last_pc = GET_THREAD()->cfp->pc; + debug_frame->info.runtime.last_pc = GET_THREAD2()->cfp->pc; if (RTEST(track_frame_args)) copy_scalar_args(debug_frame); } @@ -620,20 +632,20 @@ set_frame_source(rb_event_flag_t event, debug_context_t *debug_context, VALUE se top_frame = get_top_frame(debug_context); if(top_frame) { - top_frame->info.runtime.cfp = GET_THREAD()->cfp; - if (top_frame->info.runtime.block_iseq == GET_THREAD()->cfp->iseq) + top_frame->info.runtime.cfp = GET_THREAD2()->cfp; + if (top_frame->info.runtime.block_iseq == GET_THREAD2()->cfp->iseq) { - top_frame->info.runtime.block_pc = GET_THREAD()->cfp->pc; + top_frame->info.runtime.block_pc = GET_THREAD2()->cfp->pc; top_frame->binding = create_binding(self); /* block entered; need to rebind */ } - else if ((top_frame->info.runtime.block_pc != NULL) && (GET_THREAD()->cfp->pc == top_frame->info.runtime.block_pc)) + else if ((top_frame->info.runtime.block_pc != NULL) && (GET_THREAD2()->cfp->pc == top_frame->info.runtime.block_pc)) { top_frame->binding = create_binding(self); /* block re-entered; need to rebind */ } - top_frame->info.runtime.block_iseq = GET_THREAD()->cfp->block_iseq; + top_frame->info.runtime.block_iseq = GET_THREAD2()->cfp->block_iseq; if (event == RUBY_EVENT_LINE) - top_frame->info.runtime.last_pc = GET_THREAD()->cfp->pc; + top_frame->info.runtime.last_pc = GET_THREAD2()->cfp->pc; top_frame->self = self; top_frame->file = file; top_frame->line = line; @@ -710,8 +722,8 @@ create_catch_table(debug_context_t *debug_context, unsigned long cont) { struct iseq_catch_table_entry *catch_table = &debug_context->catch_table.tmp_catch_table; - GET_THREAD()->parse_in_eval++; - GET_THREAD()->mild_compile_error++; + GET_THREAD2()->parse_in_eval++; + GET_THREAD2()->mild_compile_error++; /* compiling with option Qfalse (no options) prevents debug hook calls during this catch routine */ #ifdef HAVE_RB_ISEQ_COMPILE_ON_BASE catch_table->iseq = rb_iseq_compile_with_option( @@ -723,8 +735,8 @@ create_catch_table(debug_context_t *debug_context, unsigned long cont) catch_table->iseq = rb_iseq_compile_with_option( rb_str_new_cstr("begin\nend"), rb_str_new_cstr("(exception catcher)"), INT2FIX(1), Qfalse); #endif - GET_THREAD()->mild_compile_error--; - GET_THREAD()->parse_in_eval--; + GET_THREAD2()->mild_compile_error--; + GET_THREAD2()->parse_in_eval--; catch_table->type = CATCH_TYPE_RESCUE; catch_table->start = 0; @@ -757,7 +769,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl char *file = (char*)rb_sourcefile(); int line = rb_sourceline(); int moved = 0; - rb_thread_t *thread = GET_THREAD(); + rb_thread_t *thread = GET_THREAD2(); struct rb_iseq_struct *iseq = thread->cfp->iseq; hook_count++; @@ -1009,9 +1021,9 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl { debug_context->stack_size--; #if VM_DEBUG_BP_CHECK - if (debug_context->frames[debug_context->stack_size].info.runtime.bp_check <= GET_THREAD()->cfp->bp_check) + if (debug_context->frames[debug_context->stack_size].info.runtime.bp_check <= GET_THREAD2()->cfp->bp_check) #else - if (debug_context->frames[debug_context->stack_size].info.runtime.bp <= GET_THREAD()->cfp->bp) + if (debug_context->frames[debug_context->stack_size].info.runtime.bp <= GET_THREAD2()->cfp->bp) #endif break; } @@ -2578,7 +2590,7 @@ context_pause(VALUE self) return(Qfalse); GetThreadPtr(context_thread_0(debug_context), th); - if (th == GET_THREAD()) + if (th == GET_THREAD2()) return(Qfalse); debug_context->thread_pause = 1; @@ -2680,7 +2692,6 @@ Init_ruby_debug() iseq.iseq = &opt_call_c_function; iseq.iseq_size = 1; iseq.iseq_encoded = NULL; - ruby_current_thread = ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())); opt_call_c_function = (VALUE)BIN(opt_call_c_function); rb_iseq_translate_threaded_code(&iseq); From 7d1bd2370d6847f78f634724cabd6dc16f098441 Mon Sep 17 00:00:00 2001 From: windwiny Date: Sat, 2 Mar 2013 17:48:49 +0800 Subject: [PATCH 4/4] increment verion --- ext/ruby_debug/ruby_debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ruby_debug/ruby_debug.c b/ext/ruby_debug/ruby_debug.c index 17cde93..6a5d2c2 100644 --- a/ext/ruby_debug/ruby_debug.c +++ b/ext/ruby_debug/ruby_debug.c @@ -9,7 +9,7 @@ #include #include "ruby_debug.h" -#define DEBUG_VERSION "0.11.30.pre11" +#define DEBUG_VERSION "0.11.30.pre12" #define FRAME_N(n) (&debug_context->frames[debug_context->stack_size-(n)-1]) #define GET_FRAME (FRAME_N(check_frame_number(debug_context, frame)))