Skip to content

Commit 855772d

Browse files
Rubyko1
Ruby
authored andcommitted
separate process with process_request
and we can intercept each requests. See #931
1 parent e3e2a82 commit 855772d

File tree

1 file changed

+163
-159
lines changed

1 file changed

+163
-159
lines changed

lib/debug/server_dap.rb

+163-159
Original file line numberDiff line numberDiff line change
@@ -284,200 +284,204 @@ def load_rdbgExtension req
284284

285285
def process
286286
while req = recv_request
287-
raise "not a request: #{req.inspect}" unless req['type'] == 'request'
288-
args = req.dig('arguments')
287+
process_request(req)
288+
end
289+
ensure
290+
send_event :terminated unless @sock.closed?
291+
end
289292

290-
case req['command']
293+
def process_request req
294+
raise "not a request: #{req.inspect}" unless req['type'] == 'request'
295+
args = req.dig('arguments')
291296

292-
## boot/configuration
293-
when 'launch'
294-
send_response req
295-
# `launch` runs on debuggee on the same file system
296-
UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') || true
297-
@nonstop = true
297+
case req['command']
298298

299-
load_rdbgExtension req
299+
## boot/configuration
300+
when 'launch'
301+
send_response req
302+
# `launch` runs on debuggee on the same file system
303+
UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') || true
304+
@nonstop = true
300305

301-
when 'attach'
302-
send_response req
303-
UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap')
306+
load_rdbgExtension req
304307

305-
if req.dig('arguments', 'nonstop') == true
306-
@nonstop = true
307-
else
308-
@nonstop = false
309-
end
308+
when 'attach'
309+
send_response req
310+
UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap')
310311

311-
load_rdbgExtension req
312+
if req.dig('arguments', 'nonstop') == true
313+
@nonstop = true
314+
else
315+
@nonstop = false
316+
end
312317

313-
when 'configurationDone'
314-
send_response req
318+
load_rdbgExtension req
315319

316-
if @nonstop
317-
@q_msg << 'continue'
318-
else
319-
if SESSION.in_subsession?
320-
send_event 'stopped', reason: 'pause',
321-
threadId: 1, # maybe ...
322-
allThreadsStopped: true
323-
end
324-
end
320+
when 'configurationDone'
321+
send_response req
325322

326-
when 'setBreakpoints'
327-
req_path = args.dig('source', 'path')
328-
path = UI_DAP.local_to_remote_path(req_path)
329-
if path
330-
SESSION.clear_line_breakpoints path
331-
332-
bps = []
333-
args['breakpoints'].each{|bp|
334-
line = bp['line']
335-
if cond = bp['condition']
336-
bps << SESSION.add_line_breakpoint(path, line, cond: cond)
337-
else
338-
bps << SESSION.add_line_breakpoint(path, line)
339-
end
340-
}
341-
send_response req, breakpoints: (bps.map do |bp| {verified: true,} end)
342-
else
343-
send_response req, success: false, message: "#{req_path} is not available"
323+
if @nonstop
324+
@q_msg << 'continue'
325+
else
326+
if SESSION.in_subsession?
327+
send_event 'stopped', reason: 'pause',
328+
threadId: 1, # maybe ...
329+
allThreadsStopped: true
344330
end
331+
end
345332

346-
when 'setFunctionBreakpoints'
347-
send_response req
333+
when 'setBreakpoints'
334+
req_path = args.dig('source', 'path')
335+
path = UI_DAP.local_to_remote_path(req_path)
336+
if path
337+
SESSION.clear_line_breakpoints path
338+
339+
bps = []
340+
args['breakpoints'].each{|bp|
341+
line = bp['line']
342+
if cond = bp['condition']
343+
bps << SESSION.add_line_breakpoint(path, line, cond: cond)
344+
else
345+
bps << SESSION.add_line_breakpoint(path, line)
346+
end
347+
}
348+
send_response req, breakpoints: (bps.map do |bp| {verified: true,} end)
349+
else
350+
send_response req, success: false, message: "#{req_path} is not available"
351+
end
348352

