diff --git a/Rakefile b/Rakefile index 245e122..cd30d84 100644 --- a/Rakefile +++ b/Rakefile @@ -9,7 +9,7 @@ manifest.exclude "ext/**/test/*", "ext/**/test/*", "ext/**/samples/*", "ext/**/b Gem::Specification.new do |gemspec| $gemspec = gemspec gemspec.name = gemspec.rubyforge_project = "therubyracer" - gemspec.version = "0.6.1" + gemspec.version = "0.7.0" gemspec.summary = "Embed the V8 Javascript interpreter into Ruby" gemspec.description = "Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript." gemspec.email = "cowboyd@thefrontside.net" @@ -41,11 +41,14 @@ task :clean do sh "rm -rf lib/v8/*.bundle lib/v8/*.so" end -namespace :clean do - desc "remove all built v8 objects" - task "v8" => "clean" do - sh "cd #{UPSTREAM} && make clean" - end +desc "remove all built v8 objects" +task "v8:clean" => "clean" do + sh "cd #{UPSTREAM} && make clean" +end + +desc "build v8 with debugging symbols (much slower)" +task "v8:debug" do + sh "cd #{UPSTREAM} && make debug" end for file in Dir['tasks/*.rake'] diff --git a/ext/v8/extconf.rb b/ext/v8/extconf.rb index 6bc9af1..856c122 100755 --- a/ext/v8/extconf.rb +++ b/ext/v8/extconf.rb @@ -14,6 +14,8 @@ have_library('pthread') have_library('objc') if RUBY_PLATFORM =~ /darwin/ $CPPFLAGS += " -Wall" unless $CPPFLAGS.split.include? "-Wall" +$CPPFLAGS += " -g" unless $CPPFLAGS.split.include? "-g" +$CPPFLAGS += " -rdynamic" unless $CPPFLAGS.split.include? "-rdynamic" CONFIG['LDSHARED'] = '$(CXX) -shared' unless RUBY_PLATFORM =~ /darwin/ diff --git a/ext/v8/upstream/Makefile b/ext/v8/upstream/Makefile index e99ccbd..9a0cb87 100644 --- a/ext/v8/upstream/Makefile +++ b/ext/v8/upstream/Makefile @@ -3,14 +3,21 @@ SCONS=build/scons/install/bin/scons SCONSSRC=build/scons V8SRC=build/v8 LIBV8=build/v8/libv8.a +LIBV8_G=build/v8/libv8_g.a GCC_VERSION=$(shell ruby -e 'puts %x{gcc --version} =~ /(\d)\.(\d)\.\d/ ? $$1 + $$2 : "UNKNOWN"') ARCH=$(shell ruby -e "puts ['foo'].pack('p').size == 8 ? 'x64' : 'ia32'") all: $(LIBV8) +debug: $(LIBV8_G) + cp $(LIBV8_G) $(LIBV8) + $(LIBV8): $(SCONS) $(V8SRC) cd build/v8 && GCC_VERSION=$(GCC_VERSION) ../scons/install/bin/scons arch=$(ARCH) +$(LIBV8_G): $(SCONS) $(V8SRC) + cd build/v8 && GCC_VERSION=$(GCC_VERSION) ../scons/install/bin/scons arch=$(ARCH) mode=debug + $(SCONS): $(SCONSSRC) mkdir -p $(SCONSSRC)/install python build/scons/setup.py install --prefix=install diff --git a/ext/v8/v8.cpp b/ext/v8/v8.cpp index 05029ab..2cd1978 100644 --- a/ext/v8/v8.cpp +++ b/ext/v8/v8.cpp @@ -10,6 +10,7 @@ #include "v8_try_catch.h" #include "v8_callbacks.h" #include "v8_external.h" +#include "v8_exception.h" #include @@ -31,5 +32,6 @@ extern "C" { rr_init_v8_try_catch(); rr_init_v8_callbacks(); rr_init_v8_external(); + rr_init_v8_exception(); } } diff --git a/ext/v8/v8_exception.cpp b/ext/v8/v8_exception.cpp new file mode 100644 index 0000000..257e699 --- /dev/null +++ b/ext/v8/v8_exception.cpp @@ -0,0 +1,27 @@ +#include "v8_exception.h" +#include "rr.h" +#include "execinfo.h" +#include "signal.h" + +namespace { + + static void* stack[20]; + + void fatal(const char* location, const char* message) { + int size = backtrace(stack, 20); + backtrace_symbols_fd(stack, size, 2); + rb_raise(rb_eFatal, "%s: %s", location, message); + } + void segfault(int sig) { + fprintf(stderr, "segfault: game over.\n"); + void *elements[20]; + int size = backtrace(stack, 20); + backtrace_symbols_fd(stack, size, 2); + exit(1); + } +} + +void rr_init_v8_exception() { + v8::V8::SetFatalErrorHandler(fatal); + signal(SIGSEGV, segfault); +} \ No newline at end of file diff --git a/ext/v8/v8_exception.h b/ext/v8/v8_exception.h new file mode 100644 index 0000000..1798099 --- /dev/null +++ b/ext/v8/v8_exception.h @@ -0,0 +1,6 @@ +#ifndef _RR_V8_EXCEPTION_ +#define _RR_V8_EXCEPTION_ + +void rr_init_v8_exception(); + +#endif \ No newline at end of file