2003-10-26 21:30:52 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2002-2006 The ScummVM project
|
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
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
2003-10-26 21:30:52 +00:00
|
|
|
|
|
|
|
// Choose between text console or ScummConsole
|
|
|
|
#define USE_CONSOLE 1
|
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
#ifdef USE_CONSOLE
|
|
|
|
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, ...);
|
|
|
|
|
2005-06-21 22:08:21 +00:00
|
|
|
#ifndef __SYMBIAN32__ // gcc/UIQ doesn't like the debugger code for some reason? Actually get a cc1plus core dump here :)
|
2006-09-16 16:58:27 +00:00
|
|
|
// FIXME: Fingolfin asks: This code *used* to be a problem when GUI::Debugger
|
|
|
|
// was a template class. But is it really still causing problems, or can
|
|
|
|
// this hack go away now?
|
2003-10-26 21:30:52 +00:00
|
|
|
virtual void onFrame();
|
|
|
|
|
|
|
|
virtual void attach(const char *entry = 0);
|
2005-06-21 22:08:21 +00:00
|
|
|
#else
|
|
|
|
void onFrame() {}
|
|
|
|
void attach(const char *entry = 0) {}
|
|
|
|
#endif
|
2003-10-26 21:30:52 +00:00
|
|
|
bool isAttached() const { return _isAttached; }
|
|
|
|
|
|
|
|
protected:
|
2006-09-16 16:58:27 +00:00
|
|
|
class Debuglet {
|
|
|
|
public:
|
|
|
|
virtual ~Debuglet() {}
|
|
|
|
virtual bool operator()(int argc, const char **argv) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class DelegateDebuglet : public Debuglet {
|
|
|
|
typedef bool (T::*Method)(int argc, const char **argv);
|
|
|
|
|
|
|
|
T *_delegate;
|
|
|
|
const Method _method;
|
|
|
|
public:
|
|
|
|
DelegateDebuglet(T *delegate, Method method)
|
|
|
|
: _delegate(delegate), _method(method) {
|
|
|
|
assert(delegate != 0);
|
|
|
|
}
|
|
|
|
virtual bool operator()(int argc, const char **argv) {
|
|
|
|
return (_delegate->*_method)(argc, argv);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Convenicence macro for registering a method of a debugger class
|
|
|
|
// as the current command.
|
|
|
|
#define WRAP_METHOD(cls, method) \
|
|
|
|
new DelegateDebuglet<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 {
|
|
|
|
char name[30];
|
|
|
|
void *variable;
|
|
|
|
int type, optional;
|
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
struct DCmd {
|
|
|
|
char name[30];
|
2006-09-16 16:58:27 +00:00
|
|
|
Debuglet *debuglet;
|
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;
|
|
|
|
|
2006-09-16 17:29:43 +00:00
|
|
|
private:
|
2006-09-16 16:58:27 +00:00
|
|
|
// TODO: Consider replacing the following two arrays by a Hashmap
|
|
|
|
int _dvar_count;
|
2003-10-26 21:30:52 +00:00
|
|
|
DVar _dvars[256];
|
2006-09-16 16:58:27 +00:00
|
|
|
|
|
|
|
int _dcmd_count;
|
2003-10-26 21:30:52 +00:00
|
|
|
DCmd _dcmds[256];
|
|
|
|
|
|
|
|
bool _isAttached;
|
|
|
|
char *_errStr;
|
|
|
|
bool _firstTime;
|
2003-11-10 23:40:48 +00:00
|
|
|
GUI::ConsoleDialog *_debuggerDialog;
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
bool tabComplete(const char *input, char*& completion);
|
2003-10-26 21:30:52 +00:00
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
protected:
|
2003-10-26 21:30:52 +00:00
|
|
|
void DVar_Register(const char *varname, void *pointer, int type, int optional);
|
2006-09-16 16:58:27 +00:00
|
|
|
void DCmd_Register(const char *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);
|
|
|
|
|
2003-10-26 21:30:52 +00:00
|
|
|
#if USE_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);
|
|
|
|
static bool debuggerCompletionCallback(GUI::ConsoleDialog *console, const char *input, char*& completion, void *refCon);
|
2003-10-26 21:30:52 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2006-09-16 16:58:27 +00:00
|
|
|
} // End of namespace GUI
|
2003-10-26 21:30:52 +00:00
|
|
|
|
|
|
|
#endif
|