dexc 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/BSDL +1 -1
- data/COPYING +1 -1
- data/dexc.gemspec +2 -0
- data/lib/dexc.rb +58 -78
- data/lib/dexc/irb/cmd/stack_explorer.rb +41 -0
- data/lib/dexc/version.rb +1 -1
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d0a30f2b433ef0df84fb07b87731dd3b3c6cd63fa7d972f09915b53c3a0b9179
|
4
|
+
data.tar.gz: 52cfcbf75dd76eedee0748e831be63cbfe9cf07a404feea207346fe0772b4abe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4f4ed54edde6d05892ec6957faa2d44e0d4f3746d140b37082ea18efbc2a3d0a71d7d561ed9aa692249bc2830405f10a081e6d0401af44aec57937aadaaa265
|
7
|
+
data.tar.gz: 5781ce31f628d3d1a6d6bb7f66c902dd8f82e5b96b34656d27fcbf9ad6c439e5b6fedd95444405937d9a189e0a6427744bb1c873cfd012ea30a70bc86c436939
|
data/BSDL
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C) 2013
|
1
|
+
Copyright (C) 2013 Kazuki Tsujimoto, All rights reserved.
|
2
2
|
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved. (lib/irb.rb)
|
3
3
|
|
4
4
|
Redistribution and use in source and binary forms, with or without
|
data/COPYING
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C) 2013
|
1
|
+
Copyright (C) 2013 Kazuki Tsujimoto, All rights reserved.
|
2
2
|
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved. (lib/irb.rb)
|
3
3
|
|
4
4
|
You can redistribute it and/or modify it under either the terms of the
|
data/dexc.gemspec
CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
15
|
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f) }
|
16
16
|
s.require_paths = ['lib']
|
17
|
+
s.add_runtime_dependency 'irb'
|
18
|
+
s.add_runtime_dependency 'binding_of_caller'
|
17
19
|
s.add_development_dependency 'rake'
|
18
20
|
s.add_development_dependency 'test-unit'
|
19
21
|
s.extra_rdoc_files = ['README.rdoc']
|
data/lib/dexc.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
# dexc.rb
|
2
2
|
#
|
3
|
-
# Copyright (C) 2013
|
3
|
+
# Copyright (C) 2013 Kazuki Tsujimoto, All rights reserved.
|
4
4
|
|
5
5
|
raise LoadError, "TracePoint is undefined. Use Ruby 2.0.0 or later." unless defined? TracePoint
|
6
6
|
|
7
7
|
require 'dexc/version'
|
8
|
+
require 'irb/color'
|
9
|
+
require 'irb/color_printer'
|
10
|
+
require 'binding_of_caller'
|
8
11
|
|
9
12
|
module Dexc
|
10
|
-
|
13
|
+
EXC_CALLERS_VAR = :@dexc_callers
|
11
14
|
|
12
15
|
class RingBuffer
|
13
16
|
def initialize(n)
|
@@ -29,42 +32,44 @@ module Dexc
|
|
29
32
|
RaiseEvent = Struct.new(:event, :raised_exception)
|
30
33
|
ReturnEvent = Struct.new(:event, :lineno, :path, :defined_class, :method_id, :return_value)
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
module IrbHelper
|
36
|
+
def dexc_print_frame
|
37
|
+
@dexc_callers.each_with_index do |i, idx|
|
38
|
+
if @dexc_callers_idx == idx
|
39
|
+
print ' => '
|
40
|
+
else
|
41
|
+
print ' '
|
42
|
+
end
|
43
|
+
print("[%#{@dexc_callers_width}d] " % idx)
|
44
|
+
filename, lineno = i.source_location
|
45
|
+
puts "#{filename}:#{lineno}:in `#{i.frame_description}'"
|
46
|
+
end
|
47
|
+
end
|
37
48
|
|
38
|
-
def
|
39
|
-
|
40
|
-
@wrapped_exception = wrapped_exception
|
49
|
+
def dexc_current_frame
|
50
|
+
@dexc_callers[@dexc_callers_idx]
|
41
51
|
end
|
42
|
-
end
|
43
52
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
53
|
+
def dexc_up_frame
|
54
|
+
if @dexc_callers_idx < @dexc_callers.length - 1
|
55
|
+
@dexc_callers_idx += 1
|
56
|
+
end
|
57
|
+
dexc_current_frame
|
49
58
|
end
|
50
|
-
end
|
51
59
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
prepend TestPassThroughException
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
60
|
+
def dexc_down_frame
|
61
|
+
if @dexc_callers_idx > 0
|
62
|
+
@dexc_callers_idx -= 1
|
63
|
+
end
|
64
|
+
dexc_current_frame
|
65
|
+
end
|
66
|
+
|
67
|
+
def dexc_change_frame(idx)
|
68
|
+
if (0...@dexc_callers.length) === idx
|
69
|
+
@dexc_callers_idx = idx
|
66
70
|
end
|
67
|
-
|
71
|
+
dexc_current_frame
|
72
|
+
end
|
68
73
|
end
|
69
74
|
|
70
75
|
def start
|
@@ -73,7 +78,7 @@ module Dexc
|
|
73
78
|
tp = TracePoint.new(:raise, :return, :c_return, :b_return) do |tp|
|
74
79
|
if tp.event == :raise
|
75
80
|
exc = tp.raised_exception
|
76
|
-
exc.instance_variable_set(
|
81
|
+
exc.instance_variable_set(EXC_CALLERS_VAR, tp.binding.callers[1..-1])
|
77
82
|
events.add(RaiseEvent.new(tp.event, exc))
|
78
83
|
else
|
79
84
|
events.add(ReturnEvent.new(tp.event, tp.lineno, tp.path, tp.defined_class, tp.method_id, tp.return_value))
|
@@ -82,19 +87,16 @@ module Dexc
|
|
82
87
|
|
83
88
|
at_exit do
|
84
89
|
exc = $!
|
85
|
-
if exc.kind_of?(ExceptionWrapper)
|
86
|
-
exc = exc.wrapped_exception
|
87
|
-
end
|
88
90
|
tp.disable
|
89
|
-
|
90
|
-
if exc.kind_of?(StandardError) and
|
91
|
+
callers = exc.instance_variable_get(EXC_CALLERS_VAR)
|
92
|
+
if exc.kind_of?(StandardError) and callers
|
91
93
|
raise_idx = events.to_a.find_index {|i| i.event == :raise and i.raised_exception == exc }
|
92
94
|
latest_events = raise_idx ? events.to_a[0...raise_idx] : []
|
93
95
|
return_events = latest_events.find_all {|i| i.event != :raise }
|
94
96
|
return_values = return_events.map(&:return_value)
|
95
97
|
|
96
98
|
show_trace(return_events)
|
97
|
-
|
99
|
+
puts exc.full_message
|
98
100
|
|
99
101
|
Kernel.module_eval do
|
100
102
|
define_method(:dexc_hist) do
|
@@ -109,18 +111,24 @@ module Dexc
|
|
109
111
|
pry.last_exception = exc
|
110
112
|
pry.backtrace = (exc.backtrace || [])
|
111
113
|
end
|
112
|
-
|
114
|
+
callers[0].pry
|
113
115
|
rescue LoadError
|
114
116
|
require 'irb'
|
115
|
-
IRB::
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
117
|
+
IRB::Context.include(IrbHelper)
|
118
|
+
require 'dexc/irb/cmd/stack_explorer'
|
119
|
+
b = callers[0]
|
120
|
+
filename = b.source_location[0]
|
121
|
+
IRB.setup(filename, argv: [])
|
122
|
+
workspace = IRB::WorkSpace.new(b)
|
123
|
+
STDOUT.print(workspace.code_around_binding)
|
124
|
+
binding_irb = IRB::Irb.new(workspace)
|
125
|
+
binding_irb.context.irb_path = File.expand_path(filename)
|
126
|
+
binding_irb.context.instance_eval do
|
127
|
+
@dexc_callers = callers
|
128
|
+
@dexc_callers_width = Math.log10(callers.length).floor + 1
|
129
|
+
@dexc_callers_idx = 0
|
122
130
|
end
|
123
|
-
IRB.
|
131
|
+
binding_irb.run(IRB.conf)
|
124
132
|
end
|
125
133
|
exit!
|
126
134
|
end
|
@@ -135,7 +143,7 @@ module Dexc
|
|
135
143
|
file_cache = {}
|
136
144
|
events.each_with_index do |i, idx|
|
137
145
|
show_line(i.path, i.lineno, idx, idx_width, file_cache)
|
138
|
-
puts " " * (idx_width + 1) + "#{i.defined_class}##{i.method_id}#{i.event == :b_return ? '(block)' : ''}: #{i.return_value.inspect}"
|
146
|
+
puts " " * (idx_width + 1) + "#{i.defined_class}##{i.method_id}#{i.event == :b_return ? '(block)' : ''}: #{IRB::ColorPrinter.pp(i.return_value.inspect, '')}"
|
139
147
|
end
|
140
148
|
puts
|
141
149
|
end
|
@@ -145,41 +153,13 @@ module Dexc
|
|
145
153
|
print "#{"%#{index_width}d" % index}:#{path}:#{lineno}"
|
146
154
|
begin
|
147
155
|
cache[path] ||= open(path).each_line.map(&:chomp)
|
148
|
-
print "> #{lineno > 0 ? cache[path][lineno - 1] : ''}"
|
156
|
+
print "> #{lineno > 0 ? ::IRB::Color.colorize_code(cache[path][lineno - 1], complete: false, ignore_error: true) : ''}"
|
149
157
|
rescue Errno::ENOENT
|
150
158
|
cache[path] = []
|
151
159
|
end
|
152
160
|
puts
|
153
161
|
end
|
154
162
|
module_function :show_line
|
155
|
-
|
156
|
-
# from Irb#eval_input(lib/irb.rb)
|
157
|
-
def error_print(exc)
|
158
|
-
print exc.class, ": ", exc, "\n"
|
159
|
-
messages = []
|
160
|
-
lasts = []
|
161
|
-
levels = 0
|
162
|
-
back_trace_limit = 30
|
163
|
-
for m in exc.backtrace
|
164
|
-
if m
|
165
|
-
if messages.size < back_trace_limit
|
166
|
-
messages.push "\tfrom "+m
|
167
|
-
else
|
168
|
-
lasts.push "\tfrom "+m
|
169
|
-
if lasts.size > back_trace_limit
|
170
|
-
lasts.shift
|
171
|
-
levels += 1
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
print messages.join("\n"), "\n"
|
177
|
-
unless lasts.empty?
|
178
|
-
printf "... %d levels...\n", levels if levels > 0
|
179
|
-
print lasts.join("\n")
|
180
|
-
end
|
181
|
-
end
|
182
|
-
module_function :error_print
|
183
163
|
end
|
184
164
|
|
185
165
|
Dexc.start
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "irb"
|
2
|
+
require "irb/cmd/nop"
|
3
|
+
require "irb/cmd/chws"
|
4
|
+
|
5
|
+
module IRB
|
6
|
+
module ExtendCommand
|
7
|
+
|
8
|
+
class DexcFrame < Nop
|
9
|
+
def execute(idx = nil)
|
10
|
+
if idx
|
11
|
+
irb_context.dexc_change_frame(idx)
|
12
|
+
STDOUT.print(irb_context.workspace.code_around_binding)
|
13
|
+
end
|
14
|
+
irb_context.dexc_print_frame
|
15
|
+
irb_context.main
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class DexcUp < Nop
|
20
|
+
def execute(*)
|
21
|
+
irb_context.change_workspace(irb_context.dexc_up_frame)
|
22
|
+
STDOUT.print(irb_context.workspace.code_around_binding)
|
23
|
+
irb_context.dexc_print_frame
|
24
|
+
irb_context.main
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class DexcDown < Nop
|
29
|
+
def execute(*)
|
30
|
+
irb_context.change_workspace(irb_context.dexc_down_frame)
|
31
|
+
STDOUT.print(irb_context.workspace.code_around_binding)
|
32
|
+
irb_context.dexc_print_frame
|
33
|
+
irb_context.main
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
IRB::ExtendCommandBundle.def_extend_command(:irb_frame, :DexcFrame, "dexc/irb/cmd/stack_explorer", [:frame, IRB::ExtendCommandBundle::OVERRIDE_ALL])
|
40
|
+
IRB::ExtendCommandBundle.def_extend_command(:irb_up, :DexcUp, "dexc/irb/cmd/stack_explorer", [:up, IRB::ExtendCommandBundle::OVERRIDE_ALL])
|
41
|
+
IRB::ExtendCommandBundle.def_extend_command(:irb_down, :DexcDown, "dexc/irb/cmd/stack_explorer", [:down, IRB::ExtendCommandBundle::OVERRIDE_ALL])
|
data/lib/dexc/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dexc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuki Tsujimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: irb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: binding_of_caller
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rake
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -54,6 +82,7 @@ files:
|
|
54
82
|
- Rakefile
|
55
83
|
- dexc.gemspec
|
56
84
|
- lib/dexc.rb
|
85
|
+
- lib/dexc/irb/cmd/stack_explorer.rb
|
57
86
|
- lib/dexc/version.rb
|
58
87
|
- test/test_dexc.rb
|
59
88
|
homepage: https://github.com/k-tsj/dexc
|
@@ -76,8 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
105
|
- !ruby/object:Gem::Version
|
77
106
|
version: '0'
|
78
107
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.5.1
|
108
|
+
rubygems_version: 3.3.0.dev
|
81
109
|
signing_key:
|
82
110
|
specification_version: 4
|
83
111
|
summary: A library that helps you to debug an exception
|