backtracer 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,16 +1,25 @@
1
- ruby_backtracer: output higher quality backtraces if an unhandled exception occurs. Originally inspired by the frustration of seeling ...24 levels... a few too many times.
1
+ backtracer: ruby gem to output higher quality backtraces if an unhandled exception is thrown.
2
2
 
3
- There are several options available (the more verbose ones rely on ruby-debug, which slows things down a bit).
4
3
 
5
- ex:
6
- a script used to output:
7
- examples>ruby crash.rb
4
+ If you've ever seen
5
+ ...24 levels...
6
+ and disliked it, this is the gem for you.
7
+
8
+ It displays the full back trace, with or without code and/or local variables, etc.
9
+
10
+ There are several options available.
11
+
12
+ example:
13
+
14
+ a script that used to output:
15
+
16
+ >ruby crash.rb
8
17
  crash.rb:2:in `go2': unhandled exception
9
18
  from crash.rb:6:in `go'
10
19
  from crash.rb:9
11
20
 
12
- Using backtracer, it now outputs:
13
- examples>ruby -rbacktracer_locals crash.rb
21
+ Now outputs:
22
+ >backtracer --locals crash.rb
14
23
 
15
24
  unhandled exception: crash.rb:2: raise
16
25
  locals: {"a"=>"3", "b"=>55}
@@ -20,7 +29,7 @@ unhandled exception: crash.rb:2: raise
20
29
  crash.rb:5 go(a=>3)
21
30
  locals: {"a"=>"3"}
22
31
  or
23
- examples>ruby -rbacktracer crash.rb
32
+ >backtracer crash.rb
24
33
  ====
