EmmyLua / VSCode-EmmyLua

Lua IDE/Debugger Plugin for VSCode
632 stars 89 forks source link

Mac 上无法加载 emmy_core 插件模块 #133

Closed waruqi closed 1 year ago

waruqi commented 1 year ago

调用模块获取到 function 后,就无法继续获取 module ,返回是空

local m = package.loadlib("/Users/ruki/.vscode//extensions/tangzx.emmylua-0.5.14/debugger/emmy/mac/x64/emmy_core.dylib", "luaopen_emmy_core")
print("m: ", m)
print("m(): ", m())
m:      function: 0x10b4a8340
m():
package.cpath = package.cpath .. ";/Users/ruki/.vscode//extensions/tangzx.emmylua-0.5.14/debugger/emmy/mac/x64/emmy_core.dylib"
local m = require("emmy_core")
print("m: ", m)
print("m(): ", m())
m:      true
error: local 'm' is not callable
 (a boolean value)
CppCXY commented 1 year ago

需要重编xlua或者tolua, 加上宏LUA_USE_MACOSX和LUA_USE_DLOPEN

CppCXY commented 1 year ago

默认的xlua插件在mac上并不具备加载动态链接库的能力

waruqi commented 1 year ago

默认的xlua插件在mac上并不具备加载动态链接库的能力

