From 059455829d45e042d71f7d0cb2a7ab1d5e3bd188 Mon Sep 17 00:00:00 2001 From: Alexey Romanoff Date: Sun, 18 Jul 2021 10:05:01 +0300 Subject: [PATCH 1/2] fix source paths by trying to match optionally defined local and remote root directories --- src/mobdebug.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/mobdebug.lua b/src/mobdebug.lua index 36fa14c..4f2acfe 100644 --- a/src/mobdebug.lua +++ b/src/mobdebug.lua @@ -26,6 +26,8 @@ local mobdebug = { checkcount = 200, yieldtimeout = 0.02, -- yield timeout (s) connecttimeout = 2, -- connect timeout (s) + remote_root_dir = nil, + local_root_dir = nil, } local HOOKMASK = "lcr" @@ -338,8 +340,16 @@ local function stack(start) if src:find("%./") == 1 then src = src:sub(3) end end + if + mobdebug.remote_root_dir + and src:find(mobdebug.remote_root_dir, 1, true) == 1 + then + src = (mobdebug.local_root_dir or "") + .. src:sub(#mobdebug.remote_root_dir + 1) + end + table.insert(stack, { -- remove basedir from source - {source.name, removebasedir(src, basedir), + {source.name, src, linemap and linemap(source.linedefined, source.source) or source.linedefined, linemap and linemap(source.currentline, source.source) or source.currentline, source.what, source.namewhat, source.short_src}, @@ -638,7 +648,14 @@ local function debug_hook(event, line) -- what is the filename and what is the source code. -- If the name doesn't start with `@`, assume it's a file name if it's all on one line. if find(file, "^@") or not find(file, "[\r\n]") then - file = gsub(gsub(file, "^@", ""), "\\", "/") + if + mobdebug.remote_root_dir + and file:find(mobdebug.remote_root_dir, 1, true) == 2 + then + file = (mobdebug.local_root_dir or "") + .. file:sub(#mobdebug.remote_root_dir + 2) + end + file = gsub(gsub(file, "^@", mobdebug.local_root_dir or ""), "\\", "/") -- normalize paths that may include up-dir or same-dir references -- if the path starts from the up-dir or reference, -- prepend `basedir` to generate absolute path to keep breakpoints working. From 384ad3e023ab5f9a4a85deca1f032e69fd24877c Mon Sep 17 00:00:00 2001 From: Alexey Romanoff Date: Wed, 12 Jan 2022 12:35:02 +0300 Subject: [PATCH 2/2] src/mobdebug.lua: add optional user breakpoint preprocessor --- src/mobdebug.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/mobdebug.lua b/src/mobdebug.lua index 4f2acfe..6dea171 100644 --- a/src/mobdebug.lua +++ b/src/mobdebug.lua @@ -28,6 +28,8 @@ local mobdebug = { connecttimeout = 2, -- connect timeout (s) remote_root_dir = nil, local_root_dir = nil, + breakpoint_preprocessor = nil, + breakpoint_preprocess_unroller = nil, } local HOOKMASK = "lcr" @@ -361,6 +363,9 @@ end local function set_breakpoint(file, line) if file == '-' and lastfile then file = lastfile elseif iscasepreserving then file = string.lower(file) end + if mobdebug.breakpoint_preprocessor then + file, line = mobdebug.breakpoint_preprocessor(file, line) + end if not breakpoints[line] then breakpoints[line] = {} end breakpoints[line][file] = true end @@ -369,10 +374,16 @@ local function remove_breakpoint(file, line) if file == '-' and lastfile then file = lastfile elseif file == '*' and line == 0 then breakpoints = {} elseif iscasepreserving then file = string.lower(file) end + if mobdebug.breakpoint_preprocessor then + file, line = mobdebug.breakpoint_preprocessor(file, line) + end if breakpoints[line] then breakpoints[line][file] = nil end end local function has_breakpoint(file, line) + if mobdebug.breakpoint_preprocessor then + file, line = mobdebug.breakpoint_preprocessor(file, line) + end return breakpoints[line] and breakpoints[line][iscasepreserving and string.lower(file) or file] end @@ -711,7 +722,13 @@ local function debug_hook(event, line) vars = vars or capture_vars(1) step_into = false step_over = false - status, res = cororesume(coro_debugger, events.BREAK, vars, file, line) + local event_file, event_line + if mobdebug.breakpoint_preprocess_unroller then + event_file, event_line = mobdebug.breakpoint_preprocess_unroller(file, line) + else + event_file, event_line = file, line + end + status, res = cororesume(coro_debugger, events.BREAK, vars, event_file, event_line) end -- handle 'stack' command that provides stack() information to the debugger