Skip to content

fix: 修复记录点(logpoint)在调试控制台中显示位置不正确的问题#353

Merged
actboy168 merged 1 commit intomasterfrom
fix/logpoint-source-location
May 8, 2026
Merged

fix: 修复记录点(logpoint)在调试控制台中显示位置不正确的问题#353
actboy168 merged 1 commit intomasterfrom
fix/logpoint-source-location

Conversation

@sumneko
Copy link
Copy Markdown
Collaborator

@sumneko sumneko commented May 8, 2026

问题描述

当使用断点的「记录点」(logpoint)功能时,调试控制台右侧显示的源码位置不正确。

实际行为:显示的位置是调用「包含记录点的函数」的那一层调用者的位置,而非记录点本身所在的文件和行号。

期望行为:显示的位置应该是记录点所在的源文件和行号。

根本原因

在 \extension/script/backend/worker/breakpoint.lua\ 的 \m.exec\ 函数中,当记录点触发并需要打印日志时,原来的代码使用了:

\\lua
rdebug.getinfo(1, 'Sl', info)
\\

在 break hook 上下文中,
debug.getinfo\ 的层级含义如下:

  • \level 0\:break hook 触发处,即记录点所在函数的当前执行位置
  • \level 1\:该函数的调用者,即调用包含记录点的函数的那一层

由于使用了 \level 1\,\stdout\ 拿到的 \info\ 是调用者的位置,最终导致调试控制台右侧显示的是错误的位置。

修复方案

将 \level 1\ 改为 \level 0\,使其取到记录点自身触发时的位置:

\\lua
rdebug.getinfo(0, 'Sl', info)
\\

疑问

请问之前使用 \level 1\ 是否是有意为之的设计?例如是否存在某些特殊情况导致 \level 0\ 无法正确取到位置信息,因此才退一层取 \level 1\?如果是有意设计,烦请说明原因,我们可以一起讨论更合适的修复方案。

Copilot AI review requested due to automatic review settings May 8, 2026 10:01
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

将层级从 1 改为 0 解决了记录点显示位置偏移的问题。但考虑到 info 表是模块级共享的(第 12 行定义),如果 rdebug.getinfo 在某些特殊情况下调用失败,info 表中会残留上一次断点触发时的位置信息,导致 stdout 输出错误的位置。建议增加返回值检查,在获取失败时传递空表以确保 stdout 不会使用过时的数据。

        if rdebug.getinfo(0, "Sl", info) then
            stdout(res, info)
        else
            stdout(res, {})
        end

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@actboy168 actboy168 merged commit bbb41fb into master May 8, 2026
10 checks passed
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.

3 participants