25
34
  crash.rb:2:in `go2'
26
35
  raise
@@ -33,78 +42,71 @@ crash.rb:2:in `go2': unhandled exception
33
42
  from crash.rb:7:in `go'
34
43
  from crash.rb:10
35
44
 
45
+ Also included is a --ping option which periodically dumps the current running threads' backtrace(s)--quite useful for figuring out where you code is spending a lot of its time.
36
46
 
37
- All the options are backtracer, backtracer_locals, backtracer_simple, backtracer_tracer
38
-
47
+ To see all possible options run
48
+ $ backtracer -h
39
49
 
40
50
  == Installation ==
41
51
 
42
- == 1.9 ==
52
+ == 1.8.x ==
43
53
 
44
- $ gem install ruby-debug19
54
+ $ gem install ruby-debug
45
55
  $ gem sources add http://gemcutter.org # if necessary
46
56
  $ gem install backtracer
47
57
 
48
- run as above
49
- $ ruby -rbacktracer script_name
58
+ now run like
59
+ $ backtracer script_name
60
+ $ backtracer --locals script_name
50
61
 
51
- == 1.8.x ==
62
+ == 1.9.1 ==
52
63
 
53
- $ gem install ruby-debug
64
+ $ gem install ruby-debug19 # if you want some of the more exotic backtraces
54
65
  $ gem sources add http://gemcutter.org # if necessary
55
- $ sudo gem install faster_rubygems # necessary to be able to load gems from the command line -- installs the file rubygemsf into your site_ruby
56
66
  $ gem install backtracer
57
67
 
58
- now run them like
59
- $ ruby -rubygemsf -rbacktracer script_name
60
-
61
- the rubygemsf is necessary because for some reason running
62
- $ ruby -rubygems -rbacktracer script_name
63
-
64
- fails [probably a bug in ruby]
68
+ run as above (backtracer executable), or as a ruby require:
69
+ $ ruby -rbacktracer script_name
70
+ $ ruby -rbacktracer_locals script_name
65
71
 
66
72
  == Descriptions ==
67
73
 
68
- Try these out if desired:
69
- create a file like:
74
+ Try out the options:
75
+ create a file like
70
76
 
71
77
  def go(a)
72
78
  raise
73
79
  end
74
80
  go(3)
75
81
 
76
- then run ruby against it like
82
+ then run backtracer against it.
77
83
 
78
- ruby -rbacktracer name
79
- outputs full backtrace with code of each line [a la Python]
80
- ruby -rbacktracer_locals name
81
- outputs full backtrace with local variables and parameters
82
- ruby -rbacktracer_simple name
83
- outputs backtrace without the ...24 levels... [yea!]
84
- ruby -backtracer_tracer name
85
- same as backtracer_locals except it shows traces of calls as they're made
84
+ == Other ==
86
85
 
86
+ Note that you can load the better backtracing capability within a script itself:
87
87
 
88
- or in 1.8.x
89
- ruby -rubygemsf -rbacktracer name
90
- etc.
88
+ require 'backtracer'
91
89
 
90
+ will cause it to output a coded backtrace at exit time, if an unhandled exception occurs. Backtracer default and backtracer_simple don't cause runtime slowdown.
92
91
 
93
- == Other ==
92
+ You can also add it to your RUBYOPT variable if you always want it to run against all scripts (backtracer_simple and backtracer don't cause any slowdowns).
93
+ Here's how:
94
+ 1.9:
94
95
 
95
- Note that you can [if desired] load these within a script iself
96
- require 'backtracer'
96
+ $ export RUBYOPT=-rbacktracer
97
97
 
98
- and it will output a backtrace if one exists at exit time.
98
+ 1.8.7:
99
+ you'll need to install a helper loader since gems can't load on the command line for some reason.
99
100
 
100
- You can also add it to your RUBYOPT variable if you always want it to run [backtracer_simple and backtracer don't cause any slowdown].
101
- $ export RUBYOPT=-rbacktracer
101
+ $ sudo gem install faster_rubygems # the helper--installs faster_rubygems.rb and some other files to your site_ruby
102
+ $ export RUBYOPT='-rfaster_rubygems -rbacktracer'
102
103
 
103
- if desired.
104
+ Enjoy.
104
105
 
105
106
  == Related projects ==
106
107
  unroller, http://eigenclass.org/hiki/method+arguments+via+introspection, liveconsole, ruby-debug
107
108
 
108
- Comments welcome to rdp on github.
109
+ Comments welcome
110
+ rdp on github.
109
111
 
110
112
  http://github.com/rdp/backtracer
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/bin/backtracer CHANGED
@@ -1,10 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
- # gems will fill this in for me
3
2
 
4
- if true # (ARGV.include? '-h') || (ARGV.include? '--help')
3
+ if (ARGV.include? '-h') || (ARGV.include? '--help')
5
4
  dir = File.dirname(__FILE__) + '/../lib'
6
- puts 'options: ( -r filename) '
7
- for file in Dir[dir + '/*.rb']
8
- puts File.basename(file)
5
+ puts 'options: '
6
+ for file in Dir[dir + '/backtracer_*.rb']
7
+ puts '--' + File.basename(file)[11..-4] # of backtracer_locals.rb, just locals
9
8
  end
10
- end
9
+ puts 'ex: $ backtracer filename.rb arg1 arg2'
10
+ puts 'ex: $ backtracer --simple filename.rb arg1 arg2'
11
+ puts 'you can also do $ ruby -rtracerr for an improved tracer (though 1.9.2 has the same already patched)'
12
+ exit
13
+ end
14
+
15
+ # expect
16
+ # backtracer --plain --simple filename options
17
+
18
+ if ARGV[0][0..1] == '--'
19
+ require 'backtracer_' + ARGV[0][2..-1] # take it off, too
20
+ ARGV.shift
21
+ else
22
+ require 'backtracer'
23
+ end
24
+
25
+ $0 = File.expand_path ARGV[0] # for their benefit :)
26
+ ARGV.shift
27
+ load $0
data/lib/backtracer.rb CHANGED
@@ -4,8 +4,8 @@ require File.dirname(__FILE__) + "/shared"
4
4
  require 'sane'
5
5
 
6
6
  at_exit {
7
- if $!
8
- puts "==== " + $!.inspect + ' ' + $!.to_s
7
+ if $! && !$!.is_a?(SystemExit) # SystemExit's are just normal, not exceptional
8
+ puts "==== ", $!.inspect + ' ' + $!.to_s
9
9
  bt2 = $!.backtrace
10
10
  backtrace_with_code = $!.backtrace.map{ |bt_line|
11
11
  if OS.windows? && bt_line[1..1] == ':'
@@ -23,7 +23,7 @@ at_exit {
23
23
  puts backtrace_with_code
24
24
  puts "===="
25
25
  else
26
- puts "(no exception found to backtrace)"
26
+ puts "(no exception found to backtrace)" if $VERBOSE
27
27
  end
28
28
  # exit! TODO I guess do this once ours isn't *so* ugly
29
29
  # TODO compare with that fella xray
@@ -39,10 +39,12 @@ time = 1 if $0 == __FILE__
39
39
  Thread.new {
40
40
  loop {
41
41
  sleep time
42
- pp fella.call
42
+ pp 'current stack trace', Time.now, fella.call
43
43
  }
44
44
  }
45
45
 
46
- if $0 == __FILE__ # a test
46
+ require File.dirname(__FILE__) + '/backtracer' # we want the normal backtracer, too
47
+
48
+ if $0 == __FILE__ # i.e. a test
47
49
  sleep
48
50
  end
@@ -1,2 +1,2 @@
1
- # this is the default
1
+ $print_trace = true
2
2
  require File.dirname(__FILE__) + '/core_backtracer.rb'
@@ -154,7 +154,7 @@ class Tracer
154
154
  type,
155
155
  get_line(file, line))
156
156
 
157
- print out if $VERBOSE
157
+ print out if $print_trace || $VERBOSE
158
158
  @@last_line = line
159
159
  @@last_file = file
160
160
  @@last_symbol = type
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backtracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-05 00:00:00 -07:00
13
- default_executable:
12
+ date: 2009-11-10 00:00:00 -07:00
13
+ default_executable: backtracer
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sane
@@ -36,7 +36,6 @@ description: Quality backtraces for ruby
36
36
  email: rogerdpack@gmail.com
37
37
  executables:
38
38
  - backtracer
39
- - backtracer~
40
39
  extensions: []
41
40
 
42
41
  extra_rdoc_files:
data/bin/backtracer~ DELETED
@@ -1,7 +0,0 @@
1
- if (ARGV.include? '-h') || (ARGV.include? '--help')
2
- dir = File.dirname(__FILE__) + '/../lib'
3
- puts 'options:'
4
- for file in Dir[dir + '/*']
5
- puts File.basename(file)
6
- end
7
- end