readapt 0.8.0 → 1.2.0

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 +80 -60
  6. data/Gemfile +4 -4
  7. data/LICENSE.txt +21 -21
  8. data/README.md +37 -29
  9. data/Rakefile +14 -14
  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 -83
  14. data/ext/readapt/breakpoints.h +11 -11
  15. data/ext/readapt/extconf.rb +0 -0
  16. data/ext/readapt/frame.c +137 -137
  17. data/ext/readapt/frame.h +17 -17
  18. data/ext/readapt/inspector.c +51 -51
  19. data/ext/readapt/inspector.h +8 -8
  20. data/ext/readapt/{hash_table.c → lookup_table.c} +211 -211
  21. data/ext/readapt/lookup_table.h +30 -0
  22. data/ext/readapt/monitor.c +42 -5
  23. data/ext/readapt/monitor.h +0 -0
  24. data/ext/readapt/normalize.c +59 -59
  25. data/ext/readapt/normalize.h +7 -7
  26. data/ext/readapt/readapt.c +18 -18
  27. data/ext/readapt/stack.c +86 -86
  28. data/ext/readapt/stack.h +20 -20
  29. data/ext/readapt/threads.c +15 -11
  30. data/ext/readapt/threads.h +2 -2
  31. data/lib/readapt.rb +21 -18
  32. data/lib/readapt/adapter.rb +98 -138
  33. data/lib/readapt/breakpoint.rb +21 -20
  34. data/lib/readapt/data_reader.rb +62 -0
  35. data/lib/readapt/debugger.rb +220 -224
  36. data/lib/readapt/error.rb +63 -0
  37. data/lib/readapt/finder.rb +34 -20
  38. data/lib/readapt/frame.rb +40 -40
  39. data/lib/readapt/input.rb +7 -0
  40. data/lib/readapt/message.rb +62 -62
  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 -26
  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 -38
  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 -61
  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 -41
  64. data/lib/readapt/snapshot.rb +0 -0
  65. data/lib/readapt/thread.rb +25 -28
  66. data/lib/readapt/variable.rb +1 -1
  67. data/lib/readapt/version.rb +3 -3
  68. data/readapt.gemspec +39 -39
  69. metadata +15 -9
  70. data/ext/readapt/hash_table.h +0 -30
@@ -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,34 @@
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
+ # Methods to find a program in the current directory or one of the
5
+ # environment paths.
6
+ #
7
+ module Finder
8
+ module_function
9
+
10
+ # Get the program's fully qualified path. Search first in the current
11
+ # directory, then the environment paths.
12
+ #
13
+ # @raise [LoadError] if the program was not found
14
+ #
15
+ # @param program [String] The name of the program
16
+ # @return [String] The fully qualified path
17
+ def find program
18
+ return program if File.exist?(program)
19
+ which(program) || raise(LoadError, "#{program} is not a valid Ruby file or program")
20
+ end
21
+
22
+ # Search the environment paths for the given program.
23
+ #
24
+ # @param program [String] The name of the program
25
+ # @return [String] The fully qualified path, or nil if it was not found
26
+ def which program
27
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
28
+ exe = File.join(path, program)
29
+ return exe if File.file?(exe)
30
+ end
31
+ nil
32
+ end
33
+ end
34
+ end
data/lib/readapt/frame.rb CHANGED
@@ -1,40 +1,40 @@
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.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
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,62 +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
- 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
+ # 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