349-
when 'setExceptionBreakpoints'
350-
process_filter = ->(filter_id, cond = nil) {
351-
bp =
352-
case filter_id
353-
when 'any'
354-
SESSION.add_catch_breakpoint 'Exception', cond: cond
355-
when 'RuntimeError'
356-
SESSION.add_catch_breakpoint 'RuntimeError', cond: cond
357-
else
358-
nil
359-
end
360-
{
361-
verified: !bp.nil?,
362-
message: bp.inspect,
363-
}
353+
when 'setFunctionBreakpoints'
354+
send_response req
355+
356+
when 'setExceptionBreakpoints'
357+
process_filter = ->(filter_id, cond = nil) {
358+
bp =
359+
case filter_id
360+
when 'any'
361+
SESSION.add_catch_breakpoint 'Exception', cond: cond
362+
when 'RuntimeError'
363+
SESSION.add_catch_breakpoint 'RuntimeError', cond: cond
364+
else
365+
nil
366+
end
367+
{
368+
verified: !bp.nil?,
369+
message: bp.inspect,
364370
}
371+
}
365372

366-
SESSION.clear_catch_breakpoints 'Exception', 'RuntimeError'
367-
368-
filters = args.fetch('filters').map {|filter_id|
369-
process_filter.call(filter_id)
370-
}
373+
SESSION.clear_catch_breakpoints 'Exception', 'RuntimeError'
371374

372-
filters += args.fetch('filterOptions', {}).map{|bp_info|
373-
process_filter.call(bp_info['filterId'], bp_info['condition'])
375+
filters = args.fetch('filters').map {|filter_id|
376+
process_filter.call(filter_id)
374377
}
375378

376-
send_response req, breakpoints: filters
379+
filters += args.fetch('filterOptions', {}).map{|bp_info|
380+
process_filter.call(bp_info['filterId'], bp_info['condition'])
381+
}
377382

378-
when 'disconnect'
379-
terminate = args.fetch("terminateDebuggee", false)
383+
send_response req, breakpoints: filters
380384

381-
SESSION.clear_all_breakpoints
382-
send_response req
385+
when 'disconnect'
386+
terminate = args.fetch("terminateDebuggee", false)
383387

384-
if SESSION.in_subsession?
385-
if terminate
386-
@q_msg << 'kill!'
387-
else
388-
@q_msg << 'continue'
389-
end
390-
else
391-
if terminate
392-
@q_msg << 'kill!'
393-
pause
394-
end
395-
end
388+
SESSION.clear_all_breakpoints
389+
send_response req
396390

397-
## control
398-
when 'continue'
399-
@q_msg << 'c'
400-
send_response req, allThreadsContinued: true
401-
when 'next'
402-
begin
403-
@session.check_postmortem
404-
@q_msg << 'n'
405-
send_response req
406-
rescue PostmortemError
407-
send_response req,
408-
success: false, message: 'postmortem mode',
409-
result: "'Next' is not supported while postmortem mode"
410-
end
411-
when 'stepIn'
412-
begin
413-
@session.check_postmortem
414-
@q_msg << 's'
415-
send_response req
416-
rescue PostmortemError
417-
send_response req,
418-
success: false, message: 'postmortem mode',
419-
result: "'stepIn' is not supported while postmortem mode"
391+
if SESSION.in_subsession?
392+
if terminate
393+
@q_msg << 'kill!'
394+
else
395+
@q_msg << 'continue'
420396
end
421-
when 'stepOut'
422-
begin
423-
@session.check_postmortem
424-
@q_msg << 'fin'
425-
send_response req
426-
rescue PostmortemError
427-
send_response req,
428-
success: false, message: 'postmortem mode',
429-
result: "'stepOut' is not supported while postmortem mode"
397+
else
398+
if terminate
399+
@q_msg << 'kill!'
400+
pause
430401
end
431-
when 'terminate'
402+
end
403+
404+
## control
405+
when 'continue'
406+
@q_msg << 'c'
407+
send_response req, allThreadsContinued: true
408+
when 'next'
409+
begin
410+
@session.check_postmortem
411+
@q_msg << 'n'
432412
send_response req
433-
exit
434-
when 'pause'
413+
rescue PostmortemError
414+
send_response req,
415+
success: false, message: 'postmortem mode',
416+
result: "'Next' is not supported while postmortem mode"
417+
end
418+
when 'stepIn'
419+
begin
420+
@session.check_postmortem
421+
@q_msg << 's'
435422
send_response req
436-
Process.kill(UI_ServerBase::TRAP_SIGNAL, Process.pid)
437-
when 'reverseContinue'
423+
rescue PostmortemError
438424
send_response req,
439-
success: false, message: 'cancelled',
440-
result: "Reverse Continue is not supported. Only \"Step back\" is supported."
441-
when 'stepBack'
442-
@q_msg << req
425+
success: false, message: 'postmortem mode',
426+
result: "'stepIn' is not supported while postmortem mode"
427+
end
428+
when 'stepOut'
429+
begin
430+
@session.check_postmortem
431+
@q_msg << 'fin'
432+
send_response req
433+
rescue PostmortemError
434+
send_response req,
435+
success: false, message: 'postmortem mode',
436+
result: "'stepOut' is not supported while postmortem mode"
437+
end
438+
when 'terminate'
439+
send_response req
440+
exit
441+
when 'pause'
442+
send_response req
443+
Process.kill(UI_ServerBase::TRAP_SIGNAL, Process.pid)
444+
when 'reverseContinue'
445+
send_response req,
446+
success: false, message: 'cancelled',
447+
result: "Reverse Continue is not supported. Only \"Step back\" is supported."
448+
when 'stepBack'
449+
@q_msg << req
443450

444-
## query
445-
when 'threads'
446-
send_response req, threads: SESSION.managed_thread_clients.map{|tc|
447-
{ id: tc.id,
448-
name: tc.name,
449-
}
451+
## query
452+
when 'threads'
453+
send_response req, threads: SESSION.managed_thread_clients.map{|tc|
454+
{ id: tc.id,
455+
name: tc.name,
450456
}
457+
}
451458

452-
when 'evaluate'
453-
expr = req.dig('arguments', 'expression')
454-
if /\A\s*,(.+)\z/ =~ expr
455-
dbg_expr = $1.strip
456-
dbg_expr.split(';;') { |cmd| @q_msg << cmd }
459+
when 'evaluate'
460+
expr = req.dig('arguments', 'expression')
461+
if /\A\s*,(.+)\z/ =~ expr
462+
dbg_expr = $1.strip
463+
dbg_expr.split(';;') { |cmd| @q_msg << cmd }
457464

458-
send_response req,
459-
result: "(rdbg:command) #{dbg_expr}",
460-
variablesReference: 0
461-
else
462-
@q_msg << req
463-
end
464-
when 'stackTrace',
465-
'scopes',
466-
'variables',
467-
'source',
468-
'completions'
465+
send_response req,
466+
result: "(rdbg:command) #{dbg_expr}",
467+
variablesReference: 0
468+
else
469469
@q_msg << req
470+
end
471+
when 'stackTrace',
472+
'scopes',
473+
'variables',
474+
'source',
475+
'completions'
476+
@q_msg << req
470477

478+
else
479+
if respond_to? mid = "custom_dap_request_#{req['command']}"
480+
__send__ mid, req
471481
else
472-
if respond_to? mid = "custom_dap_request_#{req['command']}"
473-
__send__ mid, req
474-
else
475-
raise "Unknown request: #{req.inspect}"
476-
end
482+
raise "Unknown request: #{req.inspect}"
477483
end
478484
end
479-
ensure
480-
send_event :terminated unless @sock.closed?
481485
end
482486

483487
## called by the SESSION thread

0 commit comments

Comments
 (0)