Skip to content

Set breakpoints in cppia scripts loaded after the server attaches - #48

Open
dimensionscape wants to merge 1 commit into
vshaxe:masterfrom
dimensionscape:cppia-scripts
Open

dimensionscape wants to merge 1 commit into
vshaxe:masterfrom
dimensionscape:cppia-scripts

Conversation

@dimensionscape

Copy link
Copy Markdown

The server builds its file list once, as it attaches, which is before a cppia host loads any script. A breakpoint in a script then maps to no file, addFileLineBreakpoint gets null and returns -1, and the script never stops. A stop in a script also found no file for it, and iterating the missing breakpoint list threw on the debugger thread.

This change:

  • registers hxcpp's script-loaded callback (__hxcpp_dbg_setOnScriptLoadedFunction, [cppia] Allow setting callback for script load HaxeFoundation/hxcpp#1203) when the host is scriptable and the runtime has it: API level 500, or libhxcpp at any level, which defines HXCPP_DBG_ON_SCRIPT_LOADED. Other runtimes build as before
  • in the callback, reads the files again and sets the breakpoints that were waiting for them
  • maps a script's file names, which are as Haxe was given them and often relative, to the editor's full paths by matching the end of the path; failing that, to the full path of the file if it exists from the working directory
  • reads the files again when a breakpoint names a file it does not know, so a breakpoint added while a script runs is set too
  • skips the breakpoint list on a stop in a file it has no path for, instead of throwing

Checked with libhxcpp 6.0.0 and Haxe 4.3.7. On Windows, Linux and macOS (Intel and arm64), a breakpoint set before the script loads stops, interpreted and with the JIT, locals read correctly, and next, step out and continue go where they should. On Windows, a breakpoint set while the script runs stops too, also on this branch as rebased on master.

The server built its file list once, as it attached, which is before a
cppia host loads any script, so a breakpoint in a script mapped to no
file and never stopped. It now registers hxcpp's script-loaded callback
where the runtime has it (API level 500, or libhxcpp at any level, which
defines HXCPP_DBG_ON_SCRIPT_LOADED), reads the files again there and
sets the breakpoints that were waiting. Script file names, often
relative, are matched to the editor's paths by their end, and a
breakpoint in a file the server does not know yet makes it read the
files again, so one added while a script runs is set too. A stop in a
file the server has no path for no longer throws on the debugger thread.
Jarrio pushed a commit to Jarrio/hxcpp-debugger that referenced this pull request Oct 24, 2026
…rver attaches

Server.hx's setBreakpoints conflicted with this fork's changes. vshaxe#48's
shared setBreakpoints function stays, answering as this fork does: one
id per requested breakpoint, -1 for one whose condition doesn't parse
(instead of an error for the whole request) or whose file has no code
loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019VkYci7PZjWWY3LJTcTpsa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant