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.
|
2003-10-26 21:30:52 +00:00
|
|
|
*
|
2006-02-11 09:53:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
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"
|
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
|
|
|
|
2009-07-25 23:36:24 +00:00
|
|
|
#ifndef USE_TEXT_CONSOLE
|
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
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
int DebugPrintf(const char *format, ...);
|
|
|
|
|
|
|
|
virtual void onFrame();
|
|
|
|
|
|
|
|
virtual void attach(const char *entry = 0);
|
|
|
|
bool isAttached() const { return _isAttached; }
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-05-11 18:02:27 +00:00
|
|
|
// Convenience macro for registering a method of a debugger class
|
2006-09-16 16:58:27 +00:00
|
|
|
// as the current command.
|
|
|
|
#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
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
enum {
|
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
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
struct DVar {
|
2009-05-11 18:02:27 +00:00
|
|
|
Common::String name;
|
2003-10-26 21:30:52 +00:00
|
|
|
void *variable;
|
2009-05-11 18:02:27 +00:00
|
|
|
int type;
|
|
|
|
int optional;
|
2003-10-26 21:30:52 +00:00
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
int _frame_countdown;
|
|
|
|
bool _detach_now;
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
private:
|
2009-05-11 18:02:27 +00:00
|
|
|
Common::Array<DVar> _dvars;
|
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
|
|
|
|
|
|
|
bool _isAttached;
|
|
|
|
char *_errStr;
|
|
|
|
bool _firstTime;
|
2009-07-25 23:36:24 +00:00
|
|
|
#ifndef USE_TEXT_CONSOLE
|
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:
|
2006-09-16 16:58:27 +00:00
|
|
|
// Hook for subclasses: Called just before enter() is run
|
|
|
|
virtual void preEnter() {}
|
|
|
|
|
|
|
|
// Hook for subclasses: Called just after enter() was run
|
|
|
|
virtual void postEnter() {}
|
|
|
|
|
|
|
|
// Hook for subclasses: Process the given command line.
|
|
|
|
// Should return 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);
|
|
|
|
|
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 detach();
|
|
|
|
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
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
protected:
|
2009-05-11 18:02:27 +00:00
|
|
|
void DVar_Register(const Common::String &varname, void *pointer, int type, int optional);
|
|
|
|
void DCmd_Register(const Common::String &cmdname, Debuglet *debuglet);
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
bool Cmd_Exit(int argc, const char **argv);
|
|
|
|
bool Cmd_Help(int argc, const char **argv);
|
2006-02-14 23:31:25 +00:00
|
|
|
bool Cmd_DebugFlagsList(int argc, const char **argv);
|
|
|
|
bool Cmd_DebugFlagEnable(int argc, const char **argv);
|
|
|
|
bool Cmd_DebugFlagDisable(int argc, const char **argv);
|
|
|
|
|
2009-07-25 23:36:24 +00:00
|
|
|
#ifndef USE_TEXT_CONSOLE
|
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
|
|
|
};
|
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
} // End of namespace GUI
|
2003-10-26 21:30:52 +00:00
|
|
|
|
|
|
|
#endif
|