Debugging segfault in luajit

477 views
Skip to first unread message

Aleksandar Kordic

unread,
Oct 26, 2014, 2:43:11 PM10/26/14
to open...@googlegroups.com
Hi,

I am encountering segfault in my application embedding luajit2. Here is how C stack trace looks like at segfault moment:
> lj_debug_funcname(lua_State * L=0x0000000002140a88, const TValue * frame=0x00000000004c0378, const char * * name=0x0000000140a0fa78)  Line 305 + 0x10 bytes C
  lj_debug_getinfo(lua_State * L=0x00000000004c0378, const char * what=0x0000000000000000, lj_Debug * ar=0x0000000002218080, int ext=0)  Line 485 + 0x14 bytes C
  luaL_traceback(lua_State * L=0x00000000004c0378, lua_State * L1=0x0000000002140a88, const char * msg=0x00000000025f2e28, int level=4981624)  Line 677 C
  lj_cf_debug_traceback(lua_State * L=0x00000000004c0f98)  Line 394 C
  lj_BC_FUNCC()  + 0x32 bytes
  lua_pcall(lua_State * L=0x0000000000000000, int nargs=8, int nresults=0, int errfunc=0)  Line 1042 C
  docall(lua_State * L=0x00000000004c0378, int narg=0, int clear=-1)  Line 124 C
  handle_script(lua_State * L=0x00000000004c0378, char * * argv=0x00000000004c0378, int n=0)  Line 289 + 0x11 bytes C
  pmain(lua_State * L=0x0000000000000000)  Line 544 + 0xe bytes C
  lj_BC_FUNCC()  + 0x32 bytes
  lua_cpcall(lua_State * L=0x00000000004c0378, int (lua_State *)* func=0x00000000022288e0, void * ud=0x00000001409fe3d0)  Line 1064 C

I need to determine the Lua stack trace. I am using this function for that purpose:

void __lua_stacktrace__(lua_State* L)
{
lua_Debug entry;
int depth = 0;

while (lua_getstack(L, depth, &entry))
{
int status = lua_getinfo(L, "nSlu", &entry);
//assert(status);
printf("[%d] %s(%d): %s\n", depth, entry.short_src, entry.currentline, entry.name ? entry.name : "?");
++depth;
}

printf("print complete\n");
}

But something goes wrong when executing __lua_stacktrace__(L); 
  Access violation reading location 0x0000000000000010.

Is it possible that lua_State * is not in consistent state?

What tools or code can I use to find Lua stack trace at time of the crash ?

Is there a place where I can insert code to save current Lua stack trace on every Lua instruction ? so that I cal look at saved stack trace(last stack trace) even when lua_State * is inconsistent.

Thanks,
Alex

Yichun Zhang (agentzh)

unread,
Oct 27, 2014, 3:11:46 PM10/27/14
to openresty
Hello!

On Sun, Oct 26, 2014 at 11:43 AM, Aleksandar Kordic wrote:
> I am encountering segfault in my application embedding luajit2. Here is how
> C stack trace looks like at segfault moment:

You should find the tools in our nginx-gdb-utils project useful:

https://github.com/openresty/nginx-gdb-utils

I used to use the tools there to help Mike Pall nail down quite some
really deep and obscure bugs in the JIT compiler that have hidden for
years :)

In addition, always try using valgrind to run your app with a luajit
using system allocator to ensure there is no low hanging fruit :) Most
of the time, it is just a low hanging fruit in your own app's code.
Also, ensure your luajit is the latest one in the git repos to avoid
hitting a bug that has already been fixed in the git repos.

Good luck!

Regards,
-agentzh
Reply all
Reply to author
Forward
0 new messages