backtracer 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/backtracer.rb +26 -16
- data/lib/core_backtracer.rb +1 -27
- data/lib/shared.rb +35 -0
- data/lib/tracerr.rb +5 -5
- metadata +3 -2
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ begin
|
|
7
7
|
# gemspec.homepage = "http://github.com/technicalpickles/the-perfect-gem"
|
8
8
|
# gemspec.description = "TODO"
|
9
9
|
# gemspec.authors = ["Josh Nichols"]
|
10
|
-
|
10
|
+
gemspec.dependency 'sane'
|
11
11
|
end
|
12
12
|
rescue LoadError
|
13
13
|
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/backtracer.rb
CHANGED
@@ -1,20 +1,30 @@
|
|
1
1
|
# this one display full BT with code, at the end [no performance loss]
|
2
|
-
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + "/shared"
|
4
|
+
require 'sane'
|
5
|
+
|
3
6
|
at_exit {
|
4
|
-
puts "==== "
|
5
|
-
if $!
|
6
|
-
backtrace_with_code = $!.backtrace.map{|bt|
|
7
|
-
file, line, junk = bt.split(":")
|
8
|
-
line = line.to_i - 1
|
9
|
-
actual_file = SCRIPT_LINES__[file]
|
10
|
-
actual_line = actual_file[line] if actual_file
|
11
|
-
"#{bt}\n\t#{actual_line.strip if actual_line}"
|
12
|
-
}
|
13
|
-
puts backtrace_with_code
|
14
|
-
puts "===="
|
15
|
-
else
|
16
|
-
puts "(no exception to backtrace)"
|
17
|
-
end
|
18
|
-
|
19
7
|
|
8
|
+
if $!
|
9
|
+
puts "==== "
|
10
|
+
bt2 = $!.backtrace
|
11
|
+
backtrace_with_code = $!.backtrace.map{ |bt_line|
|
12
|
+
if OS.windows? && bt_line[1..1] == ':'
|
13
|
+
#["C", "/dev/ruby/allgems/lib/allgems/GemWorker.rb", "91", "in `unpack'"]
|
14
|
+
drive, file, line, junk = bt_line.split(":")
|
15
|
+
file = drive + ":" + file
|
16
|
+
else
|
17
|
+
file, line, junk = bt_line.split(":")
|
18
|
+
end
|
19
|
+
line = line.to_i
|
20
|
+
# line -= 1 unless line == 0 # not sure if needed
|
21
|
+
actual_line = Tracer.get_line(file, line)
|
22
|
+
"#{bt_line}\n\t#{actual_line.strip if actual_line}"
|
23
|
+
}
|
24
|
+
puts backtrace_with_code
|
25
|
+
puts "===="
|
26
|
+
else
|
27
|
+
puts "(no exception found to backtrace)"
|
28
|
+
end
|
29
|
+
exit!
|
20
30
|
}
|
data/lib/core_backtracer.rb
CHANGED
@@ -12,6 +12,7 @@ Debugger.start # we use this to track args.
|
|
12
12
|
#
|
13
13
|
# tracer main class
|
14
14
|
#
|
15
|
+
require File.dirname(__FILE__) + "/shared"
|
15
16
|
class Tracer
|
16
17
|
@RCS_ID='-$Id: tracer.rb,v 1.8 1998/05/19 03:42:49 keiju Exp keiju $-'
|
17
18
|
|
@@ -82,33 +83,6 @@ class Tracer
|
|
82
83
|
self.class.get_line(file, line)
|
83
84
|
end
|
84
85
|
|
85
|
-
def self.get_line(file, line)
|
86
|
-
@get_line_procs ||= {}
|
87
|
-
if p = @get_line_procs[file]
|
88
|
-
return p.call(line)
|
89
|
-
end
|
90
|
-
|
91
|
-
unless list = SCRIPT_LINES__[file]
|
92
|
-
begin
|
93
|
-
raise 'might be a .so file' if file =~ /\.so$/
|
94
|
-
f = open(file)
|
95
|
-
begin
|
96
|
-
SCRIPT_LINES__[file] = list = f.readlines
|
97
|
-
ensure
|
98
|
-
f.close
|
99
|
-
end
|
100
|
-
|
101
|
-
rescue
|
102
|
-
SCRIPT_LINES__[file] = list = []
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
if l = list[line - 1]
|
107
|
-
l
|
108
|
-
else
|
109
|
-
"-\n"
|
110
|
-
end
|
111
|
-
end
|
112
86
|
|
113
87
|
def get_thread_no
|
114
88
|
if no = @threads[Thread.current.object_id]
|
data/lib/shared.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# tracer shared for the get_line aspect
|
2
|
+
#
|
3
|
+
class Tracer
|
4
|
+
|
5
|
+
def self.get_line(file, line)
|
6
|
+
@get_line_procs ||= {}
|
7
|
+
if p = @get_line_procs[file]
|
8
|
+
return p.call(line)
|
9
|
+
end
|
10
|
+
|
11
|
+
unless list = SCRIPT_LINES__[file]
|
12
|
+
begin
|
13
|
+
raise 'might be a .so file' if file =~ /\.so$/
|
14
|
+
f = open(file)
|
15
|
+
begin
|
16
|
+
SCRIPT_LINES__[file] = list = f.readlines
|
17
|
+
ensure
|
18
|
+
f.close
|
19
|
+
end
|
20
|
+
|
21
|
+
rescue
|
22
|
+
SCRIPT_LINES__[file] = list = []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if l = list[line - 1]
|
27
|
+
l
|
28
|
+
else
|
29
|
+
"-\n"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
|
data/lib/tracerr.rb
CHANGED
@@ -119,8 +119,8 @@ class Tracer
|
|
119
119
|
return unless p.call event, file, line, id, binding, klass
|
120
120
|
end
|
121
121
|
|
122
|
-
saved_crit = Thread.critical
|
123
|
-
Thread.critical = true
|
122
|
+
(saved_crit = Thread.critical) rescue nil
|
123
|
+
(Thread.critical = true) rescue nil
|
124
124
|
stdout.printf("#%d:%s:%d:%s:%s: %s",
|
125
125
|
get_thread_no,
|
126
126
|
file,
|
@@ -128,7 +128,7 @@ class Tracer
|
|
128
128
|
klass || '',
|
129
129
|
EVENT_SYMBOL[event],
|
130
130
|
get_line(file, line))
|
131
|
-
Thread.critical = saved_crit
|
131
|
+
(Thread.critical = saved_crit) rescue nil
|
132
132
|
end
|
133
133
|
|
134
134
|
Single = new
|
@@ -155,7 +155,7 @@ class Tracer
|
|
155
155
|
end
|
156
156
|
|
157
157
|
SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
|
158
|
-
|
158
|
+
puts caller(0).size
|
159
159
|
if $0 == __FILE__
|
160
160
|
# direct call
|
161
161
|
|
@@ -163,6 +163,6 @@ if $0 == __FILE__
|
|
163
163
|
ARGV.shift
|
164
164
|
Tracer.on
|
165
165
|
require $0
|
166
|
-
elsif caller(0).size
|
166
|
+
elsif caller(0).size <= 2
|
167
167
|
Tracer.on
|
168
168
|
end
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors: []
|
7
7
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/backtracer_tracer.rb
|
38
38
|
- lib/backtracer_tracer_args.rb
|
39
39
|
- lib/core_backtracer.rb
|
40
|
+
- lib/shared.rb
|
40
41
|
- lib/tracerr.rb
|
41
42
|
has_rdoc: true
|
42
43
|
homepage:
|
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
requirements: []
|
63
64
|
|
64
65
|
rubyforge_project:
|
65
|
-
rubygems_version: 1.3.
|
66
|
+
rubygems_version: 1.3.5
|
66
67
|
signing_key:
|
67
68
|
specification_version: 3
|
68
69
|
summary: Quality backtraces for ruby
|