|
Hello everyone,
I've been playing around for a while to get my project linked with LuaJIT for testings. The library compliled without any problems, and I needed to make some minor changes to my source code to get rid of some vanilla Lua dependencies (I used lua_number2integer macro two times in the code). However, the first time I ran it, it crashed with segfault. Valgrind said about some unconditional jumps instead of that which may happen of course. I tried to get into the LuaJIT code to figure out what was going on, but it's not so easy from the first sight. The crash is somehow connected with a run-time error in Lua (I'm calling a non-existent function from a table, not global). The Lua code looks as the following:
------------------------------------------------------------------------------
cnt = 0
a() -- <<<<< SEGFAULT HERE!!!!
print 'start!'
if true then
if startTime then
print('RPC rate: ' .. cnt / (env.time() - startTime))
end
else
while true do
if not env.rcall('localhost', env.id() + 1000) then
break
end
end
end
print 'stop!'
------------------------------------------------------------------------------
I'm posting it as is (never mind non-standard calls and libs!) because when I remove arbitrary lines, the error goes away.
So, I decided just to post my gdb output with some details. Please note that prior to debugging, I re-compiled the library with '-O0 -g'.
Unfortunately, I can't discover the details of my project (it's not public) beside mentioning that it's written in C++ and uses coroutines heavily. Furthermore, it is clean and very stable with the native Lua 5.1.
Hope the information could be useful for LuaJIT developers. I am really intending to switch to LuaJIT because maximum performance for Lua code is urgent in my case.
Best regards,
Seny
P.S. here it goes....
-----------------------------------------------------------------------------------------------------------------------------------------
[23-04-2010 02:26:50.592] 8718 MSG esrv/1.3.1 (Apr 23 2010 01:27:49 gcc 4.4.3 20100316 (prerelease)) Linux guestlinux 2.6.33-ARCH #1 SMP PREEMPT Sun Apr 4 10:27:30 CEST 2010 x86_64
[23-04-2010 02:26:50.593] 8718 MSG Start
[New Thread 0x7ffff6831710 (LWP 8719)]
[23-04-2010 02:26:50.595] 8718 DEBUG Starting LuaProcessor(1001)
[New Thread 0x7ffff6030710 (LWP 8720)]
[Switching to Thread 0x7ffff6030710 (LWP 8720)]
Breakpoint 4, currentline (L=0x40003c70, fn=0x400021d0, nextframe=0x0) at lj_err.c:136
136 return proto_line(pt, pc);
(gdb) l
131 {
132 BCPos pc = currentpc(L, fn, nextframe);
133 if (pc != ~(BCPos)0) {
134 GCproto *pt = funcproto(fn);
135 lua_assert(pc < pt->sizebc);
136 return proto_line(pt, pc);
137 } else {
138 return -1;
139 }
140 }
(gdb) print pc
$1 = 4
(gdb) print ~(BCPos)0
$2 = 4294967295
(gdb) print pt
$3 = (GCproto *) 0x400093b0
(gdb) print *pt
$4 = {nextgc = {gcptr32 = 1073775784}, marked = 1 '\001', gct = 7 '\a', numparams = 0 '\000', framesize = 5 '\005', sizebc = 40, gclist = {gcptr32 = 0}, k = {ptr32 = 1073779904}, uv = {ptr32 = 1073779912},
sizekgc = 12, sizekn = 1, sizept = 440, sizeuv = 0 '\000', flags = 1 '\001', trace = 0, chunkname = {gcptr32 = 1073757416}, lastlinedefined = 20, sizevarinfo = 0, varinfo = {ptr32 = 1073779912}, uvname = {
ptr32 = 1073779912}, lineinfo = {ptr32 = 1073779912}}
(gdb) print pc < pt->sizebc
$5 = 1
(gdb) s
140 }
(gdb) l
135 lua_assert(pc < pt->sizebc);
136 return proto_line(pt, pc);
137 } else {
138 return -1;
139 }
140 }
141
142 static const char *getvarname(const GCproto *pt, BCPos pc, BCReg slot)
143 {
144 MSize i;
(gdb) s
err_loc (L=0x40003c70, msg=0x400084e0 "attempt to call global 'a' (a nil value)", frame=0x40008350, nextframe=0x0) at lj_err.c:826
826 err_chunkid(buff, strdata(proto_chunkname(funcproto(fn))));
(gdb) l
821 if (frame) {
822 GCfunc *fn = frame_func(frame);
823 if (isluafunc(fn)) {
824 char buff[LUA_IDSIZE];
825 BCLine line = currentline(L, fn, nextframe);
826 err_chunkid(buff, strdata(proto_chunkname(funcproto(fn))));
827 lj_str_pushf(L, "%s:%d: %s", buff, line, msg);
828 return;
829 }
830 }
(gdb) n
827 lj_str_pushf(L, "%s:%d: %s", buff, line, msg);
(gdb) n
828 return;
(gdb) n
832 }
(gdb) n
err_msgv (L=0x40003c70, em=LJ_ERR_BADOPRT) at lj_err.c:844
844 lj_err_run(L);
(gdb) s
lj_err_run (L=0x61756c2e3374) at lj_err.c:798
798 {
(gdb) l
793 return 0;
794 }
795
796 /* Runtime error. */
797 LJ_NOINLINE void lj_err_run(lua_State *L)
798 {
799 ptrdiff_t ef = finderrfunc(L);
800 if (ef) {
801 TValue *errfunc = restorestack(L, ef);
802 TValue *top = L->top;
(gdb) n
799 ptrdiff_t ef = finderrfunc(L);
(gdb) n
800 if (ef) {
(gdb) n
814 lj_err_throw(L, LUA_ERRRUN);
(gdb) n
Breakpoint 4, currentline (L=0x40003c70, fn=0x400021d0, nextframe=0x40008388) at lj_err.c:136
136 return proto_line(pt, pc);
(gdb) n
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff75448bd in currentline (L=0x40003c70, fn=0x400021d0, nextframe=0x40008388) at lj_err.c:136
136 return proto_line(pt, pc);
(gdb)
-----------------------------------------------------------------------------------------------------------------------------------------