debug_inspector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0818f4d1a14ebba76cdf967f063526c1caae14f6
4
+ data.tar.gz: 5999c5d5a10721d1a824c648d1c9825491c5a1b0
5
+ SHA512:
6
+ metadata.gz: c1598e9ae43dd251033b733e15998a5e40f1acd13ea3cdca657a371377dbae8da4739f51423e18d099723efa0e6b587ef0af14cf7a525a75f03235a056045fca
7
+ data.tar.gz: b33a0f6ff4a4ea8db69186c7578768e8309138dd84357b9cea49966ac1abd3291e3f65f6ed9816efa03c1325c05fc57be38f13e0196ff5d299e3a927337a5531
@@ -0,0 +1,58 @@
1
+ debug_inspector
2
+ ===============
3
+
4
+ (C) John Mair (banisterfiend) 2012
5
+
6
+ _A Ruby wrapper for the new MRI 2.0 debug\_inspector API_
7
+
8
+ ** This library only works on MRI 2.0. Requiring it on unsupported Rubies will resort in a no-op **
9
+
10
+ Usage
11
+ -----
12
+
13
+ ```ruby
14
+ require 'debug_inspector'
15
+
16
+ # binding of nth caller frame (returns a Binding object)
17
+ RubyVM::DebugInspector.open { |i| i.frame_binding(n) }
18
+
19
+ # iseq of nth caller frame (returns a RubyVM::InstructionSequence object)
20
+ RubyVM::DebugInspector.open { |i| i.frame_iseq(n) }
21
+
22
+ # class of nth caller frame
23
+ RubyVM::DebugInspector.open { |i| i.frame_class(n) }
24
+
25
+ # backtrace locations (returns an array of Thread::Backtrace::Location objects)
26
+ RubyVM::DebugInspector.open { |i| i.backtrace_locations }
27
+ ```
28
+
29
+ Contact
30
+ -------
31
+
32
+ Problems or questions contact me at [github](http://github.com/banister)
33
+
34
+ License
35
+ -------
36
+
37
+ (The MIT License)
38
+
39
+ Copyright (c) 2012 (John Mair)
40
+
41
+ Permission is hereby granted, free of charge, to any person obtaining
42
+ a copy of this software and associated documentation files (the
43
+ 'Software'), to deal in the Software without restriction, including
44
+ without limitation the rights to use, copy, modify, merge, publish,
45
+ distribute, sublicense, and/or sell copies of the Software, and to
46
+ permit persons to whom the Software is furnished to do so, subject to
47
+ the following conditions:
48
+
49
+ The above copyright notice and this permission notice shall be
50
+ included in all copies or substantial portions of the Software.
51
+
52
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
53
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
55
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
56
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
57
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
58
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ $:.unshift 'lib'
2
+ require 'rake/clean'
3
+ require "debug_inspector/version"
4
+
5
+ dlext = RbConfig::CONFIG['DLEXT']
6
+ direc = File.expand_path(File.dirname(__FILE__))
7
+ CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
8
+ CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
9
+ "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "**/*#*", "**/*#*.*",
10
+ "ext/**/*.def", "ext/**/*.pdb", "**/*_flymake*.*", "**/*_flymake", "**/*.rbc")
11
+ desc "Show version"
12
+ task :version do
13
+ puts "debug_inspector version: #{DebugInspector::VERSION}"
14
+ end
15
+
16
+ desc "run tests"
17
+ task :default => [:test]
18
+
19
+ desc "Run tests"
20
+ task :test do
21
+ sh "bacon -Itest -rubygems -a -q"
22
+ end
23
+
24
+ task :pry do
25
+ puts "loading debug_inspector into pry"
26
+ sh "pry -r #{direc}/lib/debug_inspector"
27
+ end
28
+
29
+ desc "build the binaries"
30
+ task :compile do
31
+ chdir "#{direc}/ext/debug_inspector/" do
32
+ sh "ruby extconf.rb"
33
+ sh "make clean"
34
+ sh "make"
35
+ sh "cp *.#{dlext} ../../lib/"
36
+ end
37
+ end
38
+
39
+ desc 'cleanup the extensions'
40
+ task :cleanup do
41
+ sh "rm -rf lib/debug_inspector.#{dlext}"
42
+ chdir "#{direc}/ext/debug_inspector/" do
43
+ sh 'make clean' rescue nil
44
+ end
45
+ end
46
+
47
+ desc "(re)install gem"
48
+ task :reinstall => :gem do
49
+ sh "gem uninstall debug_inspector" rescue nil
50
+ sh "gem install -l #{direc}/debug_inspector-#{DebugInspector::VERSION}.gem"
51
+ end
52
+
53
+ task :install => :reinstall
54
+
55
+ desc "build all platform gems at once"
56
+ task :gem => [:clean, :rmgems] do
57
+ sh "gem build #{direc}/debug_inspector.gemspec"
58
+ end
59
+
60
+ desc "remove all platform gems"
61
+ task :rmgems do
62
+ sh "rm #{direc}/*.gem" rescue nil
63
+ end
64
+
65
+ desc "build and push latest gems"
66
+ task :pushgems => :gem do
67
+ chdir(direc) do
68
+ Dir["*.gem"].each do |gemfile|
69
+ sh "gem push #{gemfile}"
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/debug_inspector/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "debug_inspector"
6
+ s.version = DebugInspector::VERSION
7
+ s.authors = ["John Mair (banisterfiend)"]
8
+ s.email = ["jrmair@gmail.com"]
9
+ s.homepage = "https://github.com/banister/debug_inspector"
10
+ s.summary = "A Ruby wrapper for the MRI 2.0 debug_inspector API"
11
+ s.description = s.summary
12
+ s.files = `git ls-files`.split("\n")
13
+ s.platform = Gem::Platform::RUBY
14
+ s.extensions = ["ext/debug_inspector/extconf.rb"]
15
+ end
@@ -0,0 +1,117 @@
1
+ /**********************************************************************
2
+
3
+ debug_inspector.c
4
+
5
+ $Author: ko1 $
6
+ created at: Thu Nov 15 17:34:36 2012
7
+
8
+ Copyright (C) 1993-2012 Yukihiro Matsumoto
9
+
10
+ **********************************************************************/
11
+
12
+ #include "ruby/ruby.h"
13
+
14
+ typedef struct rb_debug_inspector_struct rb_debug_inspector_t;
15
+ typedef VALUE (*rb_debug_inspector_func_t)(const rb_debug_inspector_t *, void *);
16
+
17
+ VALUE rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data);
18
+ VALUE rb_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, int index);
19
+ VALUE rb_debug_inspector_frame_class_get(const rb_debug_inspector_t *dc, int index);
20
+ VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, int index);
21
+ VALUE rb_debug_inspector_backtrace_locations(const rb_debug_inspector_t *dc);
22
+
23
+ static size_t
24
+ di_size(const void *dummy)
25
+ {
26
+ return sizeof(void *);
27
+ }
28
+
29
+ static const rb_data_type_t di_data_type = {
30
+ "simple_debugger",
31
+ {0, 0, di_size,},
32
+ };
33
+
34
+ static const rb_debug_inspector_t *
35
+ di_get_dc(VALUE self)
36
+ {
37
+ const rb_debug_inspector_t *dc;
38
+ TypedData_Get_Struct(self, const rb_debug_inspector_t, &di_data_type, dc);
39
+ if (dc == 0) {
40
+ rb_raise(rb_eArgError, "invalid inspector context");
41
+ }
42
+ return dc;
43
+ }
44
+
45
+ static VALUE
46
+ di_backtrace_locations(VALUE self)
47
+ {
48
+ const rb_debug_inspector_t *dc = di_get_dc(self);
49
+ return rb_debug_inspector_backtrace_locations(dc);
50
+ }
51
+
52
+ static VALUE
53
+ di_binding(VALUE self, VALUE index)
54
+ {
55
+ const rb_debug_inspector_t *dc = di_get_dc(self);
56
+ return rb_debug_inspector_frame_binding_get(dc, NUM2INT(index));
57
+ }
58
+
59
+ static VALUE
60
+ di_frame_class(VALUE self, VALUE index)
61
+ {
62
+ const rb_debug_inspector_t *dc = di_get_dc(self);
63
+ return rb_debug_inspector_frame_class_get(dc, NUM2INT(index));
64
+ }
65
+
66
+ static VALUE
67
+ di_frame_iseq(VALUE self, VALUE index)
68
+ {
69
+ const rb_debug_inspector_t *dc = di_get_dc(self);
70
+ return rb_debug_inspector_frame_iseq_get(dc, NUM2INT(index));
71
+ }
72
+
73
+ static VALUE
74
+ breakpoint_i(const rb_debug_inspector_t *dc, void *ptr)
75
+ {
76
+ VALUE self = (VALUE)ptr;
77
+ VALUE result;
78
+
79
+ /* should protect */
80
+ DATA_PTR(self) = (void *)dc;
81
+ result = rb_yield(self);
82
+ return result;
83
+ }
84
+
85
+ static VALUE
86
+ di_open_body(VALUE self)
87
+ {
88
+ return rb_debug_inspector_open(breakpoint_i, (void *)self);
89
+ }
90
+
91
+ static VALUE
92
+ di_open_ensure(VALUE self)
93
+ {
94
+ DATA_PTR(self) = 0;
95
+ return self;
96
+ }
97
+
98
+ static VALUE
99
+ di_open_s(VALUE klass)
100
+ {
101
+ VALUE self = TypedData_Wrap_Struct(klass, &di_data_type, 0);
102
+ return rb_ensure(di_open_body, self, di_open_ensure, self);
103
+ }
104
+
105
+ void
106
+ Init_debug_inspector(void)
107
+ {
108
+ VALUE rb_cRubyVM = rb_const_get(rb_cObject, rb_intern("RubyVM"));
109
+ VALUE cDebugInspector = rb_define_class_under(rb_cRubyVM, "DebugInspector", rb_cObject);
110
+
111
+ rb_undef_alloc_func(cDebugInspector);
112
+ rb_define_singleton_method(cDebugInspector, "open", di_open_s, 0);
113
+ rb_define_method(cDebugInspector, "backtrace_locations", di_backtrace_locations, 0);
114
+ rb_define_method(cDebugInspector, "frame_binding", di_binding, 1);
115
+ rb_define_method(cDebugInspector, "frame_class", di_frame_class, 1);
116
+ rb_define_method(cDebugInspector, "frame_iseq", di_frame_iseq, 1);
117
+ }
@@ -0,0 +1,18 @@
1
+ def fake_makefile
2
+ File.open(File.join(File.dirname(__FILE__), "Makefile"), "w") {|f|
3
+ f.puts %[install:\n\techo "Nada."]
4
+ }
5
+ end
6
+
7
+ def mri_2?
8
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
9
+ RUBY_VERSION =~ /^2/
10
+ end
11
+
12
+
13
+ if mri_2?
14
+ require 'mkmf'
15
+ create_makefile('debug_inspector')
16
+ else
17
+ fake_makefile
18
+ end
@@ -0,0 +1,5 @@
1
+ begin
2
+ require 'debug_inspector.so'
3
+ rescue LoadError
4
+ end
5
+
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debug_inspector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Mair (banisterfiend)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-02-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Ruby wrapper for the MRI 2.0 debug_inspector API
14
+ email:
15
+ - jrmair@gmail.com
16
+ executables: []
17
+ extensions:
18
+ - ext/debug_inspector/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - Rakefile
23
+ - debug_inspector.gemspec
24
+ - ext/debug_inspector/debug_inspector.c
25
+ - ext/debug_inspector/extconf.rb
26
+ - lib/debug_inspector.rb
27
+ homepage: https://github.com/banister/debug_inspector
28
+ licenses: []
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.0.rc.2
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: A Ruby wrapper for the MRI 2.0 debug_inspector API
50
+ test_files: []