I have a C++ application (for OS X) that calls lua as a scripting language.
I’m running a large number of these applications (100s) and they can run
for a very long time (days or weeks).
Sometimes one crashes. And when it crashes it leaves me a lovely core file.
I can open this core file in gdb and find where the application crashes.
I can walk the call stack and find an instance of a lua_State variable.
My problem is that I’d like to see what the lua call stack looks like at
this time…
Keep in mind that since this is a core I don’t have access to calling C functions, which rules out several of the usual ways of debugging lua scripts.
Id like to avoid adding manual traces through debug hooks as I’m worried about the additional performance penalties, and added complexity.
How can I traverse the lua internal structures to get at call stack information?
I’ve created a GDB script to do the stuff in the web page linked to by macs. Its not beautiful, and should probably be properly wrapped into a function etc, but here it is for the curious.
NOTE: It seems that the web page is wrong about the filename for lua functions. In the case where the string comes from
luaL_dofile()the filename starts with a@symbol. If they’re called fromlua_dostring(). In that case the$filenamevariable is set to the whole of the string passed tolua_dostring()– and the user is probably only interested in one or two lines of context from that file. I wasn’t sure how to fix that up.This outputs something like:
When I debug the crash from this code:
With
a.luaand b.lua