lua-users home
lua-l archive

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


Actually now I have the complete scenario with me and this can “possibly” be a bug with lua 5.0. This is a long mail so please bear with me.

 

First a background of the application (can’t tell the full details due to NDA requirements). We needed an embedded visual studio debugger for lua since we are currently using it for our game. Since we register a lot of things in the lua_State therefore for our debugger to work properly, it was required that the application load the debugger dll and provide it with the VM instance to be debugged.  The debugger dll communicates with the visual studio addin via an IPC mechanism. The debugger dll basically halts the application in the hook procedure and communicates with the addin sending values of requested global/local variables back to the addin (providing a watch window), amongst other functionality like step in, step out etc.

Our game scripts are nested i.e. one scripts calls another (via a registered C function), which in turn calls another and so on (upto a certain level, ofcourse).

The problem arrives when the user requests a global variable that does not exist and lua returns a nil value when I call lua_getglobal() in the debugger dll. After this several executions of these nested scripts causes lua to crash (the call stack that I sent in an earlier mail). I have repeatedly checked the integrity of the stack and am positive that nothing outrageous is being done to the stack. If the global variable to be queried does exist in the global table, then the application runs as desired. If there are no nested scripts (i.e. no lua_dofile s being called from within a script) then all sorts of scenarios work perfectly).

I am frankly out of ideas and am convinced that this is a lua runtime bug! I welcome suggestions and comments. The deadline of the project is looming and I need your help. Any help is highly appreciated.

 

Regards,

Zulfiqar Inayat Malik.

 


From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Chou Eric
Sent: Wednesday, February 15, 2006 6:31 AM
To: Lua list
Subject: Re: Hook procedure problem

 

Maybe the scprit which lua_dofile() takes has some run-time error, try to use lua_atpanic() to hook error, deal it with your own error hook function. Then you can get the error message from the stack top and print it.

On 2/14/06, D Burgess <dburgess@gmail.com> wrote:

are you using setjmp/longjmp or try/throw? C or C++?

Db

