EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.74k stars 292 forks source link

idea调试无法与代码联动,vscode能高亮到行,但直接崩溃 #490

Open heyilin416 opened 2 years ago

heyilin416 commented 2 years ago

Environment(环境)

name version
IDEA version IntelliJ IDEA 2021.1.3 x64
EmmyLua version 1.3.6.224-IDEA211
OS Windows 11

What are the steps to reproduce this issue?(重现步骤?)

1.服务器是win32版本,启动时加载emmy_code包,监听端口; 2.idea直接启动调试,连接成功; 3.设置代码断点,能命中,但无法跟代码联动,不跳转,不高度;(vscode能命中,能高亮,但主程序直接崩溃)

What happens?(出现什么问题?)

vscode是直接触发visual studio的一个断点,定位是lauxlib.c中的l_alloc函数的最后 return realloc(ptr, nsize);

What were you expecting to happen?(期望?)

Any logs, error output, etc?(有没有什么log, error输出?)

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Any other comments?(其它说明)

CppCXY commented 2 years ago

对win32-x86版本的调试涉及到lua在lua5.1到lua5.4之间对整数类型定义的长度并不一致。emmylua调试器并没有办法在默认编译的调试器下,能够同时调试lua5.1到lua5.4所有版本的情况下兼容x86下整数类型不一致的问题。

之所以1.3.6.224-IDEA211能够调试不崩溃是因为那个版本的调试器默认x86下整数类型都是int32,而实际上这是不对的。

现行的办法就是下载emmylua调试器源代码,加选择目标lua版本然后使用lua源代码编译出调试器。 具体编译命令是

mkdir build && cd build 
cmake .. -DEMMY_LUA_VERSION={可选值 jit/51/52/53/54} -DEMMY_USE_LUA_SOURCE=ON
cmake --build .
heyilin416 commented 2 years ago

谢谢大神提点

heyilin416 commented 2 years ago

现在我升级程序到x64了,但现象依然还是,是不是因为我用的是lua5.1的版本,所以线上插件版本不兼容5.1?

CppCXY commented 2 years ago

如果改过lua源代码,或者你使用的lua源代码和emmylua自带的lua源代码有一些差异,那么有一些可能。所以最好是把你们使用的lua源代码复制进emmylua调试器对应的位置,然后加选项编译。 如果还有问题,源代码在手,你可以自己调试一下调试器

heyilin416 commented 2 years ago

好的,我按大神的指导方式,先试一下,太感谢您了,没有您我们是真没办法了!

heyilin416 commented 2 years ago

编译出错: D:\study\EmmyLuaDebugger\third-party\nlohmann\include\nlohmann/detail/value_t.hpp(68): error C3646: “noexcept”: 未知重写说明符 [D:\study\EmmyLuaDebugger\emmy_debugger\emmy_debugger.vcxproj] D:\study\EmmyLuaDebugger\third-party\nlohmann\include\nlohmann/detail/value_t.hpp(69): error C2143: 语法错误 : 缺少“;”(在“std: :array<uint8_t,9>”的前面) [D:\study\EmmyLuaDebugger\emmy_debugger\emmy_debugger.vcxproj] D:\study\EmmyLuaDebugger\third-party\nlohmann\include\nlohmann/detail/value_t.hpp(69): error C4430: 缺少类型说明符 - 假 定为 int。注 意: C++ 不支持默认 int [D:\study\EmmyLuaDebugger\emmy_debugger\emmy_debugger.vcxproj] D:\study\EmmyLuaDebugger\third-party\nlohmann\include\nlohmann/detail/meta/detected.hpp(33): fatal error C1903: 无法从以前的错 误中恢复;正在停止编译 [D:\study\EmmyLuaDebugger\emmy_debugger\emmy_debugger.vcxproj]

CppCXY commented 2 years ago

需要支持C++11也就是至少你得是vs2017以上

heyilin416 commented 2 years ago

嗯,我直接装了一个vs2022,编译通过了;

heyilin416 commented 2 years ago

编译完成之后,是要怎么替换了?

heyilin416 commented 2 years ago

我直接替换那个emmy_core.dll动态库,现在直接不进断点了!

heyilin416 commented 2 years ago

不过目前没有用我们自己的lua源码;

CppCXY commented 2 years ago

断点时,chunkname不能有相对路径也就是不能是 ../../aaaaaaaaa/bbbbb.lua

heyilin416 commented 2 years ago

