Code Monkey home page Code Monkey logo

Comments (5)

pilaoda avatar pilaoda commented on May 24, 2024 1
function this.getHookOffset()
	if hookLib ~= nil then
		return HOOK_LEVEL;
	end
	
	local funclayer = 0;
	repeat
		local info = debug.getinfo(funclayer, "SlLnf");
		if info ~= nil and info.func == this.real_hook_process then
			return funclayer;
		end
		funclayer = funclayer + 1;
	until not info

	return 0;
end
-- dataProcess里面
local hookOffset = this.getHookOffset(); --去除偏移量
local stackId = this.curStackId - 1 + hookOffset;
local varTable = this.getVariable(stackId, true);
msgTab.info = varTable;

我自己本地改了一下,获取real_hook_process的层级再减一下,就知道真实的堆栈层级了

from luapanda.

stuartwang avatar stuartwang commented on May 24, 2024

最近有点忙,刚看到消息。
非常感谢提出这个问题。我回顾了一下代码,这里确实是一个bug。因为 getSpecificFunctionStackLevel 会从栈顶开始逐层查找函数对应的栈帧,当一个函数存在于两个栈帧中,其中的局部变量处理就只会展示最上层栈帧的。同时这个错误有可能出现在 watch 窗口。

之所以会需要 getSpecificFunctionStackLevel 这个函数修正偏移,原因是在 lua 栈中,可能存在存在穿插 native 堆栈的情况。但是把堆栈信息发送给 vscode 时,把 native 栈过滤掉了( 参考 getStackTable() ,它的返回值就是前端获得的堆栈)。于是出现了 vscode 发到后端的堆栈并不是实际 stackId 的情况。

总的来说,可以考虑在构建前端堆栈时,不去除 native 原生栈,这样可以保持前后端堆栈对应。 如果保持过滤 native 栈,就要在后端建立映射表。

最近做了一些 js 相关的工作,也参考了下 js 调试器,后续我更倾向于保留 native 堆栈。

from luapanda.

pilaoda avatar pilaoda commented on May 24, 2024

其实就是调用 real_hook_process 里面,有可能多次递归调用 receiveMessage,dataProcess这几个函数,导致真实的 lua 层数距离断点所在的层数偏移不固定,只要从 real_hook_process 所在层数去算就能过滤掉所有 debugger 的层数了

from luapanda.

stuartwang avatar stuartwang commented on May 24, 2024

image

我画了张图表达上面的方案,这样改很好,这部分代码后面会使用你的方案修改。

上面我说得是另一个场景,即 lua 用户栈嵌套原生栈帧的问题。之前的处理方案不太好,容易引发变量和栈帧不匹配的bug,我最近一起优化。

from luapanda.

stuartwang avatar stuartwang commented on May 24, 2024

fix 9bb31aa

from luapanda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.