On 2/14/06, Zulfiqar Malik <zulfiqar.malik@itrango.com> wrote:
>
>
>
> I mailed this scenario a month or so earlier but got no replies. Now the
> problem is haunting me again and I need urgent help.
>
> Coming to the point, I have an in-house debugger integrated in visual studio
> that I use to debug our game scripts. Its an embedded debugger that uses lua
> hooks for debugging purposes (uses LUA_MASKLINE | LUA_MASKCALL |
> LUA_MASKRET). The problem arises when I am in the middle of a debugging
> session (i.e. inside the hook procedure), executing the code step by step,
> when a particular line of lua code calls a C function which in turns calls
> lua_dofile(…) on another script file. In such a scenario, the application
> crashes! The entire call stack that is accessible to me is give in the end.
> I can't seem to figure out the problem. Can someone help me out please? Is
> there something that I am doing wrong or is it a lua bug? Thanks in advance.
>
>
>
>        ntdll.dll!7c901230 ()
>
>        ntdll.dll!7c96c943()
>
>        ntdll.dll!7c96cd80()
>
>        ntdll.dll!7c96df66()
>
>        ntdll.dll!7c94a5d0()
>
>        ntdll.dll!7c9268ad()
>
>        msvcr71.dll!free(void * pBlock=0x01365f58)  Line 103   C
>
>        MJ Game.exe!_luaM_realloc()  + 0x1d
>
>        MJ Game.exe!_luaC_sweep()  + 0x11f
>
>        MJ Game.exe!_luaC_sweep()  + 0x7d
>
>        MJ Game.exe!_luaC_sweep()  + 0x188
>
>        MJ Game.exe!_luaC_sweep()  + 0x28
>
>        MJ Game.exe!_luaC_collectgarbage()  + 0x16
>
>        MJ Game.exe!_luaV_execute()  + 0x37c
>
>        MJ Game.exe!_luaD_call()  + 0x4b
>
>        MJ Game.exe!_lua_pcall()  + 0x75
>
>        MJ Game.exe!_luaD_rawrunprotected()  + 0x3a
>
>        MJ Game.exe!_luaD_pcall()  + 0x41
>
>        MJ Game.exe!_lua_pcall()  + 0x55
>
>        MJ Game.exe!_lua_dofile()  + 0x3a
>
>        MJ Game.exe!_lua_dofile()  + 0x17
>
>        MJ Game.exe!cHSExecuteScript(lua_State * L=0x013c8be8)  Line 3892 +
> 0x10   C++
>
>        MJ Game.exe!_luaD_precall()  + 0x160
>
>        MJ Game.exe!_luaV_execute()  + 0x9fd
>
>        MJ Game.exe!_luaD_call()  + 0x4b
>
>        MJ Game.exe!_lua_pcall()  + 0x75
>
>        MJ Game.exe!_luaD_rawrunprotected()  + 0x3a
>
>        MJ Game.exe!_luaD_pcall ()  + 0x41
>
>        MJ Game.exe!_lua_pcall()  + 0x55
>
>        MJ Game.exe!_lua_dofile()  + 0x3a
>
>        MJ Game.exe!_lua_dofile()  + 0x17
>
>        MJ Game.exe!cHSExecuteScript (lua_State * L=0x013c8be8)  Line 3892 +
> 0x10   C++
>
>        MJ Game.exe!_luaD_precall()  + 0x160
>
>        MJ Game.exe!_luaV_execute()  + 0x9fd
>
>        MJ Game.exe!_luaD_call ()  + 0x4b
>
>        MJ Game.exe!_lua_pcall()  + 0x75
>
>        MJ Game.exe!_luaD_rawrunprotected()  + 0x3a
>
>        MJ Game.exe!_luaD_pcall()  + 0x41
>
>        MJ Game.exe!_lua_pcall ()  + 0x55
>
>        MJ Game.exe!_lua_dofile()  + 0x3a
>
>        MJ Game.exe!_lua_dofile()  + 0x17
>
>        MJ Game.exe!cHSExecuteScript(lua_State * L=0x013c8be8)  Line 3892 +
> 0x10   C++
>
>        MJ Game.exe!_luaD_precall()  + 0x160
>
>        MJ Game.exe!_luaV_execute()  + 0x9fd
>
>        MJ Game.exe!_luaD_call()  + 0x4b
>
>        MJ Game.exe!_lua_pcall ()  + 0x75
>
>        MJ Game.exe!_luaD_rawrunprotected()  + 0x3a
>
>        MJ Game.exe!_luaD_pcall()  + 0x41
>
>        MJ Game.exe!_lua_pcall()  + 0x55
>
>        MJ Game.exe!_lua_dofile ()  + 0x3a
>
>        MJ Game.exe!_lua_dofile()  + 0x17
>
>        MJ Game.exe!cHSExecuteScript(lua_State * L=0x013c8be8)  Line 3892 +
> 0x10   C++
>
> >      Helios_1_0.dll!_luaD_precall()  + 0x160
>
>        Helios_1_0.dll!_luaV_execute()  + 0x9fd
>
>        Helios_1_0.dll!_luaD_call()  + 0x4b
>
>        Helios_1_0.dll!_lua_pcall()  + 0x75
>
>        Helios_1_0.dll!_luaD_rawrunprotected()  + 0x3a
>
>        Helios_1_0.dll!_luaD_pcall()  + 0x41
>
>        Helios_1_0.dll!_lua_pcall()  + 0x55
>
>        Helios_1_0.dll!_lua_dofile()  + 0x3a
>
>        Helios_1_0.dll!_lua_dofile()  + 0x17
>
>        Helios_1_0.dll!HCScriptManager::ExecFile(const char
> * pszFileName=0x00471f04)  Line 76 + 0x10   C++
>
>        MJ Game.exe!GameAppCB(HCWnd * poWnd=0x00000000, unsigned int
> uiMsg=1000, int wParam=1244496, int lParam=0)  Line 1490 + 0x14 C++
>
>        MJ Game.exe!GameLoop()  Line 1786 C++
>
>        MJ Game.exe!SDL_main(int argc=1, char * * argv=0x0012fee0)  Line 639
> C++
>
>        MJ Game.exe!_main()  + 0xd9 C
>
>        MJ Game.exe!_WinMain@16()  + 0x1cc C
>
>        MJ Game.exe!WinMainCRTStartup()  Line 390 + 0x1b       C
>
>        kernel32.dll!7c816d4f()
>
>        ntdll.dll!7c915b4f ()
>
>        kernel32.dll!7c8399f3()
>
>
>
> Regards,
>
> Zulfiqar Inayat Malik.




--
Best Regards
Eric

Mailto: EricChou.Cpp@gmail.com
MSN:  storm_joe@hotmail.com