Discussion:
Possible Bug in debug.sethook()
Patrick Barrett
2014-09-13 01:09:01 UTC
Permalink
Not sure if this is actual bug or if everything is just being JITed away, but
it's unexpected
behavior none the less.

Setting a debug hook to trigger on a function that does a while(1) without any
significant
code inside the loop will never trigger the debug hook. Note, adding a print
statement to the
loop in the test code, below, does have the debug hook trigger.

Tested in 2.0.3 and git HEAD. Does not occur in PUC-Rio 5.2.3 (ie, hook does
trigger).

Test Case:
-----------------------------------------------------------------
CPU_TIME_LIMIT = 0.0001

function fn()
while true do
end
end

local execution_time_limiter = function()
local start_time = os.clock()
return function()
if os.clock() - start_time > CPU_TIME_LIMIT then
error("killed", 0)
end
end
end

local co = coroutine.create(fn)
debug.sethook(co, execution_time_limiter(), "", 1000)
local status, err = coroutine.resume(co)

print(status, err)
-----------------------------------------------------------------
Paul K
2014-09-13 01:54:32 UTC
Permalink
Hi Patrick,
Post by Patrick Barrett
Setting a debug hook to trigger on a function that does a while(1) without any
significant code inside the loop will never trigger the debug hook.
Try with jit.off(); see
http://www.freelists.org/post/luajit/Debug-hooks-and-JIT,2

Paul.
Post by Patrick Barrett
Not sure if this is actual bug or if everything is just being JITed away, but
it's unexpected
behavior none the less.
Setting a debug hook to trigger on a function that does a while(1) without any
significant
code inside the loop will never trigger the debug hook. Note, adding a print
statement to the
loop in the test code, below, does have the debug hook trigger.
Tested in 2.0.3 and git HEAD. Does not occur in PUC-Rio 5.2.3 (ie, hook does
trigger).
-----------------------------------------------------------------
CPU_TIME_LIMIT = 0.0001
function fn()
while true do
end
end
local execution_time_limiter = function()
local start_time = os.clock()
return function()
if os.clock() - start_time > CPU_TIME_LIMIT then
error("killed", 0)
end
end
end
local co = coroutine.create(fn)
debug.sethook(co, execution_time_limiter(), "", 1000)
local status, err = coroutine.resume(co)
print(status, err)
-----------------------------------------------------------------
Patrick Barrett
2014-09-13 04:34:33 UTC
Permalink
Do'h. Don't know how I could have missed that in my searching. Thanks Paul.
Post by Paul K
Hi Patrick,
Post by Patrick Barrett
Setting a debug hook to trigger on a function that does a while(1) without any
significant code inside the loop will never trigger the debug hook.
Try with jit.off(); see
http://www.freelists.org/post/luajit/Debug-hooks-and-JIT,2
Paul.
Loading...