debug 1.7.1 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +2 -2
- data/README.md +50 -44
- data/Rakefile +8 -3
- data/debug.gemspec +3 -3
- data/ext/debug/debug.c +18 -4
- data/ext/debug/extconf.rb +1 -0
- data/ext/debug/iseq_collector.c +2 -0
- data/lib/debug/breakpoint.rb +6 -8
- data/lib/debug/client.rb +3 -2
- data/lib/debug/config.rb +35 -7
- data/lib/debug/console.rb +8 -29
- data/lib/debug/dap_custom/traceInspector.rb +336 -0
- data/lib/debug/frame_info.rb +9 -0
- data/lib/debug/irb_integration.rb +27 -0
- data/lib/debug/server.rb +9 -8
- data/lib/debug/server_cdp.rb +71 -72
- data/lib/debug/server_dap.rb +227 -179
- data/lib/debug/session.rb +105 -58
- data/lib/debug/source_repository.rb +3 -3
- data/lib/debug/thread_client.rb +51 -25
- data/lib/debug/tracer.rb +4 -5
- data/lib/debug/version.rb +1 -1
- data/misc/README.md.erb +42 -42
- metadata +12 -10
data/lib/debug/server_cdp.rb
CHANGED
@@ -59,7 +59,7 @@ module DEBUGGER__
|
|
59
59
|
ws_client.send sessionId: s_id, id: 5,
|
60
60
|
method: 'Page.navigate',
|
61
61
|
params: {
|
62
|
-
url: "devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&ws=#{addr}/#{uuid}",
|
62
|
+
url: "devtools://devtools/bundled/inspector.html?v8only=true&panel=sources&noJavaScriptCompletion=true&ws=#{addr}/#{uuid}",
|
63
63
|
frameId: f_id
|
64
64
|
}
|
65
65
|
when 101
|
@@ -98,7 +98,6 @@ module DEBUGGER__
|
|
98
98
|
candidates = ['C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe', 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe']
|
99
99
|
path = get_chrome_path candidates
|
100
100
|
end
|
101
|
-
uuid = SecureRandom.uuid
|
102
101
|
# The path is based on https://github.com/sindresorhus/open/blob/v8.4.0/index.js#L128.
|
103
102
|
stdin, stdout, stderr, wait_thr = *Open3.popen3("#{ENV['SystemRoot']}\\System32\\WindowsPowerShell\\v1.0\\powershell")
|
104
103
|
tf = Tempfile.create(['debug-', '.txt'])
|
@@ -450,11 +449,7 @@ module DEBUGGER__
|
|
450
449
|
end
|
451
450
|
|
452
451
|
def send_response req, **res
|
453
|
-
|
454
|
-
@ws_server.send id: req['id'], result: {}
|
455
|
-
else
|
456
|
-
@ws_server.send id: req['id'], result: res
|
457
|
-
end
|
452
|
+
@ws_server.send id: req['id'], result: res
|
458
453
|
end
|
459
454
|
|
460
455
|
def send_fail_response req, **res
|
@@ -462,11 +457,7 @@ module DEBUGGER__
|
|
462
457
|
end
|
463
458
|
|
464
459
|
def send_event method, **params
|
465
|
-
|
466
|
-
@ws_server.send method: method, params: {}
|
467
|
-
else
|
468
|
-
@ws_server.send method: method, params: params
|
469
|
-
end
|
460
|
+
@ws_server.send method: method, params: params
|
470
461
|
end
|
471
462
|
|
472
463
|
INVALID_REQUEST = -32600
|
@@ -483,7 +474,7 @@ module DEBUGGER__
|
|
483
474
|
when 'Debugger.getScriptSource'
|
484
475
|
@q_msg << req
|
485
476
|
when 'Debugger.enable'
|
486
|
-
send_response req
|
477
|
+
send_response req, debuggerId: rand.to_s
|
487
478
|
@q_msg << req
|
488
479
|
when 'Runtime.enable'
|
489
480
|
send_response req
|
@@ -557,6 +548,9 @@ module DEBUGGER__
|
|
557
548
|
activate_bp bps
|
558
549
|
end
|
559
550
|
send_response req
|
551
|
+
when 'Debugger.pause'
|
552
|
+
send_response req
|
553
|
+
Process.kill(UI_ServerBase::TRAP_SIGNAL, Process.pid)
|
560
554
|
|
561
555
|
# breakpoint
|
562
556
|
when 'Debugger.getPossibleBreakpoints'
|
@@ -564,35 +558,31 @@ module DEBUGGER__
|
|
564
558
|
when 'Debugger.setBreakpointByUrl'
|
565
559
|
line = req.dig('params', 'lineNumber')
|
566
560
|
if regexp = req.dig('params', 'urlRegex')
|
567
|
-
path = regexp.match(/(.*)\|/)[1].gsub("\\", "")
|
568
|
-
cond = req.dig('params', 'condition')
|
569
|
-
src = get_source_code path
|
570
|
-
end_line = src.lines.count
|
571
|
-
line = end_line if line > end_line
|
572
561
|
b_id = "1:#{line}:#{regexp}"
|
573
|
-
if cond != ''
|
574
|
-
SESSION.add_line_breakpoint(path, line + 1, cond: cond)
|
575
|
-
else
|
576
|
-
SESSION.add_line_breakpoint(path, line + 1)
|
577
|
-
end
|
578
562
|
bps[b_id] = bps.size
|
579
|
-
|
580
|
-
req
|
581
|
-
req['params']['lineNumber'] = line
|
582
|
-
req['params']['breakpointId'] = b_id
|
583
|
-
@q_msg << req
|
563
|
+
path = regexp.match(/(.*)\|/)[1].gsub("\\", "")
|
564
|
+
add_line_breakpoint(req, b_id, path)
|
584
565
|
elsif url = req.dig('params', 'url')
|
585
566
|
b_id = "#{line}:#{url}"
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
567
|
+
# When breakpoints are set in Script snippet, non-existent path such as "snippet:///Script%20snippet%20%231" sent.
|
568
|
+
# That's why we need to check it here.
|
569
|
+
if File.exist? url
|
570
|
+
bps[b_id] = bps.size
|
571
|
+
add_line_breakpoint(req, b_id, url)
|
572
|
+
else
|
573
|
+
send_response req,
|
574
|
+
breakpointId: b_id,
|
575
|
+
locations: []
|
576
|
+
end
|
594
577
|
else
|
595
|
-
|
578
|
+
if hash = req.dig('params', 'scriptHash')
|
579
|
+
b_id = "#{line}:#{hash}"
|
580
|
+
send_response req,
|
581
|
+
breakpointId: b_id,
|
582
|
+
locations: []
|
583
|
+
else
|
584
|
+
raise 'Unsupported'
|
585
|
+
end
|
596
586
|
end
|
597
587
|
when 'Debugger.removeBreakpoint'
|
598
588
|
b_id = req.dig('params', 'breakpointId')
|
@@ -631,6 +621,24 @@ module DEBUGGER__
|
|
631
621
|
@q_msg << 'continue'
|
632
622
|
end
|
633
623
|
|
624
|
+
def add_line_breakpoint req, b_id, path
|
625
|
+
cond = req.dig('params', 'condition')
|
626
|
+
line = req.dig('params', 'lineNumber')
|
627
|
+
src = get_source_code path
|
628
|
+
end_line = src.lines.count
|
629
|
+
line = end_line if line > end_line
|
630
|
+
if cond != ''
|
631
|
+
SESSION.add_line_breakpoint(path, line + 1, cond: cond)
|
632
|
+
else
|
633
|
+
SESSION.add_line_breakpoint(path, line + 1)
|
634
|
+
end
|
635
|
+
# Because we need to return scriptId, responses are returned in SESSION thread.
|
636
|
+
req['params']['scriptId'] = path
|
637
|
+
req['params']['lineNumber'] = line
|
638
|
+
req['params']['breakpointId'] = b_id
|
639
|
+
@q_msg << req
|
640
|
+
end
|
641
|
+
|
634
642
|
def del_bp bps, k
|
635
643
|
return bps unless idx = bps[k]
|
636
644
|
|
@@ -668,31 +676,20 @@ module DEBUGGER__
|
|
668
676
|
def cleanup_reader
|
669
677
|
super
|
670
678
|
Process.kill :KILL, @chrome_pid if @chrome_pid
|
679
|
+
rescue Errno::ESRCH # continue if @chrome_pid process is not found
|
671
680
|
end
|
672
681
|
|
673
682
|
## Called by the SESSION thread
|
674
683
|
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
def respond_fail req, **result
|
680
|
-
send_fail_response req, **result
|
681
|
-
end
|
682
|
-
|
683
|
-
def fire_event event, **result
|
684
|
-
if result.empty?
|
685
|
-
send_event event
|
686
|
-
else
|
687
|
-
send_event event, **result
|
688
|
-
end
|
689
|
-
end
|
684
|
+
alias respond send_response
|
685
|
+
alias respond_fail send_fail_response
|
686
|
+
alias fire_event send_event
|
690
687
|
|
691
688
|
def sock skip: false
|
692
689
|
yield $stderr
|
693
690
|
end
|
694
691
|
|
695
|
-
def puts result
|
692
|
+
def puts result=''
|
696
693
|
# STDERR.puts "puts: #{result}"
|
697
694
|
# send_event 'output', category: 'stderr', output: "PUTS!!: " + result.to_s
|
698
695
|
end
|
@@ -756,7 +753,11 @@ module DEBUGGER__
|
|
756
753
|
request_tc [:cdp, :scope, req, fid]
|
757
754
|
when 'global'
|
758
755
|
vars = safe_global_variables.sort.map do |name|
|
759
|
-
|
756
|
+
begin
|
757
|
+
gv = eval(name.to_s)
|
758
|
+
rescue Errno::ENOENT
|
759
|
+
gv = nil
|
760
|
+
end
|
760
761
|
prop = {
|
761
762
|
name: name,
|
762
763
|
value: {
|
@@ -836,7 +837,7 @@ module DEBUGGER__
|
|
836
837
|
end
|
837
838
|
end
|
838
839
|
|
839
|
-
def
|
840
|
+
def process_protocol_result args
|
840
841
|
type, req, result = args
|
841
842
|
|
842
843
|
case type
|
@@ -848,27 +849,25 @@ module DEBUGGER__
|
|
848
849
|
unless s_id = @scr_id_map[path]
|
849
850
|
s_id = (@scr_id_map.size + 1).to_s
|
850
851
|
@scr_id_map[path] = s_id
|
852
|
+
lineno = 0
|
853
|
+
src = ''
|
851
854
|
if path && File.exist?(path)
|
852
855
|
src = File.read(path)
|
856
|
+
@src_map[s_id] = src
|
857
|
+
lineno = src.lines.count
|
853
858
|
end
|
854
|
-
@
|
855
|
-
end
|
856
|
-
if src = @src_map[s_id]
|
857
|
-
lineno = src.lines.count
|
858
|
-
else
|
859
|
-
lineno = 0
|
860
|
-
end
|
861
|
-
frame[:location][:scriptId] = s_id
|
862
|
-
frame[:functionLocation][:scriptId] = s_id
|
863
|
-
@ui.fire_event 'Debugger.scriptParsed',
|
859
|
+
@ui.fire_event 'Debugger.scriptParsed',
|
864
860
|
scriptId: s_id,
|
865
|
-
url:
|
861
|
+
url: path,
|
866
862
|
startLine: 0,
|
867
863
|
startColumn: 0,
|
868
864
|
endLine: lineno,
|
869
865
|
endColumn: 0,
|
870
866
|
executionContextId: 1,
|
871
867
|
hash: src.hash.inspect
|
868
|
+
end
|
869
|
+
frame[:location][:scriptId] = s_id
|
870
|
+
frame[:functionLocation][:scriptId] = s_id
|
872
871
|
|
873
872
|
frame[:scopeChain].each {|s|
|
874
873
|
oid = s.dig(:object, :objectId)
|
@@ -1026,7 +1025,7 @@ module DEBUGGER__
|
|
1026
1025
|
result[:data] = evaluate_result exception
|
1027
1026
|
result[:reason] = 'exception'
|
1028
1027
|
end
|
1029
|
-
event! :
|
1028
|
+
event! :protocol_result, :backtrace, req, result
|
1030
1029
|
when :evaluate
|
1031
1030
|
res = {}
|
1032
1031
|
fid, expr, group = args
|
@@ -1071,7 +1070,7 @@ module DEBUGGER__
|
|
1071
1070
|
begin
|
1072
1071
|
orig_stdout = $stdout
|
1073
1072
|
$stdout = StringIO.new
|
1074
|
-
result =
|
1073
|
+
result = b.eval(expr.to_s, '(DEBUG CONSOLE)')
|
1075
1074
|
rescue Exception => e
|
1076
1075
|
result = e
|
1077
1076
|
res[:exceptionDetails] = exceptionDetails(e, 'Uncaught')
|
@@ -1087,7 +1086,7 @@ module DEBUGGER__
|
|
1087
1086
|
end
|
1088
1087
|
|
1089
1088
|
res[:result] = evaluate_result(result)
|
1090
|
-
event! :
|
1089
|
+
event! :protocol_result, :evaluate, req, message: message, response: res, output: output
|
1091
1090
|
when :scope
|
1092
1091
|
fid = args.shift
|
1093
1092
|
frame = @target_frames[fid]
|
@@ -1110,7 +1109,7 @@ module DEBUGGER__
|
|
1110
1109
|
vars.unshift variable(name, val)
|
1111
1110
|
end
|
1112
1111
|
end
|
1113
|
-
event! :
|
1112
|
+
event! :protocol_result, :scope, req, vars
|
1114
1113
|
when :properties
|
1115
1114
|
oid = args.shift
|
1116
1115
|
result = []
|
@@ -1152,14 +1151,14 @@ module DEBUGGER__
|
|
1152
1151
|
}
|
1153
1152
|
prop += [internalProperty('#class', M_CLASS.bind_call(obj))]
|
1154
1153
|
end
|
1155
|
-
event! :
|
1154
|
+
event! :protocol_result, :properties, req, result: result, internalProperties: prop
|
1156
1155
|
when :exception
|
1157
1156
|
oid = args.shift
|
1158
1157
|
exc = nil
|
1159
1158
|
if obj = @obj_map[oid]
|
1160
1159
|
exc = exceptionDetails obj, obj.to_s
|
1161
1160
|
end
|
1162
|
-
event! :
|
1161
|
+
event! :protocol_result, :exception, req, exceptionDetails: exc
|
1163
1162
|
end
|
1164
1163
|
end
|
1165
1164
|
|