diff --git a/.gitignore b/.gitignore index 4916c0367b42a3f6a060d947140e9efe2a1f5e08..f14df26c8438d9ea405daa8e3e385d4a54267d64 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ coverage.info *.swp* .gitignore .gdb_history +.tdbg_history* CMakeFiles CMakeCache.txt CPackConfig.cmake diff --git a/changelogs/unreleased/gh-7593-console-debugger.md b/changelogs/unreleased/gh-7593-console-debugger.md new file mode 100644 index 0000000000000000000000000000000000000000..f1be8c223b508de823410be07547a66566003f7a --- /dev/null +++ b/changelogs/unreleased/gh-7593-console-debugger.md @@ -0,0 +1,3 @@ +## feature/debugger + +* Introduced readline support to tarantool debugger (gh-7738). diff --git a/third_party/lua/luadebug.lua b/third_party/lua/luadebug.lua index d6ae4a7666516531b2f8362b9b87a1930e012065..11847e25ea54d54dbc170608e8f7e229abc7e567 100644 --- a/third_party/lua/luadebug.lua +++ b/third_party/lua/luadebug.lua @@ -26,7 +26,9 @@ local dbg +local HOME_DIR = os.getenv('HOME') local DEBUGGER = 'luadebug' +local HISTORYFILE = HOME_DIR ~= nil and HOME_DIR .. '/' .. '.tdbg_history' or nil -- Use ANSI color codes in the prompt by default. local COLOR_GRAY = "" local COLOR_RED = "" @@ -97,11 +99,21 @@ local stack_top = 0 -- Changed using the up/down commands local stack_inspect_offset = 0 --- Default dbg.read function -local function dbg_read(prompt) - dbg.write(prompt) - io.flush() - return io.read() +-- Tarantool console compatible readline support. +local function dbg_readline(prompt) + local console = require('console.lib') + local line = console.readline({ + prompt = prompt, + completion = nil, + }) + if not line then + return nil + end + console.add_history(line) + if HISTORYFILE then + console.save_history(HISTORYFILE) + end + return line end -- Default dbg.write function @@ -1045,6 +1057,9 @@ local function start_repl() return end motto() + if HISTORYFILE then + require('console.lib').load_history(HISTORYFILE) + end started = true end @@ -1085,7 +1100,7 @@ end -- Make the debugger object callable like a function. dbg = setmetatable({ - read = dbg_read, + read = dbg_readline, write = dbg_write, writeln = dbg_writeln,