Class: Trepan::Frame

Inherits:
Object
  • Object
show all
Defined in:
app/frame.rb

Overview

Call-Stack frame methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, index = 0) ⇒ Frame

Returns a new instance of Frame.



7
8
9
10
11
12
# File 'app/frame.rb', line 7

def initialize(context, index=0)
  @context = context
  @index = index
  @stack_size = @context.stack_size
  reset
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



6
7
8
# File 'app/frame.rb', line 6

def index
  @index
end

#stack_sizeObject

Returns the value of attribute stack_size.



6
7
8
# File 'app/frame.rb', line 6

def stack_size
  @stack_size
end

Instance Method Details

#argsObject



98
99
100
# File 'app/frame.rb', line 98

def args
  @args ||= @context.frame_args(@index)
end

#bindingObject



33
34
35
# File 'app/frame.rb', line 33

def binding
  @binding ||= @context.frame_binding(@index)
end

#call_string(opts = {:maxwidth=>80, :callstyle => :last}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/frame.rb', line 37

def call_string(opts={:maxwidth=>80, :callstyle => :last})
  call_str = ""
  if method_name
    locals = local_variables
    if opts[:callstyle] != :short && klass
      if opts[:callstyle] == :tracked
        arg_info = @context.frame_args_info(@index)
      end
      call_str << "#{klass}."
    end
    call_str << method_name
    if args.any?
      call_str << "("
      args.each_with_index do |name, i|
        case opts[:callstyle]
        when :short
          call_str += "%s, " % [name]
        when :last
          klass = locals[name].class
          if klass.inspect.size > 20+3
            klass = klass.inspect[0..20]+"..."
          end
          call_str += "%s#%s, " % [name, klass]
        when :tracked
          if arg_info && arg_info.size > i
            call_str += "#{name}: #{arg_info[i].inspect}, "
          else
            call_str += "%s, " % name
          end
        end
        if call_str.size > opts[:maxwidth]
          # Strip off trailing ', ' if any but add stuff for later trunc
          call_str[-2..-1] = ",...XX"
          break
        end
      end
      call_str[-2..-1] = ")" # Strip off trailing ', ' if any
    end
  end
  return call_str
end

#describe(opts = {:maxwidth => 80}) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/frame.rb', line 79

def describe(opts = {:maxwidth => 80})
  str       = ''
  # FIXME There seem to be bugs in showing call if
  # index != 0
  call_str  = index == 0 ? call_string(opts) : ''
  file = opts[:basename] ? File.basename(self.file) : self.file
  file_line = "at line %s:%d\n" % [file, line]
  unless call_str.empty?
    str += call_str + ' '
    if str.size + call_str.size + 1 + file_line.size > opts[:maxwidth]
      str += "\n       "
    else
      str += '  '
    end
  end
  str += file_line
  str
end

#fileObject



102
103
104
# File 'app/frame.rb', line 102

def file
  @file ||= @context.frame_file(@index)
end

#klassObject



106
107
108
# File 'app/frame.rb', line 106

def klass
  @klass ||= @context.frame_class(@index)
end

#lineObject



110
111
112
# File 'app/frame.rb', line 110

def line
  @line ||= @context.frame_line(@index)
end

#local_variablesObject



114
115
116
# File 'app/frame.rb', line 114

def local_variables
  @local_variables ||= @context.frame_locals(@index)
end

#method_nameObject



118
119
120
121
122
123
124
125
# File 'app/frame.rb', line 118

def method_name
  if @method_name
    @method_name
  else
    m = @context.frame_method(@index)
    @method_name = m ? m.id2name : ''
  end
end

#resetObject



14
15
16
17
# File 'app/frame.rb', line 14

def reset
  @binding = @klass = @file = @line =
    @local_variables = @method_name = @thread = nil
end

#run(code, filename = nil) ⇒ Object



28
29
30
31
# File 'app/frame.rb', line 28

def run(code, filename=nil)
  filename='(eval :%s)' % code unless filename
  eval(code, self.binding, filename)
end

#threadObject



127
128
129
# File 'app/frame.rb', line 127

def thread
  @thread ||= @context.thread
end