From cee326dd57de1f2414cf6708044f2f98cf01c0fa Mon Sep 17 00:00:00 2001 From: Martin Plicht Date: Fri, 15 Jan 2010 05:46:16 +0100 Subject: [PATCH] Debugger: Stack frame support (not finished) --- src/script/C4AulDebug.cpp | 37 +++++++++++++++++++++++++++++++++---- src/script/C4AulDebug.h | 5 +++++ src/script/C4AulExec.cpp | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/script/C4AulDebug.cpp b/src/script/C4AulDebug.cpp index cb6952a4e..224fc462a 100644 --- a/src/script/C4AulDebug.cpp +++ b/src/script/C4AulDebug.cpp @@ -18,8 +18,10 @@ C4AulDebug::C4AulDebug() } C4AulDebug::~C4AulDebug() - { - } +{ + for (std::list::iterator it = StackTrace.begin(); it != StackTrace.end(); it++) + {delete *it;} +} void C4AulDebug::PackPacket(const C4NetIOPacket &rPacket, StdBuf &rOutBuf) { @@ -182,7 +184,7 @@ void C4AulDebug::ProcessLine(const StdStrBuf &Line) else if (SEqualNoCase(szCmd, "LST")) { for (C4AulScript* script = ScriptEngine.Child0; script; script = script->Next) { - DebugLog(Config.AtRelativePath(script->ScriptName.getData())); + SendLine(Config.AtRelativePath(script->ScriptName.getData())); } } @@ -244,6 +246,15 @@ void C4AulDebug::ProcessLine(const StdStrBuf &Line) } + } + else if (SEqualNoCase(szCmd, "SST")) + { + std::list::iterator it = StackTrace.begin(); + for (it++; it != StackTrace.end(); it++) + { + SendLine("AT", (*it)->getData()); + } + SendLine("EST"); } else { @@ -371,7 +382,8 @@ void C4AulDebug::StepPoint(C4AulBCC *pCPos, C4AulScriptContext *pRetCtx, C4Value SendLine("STP", "Stepped"); // Position - SendLine("POS", FormatCodePos(pCtx, pCPos).getData()); + ObtainStackTrace(pCtx, pCPos); + SendLine("POS", StackTrace.front()->getData()); // Suspend until we get some command while(eState == DS_Stop) @@ -385,6 +397,23 @@ void C4AulDebug::StepPoint(C4AulBCC *pCPos, C4AulScriptContext *pRetCtx, C4Value Game.HaltCount--; } +void C4AulDebug::ObtainStackTrace(C4AulScriptContext* pCtx, C4AulBCC* pCPos) +{ + for (std::list::iterator it = StackTrace.begin(); it != StackTrace.end(); it++) + {delete *it;} + StackTrace.clear(); + for (int ctxNum = pExec->GetContextDepth()-1; ctxNum >= 0; ctxNum--) + { + C4AulScriptContext* c = pExec->GetContext(ctxNum); + C4AulBCC* _cpos = c == pCtx ? pCPos : c->CPos; + if (_cpos) + { + StdStrBuf* format = new StdStrBuf(FormatCodePos(c, _cpos)); + StackTrace.push_back(format); + } + } +} + StdStrBuf C4AulDebug::FormatCodePos(C4AulScriptContext *pCtx, C4AulBCC *pCPos) { // Get position in script diff --git a/src/script/C4AulDebug.h b/src/script/C4AulDebug.h index 506bdbabe..75b245d5c 100644 --- a/src/script/C4AulDebug.h +++ b/src/script/C4AulDebug.h @@ -28,6 +28,11 @@ class C4AulDebug : public C4NetIOTCP, private C4NetIO::CBClass }; DebugState eState; int iStepCallDepth; + + // temporary stuff + std::list StackTrace; + + void ObtainStackTrace(C4AulScriptContext* pCtx, C4AulBCC* pCPos); private: diff --git a/src/script/C4AulExec.cpp b/src/script/C4AulExec.cpp index 3782a5012..33eda2544 100644 --- a/src/script/C4AulExec.cpp +++ b/src/script/C4AulExec.cpp @@ -1020,7 +1020,7 @@ C4AulBCC *C4AulExec::Call(C4AulFunc *pFunc, C4Value *pReturn, C4Value *pPars, C4 ctx.Func = pSFunc; ctx.TemporaryScript = false; ctx.CPos = NULL; - pDebug->DebugStepOut(pCurCtx->CPos + 1, &ctx, pReturn); + pDebug->DebugStepOut(pCurCtx->CPos + 1, pCurCtx, pReturn); } // Remove parameters from stack