Module: PryExceptionExplorer::ShimBuilder

Defined in:
lib/pry-exception_explorer/shim_builder.rb

Constant Summary collapse

Dyname =
"so"
ShimCode =
<<-EOF
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <unistd.h>
#include <ruby.h>

void
rb_raise(VALUE exc, const char *fmt, ...)
{
    va_list args;
    VALUE mesg;

    va_start(args, fmt);
    mesg = rb_vsprintf(fmt, args);
    va_end(args);
    rb_funcall(rb_cObject, rb_intern("raise"), 2, exc, mesg);
}

void
rb_name_error(ID id, const char *fmt, ...)
{
  rb_funcall(rb_cObject, rb_intern("raise"), 2, rb_eNameError, rb_str_new2("hooked exception (pry)"));
}

EOF

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/pry-exception_explorer/shim_builder.rb', line 9

def dir
  @dir
end

.fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/pry-exception_explorer/shim_builder.rb', line 9

def file
  @file
end

Class Method Details

.compileObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/pry-exception_explorer/shim_builder.rb', line 55

def self.compile
  create_directory_and_source_file

  # -L
  lib_dir = RbConfig::CONFIG['libdir']

  # -I
  arch_include = File.join RbConfig::CONFIG['includedir'], "ruby-1.9.1",  RbConfig::CONFIG['arch']
  backward_include = File.join RbConfig::CONFIG['includedir'], "ruby-1.9.1",  "ruby/backward"
  ruby191_include = File.join RbConfig::CONFIG['includedir'], "ruby-1.9.1"

  if RUBY_PLATFORM =~ /darwin/
    compile_line = "gcc -Wall -L#{lib_dir} -lruby -I#{arch_include}  -I#{backward_include} -I#{ruby191_include} -o lib_overrides.dylib -dynamiclib #{@file}"
  else
    compile_line = "gcc -Wall -O2 -fpic -shared -ldl -g -I#{arch_include}  -I#{backward_include} -I#{ruby191_include} -o lib_overrides.so #{@file}"
  end

  FileUtils.chdir @dir do
    if !system(compile_line)
      raise CompileError, "There was a problem building the shim, aborted!"
    end
  end

end

.create_directory_and_source_fileObject



48
49
50
51
52
53
# File 'lib/pry-exception_explorer/shim_builder.rb', line 48

def self.create_directory_and_source_file
  FileUtils.mkdir_p(@dir)
  File.open(@file, 'w') do |f|
    f.puts(ShimCode)
  end
end