Beispiel #1
0
        protected unsafe void DebugHook(UIntPtr L, IntPtr ptr) //unsafe for speed
        {
            LuaStackRecord *sr = (LuaStackRecord *)ptr;

            BBLua.lua_getstack(L, 0, ptr);
            if (sr->debugEvent == LuaEvent.Call)
            {
                this.callStack++;
            }
            else if (sr->debugEvent == LuaEvent.Return || sr->debugEvent == LuaEvent.TailReturn)
            {
                this.callStack--;

                if ((this.callStack == 0) && //stepping into engine code is not possible -> resume
                    (this.CurrentRequest == DebugRequest.StepIn || this.CurrentRequest == DebugRequest.StepToLevel))
                {
                    this.CurrentRequest = DebugRequest.Resume;
                    this.CurrentState   = DebugState.Running;
                    FireStateChangedEvent();
                }
            }
            // event == line
            else if (this.CurrentRequest == DebugRequest.Pause || this.CurrentRequest == DebugRequest.StepIn)
            {
                NormalBreak();
            }
            else if (this.CurrentRequest == DebugRequest.StepToLevel && (this.callStack <= this.targetCallStackLevel))
            {
                NormalBreak();
            }
            // request == resume
            else
            {
                List <Breakpoint> bpsAtLine;
                if (!this.lineToBP.TryGetValue(sr->currentline, out bpsAtLine))
                {
                    return; //no breakpoints on this line
                }
                BBLua.lua_getinfo(L, "S", ptr);
                LuaDebugSourceRecord dr = (LuaDebugSourceRecord)Marshal.PtrToStructure(ptr, typeof(LuaDebugSourceRecord));

                foreach (Breakpoint bp in bpsAtLine)
                {
                    if (bp.File.Filename == dr.source)
                    {
                        NormalBreak();
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        public static LuaFunctionInfo ReadFunctionInfo(LuaState ls, int level)
        {
            IntPtr memBlock = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LuaDebugRecord)));

            if (BBLua.lua_getstack(ls.L, level, memBlock) == 0)
            {
                return(null);
            }
            BBLua.lua_getinfo(ls.L, "nSlu", memBlock);
            LuaDebugRecord ldr = (LuaDebugRecord)Marshal.PtrToStructure(memBlock, typeof(LuaDebugRecord));

            LuaFunctionInfo lfi = new LuaFunctionInfo(memBlock, ls, ldr.nups);

            if (ldr.source.Length > 1 && ldr.source[0] != '=')
            {
                lfi.Source = ldr.source;
                lfi.Line   = ldr.currentline;
            }
            else
            {
                lfi.Source = "unavailable";
                lfi.Line   = 0;
            }

            if (ldr.what == "C")
            {
                lfi.FunctionName = "Game Engine (direct call)";
            }
            else if (ldr.what == "main")
            {
                lfi.FunctionName = "Game Engine (code outside function)";
            }
            else if (ldr.name != "" && ldr.namewhat != "")
            {
                lfi.FunctionName = ldr.namewhat + " " + ldr.name + "()";
            }
            else if (ldr.what == "Lua" || ldr.what == "tail")
            {
                lfi.FunctionName = "Lua Code";
            }


            if (ls.LoadedFiles.ContainsKey(lfi.Source))
            {
                lfi.CanFakeEnvironment = true;
            }

            return(lfi);
        }
Beispiel #3
0
        public void FakeG()
        {
            this.fakedLocals   = new List <FakeVar>();
            this.fakedUpvalues = new List <FakeVar>();
            if (!this.CanFakeEnvironment)
            {
                return;
            }

            string varName;

            BBLua.lua_getinfo(ls.L, "f", this.funcInfo); // 'f': pushes func onto stack

            for (int i = 1; ; i++)
            {
                varName = BBLua.lua_getupvalue(ls.L, -1, i);
                if (varName == null)
                {
                    break;
                }
                TryFakeVar(varName, i, this.fakedUpvalues);
            }

            BBLua.lua_settop(ls.L, -2); //remove func from stack

            for (int i = 1; ; i++)
            {
                varName = BBLua.lua_getlocal(ls.L, this.funcInfo, i);
                if (varName == null)
                {
                    break;
                }
                if (varName.Length > 0 && varName[0] != '(')
                {
                    TryFakeVar(varName, i, this.fakedLocals);
                }
                else
                {
                    BBLua.lua_settop(ls.L, -2); //remove value
                }
            }
        }
        protected string GetTosFunctionInfo()
        {
            IntPtr memBlock = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LuaDebugRecord)));

            BBLua.lua_getinfo(this.L, ">nSf", memBlock); //fill structure and pop func back onto stack after removing it
            LuaDebugRecord ldr = (LuaDebugRecord)Marshal.PtrToStructure(memBlock, typeof(LuaDebugRecord));

            Marshal.FreeHGlobal(memBlock);

            string source;

            if (ldr.what == "C")
            {
                source = "Game Engine at 0x" + BBLua.lua_tocfunction(this.L, -1).ToInt32().ToString("X");
            }
            else
            {
                source = '\b' + ldr.source + ':' + ldr.linedefined + '\b';//" (line " + ldr.linedefined + ")";
            }
            return("<Function, defined in " + source + ">");
        }
Beispiel #5
0
        public void UnFakeG()
        {
            if (!this.CanFakeEnvironment)
            {
                return;
            }

            BBLua.lua_getinfo(ls.L, "f", this.funcInfo); // 'f': pushes func onto stack

            foreach (FakeVar fv in this.fakedUpvalues)
            {
                GetVarAndCleanG(fv.VarName);
                string vn = BBLua.lua_setupvalue(ls.L, -2, fv.Number);
            }

            BBLua.lua_settop(ls.L, -2); //remove func

            foreach (FakeVar fv in this.fakedLocals)
            {
                GetVarAndCleanG(fv.VarName);
                string vn = BBLua.lua_setlocal(ls.L, this.funcInfo, fv.Number);
            }
        }