add 'step-into-function' command
This commit is contained in:
parent
9372a5226e
commit
aa42fb1e39
@ -3,11 +3,44 @@
|
|||||||
|
|
||||||
local breakpoints = {}
|
local breakpoints = {}
|
||||||
local dbg_steps_mode = false
|
local dbg_steps_mode = false
|
||||||
|
local dbg_step_into_func = false
|
||||||
local hook_lock = false
|
local hook_lock = false
|
||||||
|
local current_func
|
||||||
|
local current_func_stack_size
|
||||||
|
|
||||||
|
local _debug_getinfo = debug.getinfo
|
||||||
|
|
||||||
|
-- 'return' hook not called for some functions
|
||||||
|
-- todo: speedup
|
||||||
|
local function calc_stack_size()
|
||||||
|
local s = debug.traceback("", 2)
|
||||||
|
local count = 0
|
||||||
|
for i in s:gmatch("\n") do
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
debug.sethook(function (e, line)
|
debug.sethook(function (e, line)
|
||||||
|
if e == "return" then
|
||||||
|
local info = _debug_getinfo(2)
|
||||||
|
if info.func == current_func then
|
||||||
|
current_func = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
if dbg_steps_mode and not hook_lock then
|
if dbg_steps_mode and not hook_lock then
|
||||||
hook_lock = true
|
hook_lock = true
|
||||||
|
|
||||||
|
if not dbg_step_into_func then
|
||||||
|
local func = _debug_getinfo(2).func
|
||||||
|
if func ~= current_func then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if current_func_stack_size ~= calc_stack_size() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
current_func = func
|
||||||
debug.breakpoint()
|
debug.breakpoint()
|
||||||
debug.pull_events()
|
debug.pull_events()
|
||||||
end
|
end
|
||||||
@ -16,13 +49,15 @@ debug.sethook(function (e, line)
|
|||||||
if not bps then
|
if not bps then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local source = debug.getinfo(2).source
|
local source = _debug_getinfo(2).source
|
||||||
if not bps[source] then
|
if not bps[source] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
current_func = _debug_getinfo(2).func
|
||||||
|
current_func_stack_size = calc_stack_size()
|
||||||
debug.breakpoint()
|
debug.breakpoint()
|
||||||
debug.pull_events()
|
debug.pull_events()
|
||||||
end, "l")
|
end, "lr")
|
||||||
|
|
||||||
local DBG_EVENT_SET_BREAKPOINT = 1
|
local DBG_EVENT_SET_BREAKPOINT = 1
|
||||||
local DBG_EVENT_RM_BREAKPOINT = 2
|
local DBG_EVENT_RM_BREAKPOINT = 2
|
||||||
@ -44,8 +79,13 @@ function debug.pull_events()
|
|||||||
debug.remove_breakpoint(event[2], event[3])
|
debug.remove_breakpoint(event[2], event[3])
|
||||||
elseif event[1] == DBG_EVENT_STEP then
|
elseif event[1] == DBG_EVENT_STEP then
|
||||||
dbg_steps_mode = true
|
dbg_steps_mode = true
|
||||||
|
dbg_step_into_func = false
|
||||||
|
elseif event[1] == DBG_EVENT_STEP_INTO_FUNCTION then
|
||||||
|
dbg_steps_mode = true
|
||||||
|
dbg_step_into_func = true
|
||||||
elseif event[1] == DBG_EVENT_RESUME then
|
elseif event[1] == DBG_EVENT_RESUME then
|
||||||
dbg_steps_mode = false
|
dbg_steps_mode = false
|
||||||
|
dbg_step_into_func = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -540,8 +580,6 @@ function file.readlines(path)
|
|||||||
return lines
|
return lines
|
||||||
end
|
end
|
||||||
|
|
||||||
local _debug_getinfo = debug.getinfo
|
|
||||||
|
|
||||||
function debug.count_frames()
|
function debug.count_frames()
|
||||||
local frames = 1
|
local frames = 1
|
||||||
while true do
|
while true do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user