pax_global_header00006660000000000000000000000064140264254630014520gustar00rootroot0000000000000052 comment=5424c4094df30adfecd961a4e77d95f1fea9bc48 debug_inspector-1.1.0/000077500000000000000000000000001402642546300146735ustar00rootroot00000000000000debug_inspector-1.1.0/.github/000077500000000000000000000000001402642546300162335ustar00rootroot00000000000000debug_inspector-1.1.0/.github/workflows/000077500000000000000000000000001402642546300202705ustar00rootroot00000000000000debug_inspector-1.1.0/.github/workflows/test.yml000066400000000000000000000053701402642546300217770ustar00rootroot00000000000000name: Test on: push: branches: [ master ] schedule: - cron: '0 0 11,25 * *' # roughly every two weeks to run on new Ruby versions pull_request: branches: [ master ] workflow_dispatch: jobs: test: name: "Unit" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - macos-latest - ubuntu-latest - windows-latest ruby: - "2.1" - "2.2" - "2.3" - "2.4" - "2.5" - "2.6" - "2.7" - "3.0" steps: - uses: actions/checkout@v2 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Test run: bundle exec rake system: name: "System" runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: - macos-latest - ubuntu-latest - windows-latest ruby: # This includes rubies that are not actually extended by this gem. # We want to make sure the gem silently fails to load on those platforms. - "2" - "3.0" - "jruby" - "truffleruby" exclude: # Windows releases of jruby and truffleruby have issues. Skip them for now. - { ruby: "jruby", os: "windows-latest" } - { ruby: "truffleruby", os: "windows-latest" } steps: - uses: actions/checkout@v2 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - name: Build gem run: bundle exec gem build --verbose debug_inspector.gemspec - name: Install gem run: gem install --verbose debug_inspector*.gem - name: Create directory for gem test run: mkdir -p tmp/gem-test - name: Create test Gemfile run: echo "gem 'debug_inspector'" > Gemfile working-directory: ./tmp/gem-test - name: Get gem installation path id: gem_path run: | gem_path=$(bundle show debug_inspector) echo "gem_path is ${gem_path}" echo "::set-output name=path::${gem_path}" shell: bash working-directory: ./tmp/gem-test - name: List installed gem contents run: find . shell: bash working-directory: ${{ steps.gem_path.outputs.path }} - name: Test gem load run: bundle exec ruby -e "require 'debug_inspector'" working-directory: ./tmp/gem-test - name: Test gem functionality if: ${{ matrix.ruby != 'jruby' && matrix.ruby != 'truffleruby' }} run: bundle exec ruby -e "require 'debug_inspector'; RubyVM::DebugInspector.open { |dc| dc.frame_binding(1) }" working-directory: ./tmp/gem-test debug_inspector-1.1.0/.gitignore000066400000000000000000000001771402642546300166700ustar00rootroot00000000000000Gemfile.lock /.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log Makefile debug_inspector-1.1.0/Gemfile000066400000000000000000000002231402642546300161630ustar00rootroot00000000000000source "https://rubygems.org" # Specify your gem's dependencies in debug_inspector.gemspec gemspec gem "rake" gem "rake-compiler" gem "minitest" debug_inspector-1.1.0/README.md000066400000000000000000000061121402642546300161520ustar00rootroot00000000000000[![Build Status](https://github.com/banister/debug_inspector/workflows/Test/badge.svg?branch=master&event=push)](https://github.com/banister/debug_inspector/actions?query=branch%3Amaster) [![Gem Version](https://img.shields.io/gem/v/debug_inspector.svg)](https://rubygems.org/gems/debug_inspector) debug_inspector =============== _A Ruby wrapper for the MRI 2.0+ debug\_inspector API_ The `debug_inspector` C extension and API were designed and built by [Koichi Sasada](https://github.com/ko1), this project is just a gemification of his work. **NOTES:** * **Do not use this library outside of debugging situations**. * This library makes use of the debug inspector API which was new in MRI 2.0.0. * Only works on MRI 2 and 3. Requiring it on unsupported Rubies will result in a no-op Usage ----- ```ruby require 'debug_inspector' # Open debug context # Passed `dc' is only active in a block RubyVM::DebugInspector.open { |dc| # backtrace locations (returns an array of Thread::Backtrace::Location objects) locs = dc.backtrace_locations # you can get depth of stack frame with `locs.size' locs.size.times do |i| # binding of i-th caller frame (returns a Binding object or nil) p dc.frame_binding(i) # iseq of i-th caller frame (returns a RubyVM::InstructionSequence object or nil) p dc.frame_iseq(i) # class of i-th caller frame p dc.frame_class(i) end } ``` Development ----------- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). Contact ------- Problems or questions contact me at [github](http://github.com/banister) License ------- (The MIT License) Copyright (c) 2012-2013 (John Mair) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. debug_inspector-1.1.0/Rakefile000077500000000000000000000010041402642546300163360ustar00rootroot00000000000000require "bundler/gem_tasks" require "rake/testtask" def can_compile_extensions? RUBY_ENGINE == "ruby" end Rake::TestTask.new(:test) do |t| t.libs << "test" t.libs << "lib" t.test_files = FileList["test/**/*_test.rb"] t.warning = true t.verbose = true end require "rake/extensiontask" if can_compile_extensions? task :build => :compile task :default => [:clobber, :compile, :test] else task :default => [:test] end Rake::ExtensionTask.new("debug_inspector") do |ext| ext.lib_dir = "lib" end debug_inspector-1.1.0/bin/000077500000000000000000000000001402642546300154435ustar00rootroot00000000000000debug_inspector-1.1.0/bin/console000077500000000000000000000005361402642546300170370ustar00rootroot00000000000000#!/usr/bin/env ruby require "bundler/setup" require "debug_inspector" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start(__FILE__) debug_inspector-1.1.0/bin/setup000077500000000000000000000002031402642546300165240ustar00rootroot00000000000000#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here debug_inspector-1.1.0/debug_inspector.gemspec000066400000000000000000000030261402642546300214150ustar00rootroot00000000000000# We don't want to define any constants if the gem extension isn't loaded, so not requiring the version file. Gem::Specification.new do |spec| spec.name = "debug_inspector" spec.version = "1.1.0" spec.authors = ["John Mair (banisterfiend)"] spec.email = ["jrmair@gmail.com"] spec.summary = %q{A Ruby wrapper for the MRI 2.0 debug_inspector API} spec.description = <<-TXT Adds methods to RubyVM::DebugInspector to allow for inspection of backtrace frames. The debug_inspector C extension and API were designed and built by Koichi Sasada, this project is just a gemification of his work. This library makes use of the debug inspector API which was added to MRI 2.0.0. Only works on MRI 2 and 3. Requiring it on unsupported Rubies will result in a no-op. Recommended for use only in debugging situations. Do not use this in production apps. TXT spec.homepage = "https://github.com/banister/debug_inspector" spec.license = "MIT" spec.required_ruby_version = Gem::Requirement.new(">= 2.0") spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/banister/debug_inspector" spec.metadata["changelog_uri"] = "https://github.com/banister/debug_inspector/releases" spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|bin)/}) } end spec.require_paths = ["lib"] if RUBY_ENGINE == "ruby" spec.extensions = ["ext/debug_inspector/extconf.rb"] end end debug_inspector-1.1.0/ext/000077500000000000000000000000001402642546300154735ustar00rootroot00000000000000debug_inspector-1.1.0/ext/debug_inspector/000077500000000000000000000000001402642546300206475ustar00rootroot00000000000000debug_inspector-1.1.0/ext/debug_inspector/debug_inspector.c000066400000000000000000000057211402642546300241740ustar00rootroot00000000000000/********************************************************************** debug_inspector.c $Author: ko1 $ created at: Thu Nov 15 17:34:36 2012 Copyright (C) 1993-2012 Yukihiro Matsumoto **********************************************************************/ #include "ruby/ruby.h" #include "ruby/debug.h" static size_t di_size(const void *dummy) { return sizeof(void *); } static const rb_data_type_t di_data_type = { "simple_debugger", {0, 0, di_size,}, }; static const rb_debug_inspector_t * di_get_dc(VALUE self) { const rb_debug_inspector_t *dc; TypedData_Get_Struct(self, const rb_debug_inspector_t, &di_data_type, dc); if (dc == 0) { rb_raise(rb_eArgError, "invalid debug context"); } return dc; } static VALUE di_backtrace_locations(VALUE self) { const rb_debug_inspector_t *dc = di_get_dc(self); return rb_debug_inspector_backtrace_locations(dc); } static VALUE di_binding(VALUE self, VALUE index) { const rb_debug_inspector_t *dc = di_get_dc(self); return rb_debug_inspector_frame_binding_get(dc, NUM2INT(index)); } static VALUE di_frame_class(VALUE self, VALUE index) { const rb_debug_inspector_t *dc = di_get_dc(self); return rb_debug_inspector_frame_class_get(dc, NUM2INT(index)); } static VALUE di_frame_iseq(VALUE self, VALUE index) { const rb_debug_inspector_t *dc = di_get_dc(self); return rb_debug_inspector_frame_iseq_get(dc, NUM2INT(index)); } static VALUE di_frame_self(VALUE self, VALUE index) { const rb_debug_inspector_t *dc = di_get_dc(self); return rb_debug_inspector_frame_self_get(dc, NUM2INT(index)); } static VALUE breakpoint_i(const rb_debug_inspector_t *dc, void *ptr) { VALUE self = (VALUE)ptr; VALUE result; /* should protect */ DATA_PTR(self) = (void *)dc; result = rb_yield(self); return result; } static VALUE di_open_body(VALUE self) { return rb_debug_inspector_open(breakpoint_i, (void *)self); } static VALUE di_open_ensure(VALUE self) { DATA_PTR(self) = 0; return self; } static VALUE di_open_s(VALUE klass) { VALUE self = TypedData_Wrap_Struct(klass, &di_data_type, 0); return rb_ensure(di_open_body, self, di_open_ensure, self); } void Init_debug_inspector(void) { VALUE rb_cRubyVM = rb_const_get(rb_cObject, rb_intern("RubyVM")); VALUE cDebugInspector = rb_define_class_under(rb_cRubyVM, "DebugInspector", rb_cObject); rb_undef_alloc_func(cDebugInspector); rb_define_singleton_method(cDebugInspector, "open", di_open_s, 0); rb_define_method(cDebugInspector, "backtrace_locations", di_backtrace_locations, 0); rb_define_method(cDebugInspector, "frame_binding", di_binding, 1); rb_define_method(cDebugInspector, "frame_class", di_frame_class, 1); rb_define_method(cDebugInspector, "frame_iseq", di_frame_iseq, 1); rb_define_method(cDebugInspector, "frame_self", di_frame_self, 1); } debug_inspector-1.1.0/ext/debug_inspector/extconf.rb000077500000000000000000000006151402642546300226470ustar00rootroot00000000000000def fake_makefile File.open("Makefile", "w") { |f| f.puts '.PHONY: install' f.puts 'install:' f.puts "\t" + '@echo "This Ruby not supported by/does not require debug_inspector."' } end def mri_2_or_3? defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION =~ /^[23]/ end if mri_2_or_3? require 'mkmf' create_makefile('debug_inspector') else fake_makefile end debug_inspector-1.1.0/lib/000077500000000000000000000000001402642546300154415ustar00rootroot00000000000000debug_inspector-1.1.0/lib/debug_inspector.rb000066400000000000000000000012111402642546300211350ustar00rootroot00000000000000require 'rbconfig' dlext = RbConfig::CONFIG['DLEXT'] begin # If the installation task did its job, the extension is in lib/ next to this file. require "debug_inspector.#{dlext}" # We only want to define constants if the extension has loaded. require_relative "rubyvm/debug_inspector/version" rescue LoadError begin # If not, maybe the extension is in ext/ require_relative "../ext/debug_inspector/debug_inspector.#{dlext}" # We only want to define constants if the extension has loaded. require_relative "rubyvm/debug_inspector/version" rescue LoadError => e puts "debug_inspector extension was not loaded" end end debug_inspector-1.1.0/lib/rubyvm/000077500000000000000000000000001402642546300167655ustar00rootroot00000000000000debug_inspector-1.1.0/lib/rubyvm/debug_inspector/000077500000000000000000000000001402642546300221415ustar00rootroot00000000000000debug_inspector-1.1.0/lib/rubyvm/debug_inspector/version.rb000066400000000000000000000001701402642546300241510ustar00rootroot00000000000000class RubyVM::DebugInspector # Don't forget to update the version string in the gemspec file. VERSION = "1.1.0" end debug_inspector-1.1.0/test/000077500000000000000000000000001402642546300156525ustar00rootroot00000000000000debug_inspector-1.1.0/test/basic_test.rb000066400000000000000000000014541402642546300203230ustar00rootroot00000000000000require "test_helper" class BasicTest < MiniTest::Test def test_version assert(RubyVM::DebugInspector::VERSION) end def test_backtrace_locations RubyVM::DebugInspector.open do |dc| assert dc.backtrace_locations.size > 0 dc.backtrace_locations.each{|e| assert_instance_of Thread::Backtrace::Location, e} end end def test_frame_binding RubyVM::DebugInspector.open do |dc| assert_equal self, dc.frame_binding(1).eval("self") assert_equal __method__, dc.frame_binding(1).eval("__method__") end end def test_frame_class RubyVM::DebugInspector.open do |dc| assert_equal self.class, dc.frame_class(1) end end def test_frame_iseq RubyVM::DebugInspector.open do |dc| assert_equal __FILE__, dc.frame_iseq(1).path end end end debug_inspector-1.1.0/test/test_helper.rb000066400000000000000000000001551402642546300205160ustar00rootroot00000000000000$LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "debug_inspector" require "minitest/autorun"