Skip to content

Instantly share code, notes, and snippets.

@rocky
Created April 24, 2011 00:49
Show Gist options
  • Select an option

  • Save rocky/939184 to your computer and use it in GitHub Desktop.

Select an option

Save rocky/939184 to your computer and use it in GitHub Desktop.
Rubinius then/else goto tagged as part of else
========== :find_main_script ===========
Arguments: 1 required, 1 total
Locals: 2: i, loc
Stack size: 7
Lines to IP: 19: 0..3, 20: 4..14, 21: 15..28, 22: 29..39, 23: 40..72, 24: 73..87, 26: 88..94, 28: 95..107, 22: 108..109
0000: cast_for_single_block_arg
0001: set_local 0
0003: pop
0004: push_local_depth 1, 0
0007: push_local 0
0009: send_stack :[], 1
0012: set_local 1
0014: pop
0015: push_literal "Object#"
0017: string_dup
0018: push_local 1
0020: send_stack :describe_receiver, 0
0023: meta_send_op_equal :==
0025: dup_top
0026: goto_if_false 38
0028: pop
0029: push_literal :__script__
0031: push_local 1
0033: send_stack :name, 0
0036: meta_send_op_equal :==
0038: goto_if_false 108
0040: push_local 1
0042: send_stack :method, 0
0045: send_stack :active_path, 0
0048: push_literal nil
0050: dup_top
0051: is_nil
0052: goto_if_false 66
0054: pop
0055: push_cpath_top
0056: find_const 9
0058: push_literal "\\/trepanx$"
0060: meta_push_0
0061: send_stack :new, 2
0064: set_literal nil
0066: send_stack :=~, 1
0069: dup_top
0070: goto_if_true 86
0072: pop
0073: push_local 1
0075: send_stack :method, 0
0078: send_stack :active_path, 0
0081: push_literal "kernel/loader.rb"
0083: string_dup
0084: meta_send_op_equal :==
0086: goto_if_false 95
0088: push_local 0
0090: set_local_depth 1, 1
0093: goto 106
0095: push_local_depth 1, 0
0098: send_stack :size, 0
0101: push_local 0
0103: meta_send_op_minus :-
0105: raise_return
0106: goto 109
0108: push_nil
0109: ret
----------------------------------------
# Copyright (C) 2010, 2011 Rocky Bernstein <rockyb@rubyforge.net>
class Trepan
module Util
module_function
def safe_repr(str, max, elipsis='... ')
if str.is_a?(String) && max > 0 && str.size > max && !str.index("\n")
"%s%s%s" % [ str[0...max/2], elipsis, str[str.size-max/2..str.size]]
else
str
end
end
# Find user portion of script skipping over Rubinius code loading.
# Unless hidestack is off, we don't show parts of the frame below this.
def find_main_script(locs)
candidate = nil
(locs.size-1).downto(0) do |i|
loc = locs[i]
if 'Object#' == loc.describe_receiver &&
:__script__ == loc.name
if loc.method.active_path =~ /\/trepanx$/ ||
loc.method.active_path == 'kernel/loader.rb'
# Might have been run from standalone trepanx.
candidate = i
else
return locs.size - i
end
end
end
candidate ? locs.size - candidate - 1 : nil
end
module_function :find_main_script
end
end
if __FILE__ == $0
include Trepan::Util
string = 'The time has come to talk of many things.'
puts safe_repr(string, 50)
puts safe_repr(string, 17)
puts safe_repr(string.inspect, 17)
puts safe_repr(string.inspect, 17, '')
locs = Rubinius::VM.backtrace(0)
locs.each_with_index do |l, i|
puts "#{i}: #{l.describe}"
end
puts "main script in above is #{locs.size() - 1 - find_main_script(locs)}"
end
@rocky
Copy link
Author

rocky commented Apr 24, 2011

In find_main_script.asm, note that at offset 93 there is a goto 106 which is the instruction goto 109. 106 however is tagged as being in part of the "else" part of an if/then/else. So we have another instance of misleading location information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment