From 35569084d4a3fbbb4069e9a26af1540ca2d1df1c Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Tue, 16 Aug 2011 00:58:11 -0600 Subject: [PATCH 1/5] Fix compilation issues for VC 2010. Note there is still a link issue as described at http://redmine.ruby-lang.org/issues/5193. --- ext/ruby_debug/extconf.rb | 2 +- ext/ruby_debug/ruby_debug.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/ruby_debug/extconf.rb b/ext/ruby_debug/extconf.rb index c667e1f..977419a 100644 --- a/ext/ruby_debug/extconf.rb +++ b/ext/ruby_debug/extconf.rb @@ -3,7 +3,7 @@ hdrs = proc { have_struct_member("rb_method_entry_t", "body", "method.h") - have_header("vm_core.h") and have_header("iseq.h") and have_header("insns.inc") and + have_header("vm_core.h") and have_header("iseq.h", "vm_core.h") and have_header("insns.inc") and have_header("insns_info.inc") and have_header("eval_intern.h") } diff --git a/ext/ruby_debug/ruby_debug.c b/ext/ruby_debug/ruby_debug.c index 2b0c675..a471514 100644 --- a/ext/ruby_debug/ruby_debug.c +++ b/ext/ruby_debug/ruby_debug.c @@ -20,12 +20,12 @@ #define STACK_SIZE_INCREMENT 128 -RUBY_EXTERN int rb_vm_get_sourceline(const rb_control_frame_t *cfp); /* from vm.c */ +int rb_vm_get_sourceline(const rb_control_frame_t *cfp); /* from vm.c */ /* from iseq.c */ #ifdef RB_ISEQ_COMPILE_6ARGS -RUBY_EXTERN VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt); +VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE filepath, VALUE line, VALUE opt); #else -RUBY_EXTERN VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE line, VALUE opt); +VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE line, VALUE opt); #endif typedef struct { @@ -861,6 +861,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl { rb_control_frame_t *cfp = top_frame->info.runtime.cfp; VALUE hit_count; + int c_hit_count; rb_iseq_t *iseq = cfp->iseq; if (iseq != NULL) { @@ -870,7 +871,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl } /* send catchpoint notification */ - int c_hit_count = FIX2INT(rb_hash_aref(rdebug_catchpoints, debug_context->catch_table.mod_name)) + 1; + c_hit_count = FIX2INT(rb_hash_aref(rdebug_catchpoints, debug_context->catch_table.mod_name)) + 1; hit_count = INT2FIX(c_hit_count); rb_hash_aset(rdebug_catchpoints, debug_context->catch_table.mod_name, hit_count); debug_context->stop_reason = CTX_STOP_CATCHPOINT; @@ -999,6 +1000,10 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl } case RUBY_EVENT_RAISE: { + VALUE ancestors; + VALUE expn_class, aclass; + int i; + if (CTX_FL_TEST(debug_context, CTX_FL_CATCHING)) { /* we're re-raising exception after processing line event, now allow the next exception to be caught, don't setup catchers */ @@ -1006,10 +1011,6 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl break; } - VALUE ancestors; - VALUE expn_class, aclass; - int i; - if(debug == Qtrue) { fprintf(stderr, "stack_size %d\n", debug_context->stack_size); for (i = 0; i < debug_context->stack_size; i++) { From 98baaffad3e0fc224fe87f24bc03f141f27fe1b3 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Thu, 15 Sep 2011 11:34:21 -0600 Subject: [PATCH 2/5] Fixes to make ruby-debug-base19x work on Ruby 1.9.3. These patches are manually applied from this pull request: https://github.com/mark-moseley/ruby-debug/pull/14 Minus the id2ref and ref2id changes (not sure if those can be removed or not). --- ext/ruby_debug/extconf.rb | 28 ++++++++++++++++++---------- ext/ruby_debug/ruby_debug.c | 36 ++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/ext/ruby_debug/extconf.rb b/ext/ruby_debug/extconf.rb index 977419a..40a04c4 100644 --- a/ext/ruby_debug/extconf.rb +++ b/ext/ruby_debug/extconf.rb @@ -2,19 +2,27 @@ require "ruby_core_source" hdrs = proc { - have_struct_member("rb_method_entry_t", "body", "method.h") + iseqs = %w[vm_core.h iseq.h] + begin + have_struct_member("rb_method_entry_t", "called_id", "method.h") or + have_struct_member("rb_control_frame_t", "method_id", "method.h") + end and have_header("vm_core.h") and have_header("iseq.h", "vm_core.h") and have_header("insns.inc") and - have_header("insns_info.inc") and have_header("eval_intern.h") + have_header("insns_info.inc") and have_header("eval_intern.h") or break + have_type("struct iseq_line_info_entry", iseqs) or + have_type("struct iseq_insn_info_entry", iseqs) or + break + if checking_for(checking_message("if rb_iseq_compile_with_option was added an argument filepath")) do + try_compile(< +#include "vm_core.h" +extern VALUE rb_iseq_new_main(NODE *node, VALUE filename, VALUE filepath); +SRC + end + $defs << '-DRB_ISEQ_COMPILE_5ARGS' + end } -if RUBY_VERSION == '1.9.1' - $CFLAGS << ' -DRUBY_VERSION_1_9_1' -end - -if RUBY_REVISION >= 26959 # rb_iseq_compile_with_option was added an argument filepath - $CFLAGS << ' -DRB_ISEQ_COMPILE_6ARGS' -end - dir_config("ruby") name = "ruby_debug" if (ENV['rvm_ruby_string']) diff --git a/ext/ruby_debug/ruby_debug.c b/ext/ruby_debug/ruby_debug.c index a471514..694153c 100644 --- a/ext/ruby_debug/ruby_debug.c +++ b/ext/ruby_debug/ruby_debug.c @@ -137,12 +137,6 @@ real_class(VALUE klass) inline static void * ruby_method_ptr(VALUE class, ID meth_id) { -#ifdef RUBY_VERSION_1_9_1 - NODE *body, *method; - st_lookup(RCLASS_M_TBL(class), meth_id, (st_data_t *)&body); - method = (NODE *)body->u2.value; - return (void *)method->u2.node->u1.value; -#else rb_method_entry_t * method; method = rb_method_entry(class, meth_id); #ifdef HAVE_ST_BODY @@ -150,7 +144,6 @@ ruby_method_ptr(VALUE class, ID meth_id) #else return (void *)method->def->body.cfunc.func; #endif -#endif } inline static VALUE @@ -191,6 +184,21 @@ context_thread_0(debug_context_t *debug_context) return id2ref(debug_context->thread_id); } +static inline const rb_data_type_t * +threadptr_data_type(void) +{ + static const rb_data_type_t *thread_data_type; + if (!thread_data_type) { + VALUE current_thread = rb_thread_current(); + thread_data_type = RTYPEDDATA_TYPE(current_thread); + } + return thread_data_type; +} + +#define ruby_threadptr_data_type *threadptr_data_type() + +#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current())) + static int is_in_locked(VALUE thread_id) { @@ -253,7 +261,7 @@ static void threads_table_mark(void* data) { threads_table_t *threads_table = (threads_table_t*)data; - st_foreach(threads_table->tbl, threads_table_mark_keyvalue, 0); + rb_mark_tbl(threads_table->tbl); } static void @@ -726,11 +734,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; -#ifdef RUBY_VERSION_1_9_1 - NODE *node = NULL; -#else rb_method_entry_t *me = NULL; -#endif rb_thread_t *thread = GET_THREAD(); struct rb_iseq_struct *iseq = thread->cfp->iseq; @@ -748,11 +752,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl if (mid == ID_ALLOCATOR) return; -#ifdef RUBY_VERSION_1_9_1 - node = rb_method_node(klass, mid); -#else me = rb_method_entry(klass, mid); -#endif /* return if thread is marked as 'ignored'. debugger's threads are marked this way @@ -964,11 +964,7 @@ debug_event_hook(rb_event_flag_t event, VALUE data, VALUE self, ID mid, VALUE kl case RUBY_EVENT_C_RETURN: { /* note if a block is given we fall through! */ -#ifdef RUBY_VERSION_1_9_1 - if(!node || !c_call_new_frame_p(klass, mid)) -#else if(!me || !c_call_new_frame_p(klass, mid)) -#endif break; } case RUBY_EVENT_RETURN: From d8efe8097590c7ad5c840189214a7b9eff60b092 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Thu, 15 Sep 2011 11:36:39 -0600 Subject: [PATCH 3/5] Makefile should not be checked in. --- ext/ruby_debug/Makefile | 189 ---------------------------------------- 1 file changed, 189 deletions(-) delete mode 100644 ext/ruby_debug/Makefile diff --git a/ext/ruby_debug/Makefile b/ext/ruby_debug/Makefile deleted file mode 100644 index aa266a2..0000000 --- a/ext/ruby_debug/Makefile +++ /dev/null @@ -1,189 +0,0 @@ - -SHELL = /bin/sh - -#### Start of system configuration section. #### - -srcdir = . -topdir = /c/ruby192/include/ruby-1.9.1 -hdrdir = /c/ruby192/include/ruby-1.9.1 -arch_hdrdir = c:/ruby192/include/ruby-1.9.1/$(arch) -VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby - -DESTDIR = c: -prefix = $(DESTDIR)/ruby192 -rubylibprefix = $(libdir)/$(RUBY_BASE_NAME) -exec_prefix = $(prefix) -vendorhdrdir = $(rubyhdrdir)/vendor_ruby -sitehdrdir = $(rubyhdrdir)/site_ruby -rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version) -vendordir = $(rubylibprefix)/vendor_ruby -sitedir = $(rubylibprefix)/site_ruby -ridir = $(datarootdir)/$(RI_BASE_NAME) -mandir = $(datarootdir)/man -localedir = $(datarootdir)/locale -libdir = $(exec_prefix)/lib -psdir = $(docdir) -pdfdir = $(docdir) -dvidir = $(docdir) -htmldir = $(docdir) -infodir = $(datarootdir)/info -docdir = $(datarootdir)/doc/$(PACKAGE) -oldincludedir = $(DESTDIR)/usr/include -includedir = $(prefix)/include -localstatedir = $(prefix)/var -sharedstatedir = $(prefix)/com -sysconfdir = $(prefix)/etc -datadir = $(datarootdir) -datarootdir = $(prefix)/share -libexecdir = $(exec_prefix)/libexec -sbindir = $(exec_prefix)/sbin -bindir = $(exec_prefix)/bin -rubylibdir = $(rubylibprefix)/$(ruby_version) -archdir = $(rubylibdir)/$(arch) -sitelibdir = $(sitedir)/$(ruby_version) -sitearchdir = $(sitelibdir)/$(sitearch) -vendorlibdir = $(vendordir)/$(ruby_version) -vendorarchdir = $(vendorlibdir)/$(sitearch) - -CC = gcc -CXX = g++ -LIBRUBY = lib$(RUBY_SO_NAME).dll.a -LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a -LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME) -LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -OUTFLAG = -o -COUTFLAG = -o - -RUBY_EXTCONF_H = -cflags = $(optflags) $(debugflags) $(warnflags) -optflags = -O3 -debugflags = -g -warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -CFLAGS = $(cflags) -INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir) -DEFS = -CPPFLAGS = -DHAVE_VM_CORE_H -DHAVE_ISEQ_H -DHAVE_INSNS_INC -DHAVE_INSNS_INFO_INC -DHAVE_EVAL_INTERN_H -Ic:/ruby192/include/ruby-1.9.1/ruby-1.9.2-p0 -CXXFLAGS = $(CFLAGS) $(cxxflags) -ldflags = -L. -dldflags = -Wl,--enable-auto-image-base,--enable-auto-import $(DEFFILE) -ARCH_FLAG = -DLDFLAGS = $(ldflags) $(dldflags) -LDSHARED = $(CC) -shared $(if $(filter-out -g -g0,$(debugflags)),,-s) -LDSHAREDXX = $(CXX) -shared $(if $(filter-out -g -g0,$(debugflags)),,-s) -AR = ar -EXEEXT = .exe - -RUBY_BASE_NAME = ruby -RUBY_INSTALL_NAME = ruby -RUBY_SO_NAME = msvcrt-ruby191 -arch = i386-mingw32 -sitearch = i386-msvcrt -ruby_version = 1.9.1 -ruby = c:/ruby192/bin/ruby -RUBY = $(ruby) -RM = rm -f -RM_RF = $(RUBY) -run -e rm -- -rf -RMDIRS = $(RUBY) -run -e rmdir -- -p -MAKEDIRS = /usr/bin/mkdir -p -INSTALL = /usr/bin/install -c -INSTALL_PROG = $(INSTALL) -m 0755 -INSTALL_DATA = $(INSTALL) -m 644 -COPY = cp - -#### End of system configuration section. #### - -preload = - -libpath = . $(libdir) -LIBPATH = -L. -L$(libdir) -DEFFILE = $(TARGET)-$(arch).def - -CLEANFILES = mkmf.log $(DEFFILE) -DISTCLEANFILES = -DISTCLEANDIRS = - -extout = -extout_prefix = -target_prefix = -LOCAL_LIBS = -LIBS = $(LIBRUBYARG_SHARED) -lshell32 -lws2_32 -SRCS = breakpoint.c ruby_debug.c -OBJS = breakpoint.o ruby_debug.o -TARGET = ruby_debug -DLLIB = $(TARGET).so -EXTSTATIC = -STATIC_LIB = - -BINDIR = $(bindir) -RUBYCOMMONDIR = $(sitedir)$(target_prefix) -RUBYLIBDIR = $(sitelibdir)$(target_prefix) -RUBYARCHDIR = $(sitearchdir)$(target_prefix) -HDRDIR = $(rubyhdrdir)/ruby$(target_prefix) -ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix) - -TARGET_SO = $(DLLIB) -CLEANLIBS = $(TARGET).so -CLEANOBJS = *.o *.bak - -all: $(DLLIB) -static: $(STATIC_LIB) -.PHONY: all install static install-so install-rb -.PHONY: clean clean-so clean-rb - -clean-rb-default:: -clean-rb:: -clean-so:: -clean: clean-so clean-rb-default clean-rb - @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) - -distclean-rb-default:: -distclean-rb:: -distclean-so:: -distclean: clean distclean-so distclean-rb-default distclean-rb - @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log - @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES) - @-$(RMDIRS) $(DISTCLEANDIRS) - -realclean: distclean -install: install-so install-rb - -install-so: $(RUBYARCHDIR) -install-so: $(RUBYARCHDIR)/$(DLLIB) -$(RUBYARCHDIR)/$(DLLIB): $(DLLIB) - @-$(MAKEDIRS) $(@D) - $(INSTALL_PROG) $(DLLIB) $(@D) -install-rb: pre-install-rb install-rb-default -install-rb-default: pre-install-rb-default -pre-install-rb: Makefile -pre-install-rb-default: Makefile -$(RUBYARCHDIR): - $(MAKEDIRS) $@ - -site-install: site-install-so site-install-rb -site-install-so: install-so -site-install-rb: install-rb - -.SUFFIXES: .c .m .cc .cxx .cpp .o - -.cc.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cxx.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.cpp.o: - $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $< - -.c.o: - $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $< - -$(DLLIB): $(DEFFILE) $(OBJS) Makefile - @-$(RM) $(@) - $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS) - - - -$(DEFFILE): - $(RUBY) -e "puts 'EXPORTS', 'Init_$(TARGET)'" > $@ - -$(OBJS): $(hdrdir)/ruby.h $(hdrdir)/ruby/defines.h $(arch_hdrdir)/ruby/config.h From a806f575e87a4a345b75719439f40f0e47b9f57f Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Thu, 15 Sep 2011 11:37:10 -0600 Subject: [PATCH 4/5] Ignore netbeans project. --- .gitignore | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 31308ce..1f20ba0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -*.gem -*.o -*.so -*.def \ No newline at end of file +*.gem +*.o +*.so +*.def +/nbproject/private/ \ No newline at end of file From 45692936c390c1b6ec04d617e8d6fd8c82880ef8 Mon Sep 17 00:00:00 2001 From: Charlie Savage Date: Sat, 17 Mar 2012 22:39:50 -0600 Subject: [PATCH 5/5] Fix for compiling on windows - the check should be _WIN32 not __WIN32__. Also, you have to ifdef the rest of the filename_cmp method because realpath does not exist on windows. --- ext/ruby_debug/ruby_debug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/ruby_debug/ruby_debug.c b/ext/ruby_debug/ruby_debug.c index 378c44f..a4d314d 100644 --- a/ext/ruby_debug/ruby_debug.c +++ b/ext/ruby_debug/ruby_debug.c @@ -521,9 +521,9 @@ filename_cmp_impl(VALUE source, char *file); int filename_cmp(VALUE source, char *file) { -#ifdef __WIN32__ +#ifdef _WIN32 return filename_cmp_impl(source, file); -#endif +#else if (!RTEST(resolve_symlinks)) { return filename_cmp_impl(source, file); @@ -547,6 +547,7 @@ filename_cmp(VALUE source, char *file) { return result; } #endif +#endif } int