Re: Stack trace on SIGSEGV?

  • From: Mike Pall <mike-1210@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 8 Oct 2012 11:07:38 +0200

Luke Gorrie wrote:
> Is there an easy trick to print a Lua stack trace when I hit a
> SIGSEGV? This would be convenient when debugging FFI code that hits
> invalid pointers.

Well, that gets tricky when you have to deal with JIT-compiled
frames. You could just call luaL_traceback() in the signal
handler. It won't catch the locations for JIT-compiled frames, but
that's still better than nothing. Oh, and you better not continue
execution after that -- the Lua state may be messed up.

> Perhaps somebody has a clever hack for runtime bounds checking on
> pointer arithmetic, even?

Wrap pointers in a struct and use bounds-checking metamethods. But
prepare to disable that for production -- it may cause unacceptable
slowdowns, depending on how you do it.

--Mike

Other related posts: