新增 syntaxCompatibility 配置项:显式指定使用调试目标解释器解析源码 - #358
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new dump/error-propagation and undump paths can mask real syntax errors and can throw on unsupported bytecode formats without graceful handling, which risks breaking breakpoint calculation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an opt-in syntaxCompatibility launch configuration to improve breakpoint line mapping when the debug target uses non-default Lua syntax, by optionally compiling/dumping via the target VM; also fixes a Lua 5.5 undump string-cache retention issue to avoid cross-call leakage.
Changes:
- Introduces
syntaxCompatibilityconfig plumbing (schema + i18n) and propagates it into breakpoint line-info parsing. - Restores an
eval.dump-based path to obtain dumped bytecode for line-info generation. - Resets
undump55’s internal string cache per invocation to prevent memory growth and index mismatches across parses.
File summaries
| File | Description |
|---|---|
| extension/script/backend/worker/undump.lua | Resets Lua 5.5 undump string cache per call to avoid cross-parse cache corruption/leaks. |
| extension/script/backend/worker/parser.lua | Adds optional target-VM dumping path for syntax compatibility during line-info generation. |
| extension/script/backend/worker/eval/dump.lua | New helper chunk used to compile + dump source content. |
| extension/script/backend/worker/eval.lua | Adds eval.dump generator that loads/executes the dump helper via local or target VM mechanisms. |
| extension/script/backend/worker/breakpoint.lua | Reads config.syntaxCompatibility and passes it into the parser; resets on termination. |
| extension/package.nls.json | Adds localized description for the new launch setting. |
| compile/common/package_json.lua | Adds syntaxCompatibility to the generated launch configuration schema. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| generate("dump", function() | ||
| if luaver.LUAVERSION <= 52 then | ||
| local compat_dump = assert(load(readfile 'backend.worker.eval.dump')) | ||
| return function(content) | ||
| local res, err = compat_dump(content) | ||
| if res then | ||
| return true, res | ||
| end | ||
| return false, err | ||
| end | ||
| else | ||
| local eval_dump = assert(rdebug.load(readfile 'backend.worker.eval.dump')) | ||
| return function(content) | ||
| return rdebug.eval(eval_dump, content, 0) | ||
| end | ||
| end | ||
| end) |
| if not bin then | ||
| local log = require 'common.log' | ||
| log.error("ERROR:"..err) | ||
| log.error("ERROR:"..(err or "unknown error")) | ||
| return | ||
| end |
| "lua.debug.launch.console.integratedTerminal.description": "VS Code integrated terminal.", | ||
| "lua.debug.launch.console.externalTerminal.description": "External terminal that can be configured in user settings.", | ||
| "lua.debug.launch.luaVersion.description": "Default lua version.", | ||
| "lua.debug.launch.syntaxCompatibility.description": "Use the target Lua VM to parse source syntax for breakpoint line information.", |
| log.error("ERROR:"..(err or "unknown error")) | ||
| return | ||
| end | ||
| local ok, cl, v = pcall(undump, bin) |
There was a problem hiding this comment.
对于string.dump + undump的组合来说,是绝对安全的,无需pcall,只有未知的dump函数+undump才需要pcall保护
| end | ||
|
|
||
| generate("dump", function() | ||
| if luaver.LUAVERSION <= 52 then |
There was a problem hiding this comment.
这里处理5.2是没意义的,因为自带的undump函数不支持5.2的dump,如果是fallback到string.dump+undump,直接不调用这个新的分支即可。
之前解析文件时只使用默认解释器。如果调试目标使用了自定义语法,那么将会解析失败,导致断点无法生效。
本次改动:
syntaxCompatibility(默认关闭)。开启后使用调试目标的解释器执行load+string.dump,为断点生成行号信息(恢复此前删除的 eval.dump 机制)。undump55的字符串缓存未重置问题:多次解析时缓存跨调用残留,导致内存累积与字符串索引错位。注意:该配置只能解决语法解析问题,无法解决字节码格式不兼容的情况。