[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Intermixing C-stack with Lua-stack
- From: Richter, Jörg <Joerg.Richter@...>
- Date: Mon, 30 Apr 2012 07:46:41 +0000
>I'd be curious to hear more if you have luck extracting a co-mingled C/Lua
>stack reliably. I've considered taking a crack at that myself.
My use-case is to get a backtrace from the running process. It would be
best if there is a solution that works from signal-handlers. But that is
optional.
So I tried to solve the problem and got some nice results. I've used
libunwind to find all luaV_execute calls and to query all
callee-safed registers. The lua_State pointer happened to be in
RBX (x86_64). From there it was easy to call lua_debug&co.
Of course the register isn't fixed. But for one set of
optimisation-settings it should always be se same, I think.
And the case that the lua_State pointer isn't saved to the stack
is also possible. Then you have to modify luaV_execute to force L
to be pushed on the stack somehow.
The next problem is to identify which Lua calls belong to this
luaV_execute call. This should be easy to solve. Just print the
Lua function till the first C-function. The next time you hit
luaV_execute with the same L-pointer print the next Lua-functions
until the second C-function. And so forth. Might be harder, I haven't
implemented it yet.
A more portable solution might be to let the luaV_execute function
register its activation record somewhere and use this information
instead of the stack peeking.
Jörg