# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

context_debug.cpp

Go to the documentation of this file.
00001 
00007 /* Copyright, 2000 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX D.T.C. SYSTEM.
00010  * NEVRAX D.T.C. SYSTEM is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX D.T.C. SYSTEM is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX D.T.C. SYSTEM; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #include "nel/ai/script/context_debug.h"
00027 #include "nel/ai/script/code_branche_run_debug.h"
00028 #include "nel/ai/script/codage.h"
00029 
00030 namespace NLAISCRIPT
00031 {
00032         CContextDebug::CContextDebug(): HeapDebug(*(new CStackPointer()))
00033         {
00034                 _DebugMode = stepByStepMode;
00035                 Active = false;
00036                 _StepIndex = 1;
00037                 _LastCommandLine = new char[1024];
00038                 _LastCommandLine[0] = ' ';
00039                 _LastCommandLine[1] = '\0';
00040         }
00041 
00042         CContextDebug::~CContextDebug()
00043         {
00044                 _CallStack.clear();
00045                 delete _LastCommandLine;
00046                 delete &HeapDebug;
00047                 if (Param.size() >0 )
00048                 {
00049                         std::list<NLAIAGENT::IObjectIA	*>::const_iterator It = Param.begin();
00050                         while(It != Param.end())
00051                         {
00052                                 (*It)->release();
00053                                 It++;
00054                         }
00055                 }
00056         }
00057 
00058         const NLAIC::CIdentType &CContextDebug::getType() const
00059         {
00060                 return IdContextDebug;
00061         }
00062 
00063         const NLAIC::IBasicType* CContextDebug::clone() const
00064         {
00065                 NLAIC::IBasicType *x = new (CContextDebug);
00066                 return x;
00067         }
00068 
00069         const NLAIC::IBasicType* CContextDebug::newInstance() const
00070         {
00071                 return clone();
00072         }
00073 
00074         void CContextDebug::getDebugString(std::string &dbgStr) const
00075         {
00076         }
00077 
00078         void CContextDebug::save(NLMISC::IStream &os)
00079         {
00080         }
00081 
00082         void CContextDebug::load(NLMISC::IStream &is)
00083         {
00084         }
00085 
00086         bool CContextDebug::isEqual(const NLAIAGENT::IBasicObjectIA &a) const
00087         {
00088                 return true;
00089         }
00090 
00091         const NLAIAGENT::IObjectIA::CProcessResult &CContextDebug::run()
00092         {               
00093                 return NLAIAGENT::IObjectIA::ProcessRun;
00094         }
00095         void CContextDebug::setDebugMode (TDebugMode dm)
00096         {
00097                 _DebugMode = dm;
00098         }
00099 
00100         TDebugMode CContextDebug::getDebugMode () const
00101         {
00102                 return _DebugMode;
00103         }
00104 
00105         void CContextDebug::setStepIndex(uint16 si)
00106         {
00107                 _StepIndex = si;
00108         }
00109 
00110         uint16 CContextDebug::getStepIndex () const
00111         {
00112                 return _StepIndex;
00113         }
00114 
00115         uint16 CContextDebug::getCallStackTopIndex() const
00116         {
00117                 return _CallStack.size();
00118         }
00119 
00120         void CContextDebug::callStackPop()
00121         {
00122                 _CallStack.pop_back();
00123         }
00124 
00125         void CContextDebug::callStackPush(const CCodeBrancheRun* cbr)
00126         {
00127                 _CallStack.push_back(cbr);
00128         }
00129 
00130         void CContextDebug::addBreakPoint(uint16 line, const char* fileName)
00131         {
00132                 std::map<mystring, uintSet>::iterator itu;
00133                 std::set<uint16>::iterator it;
00134                 if ((itu = _BreakPointSet.find(fileName)) != _BreakPointSet.end())
00135                 {
00136                         if ((it = itu->second.find(line)) == itu->second.end())
00137                         {
00138                                 itu->second.insert(line);
00139                         }
00140                 }
00141                 else
00142                 {
00143                         _BreakPointSet[fileName].insert(line);
00144                 }
00145         }
00146 
00147         void CContextDebug::eraseBreakPoint(uint16 line, const char* fileName)
00148         {
00149                 std::map<mystring, uintSet>::iterator itu;
00150                 std::set<uint16>::iterator it;
00151                 if ((itu = _BreakPointSet.find(fileName)) != _BreakPointSet.end())
00152                 {
00153                         if ((it = itu->second.find(line)) != itu->second.end())
00154                         {
00155                                 itu->second.erase(it);
00156                         }
00157                 }
00158         }
00159 
00160         bool CContextDebug::getBreakPointValue(uint16 line, const char* fileName) const
00161         {
00162                 std::map<mystring, uintSet>::const_iterator itu;
00163                 std::set<uint16>::iterator it;
00164                 if (   (itu = _BreakPointSet.find(fileName)) != _BreakPointSet.end()
00165                         && (it = itu->second.find(line)) != itu->second.end() )
00166                         return true;
00167                 else
00168                         return false;
00169         }
00170 
00171         void CContextDebug::callStackPrint(NLAIC::IIO *inputOutput) const
00172         {
00173                 CCodeBrancheRunDebug* pCbrd;
00174                 std::list<const CCodeBrancheRun*>::const_iterator itC = _CallStack.begin();
00175                 while (itC != _CallStack.end())
00176                 {
00177                         if ((*itC)->getType() == CCodeBrancheRunDebug::IdCodeBrancheRunDebug)
00178                         {
00179                                 pCbrd = (CCodeBrancheRunDebug*)(*itC);
00180                                 inputOutput->Echo("%s\n",pCbrd->getSourceFileName().c_str());
00181                                 pCbrd->printCurrentSourceCodeLine();
00182                         }
00183                         itC++;
00184                 }
00185         }
00186 
00187         void CContextDebug::stepIndexUp()
00188         {
00189                 if (_StepIndex < _CallStack.size())
00190                 {
00191                         _StepIndex ++;
00192                 }
00193         }
00194 
00195         void CContextDebug::stepIndexDown()
00196         {
00197                 if (_StepIndex > 0)
00198                 {
00199                         _StepIndex --;
00200                 }
00201         }
00202 
00203         void CContextDebug::printActiveBeaks(NLAIC::IIO *inputOutput) const
00204         {
00205                 std::map<mystring, uintSet>::const_iterator itu = _BreakPointSet.begin();
00206                 std::set<uint16>::iterator it;
00207                 while (itu != _BreakPointSet.end())
00208                 {
00209                         inputOutput->Echo("File name : %s\nLines : ", (*itu).first.c_str());
00210                         it = (*itu).second.begin();
00211                         while (it != (*itu).second.end())
00212                         {
00213                                 inputOutput->Echo("%d ", (*it));
00214                                 it++;
00215                         }
00216                         inputOutput->Echo("\n");
00217                         itu++;
00218                 }
00219         }
00220 
00221         const char* CContextDebug::getLastCommandLine() const
00222         {
00223                 return _LastCommandLine;
00224         }
00225 
00226         void CContextDebug::setLastCommandLine(const char* c)
00227         {
00228                 strcpy(_LastCommandLine, c);
00229         }
00230 }