Getting lua stack trace after a crash

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting lua stack trace after a crash

Abhijit Nandy
Hi,

We have a C/C++ application that embeds lua. Some of our business logic is in Lua. We use luabind to bind our C++ classes to Lua. If there is a crash, we would like to get a lua trace as well, to see what part of the business logic initiated the call into C++.

Has anyone tried to get a lua stack trace in the event of a crash in the C/C++ side in Windows/Linux? Say due to a nullptr. 
Do the normal Lua C APIs work for this if the crash was in some C++ code not related to lua or luabind - like if some C++ function was getting called and that had a bug?

Thanks,
Abhijit
Reply | Threaded
Open this post in threaded view
|

Re: EXT SENDER - Getting lua stack trace after a crash

Chodera, Ian
Hi Abhjit

I don't use luabind, but my interfaces to my c++ code tend to look like this

int
luaFunction (lua_State *L)
{
   try
   {
         int luaParamCount = lua_gettop(L)  ;
         if  (luaParamCount  >= 1 && luaParams <= 2) 
         {
              int param1 = lua_tointeger (L, 1) ; // always
              int param2 = luaParamCount  > 1 ? lua_tointeger (L, 2) : 0 ; // optional with default

              CPPObject->PublicFunction  (param1, param2) ;
         }
         else
         {
             throw Exception ("Wrong no of parameters") ;
         }
    }
    catch (Exception& e)
    {
        luaL_error (L, (string ("luaFunction:") + e.Message).c_str ()) ;
    }

    return 0 ;
}

Any error in my C++ functions results in a 'throw Exception ()' - which then reports neatly as a Lua error.

HTH. Regards
Ian



From: Abhijit Nandy <[hidden email]>
Sent: 17 November 2020 07:21
To: Lua mailing list <[hidden email]>
Subject: EXT SENDER - Getting lua stack trace after a crash
 
Hi,

We have a C/C++ application that embeds lua. Some of our business logic is in Lua. We use luabind to bind our C++ classes to Lua. If there is a crash, we would like to get a lua trace as well, to see what part of the business logic initiated the call into C++.

Has anyone tried to get a lua stack trace in the event of a crash in the C/C++ side in Windows/Linux? Say due to a nullptr. 
Do the normal Lua C APIs work for this if the crash was in some C++ code not related to lua or luabind - like if some C++ function was getting called and that had a bug?

Thanks,
Abhijit