readapt 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 540b9c4c18bdbd634b6db72f49fa456dc306f41f139f966770795f89850a130a
4
- data.tar.gz: c0ebaf5c647ddb1c794904928902da3f8bed362562d631c25badf89acbebaef1
3
+ metadata.gz: 7be0d8ef56332ff58877c89e39b738afc657a831c753c28412f4e418b5edfbc9
4
+ data.tar.gz: cc7c1cc3bcf5e0ca5aadbc67dd03e97549ad9ef9fb047c737898ab7b9a7b1d96
5
5
  SHA512:
6
- metadata.gz: b6da35b56e5244c2f3e1071ca3899f790edbfd78291d2756f1a5b0c1ab22e746ac1e83e20ec8f899eaf6fe77a408d671f5a838c2b68fda3d4798ab10ac7b0e6a
7
- data.tar.gz: 6a97d5f44f5b866e3b68a78a804b52ed90b2114204f9db180fe3fe7fbe49ccbb3d08567ccdd4783e565acdb0278b195fdd0676d9193c0e59b8cd73d3578a74f2
6
+ metadata.gz: 5828479f0932064d54fb722763e31d0c9cf5c4edb65d24e1fb712254ff641ee2c10af0ec5b2f248b945fd2d3eecf8e08204face7ad884e6809cc0161ecaca0ac
7
+ data.tar.gz: b7aaabdcf80008587403f20e24d03c537f20e33eaf977f18b3fea60687f8fb9e12e641baefda5a0ea85a31ff63339892dd78aa44fc1ae04f2e2aedcec4dfb285
@@ -1,3 +1,7 @@
1
+ # 0.7.0 - October 12, 2019
2
+ - Conditional breakpoints
3
+ - Graceful shutdown (#2)
4
+
1
5
  # 0.6.2 - September 10, 2019
2
6
  - Monitor processes all new threads
3
7
  - Discard buggy output redirection
@@ -1,6 +1,7 @@
1
1
  require 'backport'
2
2
 
3
3
  require 'readapt/version'
4
+ require 'readapt/breakpoint'
4
5
  require 'readapt/location'
5
6
  require 'readapt/thread'
6
7
  require 'readapt/frame'
@@ -0,0 +1,13 @@
1
+ module Readapt
2
+ class Breakpoint
3
+ attr_reader :source
4
+ attr_reader :line
5
+ attr_reader :condition
6
+
7
+ def initialize source, line, condition
8
+ @source = source
9
+ @line = line
10
+ @condition = condition
11
+ end
12
+ end
13
+ end
@@ -23,6 +23,7 @@ module Readapt
23
23
  @config = {}
24
24
  @original_argv = ARGV.clone
25
25
  @machine = machine
26
+ @breakpoints = {}
26
27
  end
27
28
 
28
29
  def config arguments, request
@@ -91,6 +92,20 @@ module Readapt
91
92
  })
92
93
  end
93
94
 
95
+ def get_breakpoint source, line
96
+ @breakpoints["#{source}:#{line}"] || Breakpoint.new(source, line, nil)
97
+ end
98
+
99
+ def set_breakpoint source, line, condition
100
+ @breakpoints["#{source}:#{line}"] = Breakpoint.new(source, line, condition)
101
+ end
102
+
103
+ def clear_breakpoints source
104
+ @breakpoints.delete_if { |key, value|
105
+ value.source == source
106
+ }
107
+ end
108
+
94
109
  def disconnect
95
110
  shutdown if launched?
96
111
  @request = nil
@@ -126,6 +141,25 @@ module Readapt
126
141
  # elsif snapshot.event == :entry
127
142
  # snapshot.control = :continue
128
143
  else
144
+ if snapshot.event == :breakpoint
145
+ bp = get_breakpoint(snapshot.file, snapshot.line)
146
+ unless bp.condition.nil? || bp.condition.empty?
147
+ # @type [Binding]
148
+ bnd = ObjectSpace._id2ref(snapshot.binding_id)
149
+ begin
150
+ unless bnd.eval(bp.condition)
151
+ snapshot.control = :continue
152
+ return
153
+ end
154
+ rescue Exception => e
155
+ STDERR.puts "Breakpoint condition raised an error"
156
+ STDERR.puts "#{snapshot.file}:#{snapshot.line} - `#{bp.condition}`"
157
+ STDERR.puts "[#{e.class}] #{e.message}"
158
+ snapshot.control = :continue
159
+ return
160
+ end
161
+ end
162
+ end
129
163
  changed
130
164
  thread = self.thread(snapshot.thread_id)
131
165
  thread.control = :pause
@@ -5,16 +5,20 @@ module Readapt
5
5
  class SetBreakpoints < Base
6
6
  def run
7
7
  path = Readapt.normalize_path(arguments['source']['path'])
8
- Breakpoints.set(path, arguments['lines'])
8
+ debugger.clear_breakpoints path
9
+ lines = []
9
10
  set_body(
10
- breakpoints: arguments['lines'].map do |l|
11
+ breakpoints: arguments['breakpoints'].map do |val|
12
+ debugger.set_breakpoint path, val['line'], val['condition']
13
+ lines.push val['line']
11
14
  {
12
15
  verified: true, # @todo Verify
13
16
  source: arguments['source'],
14
- line: l
17
+ line: val['line']
15
18
  }
16
19
  end
17
20
  )
21
+ Breakpoints.set(path, lines)
18
22
  end
19
23
  end
20
24
  end
@@ -1,6 +1,4 @@
1
1
  require 'thor'
2
- require 'socket'
3
- require 'stringio'
4
2
  require 'backport'
5
3
 
6
4
  module Readapt
@@ -19,10 +17,10 @@ module Readapt
19
17
  machine = Backport::Machine.new
20
18
  machine.run do
21
19
  Signal.trap("INT") do
22
- Backport.stop
20
+ graceful_shutdown
23
21
  end
24
22
  Signal.trap("TERM") do
25
- Backport.stop
23
+ graceful_shutdown
26
24
  end
27
25
  debugger = Readapt::Debugger.new(machine)
28
26
  Readapt::Adapter.host debugger
@@ -30,5 +28,12 @@ module Readapt
30
28
  STDERR.puts "Readapt Debugger #{Readapt::VERSION} is listening HOST=#{options[:host]} PORT=#{options[:port]} PID=#{Process.pid}"
31
29
  end
32
30
  end
31
+
32
+ private
33
+
34
+ def graceful_shutdown
35
+ Backport.stop
36
+ exit
37
+ end
33
38
  end
34
39
  end
@@ -1,3 +1,3 @@
1
1
  module Readapt
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: readapt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2019-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -130,6 +130,7 @@ files:
130
130
  - ext/readapt/threads.h
131
131
  - lib/readapt.rb
132
132
  - lib/readapt/adapter.rb
133
+ - lib/readapt/breakpoint.rb
133
134
  - lib/readapt/debugger.rb
134
135
  - lib/readapt/finder.rb
135
136
  - lib/readapt/frame.rb