pax_global_header00006660000000000000000000000064145360545330014522gustar00rootroot0000000000000052 comment=582251ce778213e4f5fc18478905b0b3404994de banister-debug_inspector-582251c/000077500000000000000000000000001453605453300167565ustar00rootroot00000000000000banister-debug_inspector-582251c/.github/000077500000000000000000000000001453605453300203165ustar00rootroot00000000000000banister-debug_inspector-582251c/.github/workflows/000077500000000000000000000000001453605453300223535ustar00rootroot00000000000000banister-debug_inspector-582251c/.github/workflows/test.yml000066400000000000000000000060671453605453300240660ustar00rootroot00000000000000name: 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" - "3.1" - "3.2" - "truffleruby" exclude: # 2.2 segfaults on recent Ubuntu: https://github.com/ruby/setup-ruby/issues/496 - { ruby: "2.2", os: "ubuntu-latest" } # TruffleRuby does not support Windows. - { ruby: "truffleruby", os: "windows-latest" } steps: - uses: actions/checkout@v4 - 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 have issues. Skip them for now. - { ruby: "jruby", os: "windows-latest" } # TruffleRuby does not support Windows. - { ruby: "truffleruby", os: "windows-latest" } steps: - uses: actions/checkout@v4 - 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' }} run: bundle exec ruby -e "require 'debug_inspector'; DebugInspector.open { |dc| dc.frame_binding(1) }" working-directory: ./tmp/gem-test banister-debug_inspector-582251c/.gitignore000066400000000000000000000001771453605453300207530ustar00rootroot00000000000000Gemfile.lock /.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log Makefile banister-debug_inspector-582251c/Gemfile000066400000000000000000000002231453605453300202460ustar00rootroot00000000000000source "https://rubygems.org" # Specify your gem's dependencies in debug_inspector.gemspec gemspec gem "rake" gem "rake-compiler" gem "minitest" banister-debug_inspector-582251c/LICENSE000066400000000000000000000020571453605453300177670ustar00rootroot00000000000000MIT 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. banister-debug_inspector-582251c/README.md000066400000000000000000000042161453605453300202400ustar00rootroot00000000000000[![Build Status](https://github.com/banister/debug_inspector/actions/workflows/test.yml/badge.svg)](https://github.com/banister/debug_inspector/actions/workflows/test.yml) [![Gem Version](https://img.shields.io/gem/v/debug_inspector.svg)](https://rubygems.org/gems/debug_inspector) debug_inspector =============== _A Ruby wrapper for the Ruby 2.0+ debug_inspector C 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 CRuby 2.0.0. * Only works on CRuby 2+ and TruffleRuby. 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 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 in `debug_inspector.gemspec`, 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 `debug_inspector` is released under the [MIT License](https://opensource.org/licenses/MIT). banister-debug_inspector-582251c/Rakefile000077500000000000000000000010431453605453300204240ustar00rootroot00000000000000require "bundler/gem_tasks" require "rake/testtask" def can_compile_extensions? RUBY_ENGINE == "ruby" or RUBY_ENGINE == "truffleruby" 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 banister-debug_inspector-582251c/bin/000077500000000000000000000000001453605453300175265ustar00rootroot00000000000000banister-debug_inspector-582251c/bin/console000077500000000000000000000005361453605453300211220ustar00rootroot00000000000000#!/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__) banister-debug_inspector-582251c/bin/setup000077500000000000000000000002031453605453300206070ustar00rootroot00000000000000#!/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 banister-debug_inspector-582251c/debug_inspector.gemspec000066400000000000000000000027531453605453300235060ustar00rootroot00000000000000# 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.2.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 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"] spec.extensions = ["ext/debug_inspector/extconf.rb"] end banister-debug_inspector-582251c/ext/000077500000000000000000000000001453605453300175565ustar00rootroot00000000000000banister-debug_inspector-582251c/ext/debug_inspector/000077500000000000000000000000001453605453300227325ustar00rootroot00000000000000banister-debug_inspector-582251c/ext/debug_inspector/debug_inspector.c000066400000000000000000000055701453605453300262610ustar00rootroot00000000000000/********************************************************************** 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 cDebugInspector = rb_define_class("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); } banister-debug_inspector-582251c/ext/debug_inspector/extconf.rb000077500000000000000000000006151453605453300247320ustar00rootroot00000000000000def 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 can_compile_extensions? RUBY_ENGINE == "ruby" or RUBY_ENGINE == "truffleruby" end if can_compile_extensions? require 'mkmf' create_makefile('debug_inspector') else fake_makefile end banister-debug_inspector-582251c/lib/000077500000000000000000000000001453605453300175245ustar00rootroot00000000000000banister-debug_inspector-582251c/lib/debug_inspector.rb000066400000000000000000000015021453605453300232230ustar00rootroot00000000000000require '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 "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 "debug_inspector/version" rescue LoadError => e puts "debug_inspector extension was not loaded (#{e})" end end if defined?(RubyVM) && defined?(DebugInspector) RubyVM::DebugInspector = DebugInspector if RubyVM.respond_to?(:deprecate_constant) RubyVM.deprecate_constant :DebugInspector end end banister-debug_inspector-582251c/lib/debug_inspector/000077500000000000000000000000001453605453300227005ustar00rootroot00000000000000banister-debug_inspector-582251c/lib/debug_inspector/version.rb000066400000000000000000000001601453605453300247070ustar00rootroot00000000000000class DebugInspector # Don't forget to update the version string in the gemspec file. VERSION = "1.2.0" end banister-debug_inspector-582251c/test/000077500000000000000000000000001453605453300177355ustar00rootroot00000000000000banister-debug_inspector-582251c/test/basic_test.rb000066400000000000000000000026471453605453300224130ustar00rootroot00000000000000require "test_helper" class BasicTest < Minitest::Test def setup @offset = DebugInspector.open do |dc| dc.backtrace_locations.index { |loc| loc.path == __FILE__ and loc.label == "setup" } end end def test_version assert(DebugInspector::VERSION) end def test_legacy_name if RUBY_ENGINE == "ruby" if RubyVM.respond_to?(:deprecate_constant) warning = /warning: constant RubyVM::DebugInspector is deprecated/ else warning = '' end assert_output('', warning) do assert_same DebugInspector, RubyVM::DebugInspector end else assert !defined?(RubyVM::DebugInspector) end end def test_backtrace_locations 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 DebugInspector.open do |dc| assert_equal self, dc.frame_binding(@offset).eval("self") assert_equal __method__, dc.frame_binding(@offset).eval("__method__") end end def test_frame_class DebugInspector.open do |dc| assert_equal self.class, dc.frame_class(@offset) end end def test_frame_iseq DebugInspector.open do |dc| if RUBY_ENGINE == "ruby" assert_equal __FILE__, dc.frame_iseq(@offset).path else assert_nil dc.frame_iseq(@offset) end end end end banister-debug_inspector-582251c/test/test_helper.rb000066400000000000000000000001551453605453300226010ustar00rootroot00000000000000$LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "debug_inspector" require "minitest/autorun"