mirror of
				https://github.com/rubyjs/therubyracer
				synced 2023-03-27 23:21:42 -04:00 
			
		
		
		
	add exception backtraces for segfaults and fatal errors.
This commit is contained in:
		
							parent
							
								
									83abd10113
								
							
						
					
					
						commit
						e509bebe05
					
				
					 6 changed files with 53 additions and 6 deletions
				
			
		
							
								
								
									
										15
									
								
								Rakefile
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								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']
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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/
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@
 | 
			
		|||
#include "v8_try_catch.h"
 | 
			
		||||
#include "v8_callbacks.h"
 | 
			
		||||
#include "v8_external.h"
 | 
			
		||||
#include "v8_exception.h"
 | 
			
		||||
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -31,5 +32,6 @@ extern "C" {
 | 
			
		|||
        rr_init_v8_try_catch();
 | 
			
		||||
        rr_init_v8_callbacks();
 | 
			
		||||
        rr_init_v8_external();
 | 
			
		||||
        rr_init_v8_exception();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										27
									
								
								ext/v8/v8_exception.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								ext/v8/v8_exception.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								ext/v8/v8_exception.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								ext/v8/v8_exception.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
#ifndef _RR_V8_EXCEPTION_
 | 
			
		||||
#define _RR_V8_EXCEPTION_
 | 
			
		||||
 | 
			
		||||
void rr_init_v8_exception();
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue