[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Using debug.sethook() across coroutines
- From: Paul K <paulclinger@...>
- Date: Fri, 15 Feb 2013 17:08:20 -0800
> Once the coroutine starts my sethook callback (covHandler) is no longer
hit. I see no callbacks for calls inside of "calledInt()". Any help or
suggestions would be MUCH appreciated.
You need to call debug.sethook for each coroutine. You can pass coroutine as the first parameter to debug.sethook.
If you want to avoid modifying your existing code, you need to overwrite coroutine.create with your own version that enables the hook. I have something similar in Mobdebug that may work for you:
local function coro()
local cocreate = coroutine.create
coroutine.create = function(f, ...)
debug.sethook(coroutine.running, covHandler, "l")
You can check inside your debug hook if it is called from a coroutine by using coroutine.running. This is not tested, but you should get an idea.
On Fri, Feb 15, 2013 at 4:25 PM, Moore, Tysen <Tysen.Moore@xs-embedded.com>
I am writing a simple Lua coverage script to gauge the coverage of my Lua source code. I have found that it works fairly well when I have a simple test file that executes without
coroutines. When I run the same tool against more complex code that has coroutines I find the sethook callbacks ends. Is there a way to use sethook that will work across coroutines without modifying my original source code? I'd prefer not to modify the
code I am profiling. Or is there anyway to get this to work?
Basically the code does the following:
> lua lcov.lua main.lua
local f = assert( loadfile(fileToExec) ) -- execute main.lua
debug.sethook(covHandler, "l" )
f() -- run the main program
(I've also tried just: dofile( fileToExec ) for what it's worth)
main.lua does the following:
function calledInt( fmt, ... )
local msg = string.format(fmt, unpack(arg))
local function main()
calledInt("Value: %d", 0)
local co = coroutine.create( main )
coroutine.resume( co )
Once the coroutine starts my sethook callback (covHandler) is no longer hit. I see no callbacks for calls inside of "calledInt()". Any help or suggestions would be MUCH appreciated.
|XS Embedded LLC
Managing Director: Joachim Kobinger
|Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain
confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.