2 # Contains all logic for gathering and displaying backtraces.
8 attr_accessor :top_context
9 attr_accessor :first_color
10 attr_accessor :kernel_color
11 attr_accessor :eval_color
16 @first_color = "\033[0;31m"
17 @kernel_color = "\033[0;34m"
18 @eval_color = "\033[0;33m"
25 def show(sep="\n", colorize = true)
27 color_config = Rubinius::RUBY_CONFIG["rbx.colorize_backtraces"]
28 if color_config == "no" or color_config == "NO"
36 formatted = @frames.map do |ctx|
39 color = color_from_loc(loc, first) if colorize
40 first = false # special handling for first line
41 times = @max - recv.size
42 times = 0 if times < 0
43 "#{color} #{' ' * times}#{recv} at #{loc}#{clear}"
45 return formatted.join(sep)
52 alias_method :to_s, :show
54 def color_from_loc(loc, first)
55 return @first_color if first
58 elsif loc =~ /\(eval\)/
70 # Skip the first frame if we are raising an exception from
71 # an eval's BlockContext
72 if @frames.at(0).from_eval?
73 frames = @frames[1, @frames.length - 1]
78 frames.each_with_index do |ctx, i|
80 @max = str.size if str.size > @max
81 @backtrace << [str, ctx.location]
83 @max = MAX_WIDTH if @max > MAX_WIDTH
86 def self.backtrace(ctx=nil)
87 ctx ||= MethodContext.current.sender
90 obj.frames = ctx.context_stack
92 # TODO - Consider not doing this step if we know we want MRI output
98 @backtrace.each { |f| yield f.last }
103 return @top_context.stack_trace_starting_at(0)