Permalink
Browse files

Remove infinite loop from Kernel.enhanced_caller to

itself. Used "module Trepan; class << self ..." to solve
this. Don't know what this does but saw EventMachine doing
it. Changed some indentation as a consequence.

Fixed some typoed variable names

Added $trepan_verbose variable

Fixed a thinko w/ populating caller_argv improperly

caller_argv was off by one in it's size. To match against
Kernel.caller properly, the very most outer caller has no
corresponding rb_call.
  • Loading branch information...
1 parent 68c86fc commit 023b5b58a22d0e19e6b2d0516037fd2673b1fdef Joshua ben Jore committed Aug 13, 2009
Showing with 66 additions and 47 deletions.
  1. +66 −47 lib/trepan.rb
View
@@ -3,7 +3,7 @@
module Kernel
def enhanced_caller
- Trepan.enhanced_caller
+ ::Trepan.enhanced_caller()
end
end
@@ -22,68 +22,87 @@ module Trepan
#
TREPAN = File.join( Config::CONFIG['bindir'], 'trepan-backend' )
+ # Trepan's debugging output is off by default
+ #
+ if ! defined?( $trepan_verbose ) ||
+ $trepan_verbose.nil?
+ $trepan_verbose = false
+ end
+
# === Description
# TODO: description goes here
#
# === Returns
# TODO: description goes here
#
- def enhanced_caller
+ class << self
+ def enhanced_caller()
- # Disable GC for a moment so I won't suffer a bad pointer while
- # I'm plucking objects right out of memory.
- #
- gc_was_disabled = GC.disable
+ # Disable GC for a moment so I won't suffer a bad pointer while
+ # I'm plucking objects right out of memory.
+ #
+ gc_was_disabled = GC.disable
- # Open my own brain for inspection. This is going to produce a
- # bunch of data like:
- #
- # VALUE[0][0] = 85
- # VALUE[0][1] = ...
- #
- my_brain = `#{ruby} #{trepane_rb} #{$$}`
+ # Open my own brain for inspection. This is going to produce a
+ # bunch of data like:
+ #
+ # VALUE[0][0] = 85
+ # VALUE[0][1] = ...
+ #
+ my_brain = `#{RUBY} #{TREPAN} #{$$}`
+ if $trepan_verbose
+ puts my_brain
+ end
- # Reach into our memory and pluck some objects out.
- #
- caller_argv = []
- my_brain.scan( /VALUE\[(\d+)\]\[(\d+)\]=(\d+)/ ) do
- | match |
+ # Reach into our memory and pluck some objects out.
+ #
+ caller_argv = []
+ my_brain.scan( /VALUE\[(\d+)\]\[(\d+)\]=(\d+)/ ) do
+ | match |
- caller_ix = match[0].to_i
- argv_ix = match[1].to_i
- pointer = match[2].to_i
+ caller_ix = match[0].to_i
+ argv_ix = match[1].to_i
+ pointer = match[2].to_i
- caller_argv[caller_ix] ||= []
- caller_argv[argv_ix] = pointer.__object__
- end
+ caller_argv[caller_ix] ||= []
+ caller_argv[caller_ix][argv_ix] = pointer.__object__
+ end
- # Re-enable GC if relevant because I've finished capturing
- # everything
- #
- if gc_was_disabled
- GC.enable
- end
+ # Re-enable GC if relevant because I've finished capturing
+ # everything
+ #
+ if gc_was_disabled
+ GC.enable
+ end
- # The top level of caller_argv ought to have the Kernel.`...`
- # function call so remove it.
- #
- stack = Kernel.caller
- while caller_argv.length > stack.length
- caller_argv.shift
- end
+ if $trepan_verbose
+ require 'pp'
+ pp( caller_argv )
+ end
- # Make the enhanced caller results
- #
- stack.
- zip( caller_argv )\
- .collect do
- | src, args |
- {
- :src => src,
- :args => args
- }
+ # The top level of caller_argv ought to have the Kernel.`...`
+ # function call so remove it. Also, there are N+1 levels in
+ # caller() because the top level rb_main() is in Kernel#caller
+ # but I'm not going to see anything useful in caller_argv.
+ #
+ stack = Kernel.caller
+ while caller_argv.length > stack.length - 1
+ caller_argv.shift
end
+
+ # Make the enhanced caller results
+ #
+ stack.
+ zip( caller_argv )\
+ .collect do
+ | src, args |
+ {
+ :src => src,
+ :args => args
+ }
+ end
+ end
end
end

0 comments on commit 023b5b5

Please sign in to comment.