How to get the line number of an error from crash address in LuaJIT bytecode

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

How to get the line number of an error from crash address in LuaJIT bytecode

Baozeng
Hello all, 
Without debug information, it cannot get the line number when an error occurs. For instance.
A simple test.lua:
a = 5
a.x = 8

When running  with the source code(luajit test.lua) or the bytecode generated with debuginfo( luajit -bg test.lua test.bc), it shows:

luajit: test.lua:2: attempt to index global 'a' (a number value)

stack traceback:

        test.lua:2: in main chunk

        [C]: at 0x004048f0


But when I generate the bytecode  with `-b`(luajit -b test.lua test.bc), and run the bytecode, it shows:

stack traceback:

        test.bc: in function <test.bc:0>

        [C]: at 0x004048f0


It cannot get the line number of the error since there is no debug information in the bytecode. Then how to get the line number of an error without debug information in LuaJIT bytecode since I only want to release my LuaJIT scripts generated by '-b'. 


One way is to release the '-b' version and keep the '-bg' version locally. When there is an error stack trace occurs from the `-b` version,  we can get the line number from the '-bg' version. Then the question is: how can we get the line number from the PC, (just like 0x004048f0) above? Are there any tool in LuaJIT similar to addr2line in C? Thanks. 

--
     Best Regards,
     Baozeng Ding
                                                                
Reply | Threaded
Open this post in threaded view
|

Re: How to get the line number of an error from crash address in LuaJIT bytecode

Baozeng
Sorry I should send the mail to luajit mailing list. Ignore the above email.

Baozeng <[hidden email]> 于2019年7月2日周二 下午3:06写道:
Hello all, 
Without debug information, it cannot get the line number when an error occurs. For instance.
A simple test.lua:
a = 5
a.x = 8

When running  with the source code(luajit test.lua) or the bytecode generated with debuginfo( luajit -bg test.lua test.bc), it shows:

luajit: test.lua:2: attempt to index global 'a' (a number value)

stack traceback:

        test.lua:2: in main chunk

        [C]: at 0x004048f0


But when I generate the bytecode  with `-b`(luajit -b test.lua test.bc), and run the bytecode, it shows:

stack traceback:

        test.bc: in function <test.bc:0>

        [C]: at 0x004048f0


It cannot get the line number of the error since there is no debug information in the bytecode. Then how to get the line number of an error without debug information in LuaJIT bytecode since I only want to release my LuaJIT scripts generated by '-b'. 


One way is to release the '-b' version and keep the '-bg' version locally. When there is an error stack trace occurs from the `-b` version,  we can get the line number from the '-bg' version. Then the question is: how can we get the line number from the PC, (just like 0x004048f0) above? Are there any tool in LuaJIT similar to addr2line in C? Thanks. 

--
     Best Regards,
     Baozeng Ding
                                                                


--
     Best Regards,
     Baozeng Ding