Skip to content
Snippets Groups Projects
Commit f32808f9 authored by Timur Safin's avatar Timur Safin Committed by Igor Munkin
Browse files

debugger: provide access to box lua sources

tarantool.debug.getsources() used to provide
lua sources only for libserver lua modules,
and was not providing sources for src/box/lua/*
modules.

Now this code works:
```lua
local tnt = require 'tarantool'
local code1 = tnt.debug.getsources('box/session')
local code1 = tnt.debug.getsources('@builtin/box/session..lua')
```

Closes #7839

NO_DOC=bugfix
NO_CHANGELOG=later
parent 0ecce056
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "lua/utils.h" /* luaT_error() */ #include "lua/utils.h" /* luaT_error() */
#include "lua/trigger.h" #include "lua/trigger.h"
#include "lua/msgpack.h" #include "lua/msgpack.h"
#include "lua/builtin_modcache.h"
#include "box/box.h" #include "box/box.h"
#include "box/txn.h" #include "box/txn.h"
...@@ -563,6 +564,7 @@ box_lua_init(struct lua_State *L) ...@@ -563,6 +564,7 @@ box_lua_init(struct lua_State *L)
panic("Error loading Lua module %s...: %s", panic("Error loading Lua module %s...: %s",
modname, lua_tostring(L, -1)); modname, lua_tostring(L, -1));
lua_pop(L, 1); /* modfile */ lua_pop(L, 1); /* modfile */
builtin_modcache_put(modname, modsrc);
} }
assert(lua_gettop(L) == 0); assert(lua_gettop(L) == 0);
......
...@@ -15,6 +15,14 @@ local files = { ...@@ -15,6 +15,14 @@ local files = {
'fiber', 'fiber',
'env', 'env',
'datetime', 'datetime',
'box/session',
'box/tuple',
'box/key_def',
'box/schema',
'box/xlog',
'box/net_box',
'box/console',
'box/merger',
} }
-- calculate reporsitory root using directory of a current -- calculate reporsitory root using directory of a current
...@@ -32,6 +40,9 @@ g.test_tarantool_debug_getsources = function() ...@@ -32,6 +40,9 @@ g.test_tarantool_debug_getsources = function()
local lua_src_dir = fio.pathjoin(git_root, '/src/lua') local lua_src_dir = fio.pathjoin(git_root, '/src/lua')
t.assert_is_not(lua_src_dir, nil) t.assert_is_not(lua_src_dir, nil)
t.assert(fio.stat(lua_src_dir):is_dir()) t.assert(fio.stat(lua_src_dir):is_dir())
local box_lua_dir = fio.pathjoin(git_root, '/src/box/lua')
t.assert_is_not(box_lua_dir, nil)
t.assert(fio.stat(box_lua_dir):is_dir())
local tnt = require('tarantool') local tnt = require('tarantool')
t.assert_is_not(tnt, nil) t.assert_is_not(tnt, nil)
...@@ -39,7 +50,14 @@ g.test_tarantool_debug_getsources = function() ...@@ -39,7 +50,14 @@ g.test_tarantool_debug_getsources = function()
t.assert_is_not(luadebug, nil) t.assert_is_not(luadebug, nil)
for _, file in pairs(files) do for _, file in pairs(files) do
local path = ('%s/%s.lua'):format(lua_src_dir, file) local box_prefix = 'box/'
local path
if file:match(box_prefix) ~= nil then
path = ('%s/%s.lua'):format(box_lua_dir,
file:sub(#box_prefix + 1, #file))
else
path = ('%s/%s.lua'):format(lua_src_dir, file)
end
local text = readfile(path) local text = readfile(path)
t.assert_is_not(text, nil) t.assert_is_not(text, nil)
local source = luadebug.getsources(file) local source = luadebug.getsources(file)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment