Merged
Conversation
There was a problem hiding this comment.
Code Review
This pull request adjusts the stack frame level in rdebug.getinfo from 1 to 0 to correct a position offset issue for logpoints. The review feedback highlights a potential bug where the shared info table could retain stale data if rdebug.getinfo fails, and suggests adding a conditional check to ensure stdout receives accurate information.
Comment on lines
+314
to
315
| rdebug.getinfo(0, "Sl", info) | ||
| stdout(res, info) |
There was a problem hiding this comment.
Pull request overview
该 PR 修复了在使用断点「记录点(logpoint)」输出日志时,调试控制台右侧展示的源码位置不正确的问题;通过调整获取栈帧信息的层级,使输出位置指向记录点触发处而不是其调用者位置。
Changes:
- 在
breakpoint.lua的 logpoint 输出路径中,将rdebug.getinfo的层级从1调整为0,用于获取记录点触发处的文件与行号。 - 保持
stdout(res, info)的输出结构不变,仅修正其输入info的定位来源。
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
当使用断点的「记录点」(logpoint)功能时,调试控制台右侧显示的源码位置不正确。
实际行为:显示的位置是调用「包含记录点的函数」的那一层调用者的位置,而非记录点本身所在的文件和行号。
期望行为:显示的位置应该是记录点所在的源文件和行号。
根本原因
在 \extension/script/backend/worker/breakpoint.lua\ 的 \m.exec\ 函数中,当记录点触发并需要打印日志时,原来的代码使用了:
\\lua
rdebug.getinfo(1, 'Sl', info)
\\
在 break hook 上下文中,
debug.getinfo\ 的层级含义如下:
由于使用了 \level 1\,\stdout\ 拿到的 \info\ 是调用者的位置,最终导致调试控制台右侧显示的是错误的位置。
修复方案
将 \level 1\ 改为 \level 0\,使其取到记录点自身触发时的位置:
\\lua
rdebug.getinfo(0, 'Sl', info)
\\
疑问
请问之前使用 \level 1\ 是否是有意为之的设计?例如是否存在某些特殊情况导致 \level 0\ 无法正确取到位置信息,因此才退一层取 \level 1\?如果是有意设计,烦请说明原因,我们可以一起讨论更合适的修复方案。