chunkname是什么,之前的版本为什么能断?

CppCXY commented 2 years ago

因为之前得版本支持这个,现在得版本早就砍掉了这一项

CppCXY commented 2 years ago

同时支持这个得版本BUG非常多

heyilin416 commented 2 years ago

那要改成什么标准的,我怎么改,我没明白;

CppCXY commented 2 years ago

aaaa/bbbbbbbbbbb/ccccccc.lua得形式或者绝对路径,chunkname是传递给luaL_loadbuffer得叫name得参数

CppCXY commented 2 years ago

当前文件得chunkname你可以通过打印 debug.getinfo(1).source看到

heyilin416 commented 2 years ago

lua_getglobal(L, "package"); lua_pushstring(L, "../../data/long/script/?.lua;../../data/long/script/?/init.lua"); lua_setfield(L, -2, "path"); lua_pop(L, 1);

    lua_getglobal(L,"server");
    ScriptLua** a = (ScriptLua**)lua_newuserdata(L, sizeof(ScriptLua*));
    *a = this;
    lua_setfield(L,-2,"This");
    lua_pop(L,1);

    if (dofile(L, "../../data/long/script/init.lua") != 0)
    {
        lua_close(L);
        L = 0;
    }
    if (L) {
        LoadLuaConst(L);
        LoadLuaItemConst(L);
        LoadLuaLogType(L);
        LoadLuaData(L);
    }
heyilin416 commented 2 years ago

是不是就是这种原因引起的?

CppCXY commented 2 years ago

对得,lua会直接传给luaL_laodbuffer

CppCXY commented 2 years ago

一般来说配绝对路径比较好,或者要么自己写custom loader

heyilin416 commented 2 years ago

那得用绝对路径是吧,那我改成配置文件配置,这样就好支持了;

CppCXY commented 2 years ago

可以试试

heyilin416 commented 2 years ago

感谢大神这么有耐心,我感觉这种问题是不是要放到README.md说明一下比较好,真的没你的指引,我完成是一头雾水,emmylua这个调试对于我们程序员真的是太重要了,再次感谢大神!!!

heyilin416 commented 2 years ago

完美解决,真是太好了!!!

heyilin416 commented 2 years ago

大神,还有一个问题,我现在idea正常了,但vscode不能进断点,这个是不是要编不同版本的emmy_core.dll?

CppCXY commented 2 years ago

你vscode什么版本

heyilin416 commented 2 years ago

1.70.0,应该是更新到最样的版本了;

CppCXY commented 2 years ago

emmylua是什么版本

heyilin416 commented 2 years ago

v0.5.7

heyilin416 commented 2 years ago

debugger源码是master分支的

CppCXY commented 2 years ago

你可以加上dbg.breakHere()强断,看下各方面信息是不是有问题

heyilin416 commented 2 years ago

dbg.breakHere()加了,依然没有断下来;

CppCXY commented 2 years ago

操作方式问题, 整个这一套从tcpListen()之后 如果在启动代码中可以加 dbg.waitIDE() dbg.breakHere()

heyilin416 commented 2 years ago

我在监听之后加了这两行代码,主程序根本不阻塞,直接就向下运行了;

CppCXY commented 2 years ago

理论上这是不可能得,你把所有插入代码删掉,试下emmylua launch调试

heyilin416 commented 2 years ago

知道问题了,因为之前vscode打开的是我们内部的lua代码,现在为了跟人使用,lua代码是一个公共仓库的,所以是运行的目录与vscode打开的目录不一致造成的,耽误大神了,抱歉!!!

qq21 commented 4 months ago

大佬,自定义 自定义loader 是直接返回空吗,现在断点 能进,然后就卡死了,break 都没有用 package.cpath = package.cpath .. ';C:/Users/xxx/AppData/Roaming/JetBrains/IntelliJIdea2021.1/plugins/EmmyLua/classes/debugger/emmy/windows/x64/?.dll' local dbg = require('emmy_core') dbg.tcpConnect('localhost', 7590)

CppCXY commented 4 months ago

大佬,自定义 自定义loader 是直接返回空吗,现在断点 能进,然后就卡死了,break 都没有用 package.cpath = package.cpath .. ';C:/Users/xxx/AppData/Roaming/JetBrains/IntelliJIdea2021.1/plugins/EmmyLua/classes/debugger/emmy/windows/x64/?.dll' local dbg = require('emmy_core') dbg.tcpConnect('localhost', 7590)

加群聊