readapt 0.7.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +16 -14
  3. data/.rspec +2 -2
  4. data/.travis.yml +18 -13
  5. data/CHANGELOG.md +76 -53
  6. data/Gemfile +4 -4
  7. data/LICENSE.txt +21 -21
  8. data/README.md +37 -29
  9. data/Rakefile +14 -25
  10. data/bin/console +14 -14
  11. data/bin/setup +8 -8
  12. data/exe/readapt +5 -5
  13. data/ext/readapt/breakpoints.c +83 -88
  14. data/ext/readapt/breakpoints.h +11 -12
  15. data/ext/readapt/extconf.rb +0 -0
  16. data/ext/readapt/frame.c +137 -0
  17. data/ext/readapt/frame.h +17 -0
  18. data/ext/readapt/hash_table.c +211 -212
  19. data/ext/readapt/hash_table.h +30 -32
  20. data/ext/readapt/inspector.c +51 -0
  21. data/ext/readapt/inspector.h +8 -0
  22. data/ext/readapt/monitor.c +40 -27
  23. data/ext/readapt/monitor.h +0 -0
  24. data/ext/readapt/normalize.c +59 -53
  25. data/ext/readapt/normalize.h +7 -7
  26. data/ext/readapt/readapt.c +18 -16
  27. data/ext/readapt/stack.c +86 -0
  28. data/ext/readapt/stack.h +20 -0
  29. data/ext/readapt/threads.c +111 -17
  30. data/ext/readapt/threads.h +11 -4
  31. data/lib/readapt.rb +21 -19
  32. data/lib/readapt/adapter.rb +98 -138
  33. data/lib/readapt/breakpoint.rb +20 -13
  34. data/lib/readapt/data_reader.rb +62 -0
  35. data/lib/readapt/debugger.rb +220 -204
  36. data/lib/readapt/error.rb +63 -0
  37. data/lib/readapt/finder.rb +20 -20
  38. data/lib/readapt/frame.rb +40 -42
  39. data/lib/readapt/input.rb +7 -0
  40. data/lib/readapt/message.rb +62 -59
  41. data/lib/readapt/message/attach.rb +11 -11
  42. data/lib/readapt/message/base.rb +32 -32
  43. data/lib/readapt/message/configuration_done.rb +11 -11
  44. data/lib/readapt/message/continue.rb +15 -15
  45. data/lib/readapt/message/disconnect.rb +13 -14
  46. data/lib/readapt/message/evaluate.rb +18 -18
  47. data/lib/readapt/message/initialize.rb +13 -13
  48. data/lib/readapt/message/launch.rb +11 -11
  49. data/lib/readapt/message/next.rb +12 -12
  50. data/lib/readapt/message/pause.rb +11 -11
  51. data/lib/readapt/message/scopes.rb +26 -25
  52. data/lib/readapt/message/set_breakpoints.rb +25 -25
  53. data/lib/readapt/message/set_exception_breakpoints.rb +8 -8
  54. data/lib/readapt/message/stack_trace.rb +38 -26
  55. data/lib/readapt/message/step_in.rb +11 -11
  56. data/lib/readapt/message/step_out.rb +11 -11
  57. data/lib/readapt/message/threads.rb +18 -18
  58. data/lib/readapt/message/variables.rb +61 -57
  59. data/lib/readapt/monitor.rb +0 -0
  60. data/lib/readapt/output.rb +25 -0
  61. data/lib/readapt/references.rb +27 -0
  62. data/lib/readapt/server.rb +22 -0
  63. data/lib/readapt/shell.rb +104 -39
  64. data/lib/readapt/snapshot.rb +1 -13
  65. data/lib/readapt/thread.rb +23 -39
  66. data/lib/readapt/variable.rb +1 -1
  67. data/lib/readapt/version.rb +3 -3
  68. data/readapt.gemspec +39 -39
  69. metadata +19 -8
  70. data/lib/readapt/location.rb +0 -25
