Skip to content
Browse files

add a new option that is a default of just seeing the code lines, not…

… where they were--I think I like it better
  • Loading branch information...
1 parent d25f55e commit 886e07ac7efd8a94854df76e95e838bd44ba92c4 @rdp committed
View
7 bin/backtracer
@@ -1,15 +1,14 @@
#!/usr/bin/env ruby
-if (ARGV.include? '-h') || (ARGV.include? '--help')
+if (ARGV.include? '-h') || (ARGV.include? '--help') || ARGV.length == 0
dir = File.dirname(__FILE__) + '/../lib'
puts 'options: '
for file in Dir[dir + '/backtracer_*.rb'].sort.reverse
puts '--' + File.basename(file)[11..-4] # of backtracer_locals.rb, just locals
end
- puts 'ex: $ backtracer filename.rb arg1 arg2'
+ puts 'ex\'s:', '$ backtracer filename.rb arg1 arg2'
puts '$ backtracer --simple filename.rb arg1 arg2'
- puts 'or its equivalent: $ ruby -rbacktracer_simple filename.rb arg1 arg2'
- puts '$ ruby -rtracerr'
+ puts 'or its equivalent:', '$ ruby -rbacktracer_simple filename.rb arg1 arg2'
exit
end
View
44 lib/backtracer.rb
@@ -16,7 +16,7 @@
$!.backtrace.each{|bt_line| max = [bt_line.length, max].max}
backtrace_with_code = $!.backtrace.map{ |bt_line|
- next if bt_line.include? 'bin/backtracer' # binary lines...
+ next if bt_line.include? 'bin/backtracer' # lines from ourself...
if DOZE && bt_line[1..1] == ':'
drive, file, line, junk = bt_line.split(":")
@@ -26,10 +26,44 @@
file, line, junk = bt_line.split(":")
end
line = line.to_i
- actual_line = Tracer.get_line(file, line)
-
- "%-#{max + 1}s #{"\n\t" unless defined?($same_line)}%s" % [bt_line, (actual_line.strip if actual_line)]
- }.compact
+ actual_code = Tracer.get_line(file, line)
+ output_line = ''
+ output_line += "%-#{max + 1}s " % bt_line unless $no_code_line_numbers
+ if actual_code && actual_code != '-'
+ output_line += "\n\t" unless defined?($same_line)
+ output_line += actual_code.strip
+ end
+ output_line
+ }
+
+ previous_line = nil
+ count = 0
+
+ backtrace_with_code = backtrace_with_code.map{|line|
+ if previous_line == nil
+ # startup
+ previous_line = line
+ line
+ elsif previous_line == line
+ # redundant line
+ count += 1
+
+ nil
+ else
+ # good line
+ previous_line = line
+ if count > 0
+ # first good line after a string of bad
+ a = [" (repeat #{count} times) ", line]
+ count = 0
+ a
+ else
+ line
+ end
+ end
+ }.flatten.compact
+
+
puts backtrace_with_code
puts # blank line
# for some reason this can be nil...
View
2 lib/backtracer_code_same_line.rb
@@ -1,6 +1,4 @@
# this one display full BT with code, at the end [no performance loss]
-require 'rbconfig'
-WINDOZE = Config::CONFIG['host_os'] =~ /mswin|mingw/
$same_line = true
require File.dirname(__FILE__) + "/shared"
View
4 lib/backtracer_just_code_lines.rb
@@ -1,7 +1,5 @@
# this one display full BT with code, at the end [no performance loss]
-require 'rbconfig'
-WINDOZE = Config::CONFIG['host_os'] =~ /mswin|mingw/
+$no_code_line_numbers = true
$same_line = true
-
require File.dirname(__FILE__) + "/shared"
require File.dirname(__FILE__) + "/backtracer.rb"
View
2 lib/backtracer_locals.rb
@@ -1,2 +1,2 @@
# this is the default
-require File.dirname(__FILE__) + '/core_backtracer.rb'
+require File.dirname(__FILE__) + '/core_backtracer_locals.rb'
View
2 lib/backtracer_tracer.rb
@@ -1,2 +1,2 @@
$print_trace = true
-require File.dirname(__FILE__) + '/core_backtracer.rb'
+require File.dirname(__FILE__) + '/core_backtracer_locals.rb'
View
2 lib/backtracer_tracer_args.rb
@@ -1,3 +1,3 @@
# this is the default
$VERBOSE = 1 # how we tell it to do args currently
-require File.dirname(__FILE__) + '/core_backtracer.rb'
+require File.dirname(__FILE__) + '/core_backtracer_locals.rb'
View
21 lib/backtracer_tracer_exception_creation.rb
@@ -1,21 +0,0 @@
-require 'faster_rubygems'
-require 'event_hook'
-
-class Demo < EventHook
- def self.process(*args)
-
- # args => [64, #<RuntimeError: hello>, :initialize, Exception]
- begin
- if args[1].is_a? Exception
- puts args.inspect
- end
- rescue
- # fantastically, this check fails within rails at times
- end
- end
-end
-
-Demo.start_hook
-
-# TODO 1.9 compat
-#set_trace_func proc {|*args| puts args.inspect }
View
11 test/test.rb
@@ -1,4 +1,9 @@
-def go
- go
+def go number
+ if number == 4
+ raise 'done'
+ else
+ go number + 1
+ end
end
-go
+
+go 0
View
9 test/test2.rb
@@ -0,0 +1,9 @@
+def go1
+ go2
+end
+
+def go2
+ go1
+end
+
+go2

0 comments on commit 886e07a

Please sign in to comment.
Something went wrong with that request. Please try again.