ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

debugger.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GUI_DEBUGGER_H
00024 #define GUI_DEBUGGER_H
00025 
00026 #include "common/func.h"
00027 #include "common/ptr.h"
00028 #include "common/hashmap.h"
00029 #include "common/hash-str.h"
00030 #include "common/array.h"
00031 #include "common/str.h"
00032 #include "common/str-array.h"
00033 
00034 namespace GUI {
00035 
00036 #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
00037 class ConsoleDialog;
00038 #endif
00039 
00040 class Debugger {
00041 public:
00042     Debugger();
00043     virtual ~Debugger();
00044 
00045     int getCharsPerLine();
00046 
00047     int debugPrintf(const char *format, ...) GCC_PRINTF(2, 3);
00048 
00049     void debugPrintColumns(const Common::StringArray &list);
00050 
00062     virtual void onFrame();
00063 
00068     virtual void attach(const char *entry = 0);
00069 
00074     bool isActive() const { return _isActive; }
00075 
00076 protected:
00077     typedef Common::Functor2<int, const char **, bool> Debuglet;
00078 
00087     #define WRAP_METHOD(cls, method) \
00088         new Common::Functor2Mem<int, const char **, bool, cls>(this, &cls::method)
00089 
00090     enum VarType {
00091         DVAR_BYTE,
00092         DVAR_INT,
00093         DVAR_BOOL,
00094         DVAR_INTARRAY,
00095         DVAR_STRING
00096     };
00097 
00098     struct Var {
00099         Common::String name;
00100         void *variable;
00101         VarType type;
00102         int arraySize;
00103     };
00104 
00105 private:
00114     void registerVar(const Common::String &varname, void *variable, VarType type, int arraySize);
00115 
00116 protected:
00117     void registerVar(const Common::String &varname, byte *variable) {
00118         registerVar(varname, variable, DVAR_BYTE, 0);
00119     }
00120 
00121     void registerVar(const Common::String &varname, int *variable) {
00122         registerVar(varname, variable, DVAR_INT, 0);
00123     }
00124 
00125     void registerVar(const Common::String &varname, bool *variable) {
00126         registerVar(varname, variable, DVAR_BOOL, 0);
00127     }
00128 
00129     void registerVar(const Common::String &varname, int32 **variable, int arraySize) {
00130         registerVar(varname, variable, DVAR_INTARRAY, arraySize);
00131     }
00132 
00133     void registerVar(const Common::String &varname, Common::String *variable) {
00134         registerVar(varname, variable, DVAR_STRING, 0);
00135     }
00136 
00137     void registerCmd(const Common::String &cmdname, Debuglet *debuglet);
00138 
00139 
00140 private:
00152     uint _frameCountdown;
00153 
00154     Common::Array<Var> _vars;
00155 
00156     typedef Common::HashMap<Common::String, Common::SharedPtr<Debuglet>, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> CommandsMap;
00157     CommandsMap _cmds;
00158 
00163     bool _isActive;
00164 
00165     Common::String _errStr;
00166 
00173     bool _firstTime;
00174 
00175 #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
00176     GUI::ConsoleDialog *_debuggerDialog;
00177 #endif
00178 
00179 protected:
00186     virtual void preEnter();
00187 
00194     virtual void postEnter();
00195 
00203     void detach();
00204 
00205 private:
00206     void enter();
00207 
00212     void splitCommand(Common::String &input, int &argc, const char **argv);
00213 
00214     bool parseCommand(const char *input);
00215     bool tabComplete(const char *input, Common::String &completion) const;
00216 
00222     virtual bool handleCommand(int argc, const char **argv, bool &keepRunning);
00223 
00224 protected:
00225     bool cmdExit(int argc, const char **argv);
00226     bool cmdHelp(int argc, const char **argv);
00227     bool cmdOpenLog(int argc, const char **argv);
00228 #ifndef DISABLE_MD5
00229     bool cmdMd5(int argc, const char **argv);
00230     bool cmdMd5Mac(int argc, const char **argv);
00231 #endif
00232     bool cmdDebugLevel(int argc, const char **argv);
00233     bool cmdDebugFlagsList(int argc, const char **argv);
00234     bool cmdDebugFlagEnable(int argc, const char **argv);
00235     bool cmdDebugFlagDisable(int argc, const char **argv);
00236 
00237 #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
00238 private:
00239     static bool debuggerInputCallback(GUI::ConsoleDialog *console, const char *input, void *refCon);
00240     static bool debuggerCompletionCallback(GUI::ConsoleDialog *console, const char *input, Common::String &completion, void *refCon);
00241 #elif defined(USE_READLINE)
00242 public:
00243     char *readlineComplete(const char *input, int state);
00244 #endif
00245 
00246 };
00247 
00248 } // End of namespace GUI
00249 
00250 #endif


Generated on Sat Sep 14 2019 05:01:11 for ResidualVM by doxygen 1.7.1
curved edge   curved edge