From 72f646059b55328f50828d0cd8cc464956d7f1e4 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 14 Mar 2025 16:18:09 +0000 Subject: [PATCH 1/4] Support breakpoints in cppia scripts In cppia, script files are not known initially so breakpoints will fail to be set properly. With this patch, the debug server now assigns its own breakpoint id for failed breakpoints and attempts to readd them whenever a new cppia script is loaded. --- .../hxcpp/debug/jsonrpc/Server.hx | 101 ++++++++++++++++-- 1 file changed, 93 insertions(+), 8 deletions(-) diff --git a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx index 193e77b..2a222e0 100644 --- a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx +++ b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx @@ -27,6 +27,9 @@ typedef BreakpointInfo = { var line:Int; @:optional var column:Int; @:optional var condition:Expr; + #if scriptable + @:optional var internalId:Int; + #end } private class References { @@ -66,6 +69,12 @@ class Server { var scopes:Map>; var threads:Map; var breakpoints:Map>; + #if scriptable + var missedBreakpoints:Map>; + var nextMappedBreakpointId:Int; + // map of hxcpp internal ids to ids used by client + var mappedBreakpointIds:Map; + #end var references:References; var started:Bool; var path2file:Map; @@ -100,6 +109,48 @@ class Server { isWindows = Sys.systemName() == "Windows"; Debugger.enableCurrentThreadDebugging(false); + + #if scriptable + nextMappedBreakpointId = -2; + mappedBreakpointIds = new Map(); + missedBreakpoints = new Map>(); + + #if (hxcpp_api_level >= 500) + Debugger.setOnScriptLoadedFunction(function() { + generateFilePathMaps(); + + for (file in missedBreakpoints.keys()) { + if (!path2file.exists(file)) { + // file is still not found + continue; + } + + var added = []; + + for (rm in breakpoints[file]) { + #if scriptable + if (mappedBreakpointIds.exists(rm.id)) + Debugger.deleteBreakpoint(mappedBreakpointIds[rm.id]); + else + #end + Debugger.deleteBreakpoint(rm.id); + } + + for (bInfo in missedBreakpoints[file]) { + var id = Debugger.addFileLineBreakpoint(path2file[file], bInfo.line); + bInfo.internalId = id; + mappedBreakpointIds[id] = bInfo.id; + } + + breakpoints[file] = added; + missedBreakpoints.remove(file); + } + }); + #else + log("Please use Haxe 5 to debug with CPPIA"); + #end + #end + if (connect()) { Thread.create(debuggerThreadMain); startQueue.pop(true); @@ -183,11 +234,7 @@ class Server { stateMutex.release(); } - private function debuggerThreadMain() { - Debugger.setEventNotificationHandler(handleThreadEvent); - Debugger.enableCurrentThreadDebugging(false); - Debugger.breakNow(true); - + private function generateFilePathMaps() { var fullPathes = Debugger.getFilesFullPath(); var files = Debugger.getFiles(); for (i in 0...files.length) { @@ -196,6 +243,14 @@ class Server { path2file[path2Key(path)] = file; file2path[path2Key(file)] = path; } + } + + private function debuggerThreadMain() { + Debugger.setEventNotificationHandler(handleThreadEvent); + Debugger.enableCurrentThreadDebugging(false); + Debugger.breakNow(true); + + generateFilePathMaps(); var classes = Debugger.getClasses(); @:privateAccess Interp.globals = new Map(); @@ -276,13 +331,25 @@ class Server { case Protocol.SetBreakpoints: var params:SetBreakpointsParams = m.params; var result = []; + var breakpointIds = []; if (!breakpoints.exists(path2Key(params.file))) breakpoints[path2Key(params.file)] = []; for (rm in breakpoints[path2Key(params.file)]) { - Debugger.deleteBreakpoint(rm.id); + #if scriptable + if (rm.internalId != null && mappedBreakpointIds[rm.internalId] != null) + Debugger.deleteBreakpoint(rm.internalId); + else + #end + Debugger.deleteBreakpoint(rm.id); + } + + #if scriptable + if (missedBreakpoints.exists(path2Key(params.file))) { + missedBreakpoints[path2Key(params.file)] = []; } + #end for (b in params.breakpoints) { var bInfo:BreakpointInfo = {id: 0, line: b.line}; if (b.condition != null) { @@ -294,11 +361,29 @@ class Server { continue; } } - bInfo.id = Debugger.addFileLineBreakpoint(path2file[path2Key(params.file)], bInfo.line); + var id = Debugger.addFileLineBreakpoint(path2file[path2Key(params.file)], bInfo.line); + #if scriptable + if (id == -1) { + bInfo.id = nextMappedBreakpointId--; + + var missedBreakpointsForFile = if (missedBreakpoints.exists(path2Key(params.file))) { + missedBreakpoints[path2Key(params.file)]; + } else { + missedBreakpoints[path2Key(params.file)] = []; + }; + + missedBreakpointsForFile.push(bInfo); + } else if (mappedBreakpointIds.exists(id)) + bInfo.id = mappedBreakpointIds[id]; + else + #end + bInfo.id = id; + breakpointIds.push(bInfo.id); + result.push(bInfo); } breakpoints[path2Key(params.file)] = result; - m.result = [for (b in result) b.id]; + m.result = breakpointIds; case Protocol.Pause: Debugger.breakNow(true); From abcd9443b834c7a9262c728f694eb0002f074da0 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 14 Mar 2025 16:36:03 +0000 Subject: [PATCH 2/4] Add warning for relative source paths in cppia --- hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx index 2a222e0..13578a1 100644 --- a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx +++ b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx @@ -235,11 +235,21 @@ class Server { } private function generateFilePathMaps() { + #if scriptable + var isUpdate = path2file.keys().hasNext(); + #end var fullPathes = Debugger.getFilesFullPath(); var files = Debugger.getFiles(); for (i in 0...files.length) { var file = files[i]; var path = fullPathes[i]; + + #if scriptable + if (isUpdate && !path2file.exists(path2Key(path)) && !haxe.io.Path.isAbsolute(path)) { + log("Warning: cppia script was loaded containing relative source file paths. Make sure the script is compiled with -D cppia.absolute-source-paths"); + } + #end + path2file[path2Key(path)] = file; file2path[path2Key(file)] = path; } From c5226b8045962cc95e22e12109b8d01151398854 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 14 Mar 2025 22:01:36 +0000 Subject: [PATCH 3/4] Show cppia relative source path warning only once --- hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx index 13578a1..35c117e 100644 --- a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx +++ b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx @@ -237,6 +237,7 @@ class Server { private function generateFilePathMaps() { #if scriptable var isUpdate = path2file.keys().hasNext(); + var relativeSourceWarningShown = false; #end var fullPathes = Debugger.getFilesFullPath(); var files = Debugger.getFiles(); @@ -245,8 +246,10 @@ class Server { var path = fullPathes[i]; #if scriptable - if (isUpdate && !path2file.exists(path2Key(path)) && !haxe.io.Path.isAbsolute(path)) { - log("Warning: cppia script was loaded containing relative source file paths. Make sure the script is compiled with -D cppia.absolute-source-paths"); + if (isUpdate && !path2file.exists(path2Key(path)) && !haxe.io.Path.isAbsolute(path) && !relativeSourceWarningShown) { + log("Warning: cppia script was loaded containing relative source file paths." + + " Make sure the script is compiled with -D cppia.absolute-source-paths"); + relativeSourceWarningShown = true; } #end From 004ec558df25b8465880fecf787ea17dbea93153 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Mon, 7 Apr 2025 10:45:12 +0100 Subject: [PATCH 4/4] Remove warning about absolute debug paths Haxe 5 now generates absolute debug paths by default for cppia. If haxe 5 is not being used, a warning will already be shown earlier on anyway. --- hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx index 35c117e..2a222e0 100644 --- a/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx +++ b/hxcpp-debug-server/hxcpp/debug/jsonrpc/Server.hx @@ -235,24 +235,11 @@ class Server { } private function generateFilePathMaps() { - #if scriptable - var isUpdate = path2file.keys().hasNext(); - var relativeSourceWarningShown = false; - #end var fullPathes = Debugger.getFilesFullPath(); var files = Debugger.getFiles(); for (i in 0...files.length) { var file = files[i]; var path = fullPathes[i]; - - #if scriptable - if (isUpdate && !path2file.exists(path2Key(path)) && !haxe.io.Path.isAbsolute(path) && !relativeSourceWarningShown) { - log("Warning: cppia script was loaded containing relative source file paths." - + " Make sure the script is compiled with -D cppia.absolute-source-paths"); - relativeSourceWarningShown = true; - } - #end - path2file[path2Key(path)] = file; file2path[path2Key(file)] = path; }