2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-10-26 21:30:52 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2003-10-26 21:30:52 +00:00
|
|
|
*/
|
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
#ifndef GUI_DEBUGGER_H
|
|
|
|
#define GUI_DEBUGGER_H
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2008-04-20 15:47:11 +00:00
|
|
|
#include "common/func.h"
|
2009-05-11 18:02:27 +00:00
|
|
|
#include "common/ptr.h"
|
|
|
|
#include "common/hashmap.h"
|
|
|
|
#include "common/hash-str.h"
|
2011-07-02 22:15:30 +00:00
|
|
|
#include "common/array.h"
|
2008-04-20 15:47:11 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2011-05-05 15:32:31 +00:00
|
|
|
#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
|
2006-09-16 16:58:27 +00:00
|
|
|
class ConsoleDialog;
|
|
|
|
#endif
|
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
class Debugger {
|
|
|
|
public:
|
2003-11-02 02:18:16 +00:00
|
|
|
Debugger();
|
2003-10-26 21:30:52 +00:00
|
|
|
virtual ~Debugger();
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2014-05-27 00:04:07 +00:00
|
|
|
int debugPrintf(const char *format, ...) GCC_PRINTF(2, 3);
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* The onFrame() method should be invoked by the engine at regular
|
|
|
|
* intervals (usually once per main loop iteration) whenever the
|
|
|
|
* debugger is attached.
|
|
|
|
* This will open up the console and accept user input if certain
|
|
|
|
* preconditions are met, such as the frame countdown having
|
|
|
|
* reached zero.
|
|
|
|
*
|
|
|
|
* Subclasses can override this to e.g. check for breakpoints being
|
|
|
|
* triggered.
|
|
|
|
*/
|
2003-10-26 21:30:52 +00:00
|
|
|
virtual void onFrame();
|
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* 'Attach' the debugger. This ensures that the next time onFrame()
|
|
|
|
* is invoked, the debugger will activate and accept user input.
|
|
|
|
*/
|
2003-10-26 21:30:52 +00:00
|
|
|
virtual void attach(const char *entry = 0);
|
2010-07-17 18:38:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the debugger is currently active (i.e. executing
|
|
|
|
* a command or waiting for use input).
|
|
|
|
*/
|
|
|
|
bool isActive() const { return _isActive; }
|
2003-10-26 21:30:52 +00:00
|
|
|
|
|
|
|
protected:
|
2008-04-20 15:47:11 +00:00
|
|
|
typedef Common::Functor2<int, const char **, bool> Debuglet;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
2011-06-03 11:43:10 +00:00
|
|
|
* Convenience macro that makes it easier to register a method
|
2010-07-17 18:38:42 +00:00
|
|
|
* of a debugger subclass as a command.
|
|
|
|
* Usage example:
|
2014-05-27 00:04:08 +00:00
|
|
|
* registerCmd("COMMAND", WRAP_METHOD(MyDebugger, myCmd));
|
|
|
|
* would register the method MyDebugger::myCmd(int, const char **)
|
2010-07-17 18:38:42 +00:00
|
|
|
* under the command name "COMMAND".
|
|
|
|
*/
|
2006-09-16 16:58:27 +00:00
|
|
|
#define WRAP_METHOD(cls, method) \
|
2008-04-20 15:47:11 +00:00
|
|
|
new Common::Functor2Mem<int, const char **, bool, cls>(this, &cls::method)
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
enum VarType {
|
2004-08-08 22:44:15 +00:00
|
|
|
DVAR_BYTE,
|
2003-10-26 21:30:52 +00:00
|
|
|
DVAR_INT,
|
|
|
|
DVAR_BOOL,
|
|
|
|
DVAR_INTARRAY,
|
|
|
|
DVAR_STRING
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2014-05-27 00:04:08 +00:00
|
|
|
struct Var {
|
2009-05-11 18:02:27 +00:00
|
|
|
Common::String name;
|
2003-10-26 21:30:52 +00:00
|
|
|
void *variable;
|
2010-07-17 18:38:42 +00:00
|
|
|
VarType type;
|
|
|
|
int arraySize;
|
2003-10-26 21:30:52 +00:00
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2014-05-27 00:04:08 +00:00
|
|
|
private:
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* Register a variable with the debugger. This allows the user to read and modify
|
|
|
|
* this variable.
|
|
|
|
* @param varname the identifier with which the user may access the variable
|
|
|
|
* @param variable pointer to the actual storage of the variable
|
|
|
|
* @param type the type of the variable (byte, int, bool, ...)
|
2014-08-29 01:28:59 +00:00
|
|
|
* @param arraySize for type DVAR_INTARRAY this specifies the size of the array
|
2010-07-17 18:38:42 +00:00
|
|
|
*/
|
2014-05-27 00:04:07 +00:00
|
|
|
void registerVar(const Common::String &varname, void *variable, VarType type, int arraySize);
|
2014-05-27 00:04:08 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void registerVar(const Common::String &varname, byte *variable) {
|
|
|
|
registerVar(varname, variable, DVAR_BYTE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerVar(const Common::String &varname, int *variable) {
|
|
|
|
registerVar(varname, variable, DVAR_INT, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerVar(const Common::String &varname, bool *variable) {
|
|
|
|
registerVar(varname, variable, DVAR_BOOL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerVar(const Common::String &varname, int32 **variable, int arraySize) {
|
|
|
|
registerVar(varname, variable, DVAR_INTARRAY, arraySize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerVar(const Common::String &varname, Common::String *variable) {
|
|
|
|
registerVar(varname, variable, DVAR_STRING, 0);
|
|
|
|
}
|
|
|
|
|
2014-05-27 00:04:08 +00:00
|
|
|
void registerCmd(const Common::String &cmdname, Debuglet *debuglet);
|
2010-07-17 18:38:42 +00:00
|
|
|
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
private:
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* The frame countdown specifies a number of frames that must pass
|
|
|
|
* until the console will show up. This value is decremented by one
|
|
|
|
* each time onFrame() is called, until it reaches 0, at which point
|
|
|
|
* onFrame() will open the console and handle input into it.
|
|
|
|
*
|
|
|
|
* The user can modify this value using the debug_countdown command.
|
|
|
|
*
|
|
|
|
* Note: The console must be in *attached* state, otherwise, it
|
|
|
|
* won't show up (and the countdown won't count down either).
|
|
|
|
*/
|
|
|
|
uint _frameCountdown;
|
|
|
|
|
2014-05-27 00:04:08 +00:00
|
|
|
Common::Array<Var> _vars;
|
2006-09-16 16:58:27 +00:00
|
|
|
|
2009-05-11 18:02:27 +00:00
|
|
|
typedef Common::HashMap<Common::String, Common::SharedPtr<Debuglet>, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> CommandsMap;
|
|
|
|
CommandsMap _cmds;
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* True if the debugger is currently active (i.e. executing
|
|
|
|
* a command or waiting for use input).
|
|
|
|
*/
|
|
|
|
bool _isActive;
|
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
char *_errStr;
|
2010-07-17 18:38:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initially true, set to false when Debugger::enter is called
|
|
|
|
* the first time. We use this flag to show a greeting message
|
|
|
|
* to the user once, when he opens the debugger for the first
|
|
|
|
* time.
|
|
|
|
*/
|
2003-10-26 21:30:52 +00:00
|
|
|
bool _firstTime;
|
2010-07-17 18:38:42 +00:00
|
|
|
|
2011-05-05 15:32:31 +00:00
|
|
|
#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
|
2003-11-10 23:40:48 +00:00
|
|
|
GUI::ConsoleDialog *_debuggerDialog;
|
2009-07-19 21:06:25 +00:00
|
|
|
#endif
|
2003-10-26 21:30:52 +00:00
|
|
|
|
|
|
|
protected:
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* Hook for subclasses which is called just before enter() is run.
|
|
|
|
* A typical usage example is pausing music and sound effects.
|
2010-12-07 18:54:21 +00:00
|
|
|
*
|
|
|
|
* The default implementation invokes Engine::pauseEngine(true).
|
2010-07-17 18:38:42 +00:00
|
|
|
*/
|
2010-12-07 18:54:21 +00:00
|
|
|
virtual void preEnter();
|
2006-09-16 16:58:27 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* Hook for subclasses which is called just after enter() was run.
|
|
|
|
* A typical usage example is resuming music and sound effects.
|
2010-12-07 18:54:21 +00:00
|
|
|
*
|
|
|
|
* The default implementation invokes Engine::pauseEngine(false).
|
2010-07-17 18:38:42 +00:00
|
|
|
*/
|
2010-12-07 18:54:21 +00:00
|
|
|
virtual void postEnter();
|
2006-09-16 16:58:27 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
2014-05-27 00:04:08 +00:00
|
|
|
* Subclasses should invoke the detach() method in their cmdFOO methods
|
2010-07-17 18:38:42 +00:00
|
|
|
* if that command will resume execution of the program (as opposed to
|
|
|
|
* executing, say, a "single step through code" command).
|
|
|
|
*
|
|
|
|
* This currently only hides the virtual keyboard, if any.
|
|
|
|
*/
|
|
|
|
void detach();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
private:
|
2003-10-26 21:30:52 +00:00
|
|
|
void enter();
|
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
bool parseCommand(const char *input);
|
2009-05-11 18:02:27 +00:00
|
|
|
bool tabComplete(const char *input, Common::String &completion) const;
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
/**
|
|
|
|
* Process the given command line.
|
|
|
|
* Returns true if and only if argv[0] is a known command and was
|
|
|
|
* handled, false otherwise.
|
|
|
|
*/
|
|
|
|
virtual bool handleCommand(int argc, const char **argv, bool &keepRunning);
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2010-07-17 18:38:42 +00:00
|
|
|
protected:
|
2014-05-27 00:04:08 +00:00
|
|
|
bool cmdExit(int argc, const char **argv);
|
|
|
|
bool cmdHelp(int argc, const char **argv);
|
|
|
|
bool cmdOpenLog(int argc, const char **argv);
|
2014-09-01 17:52:44 +00:00
|
|
|
#ifndef DISABLE_MD5
|
|
|
|
bool cmdMd5(int argc, const char **argv);
|
2014-09-01 19:19:48 +00:00
|
|
|
bool cmdMd5Mac(int argc, const char **argv);
|
2014-09-01 17:52:44 +00:00
|
|
|
#endif
|
2014-05-27 00:04:08 +00:00
|
|
|
bool cmdDebugLevel(int argc, const char **argv);
|
|
|
|
bool cmdDebugFlagsList(int argc, const char **argv);
|
|
|
|
bool cmdDebugFlagEnable(int argc, const char **argv);
|
|
|
|
bool cmdDebugFlagDisable(int argc, const char **argv);
|
2006-02-14 23:31:25 +00:00
|
|
|
|
2011-05-05 15:32:31 +00:00
|
|
|
#ifndef USE_TEXT_CONSOLE_FOR_DEBUGGER
|
2006-09-16 16:58:27 +00:00
|
|
|
private:
|
2003-11-10 23:40:48 +00:00
|
|
|
static bool debuggerInputCallback(GUI::ConsoleDialog *console, const char *input, void *refCon);
|
2009-05-11 18:02:27 +00:00
|
|
|
static bool debuggerCompletionCallback(GUI::ConsoleDialog *console, const char *input, Common::String &completion, void *refCon);
|
2009-07-25 23:36:24 +00:00
|
|
|
#elif defined(USE_READLINE)
|
|
|
|
public:
|
2009-07-26 07:07:35 +00:00
|
|
|
char *readlineComplete(const char *input, int state);
|
2003-10-26 21:30:52 +00:00
|
|
|
#endif
|
2009-07-25 23:36:24 +00:00
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
};
|
|
|
|
|
2013-01-26 18:33:27 +00:00
|
|
|
} // End of namespace GUI
|
2003-10-26 21:30:52 +00:00
|
|
|
|
|
|
|
#endif
|