From ab2a1edfee2743369bdc325b5cad4cfad8bbf126 Mon Sep 17 00:00:00 2001 From: Ruby Date: Tue, 9 May 2023 02:27:32 +0900 Subject: [PATCH] support `config.rdbgInitialScripts` for future extensions. And rename: * `load_rdbgExtension` -> `load_extensions` * `config.rdbgExtension` -> `config.rdbgExtensions` --- lib/debug/server_dap.rb | 19 +++++++++++++---- test/protocol/rdbgTraceInspctor_test.rb | 28 ++++++++++++------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/debug/server_dap.rb b/lib/debug/server_dap.rb index fac6dd4bb..8dbefda8a 100644 --- a/lib/debug/server_dap.rb +++ b/lib/debug/server_dap.rb @@ -274,12 +274,23 @@ def recv_request retry end - def load_rdbgExtension req - if exts = req.dig('arguments', 'rdbgExtension') + def load_extensions req + if exts = req.dig('arguments', 'rdbgExtensions') exts.each{|ext| require_relative "dap_custom/#{File.basename(ext)}" } end + + if scripts = req.dig('arguments', 'rdbgInitialScripts') + scripts.each do |script| + begin + eval(script) + rescue Exception => e + puts e.message + puts e.backtrace.inspect + end + end + end end def process @@ -303,7 +314,7 @@ def process_request req UI_DAP.local_fs_map_set req.dig('arguments', 'localfs') || req.dig('arguments', 'localfsMap') || true @nonstop = true - load_rdbgExtension req + load_extensions req when 'attach' send_response req @@ -315,7 +326,7 @@ def process_request req @nonstop = false end - load_rdbgExtension req + load_extensions req when 'configurationDone' send_response req diff --git a/test/protocol/rdbgTraceInspctor_test.rb b/test/protocol/rdbgTraceInspctor_test.rb index 18a94b61f..f42049b63 100644 --- a/test/protocol/rdbgTraceInspctor_test.rb +++ b/test/protocol/rdbgTraceInspctor_test.rb @@ -13,7 +13,7 @@ class RdbgTraceInspectorTraceTest < ProtocolTestCase RUBY def test_defaut_setting - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_trace_enable req_add_breakpoint 5 @@ -43,11 +43,11 @@ def test_defaut_setting req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end def test_call_event - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_trace_enable(events: ['traceCall']) req_add_breakpoint 5 @@ -65,11 +65,11 @@ def test_call_event req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end def test_return_event - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_trace_enable(events: ['traceReturn']) req_add_breakpoint 5 @@ -88,11 +88,11 @@ def test_return_event req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end def test_line_event - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_trace_enable(events: ['traceLine']) req_add_breakpoint 5 @@ -109,11 +109,11 @@ def test_line_event req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end def test_restart_trace - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_trace_enable req_rdbgTraceInspector_trace_disable @@ -132,7 +132,7 @@ def test_restart_trace req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end end @@ -150,7 +150,7 @@ class RdbgTraceInspectorRecordTest < ProtocolTestCase RUBY def test_defaut_setting - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_record_enable req_add_breakpoint 5 @@ -178,11 +178,11 @@ def test_defaut_setting req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end def test_restart_trace - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtension] = ["traceInspector"] + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments][:rdbgExtensions] = ["traceInspector"] run_protocol_scenario(PROGRAM, cdp: false) do req_rdbgTraceInspector_record_enable req_rdbgTraceInspector_record_disable @@ -212,7 +212,7 @@ def test_restart_trace req_terminate_debuggee end ensure - DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtension + DEBUGGER__::INITIALIZE_DAP_MSGS[1][:arguments].delete :rdbgExtensions end end end