@@ -0,0 +1,63 @@
1
+ require 'securerandom'
2
+
3
+ module Readapt
4
+ module Error
5
+ class << self
6
+ attr_accessor :adapter
7
+ end
8
+
9
+ def opening
10
+ @buffer = ''
11
+ end
12
+
13
+ def receiving data
14
+ output = ''
15
+ data.each_char do |char|
16
+ @buffer += char
17
+ if open_message.start_with?(@buffer) || @buffer.start_with?(open_message)
18
+ if @buffer.end_with?(close_message)
19
+ msg = @buffer[open_message.length..-(close_message.length+1)]
20
+ exit if msg == '__TERMINATE__'
21
+ Error.adapter.write msg
22
+ @buffer.clear
23
+ end
24
+ else
25
+ output += @buffer
26
+ @buffer.clear
27
+ end
28
+ end
29
+ return if output.empty?
30
+ send_event('output', {
31
+ output: output,
32
+ category: 'stderr'
33
+ })
34
+ end
35
+
36
+ def send_event event, data
37
+ obj = {
38
+ type: 'event',
39
+ event: event
40
+ }
41
+ obj[:body] = data unless data.nil?
42
+ json = obj.to_json
43
+ envelope = "Content-Length: #{json.bytesize}\r\n\r\n#{json}"
44
+ Error.adapter.write envelope
45
+ end
46
+
47
+ def self.procid= pid
48
+ @@procid = pid
49
+ end
50
+
51
+ def procid
52
+ @@procid
53
+ end
54
+
55
+ def open_message
56
+ @@open_message ||= "<readapt-#{procid}>"
57
+ end
58
+
59
+ def close_message
60
+ @@close_message ||= "</readapt-#{procid}>"
61
+ end
62
+ end
63
+ end
@@ -1,20 +1,20 @@
1
- require 'pathname'
2
-
3
- module Readapt
4
- module Finder
5
- module_function
6
-
7
- def find program
8
- return program if File.exist?(program)
9
- which(program) || raise(LoadError, "#{program} is not a valid Ruby file or program")
10
- end
11
-
12
- def which program
13
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
14
- exe = File.join(path, program)
15
- return exe if File.file?(exe)
16
- end
17
- nil
18
- end
19
- end
20
- end
1
+ require 'pathname'
2
+
3
+ module Readapt
4
+ module Finder
5
+ module_function
6
+
7
+ def find program
8
+ return program if File.exist?(program)
9
+ which(program) || raise(LoadError, "#{program} is not a valid Ruby file or program")
10
+ end
11
+
12
+ def which program
13
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
14
+ exe = File.join(path, program)
15
+ return exe if File.file?(exe)
16
+ end
17
+ nil
18
+ end
19
+ end
20
+ end
@@ -1,42 +1,40 @@
1
- # frozen_string_literal: true
2
-
3
- module Readapt
4
- class Frame
5
- attr_reader :location
6
-
7
- def initialize location, binding_id
8
- @location = location
9
- @binding = ObjectSpace._id2ref(binding_id)
10
- end
11
-
12
- def evaluate code
13
- @binding.eval(code).inspect
14
- rescue Exception => e
15
- "[#{e.class}] #{e.message}"
16
- end
17
-
18
- def local_id
19
- @binding.object_id
20
- end
21
-
22
- def locals
23
- return [] if @binding.nil?
24
- result = []
25
- @binding.local_variables.each do |sym|
26
- var = @binding.local_variable_get(sym)
27
- result.push Variable.new(sym, var)
28
- end
29
- if @binding.receiver != TOPLEVEL_BINDING.receiver
30
- result.push Variable.new(:self, @binding.receiver)
31
- end
32
- result
33
- end
34
-
35
- def local sym
36
- return @binding.receiver if sym == :self
37
- @binding.local_variable_get sym
38
- end
39
-
40
- NULL_FRAME = Frame.new(nil, nil.object_id)
41
- end
42
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Readapt
4
+ # @!method file
5
+ # @return [String]
6
+ # @!method line
7
+ # @return [Integer]
8
+ # @!method binding_id
9
+ # @return [Integer]
10
+ # @!method initialize(file, line, binding_id)
11
+ class Frame
12
+ def evaluate code
13
+ frame_binding.eval(code).inspect
14
+ rescue Exception => e
15
+ "[#{e.class}] #{e.message}"
16
+ end
17
+
18
+ def local_id
19
+ frame_binding.object_id
20
+ end
21
+
22
+ def locals
23
+ return [] if frame_binding.nil?
24
+ result = []
25
+ frame_binding.local_variables.sort.each do |sym|
26
+ var = frame_binding.local_variable_get(sym)
27
+ result.push Variable.new(sym, var)
28
+ end
29
+ result.push Variable.new(:self, frame_binding.receiver)
30
+ result
31
+ end
32
+
33
+ def local sym
34
+ return frame_binding.receiver if sym == :self
35
+ frame_binding.local_variable_get sym
36
+ end
37
+
38
+ NULL_FRAME = Frame.new("", 0, nil)
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ module Readapt
2
+ module Input
3
+ def receiving data
4
+ print data
5
+ end
6
+ end
7
+ end
@@ -1,59 +1,62 @@
1
- # frozen_string_literal: true
2
-
3
- require 'readapt/message/base'
4
- require 'readapt/message/initialize'
5
- require 'readapt/message/launch'
6
- require 'readapt/message/set_breakpoints'
7
- require 'readapt/message/set_exception_breakpoints'
8
- require 'readapt/message/configuration_done'
9
- require 'readapt/message/threads'
10
- require 'readapt/message/stack_trace'
11
- require 'readapt/message/scopes'
12
- require 'readapt/message/continue'
13
- require 'readapt/message/variables'
14
- require 'readapt/message/next'
15
- require 'readapt/message/step_in'
16
- require 'readapt/message/step_out'
17
- require 'readapt/message/disconnect'
18
- require 'readapt/message/attach'
19
- require 'readapt/message/pause'
20
- require 'readapt/message/evaluate'
21
-
22
- module Readapt
23
- module Message
24
- @@messages = {}
25
- @@seq = 0
26
-
27
- def self.register name, klass
28
- @@messages[name] = klass
29
- end
30
-
31
- def self.process arguments, debugger
32
- message = @@messages[arguments['command']].new(arguments['arguments'], debugger)
33
- message.run
34
- message
35
- rescue Exception => e
36
- STDERR.puts "Skipping error: #{e.message}"
37
- STDERR.puts "Received: #{arguments}"
38
- STDERR.puts e.backtrace
39
- end
40
-
41
- register 'initialize', Message::Initialize
42
- register 'attach', Message::Attach
43
- register 'launch', Message::Launch
44
- register 'setBreakpoints', Message::SetBreakpoints
45
- register 'setExceptionBreakpoints', Message::SetExceptionBreakpoints
46
- register 'configurationDone', Message::ConfigurationDone
47
- register 'threads', Message::Threads
48
- register 'stackTrace', Message::StackTrace
49
- register 'scopes', Message::Scopes
50
- register 'continue', Message::Continue
51
- register 'variables', Message::Variables
52
- register 'next', Message::Next
53
- register 'stepIn', Message::StepIn
54
- register 'stepOut', Message::StepOut
55
- register 'disconnect', Message::Disconnect
56
- register 'pause', Message::Pause
57
- register 'evaluate', Message::Evaluate
58
- end
59
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'readapt/message/base'
4
+ require 'readapt/message/initialize'
5
+ require 'readapt/message/launch'
6
+ require 'readapt/message/set_breakpoints'
7
+ require 'readapt/message/set_exception_breakpoints'
8
+ require 'readapt/message/configuration_done'
9
+ require 'readapt/message/threads'
10
+ require 'readapt/message/stack_trace'
11
+ require 'readapt/message/scopes'
12
+ require 'readapt/message/continue'
13
+ require 'readapt/message/variables'
14
+ require 'readapt/message/next'
15
+ require 'readapt/message/step_in'
16
+ require 'readapt/message/step_out'
17
+ require 'readapt/message/disconnect'
18
+ require 'readapt/message/attach'
19
+ require 'readapt/message/pause'
20
+ require 'readapt/message/evaluate'
21
+
22
+ module Readapt
23
+ module Message
24
+ @@messages = {}
25
+ @@seq = 0
26
+
27
+ def self.register name, klass
28
+ @@messages[name] = klass
29
+ end
30
+
31
+ def self.process arguments, debugger
32
+ klass = @@messages[arguments['command']]
33
+ if klass.nil?
34
+ STDERR.puts "Debugger received unrecognized command `#{arguments['command']}`"
35
+ Message::Base.new(arguments, debugger)
36
+ else
37
+ message = klass.new(arguments['arguments'], debugger)
38
+ message.run
39
+ message
40
+ end
41
+ end
42
+
43
+ register 'initialize', Message::Initialize
44
+ register 'attach', Message::Attach
45
+ register 'launch', Message::Launch
46
+ register 'setBreakpoints', Message::SetBreakpoints
47
+ register 'setExceptionBreakpoints', Message::SetExceptionBreakpoints
48
+ register 'configurationDone', Message::ConfigurationDone
49
+ register 'threads', Message::Threads
50
+ register 'stackTrace', Message::StackTrace
51
+ register 'scopes', Message::Scopes
52
+ register 'continue', Message::Continue
53
+ register 'variables', Message::Variables
54
+ register 'next', Message::Next
55
+ register 'stepIn', Message::StepIn
56
+ register 'stepOut', Message::StepOut
57
+ register 'disconnect', Message::Disconnect
58
+ register 'pause', Message::Pause
59
+ register 'evaluate', Message::Evaluate
60
+ # register 'source', Message::Base # @todo Placeholder
61
+ end
62
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Readapt
4
- module Message
5
- class Attach < Base
6
- def run
7
- debugger.config arguments, :attach
8
- end
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Readapt
4
+ module Message
5
+ class Attach < Base
6
+ def run
7
+ debugger.config arguments, :attach
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,32 +1,32 @@
1
- # frozen_string_literal: true
2
-
3
- module Readapt
4
- module Message
5
- class Base
6
- # @return [Hash]
7
- attr_reader :arguments
8
-
9
- # @return [Debugger]
10
- attr_reader :debugger
11
-
12
- def initialize arguments, debugger
13
- @arguments = arguments
14
- @debugger = debugger
15
- end
16
-
17
- def run; end
18
-
19
- def body
20
- @body ||= {}
21
- end
22
-
23
- def set_body hash
24
- @body = hash
25
- end
26
-
27
- def self.run arguments, debugger
28
- new(arguments, debugger).run
29
- end
30
- end
31
- end
32
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Readapt
4
+ module Message
5
+ class Base
6
+ # @return [Hash]
7
+ attr_reader :arguments
8
+
9
+ # @return [Debugger]
10
+ attr_reader :debugger
11
+
12
+ def initialize arguments, debugger
13
+ @arguments = arguments
14
+ @debugger = debugger
15
+ end
16
+
17
+ def run; end
18
+
19
+ def body
20
+ @body ||= {}
21
+ end
22
+
23
+ def set_body hash
24
+ @body = hash
25
+ end
26
+
27
+ def self.run arguments, debugger
28
+ new(arguments, debugger).run
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,11 +1,11 @@
1
- # frozen_string_literal: true
2
-
3
- module Readapt
4
- module Message
5
- class ConfigurationDone < Base
6
- def run
7
- debugger.start
8
- end
9
- end
10
- end
11
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Readapt
4
+ module Message
5
+ class ConfigurationDone < Base
6
+ def run
7
+ debugger.start
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,15 +1,15 @@
1
- # frozen_string_literal: true
2
-
3
- module Readapt
4
- module Message
5
- class Continue < Base
6
- def run
7
- thread = debugger.thread(arguments['threadId'])
8
- thread.control = :continue
9
- set_body({
10
- allThreadsContinued: false
11
- })
12
- end
13
- end
14
- end
15
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Readapt
4
+ module Message
5
+ class Continue < Base
6
+ def run
7
+ thread = debugger.thread(arguments['threadId'])
8
+ thread.control = :continue
9
+ set_body({
10
+ allThreadsContinued: false
11
+ })
12
+ end
13
+ end
14
+ end
15
+ end