lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Tysen,

> 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, ...)
    return cocreate(function(...)
      debug.sethook(coroutine.running, covHandler, "l")
      return f(...)
    end, ...)
  end
end

coro()

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.

Paul.

On Fri, Feb 15, 2013 at 4:25 PM, Moore, Tysen <Tysen.Moore@xs-embedded.com> wrote:
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

lcov.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))
    print("calledInt: "..msg)

end

local function main()
    calledInt("Value: %d", 0)
end

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.

Tysen


XSe Logo

XS Embedded LLC
28850 Cabot Drive, Suite 1000
Novi, MI 48377
USA

Phone +1 (248) 209 - 6613
Fax +1 (248) 281 - 7020

www.xs-embedded.com
Tysen.Moore@xs-embedded.com

:::::::::: based.on.visions ::::::::::

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.