mirror of
https://github.com/neovim/neovim.git
synced 2026-05-25 22:38:29 +00:00
fix(lua): don't strip debuginfo in precompile module #39191
Problem:
debug.getinfo on bytecode module/func don't give you detail source info.
Solution:
- Use `loadstring`+`string.dump` to replace LUAC_PRG(`luac`/`luajit -b`)
- `string.dump(…,false)` to generate non-strip version bytecode
- `loadstring(…,fname)` to specify the full source name
BEFORE:
$ nvim --clean +'=debug.getinfo(vim.fn.maparg("]<Space>", "n", 0, 1).callback, "Sl")' --headless +q
{
currentline = -1,
lastlinedefined = 456,
linedefined = 452,
short_src = "?",
source = "=?",
what = "Lua"
}
AFTER:
$ nvim --clean +'=debug.getinfo(vim.fn.maparg("]<Space>", "n", 0, 1).callback, "Sl")' --headless +q
{
currentline = -1,
lastlinedefined = 456,
linedefined = 452,
short_src = "/home/xx/b/neovim/runtime/lua/vim/_core/defaults.lua",
source = "@/home/xx/b/neovim/runtime/lua/vim/_core/defaults.lua",
what = "Lua"
}
This commit is contained in:
@@ -769,13 +769,7 @@ static int nlua_module_preloader(lua_State *lstate)
|
||||
{
|
||||
size_t i = (size_t)lua_tointeger(lstate, lua_upvalueindex(1));
|
||||
ModuleDef def = builtin_modules[i];
|
||||
char name[256];
|
||||
name[0] = '@';
|
||||
size_t off = xstrlcpy(name + 1, def.name, (sizeof name) - 2);
|
||||
strchrsub(name + 1, '.', '/');
|
||||
xstrlcpy(name + 1 + off, ".lua", (sizeof name) - 2 - off);
|
||||
|
||||
if (luaL_loadbuffer(lstate, (const char *)def.data, def.size - 1, name)) {
|
||||
if (luaL_loadbuffer(lstate, (const char *)def.data, def.size - 1, NULL)) {
|
||||
return lua_error(lstate);
|
||||
}
|
||||
|
||||
@@ -2372,15 +2366,6 @@ void nlua_set_sctx(sctx_T *current)
|
||||
lua_State *const lstate = active_lstate;
|
||||
lua_Debug *info = (lua_Debug *)xmalloc(sizeof(lua_Debug));
|
||||
|
||||
// Files where internal wrappers are defined so we can ignore them
|
||||
// like vim.o/opt etc are defined in _options.lua
|
||||
char *ignorelist[] = {
|
||||
"vim/_core/editor.lua",
|
||||
"vim/_core/options.lua",
|
||||
"vim/keymap.lua",
|
||||
};
|
||||
int ignorelist_size = sizeof(ignorelist) / sizeof(ignorelist[0]);
|
||||
|
||||
for (int level = 1; true; level++) {
|
||||
if (lua_getstack(lstate, level, info) != 1) {
|
||||
goto cleanup;
|
||||
@@ -2388,19 +2373,7 @@ void nlua_set_sctx(sctx_T *current)
|
||||
if (lua_getinfo(lstate, "nSl", info) == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
bool is_ignored = false;
|
||||
if (info->what[0] == 'C' || info->source[0] != '@') {
|
||||
is_ignored = true;
|
||||
} else {
|
||||
for (int i = 0; i < ignorelist_size; i++) {
|
||||
if (strncmp(ignorelist[i], info->source + 1, strlen(ignorelist[i])) == 0) {
|
||||
is_ignored = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_ignored) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user