backtracer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,14 +1,16 @@
1
- ruby_backtracer: a library to output higher quality backtraces if an unhandled exception is raised
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.
2
2
 
3
- ex:
4
- running given script examples/crash.rb used to output:
3
+ There are several options available (the more verbose ones rely on ruby-debug, which slows things down a bit).
4
+
5
+ ex:
6
+ a script used to output:
5
7
  examples>ruby crash.rb
6
8
  crash.rb:2:in `go2': unhandled exception
7
9
  from crash.rb:6:in `go'
8
10
  from crash.rb:9
9
11
 
10
- now outputs:
11
- examples>ruby -r../backtrace_with_code_and_locals crash.rb
12
+ Using backtracer, it now outputs:
13
+ examples>ruby -rbacktracer_locals crash.rb
12
14
 
13
15
  unhandled exception: crash.rb:2: raise
14
16
  locals: {"a"=>"3", "b"=>55}
@@ -17,23 +19,92 @@ unhandled exception: crash.rb:2: raise
17
19
  locals: {"a"=>"3", "b"=>55}
18
20
  crash.rb:5 go(a=>3)
19
21
  locals: {"a"=>"3"}
22
+ or
23
+ examples>ruby -rbacktracer crash.rb
24
+ ====
25
+ crash.rb:2:in `go2'
26
+ raise
27
+ crash.rb:7:in `go'
28
+ go2(a, 55)
29
+ crash.rb:10
30
+ go '3'
31
+ ====
32
+ crash.rb:2:in `go2': unhandled exception
33
+ from crash.rb:7:in `go'
34
+ from crash.rb:10
35
+
36
+
37
+ All the options are backtracer, backtracer_locals, backtracer_simple, backtracer_tracer
38
+
39
+
40
+ == Installation ==
41
+
42
+ == 1.9 ==
43
+
44
+ $ gem install ruby-debug19
45
+ $ gem sources add http://gemcutter.org # if necessary
46
+ $ gem install backtracer
47
+
48
+ run as above
49
+ $ ruby -rbacktracer script_name
50
+
51
+ == 1.8.x ==
52
+
53
+ $ gem install ruby-debug
54
+ $ 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
+ $ gem install backtracer
57
+
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]
65
+
66
+ == Descriptions ==
67
+
68
+ Try these out if desired:
69
+ create a file like:
70
+
71
+ def go(a)
72
+ raise
73
+ end
74
+ go(3)
75
+
76
+ then run ruby against it like
77
+
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
86
+
87
+
88
+ or in 1.8.x
89
+ ruby -rubygemsf -rbacktracer name
90
+ etc.
20
91
 
21
- Now wasn't that prettier?
22
92
 
23
- There are several other tracing options provided, if you don't want as much output, or want more speed. Specify which by script name.
93
+ == Other ==
24
94
 
25
- ex: backtrace_nothing_swallowed.rb outputs the same as the default exception output, except it doesn't have the
26
- ...skip 24 lines...
27
- line in the middle (also no speed slowdown, and no local variables displayed).
95
+ Note that you can [if desired] load these within a script iself
96
+ require 'backtracer'
28
97
 
29
- Try them out by running test_all.rb in the examples folder, or eyeball the example output files in examples/example_output*
98
+ and it will output a backtrace if one exists at exit time.
30
99
 
31
- http://github.com/rogerdpack/ruby_backtracer/tree/master
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
32
102
 
33
- Note: some options depends on ruby-debug [MRI] gem, some don't.
103
+ if desired.
34
104
 
35
- To install clone from github, above, then ruby -rscriptname your_script.
105
+ == Related projects ==
106
+ unroller, http://eigenclass.org/hiki/method+arguments+via+introspection, liveconsole, ruby-debug
36
107
 
37
- related projects: unroller, http://eigenclass.org/hiki/method+arguments+via+introspection, liveconsole, ruby-debug
108
+ Comments welcome to rdp on github.
38
109
 
39
- send comments to rogerdpack on github.
110
+ http://github.com/rdp/backtracer
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/examples/crash.rb CHANGED
@@ -2,8 +2,9 @@ def go2(a, b)
2
2
  raise
3
3
  end
4
4
 
5
- def go(a);
6
- go2(a, 55);
5
+ def go(a)
6
+ b = 3
7
+ go2(a, 55)
7
8
  end
8
9
 
9
10
  go '3'
data/lib/backtracer.rb CHANGED
@@ -2,15 +2,19 @@
2
2
  SCRIPT_LINES__ = {}
3
3
  at_exit {
4
4
  puts "==== "
5
-
6
- backtrace_with_code = $!.backtrace.map{|bt|
5
+ if $!
6
+ backtrace_with_code = $!.backtrace.map{|bt|
7
7
  file, line, junk = bt.split(":")
8
8
  line = line.to_i - 1
9
9
  actual_file = SCRIPT_LINES__[file]
10
10
  actual_line = actual_file[line] if actual_file
11
11
  "#{bt}\n\t#{actual_line.strip if actual_line}"
12
- }
12
+ }
13
+ puts backtrace_with_code
14
+ puts "===="
15
+ else
16
+ puts "(no exception to backtrace)"
17
+ end
13
18
 
14
- puts backtrace_with_code
15
- puts "===="
19
+
16
20
  }
@@ -0,0 +1,10 @@
1
+ # this one is easy
2
+ at_exit {
3
+ if $!
4
+ puts "==== "
5
+ puts $!.backtrace.join("\n")
6
+ puts "===="
7
+ else
8
+ puts "(no exception detected)"
9
+ end
10
+ }
@@ -0,0 +1,3 @@
1
+ # this is the default
2
+ $VERBOSE = true # now it will output everything :)
3
+ require File.dirname(__FILE__) + '/core_backtracer.rb'
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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-29 00:00:00 -06:00
12
+ date: 2009-10-31 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,9 +31,10 @@ files:
31
31
  - examples/example_test_large_output
32
32
  - examples/run_all_styles_of_backtracer.rb
33
33
  - examples/run_large_style_output.rb
34
- - lib/backtrace_nothing_swallowed.rb
35
- - lib/backtrace_with_code_and_locals.rb
36
34
  - lib/backtracer.rb
35
+ - lib/backtracer_locals.rb
36
+ - lib/backtracer_simple.rb
37
+ - lib/backtracer_tracer.rb
37
38
  - lib/core_backtracer.rb
38
39
  has_rdoc: true
39
40
  homepage:
@@ -1,6 +0,0 @@
1
- # this one is easy
2
- at_exit {
3
- puts "==== "
4
- puts $!.backtrace.join("\n")
5
- puts "===="
6
- }