ScummVM API documentation
debugger.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GUI_DEBUGGER_H
23 #define GUI_DEBUGGER_H
24 
25 #include "common/func.h"
26 #include "common/ptr.h"
27 #include "common/hashmap.h"
28 #include "common/hash-str.h"
29 #include "common/array.h"
30 #include "common/str.h"
31 #include "common/str-array.h"
32 
33 #include "engines/engine.h"
34 
35 namespace GUI {
36 
37 #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
38 class ConsoleDialog;
39 #endif
40 
41 class Debugger {
42 public:
43  Debugger();
44  virtual ~Debugger();
45 
46  int getCharsPerLine();
47 
48  int debugPrintf(MSVC_PRINTF const char *format, ...) GCC_PRINTF(2, 3);
49 
50  void debugPrintColumns(const Common::StringArray &list);
51 
63  virtual void onFrame();
64 
69  virtual void attach(const char *entry = nullptr);
70 
75  bool isActive() const { return _isActive; }
76 
77 protected:
80 
89  #define WRAP_METHOD(cls, method) \
90  new Common::Functor2Mem<int, const char **, bool, cls>(this, &cls::method)
91 
97  #define WRAP_DEFAULTCOMMAND(cls, command) \
98  new Common::Functor1Mem<const char *, bool, cls>(this, &cls::command)
99 
100  enum VarType {
101  DVAR_BYTE,
102  DVAR_INT,
103  DVAR_FLOAT,
104  DVAR_BOOL,
105  DVAR_INTARRAY,
106  DVAR_STRING
107  };
108 
109  struct Var {
110  Common::String name;
111  void *variable;
112  VarType type;
113  int arraySize;
114  };
115 
116 private:
125  void registerVarImpl(const Common::String &varname, void *variable, VarType type, int arraySize);
126 
127 protected:
128  void registerVar(const Common::String &varname, byte *variable) {
129  registerVarImpl(varname, variable, DVAR_BYTE, 0);
130  }
131 
132  void registerVar(const Common::String &varname, int *variable) {
133  registerVarImpl(varname, variable, DVAR_INT, 0);
134  }
135 
136  void registerVar(const Common::String &varname, float *variable) {
137  registerVarImpl(varname, variable, DVAR_FLOAT, 0);
138  }
139 
140  void registerVar(const Common::String &varname, bool *variable) {
141  registerVarImpl(varname, variable, DVAR_BOOL, 0);
142  }
143 
144  void registerVar(const Common::String &varname, int32 **variable, int arraySize) {
145  registerVarImpl(varname, variable, DVAR_INTARRAY, arraySize);
146  }
147 
148  void registerVar(const Common::String &varname, Common::String *variable) {
149  registerVarImpl(varname, variable, DVAR_STRING, 0);
150  }
151 
152  void registerCmd(const Common::String &cmdname, Debuglet *debuglet);
153 
163  void registerDefaultCmd(defaultCommand *defaultCommandProcessor) {
164  _defaultCommandProcessor = defaultCommandProcessor; }
165 
169  void clearVars();
170 
171  void setPrompt(Common::String prompt);
172  void resetPrompt();
173 
174 private:
186  uint _frameCountdown;
187 
188  Common::Array<Var> _vars;
189 
191  CommandsMap _cmds;
192 
197  bool _isActive;
198 
199  Common::String _errStr;
200 
207  bool _firstTime;
208 
212  defaultCommand *_defaultCommandProcessor;
213 
214 protected:
215  PauseToken _debugPauseToken;
216 
217 #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
218  GUI::ConsoleDialog *_debuggerDialog;
219 #endif
220 
221 protected:
228  virtual void preEnter();
229 
236  virtual void postEnter();
237 
243  virtual bool handleCommand(int argc, const char **argv, bool &keepRunning);
244 
252  void detach();
253 
254 private:
255  void enter();
256 
261  void splitCommand(Common::String &input, int &argc, const char **argv);
262 
263  bool parseCommand(const char *input);
264  bool tabComplete(const char *input, Common::String &completion) const;
265 
266 protected:
267  bool cmdExit(int argc, const char **argv);
268  bool cmdHelp(int argc, const char **argv);
269  bool cmdOpenLog(int argc, const char **argv);
270 #ifndef DISABLE_MD5
271  bool cmdMd5(int argc, const char **argv);
272  bool cmdMd5Mac(int argc, const char **argv);
273 #endif
274  bool cmdDebugLevel(int argc, const char **argv);
275  bool cmdDebugFlagsList(int argc, const char **argv);
276  bool cmdDebugFlagEnable(int argc, const char **argv);
277  bool cmdDebugFlagDisable(int argc, const char **argv);
278  bool cmdClearLog(int argc, const char **argv);
279  bool cmdExecFile(int argc, const char **argv);
280 
281 #ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
282 private:
283  static bool debuggerInputCallback(GUI::ConsoleDialog *console, const char *input, void *refCon);
284  static bool debuggerCompletionCallback(GUI::ConsoleDialog *console, const char *input, Common::String &completion, void *refCon);
285 #elif defined(USE_READLINE)
286 public:
287  char *readlineComplete(const char *input, int state);
288 #endif
289 
290 };
291 
292 } // End of namespace GUI
293 
294 #endif
Definition: engine.h:102
Definition: console.h:64
void registerDefaultCmd(defaultCommand *defaultCommandProcessor)
Definition: debugger.h:163
void clearVars()
Definition: str.h:59
virtual bool handleCommand(int argc, const char **argv, bool &keepRunning)
Definition: debugger.h:41
Definition: system.h:45
virtual void preEnter()
int FORCEINLINE GCC_PRINTF(2, 0) int vsprintf_s(T(&dst)[N]
Definition: hashmap.h:85
bool isActive() const
Definition: debugger.h:75
Definition: func.h:437
virtual void postEnter()
virtual void attach(const char *entry=nullptr)
virtual void onFrame()
Definition: debugger.h:109
Definition: func.h:473
Definition: hash-str.h:49
Definition: hash-str.h:45