不是 xlua,是 xmake 里面 (https://github.com/xmake-io/xmake) ,我在测试 lua 调试。

库加载应该没问题,上面的 logs ,package.loadlib 其实已经加载返回有效的 function 了,只是在获取 module 时候,返回了空。

另外,我用 package.loadlib 加载测试自己的一些 lua dylib 库模块,加载都是正常的,没啥问题

CppCXY commented 1 year ago

emmylua默认编译的调试器并没有内部集成lua api, 他需要从宿主获取lua api, 所以需要宿主进程导出lua符号

CppCXY commented 1 year ago

另一个选择是下载emmylua调试器源码, 编译一个自带lua符号的emmy_core, 需要加一些宏

waruqi commented 1 year ago

另一个选择是下载emmylua调试器源码, 编译一个自带lua符号的emmy_core, 需要加一些宏

我试下 谢谢

CppCXY commented 1 year ago

下载地址 https://github.com/EmmyLua/EmmyLuaDebugger/releases 编译时需要添加 -DEMMY_USE_LUA_SOURCE=ON

waruqi commented 1 year ago

下载地址 https://github.com/EmmyLua/EmmyLuaDebugger/releases 编译时需要添加 -DEMMY_USE_LUA_SOURCE=ON

好的

waruqi commented 1 year ago

用自己编译的库,遇到了其他的错误 (mac 上)

m:      function: 0x10a9c0b30
stack overflow (too manyupvalues)

获取 module 的时候,溢出了

CppCXY commented 1 year ago

用自己编译的库,遇到了其他的错误 (mac 上)

m:      function: 0x10a9c0b30
stack overflow (too manyupvalues)

获取 module 的时候,溢出了

可能有bug, 但我不知道发生了什么, 是否有必现工程

waruqi commented 1 year ago

测试代码, testdbg 分支

$ git clone https://github.com/xmake-io/xmake.git -b testdbg
$ cd xmake

https://github.com/xmake-io/xmake/blob/ba70a999262d80cf93746fe70013d6a8f3895ba8/xmake/core/_xmake_main.lua#L46

修改里面的 dylib 路径到自己编译的版本,然后执行

$ ./configure
$ make
$ source scripts/srcenv.profile
$ xmake --version
m:      function: 0x10a9c0b30
error: .../ruki/projects/personal/xmake/xmake/core/_xmake_main.lua:47: stack overflow (too many
upvalues)

dylib 编译目前附带的编译参数:-DEMMY_USE_LUA_SOURCE=ON -DEMMY_LUA_VERSION=54 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/Users/ruki/.xmake/packages/e/emmylua_debugger/1.6.2/5ac9d51f3ee84cc7b5f692eef acc4ac1 -DCMAKE_INSTALL_LIBDIR:PATH=lib -G "Unix Makefiles" -DCMAKE_POSITION_INDEPENDENT_CODE=ON

CppCXY commented 1 year ago

测试了一下, 是emmylua 自带的lua5.4版本太低, 不兼容导致的, 切换为lua5.4.6后可以正常调试, windows下的编译我改了. lua版本升级我后面再看看兼容性, 你可以自己把5.4.6的源码复制到emmylua的5.4.0目录 image

waruqi commented 1 year ago

确实是版本问题,初步测试能获取到 module 了,一会我再测下调试

waruqi commented 1 year ago

还是不对,之前是我切到自己外置的 5.4.6 ,是可以了。。

但是用你刚最新 commit ,还是获取不到 modules,看编译,用的还是 5.4.0

/usr/local/bin/cmake -DEMMY_USE_LUA_SOURCE=ON -DEMMY_LUA_VERSION=54 -DCMAKE_BUILD_TYPE=Release -
DCMAKE_INSTALL_PREFIX=/Users/ruki/.xmake/packages/e/emmylua_debugger/2023.08.25/ab519e5eda1345da
bf71170c50880405 -DCMAKE_INSTALL_LIBDIR:PATH=lib -G "Unix Makefiles" -DCMAKE_POSITION_INDEPENDEN
T_CODE=ON /Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.25/source/emmylua_de
bugger

make[1]: Entering directory '/Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.2
5/source/emmylua_debugger/build_ab519e5e'
make  -f third-party/lua-5.4.0/CMakeFiles/lua54.dir/build.make third-party/lua-5.4.0/CMakeFiles/
lua54.dir/depend
cd /Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.25/source/emmylua_debugger/
build_ab519e5e/third-party/lua-5.4.0 && /Applications/Xcode.app/Contents/Developer/Toolchains/Xc
odeDefault.xctoolchain/usr/bin/cc -DEMMY_CORE_VERSION=\"DEV\" -DEMMY_LUA_54 -DEMMY_USE_LUA_SOURC
E -DLUA_USE_MACOSX -I/Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.25/source
/emmylua_debugger/third-party/lua-5.4.0/src -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Conte
nts/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -mmacosx-version-min=12.6
-fPIC -fPIC -MD -MT third-party/lua-5.4.0/CMakeFiles/lua54.dir/src/lcode.c.o -MF CMakeFiles/lua5
4.dir/src/lcode.c.o.d -o CMakeFiles/lua54.dir/src/lcode.c.o -c /Users/ruki/.xmake/cache/packages
/2308/e/emmylua_debugger/2023.08.25/source/emmylua_debugger/third-party/lua-5.4.0/src/lcode.c
cd /Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.25/source/emmylua_debugger/
build_ab519e5e/third-party/libuv-1.29.0 && /Applications/Xcode.app/Contents/Developer/Toolchains
/XcodeDefault.xctoolchain/usr/bin/cc -DEMMY_CORE_VERSION=\"DEV\" -DEMMY_LUA_54 -DEMMY_USE_LUA_SO
URCE -D_DARWIN_UNLIMITED_SELECT=1 -D_DARWIN_USE_64_BIT_INODE=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFI
LE_SOURCE -I/Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.25/source/emmylua_
debugger/third-party/lua-5.4.0/src -I/Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2
023.08.25/source/emmylua_debugger/third-party/libuv-1.29.0/include -I/Users/ruki/.xmake/cache/pa
ckages/2308/e/emmylua_debugger/2023.08.25/source/emmylua_debugger/third-party/libuv-1.29.0/src -
O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Devel
oper/SDKs/MacOSX13.0.sdk -mmacosx-version-min=12.6 -fPIC -fvisibility=hidden --std=gnu89 -Wall -
Wextra -Wstrict-prototypes -Wno-unused-parameter -MD -MT third-party/libuv-1.29.0/CMakeFiles/uv_
a.dir/src/inet.c.o -MF CMakeFiles/uv_a.dir/src/inet.c.o.d -o CMakeFiles/uv_a.dir/src/inet.c.o -c
 /Users/ruki/.xmake/cache/packages/2308/e/emmylua_debugger/2023.08.25/source/emmylua_debugger/th
ird-party/libuv-1.29.0/src/inet.c

2b2485d2a4bf6fce80aa05d7f93cf1bfad58a1e8 的提交

CppCXY commented 1 year ago

但是我从release里面下载下来的里面已经没有5.4.0这个目录了 image

waruqi commented 1 year ago

哦 是我这拉取的问题,我再看看

waruqi commented 1 year ago

可以了,https://github.com/xmake-io/xmake/pull/4121

非常感谢

$ xmake update -s dev
$ xrepo update-repo
$ xrepo env -b emmylua_debugger xmake --version

image