[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Low-level access to the innards
- From: Dan Tull <dtull@...>
- Date: Wed, 9 Jan 2013 12:22:14 -0800
> Suppose that we've set a breakpoint in math_sin, and then we ran
> this Lua code:
outer_fun = function (a, b)
local c, d, e = "CC", "DD", "EE"
return 1 + inner_fun("FF", "GG")
end
inner_fun = function (f, g)
local h, i, j = "HH", "II", "JJ"
return math.sin(0)
end
twentytwo = "22"
twentytwon = 22
outer_fun("AA", "BB")
> So now we are at the GDB prompt, in math_sin ...
> So, it _must_ be possible to start from just L ...through
> a contorted series of array and field accesses...
> 1) the value of the variable "twentytwo" (as a string),
> 2) the value of the variable "twentytwon" (as a number),
> 3) the name of the variable "twentytwo" (as a string),
> 4) the value of the parameter "g" of inner_fun,
> 5) the name - "g" - of the second parameter of inner_fun,
> 6) the value of the local variable "e" of outer_fun,
> 7) the name of the local variable "e" of outer_fun.
I've been known to do things of this sort in gdb/lldb. The same
techniques are also useful in WinDbg for doing post mortem on
a full memory dump of a crashed or hung process.
I even had a (really, really, ugly) blob of WinDbg hackery
that would dump out the Lua call stack at a particular point*
so I could track down a tricky hang.
> Think that your expressions will be used to explain the data
> structures of Lua...and they can sort of complement texts like:
>
> http://luaforge.net/docman/83/98/ANoFrillsIntroToLua51VMInstructions.pdf
> http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/jucs05.pdf
So are you writing such a doc and using this post as a means
to crowd source some of the content?
I can't help but feel I'm being tricked into doing somebody
else's homework... ;o)
On a related note, I've considered composing a series of gdb/lldb
console or Visual Studio immediate window macros* to make it
easier to access certain commonly interesting pieces of Lua state
information in a native debugger, which entails a similar enumeration
and generalization of recipes for such internal access.
Which is as good a time as any to ask: has somebody else already done
and shared such a thing? (I wouldn't want to duplicate effort)
Dan Tull
Lua Tools Dev
Adobe
* Note I've seen such things done by calling functions, but often they
result in crashing the app in the debugger due to using the Lua state
while it is potentially in the middle of doing something else. My method
was directly reading the structures to avoid bad side effects. Also, you
it works on a memory dump where you can't call functions.
Looks like I'm not alone:
http://zeuxcg.org/2010/11/07/lua-callstack-with-c-debugger/