- Pushed debugstate into debug.h

- When an error occurs, manipulate the execution stack before error() opens the console inside getDebugger(), like FreeSCI did. Added another method for obtaining the SCI console for use by the engine itself.

svn-id: r42062
This commit is contained in:
Filippos Karapetis 2009-07-03 14:22:50 +00:00
parent 69da51e71d
commit 6fa8541aed
12 changed files with 38 additions and 36 deletions

View File

@ -50,7 +50,6 @@ int g_debug_sleeptime_factor = 1;
int g_debug_simulated_key = 0;
bool g_debug_track_mouse_clicks = false;
bool g_debug_weak_validations = true;
extern DebugState debugState;
Console::Console(SciEngine *vm) : GUI::Debugger() {
_vm = vm;
@ -1598,7 +1597,7 @@ bool Console::cmdGCObjects(int argc, const char **argv) {
void _print_address(void * _, reg_t addr) {
if (addr.segment)
((SciEngine *)g_engine)->getDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr));
((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf(" %04x:%04x\n", PRINT_REG(addr));
}
bool Console::cmdGCShowReachable(int argc, const char **argv) {

View File

@ -154,6 +154,7 @@ private:
private:
SciEngine *_vm;
bool _mouseVisible;
};
} // End of namespace Sci

View File

@ -28,12 +28,6 @@
namespace Sci {
// Various global variables used for debugging are declared here
extern int g_debug_sleeptime_factor;
extern int g_debug_simulated_key;
extern bool g_debug_track_mouse_clicks;
extern bool g_debug_weak_validations;
enum DebugSeeking {
kDebugSeekNothing = 0,
kDebugSeekCallk = 1, // Step forward until callk is found
@ -50,6 +44,8 @@ struct DebugState {
int runningStep; // Set to > 0 to allow multiple stepping
int seekLevel; // Used for seekers that want to check their exec stack depth
int seekSpecial; // Used for special seeks
int old_pc_offset;
StackPtr old_sp;
reg_t *p_pc;
StackPtr *p_sp;
StackPtr *p_pp;
@ -61,6 +57,13 @@ struct DebugState {
int *p_var_max; // May be NULL even in valid state!
};
// Various global variables used for debugging are declared here
extern int g_debug_sleeptime_factor;
extern int g_debug_simulated_key;
extern bool g_debug_track_mouse_clicks;
extern bool g_debug_weak_validations;
extern DebugState debugState;
} // End of namespace Sci
#endif

View File

@ -351,7 +351,7 @@ parse_rule_list_t *Vocabulary::buildGNF(bool verbose) {
int ntrules_nr;
parse_rule_list_t *ntlist = NULL;
parse_rule_list_t *tlist, *new_tlist;
GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
Console *con = ((SciEngine *)g_engine)->getSciDebugger();
for (uint i = 1; i < _parserBranches.size(); i++) { // branch rule 0 is treated specially
parse_rule_t *rule = _vbuild_rule(&_parserBranches[i]);
@ -477,7 +477,7 @@ static int _vbpt_write_subexpression(parse_tree_node_t *nodes, int *pos, parse_r
}
int Vocabulary::parseGNF(parse_tree_node_t *nodes, const ResultWordList &words, bool verbose) {
GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
Console *con = ((SciEngine *)g_engine)->getSciDebugger();
// Get the start rules:
parse_rule_list_t *work = _vocab_clone_rule_list_by_id(_parserRules, _parserBranches[0].data[1]);
parse_rule_list_t *results = NULL;

View File

@ -33,8 +33,6 @@
namespace Sci {
extern DebugState debugState;
#define SCI_VARIABLE_GAME_SPEED 3
reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
@ -112,7 +110,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
// track left buttton clicks, if requested
if (e.type == SCI_EVT_MOUSE_PRESS && e.data == 1 && g_debug_track_mouse_clicks) {
((SciEngine *)g_engine)->getDebugger()->DebugPrintf("Mouse clicked at %d, %d\n",
((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("Mouse clicked at %d, %d\n",
s->gfx_state->pointer_pos.x, s->gfx_state->pointer_pos.y);
}
@ -143,7 +141,7 @@ reg_t kGetEvent(EngineState *s, int funct_nr, int argc, reg_t *argv) {
debugState.stopOnEvent = false;
// A SCI event occured, and we have been asked to stop, so open the debug console
GUI::Debugger *con = ((Sci::SciEngine*)g_engine)->getDebugger();
Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
con->DebugPrintf("SCI event occured: ");
switch (e.type) {
case SCI_EVT_QUIT:

View File

@ -93,8 +93,6 @@ reg_t kFlushResources(EngineState *s, int funct_nr, int argc, reg_t *argv) {
return s->r_acc;
}
extern DebugState debugState;
reg_t kSetDebug(EngineState *s, int funct_nr, int argc, reg_t *argv) {
sciprintf("Debug mode activated\n");

View File

@ -49,7 +49,6 @@ reg_t NULL_REG = {0, 0};
int script_abort_flag = 0; // Set to 1 to abort execution. Set to 2 to force a replay afterwards // FIXME: Avoid non-const global vars
int script_step_counter = 0; // Counts the number of steps executed // FIXME: Avoid non-const global vars
int script_gc_interval = GC_INTERVAL; // Number of steps in between gcs // FIXME: Avoid non-const global vars
extern DebugState debugState;
static bool breakpointFlag = false; // FIXME: Avoid non-const global vars
static reg_t _dummy_register; // FIXME: Avoid non-const global vars
@ -606,14 +605,12 @@ void run_vm(EngineState *s, int restoring) {
while (1) {
byte opcode;
int old_pc_offset;
StackPtr old_sp;
byte opnumber;
int var_type; // See description below
int var_number;
old_pc_offset = xs->addr.pc.offset;
old_sp = xs->sp;
debugState.old_pc_offset = xs->addr.pc.offset;
debugState.old_sp = xs->sp;
if (s->_executionStackPosChanged) {
Script *scr;
@ -1424,16 +1421,7 @@ void run_vm(EngineState *s, int restoring) {
opnumber);
}
//#endif
#if 0
if (script_error_flag) {
debugState.runningStep = 0; // Stop multiple execution
debugState.seeking = 0; // Stop special seeks
xs->addr.pc.offset = old_pc_offset;
xs->sp = old_sp;
} else
#endif
++script_step_counter;
++script_step_counter;
}
}

View File

@ -1418,8 +1418,9 @@ static sci_event_t scummvm_get_event(GfxDriver *drv) {
// Debug console
if (ev.kbd.flags == Common::KBD_CTRL && ev.kbd.keycode == Common::KEYCODE_d) {
// Open debug console
((Sci::SciEngine*)g_engine)->getDebugger()->attach();
((Sci::SciEngine*)g_engine)->getDebugger()->onFrame();
Console *con = ((Sci::SciEngine*)g_engine)->getSciDebugger();
con->attach();
con->onFrame();
// Clear keyboard event
input.type = SCI_EVT_NONE;

View File

@ -29,6 +29,7 @@
#include "engines/advancedDetector.h"
#include "sci/sci.h"
#include "sci/debug.h"
#include "sci/console.h"
#include "sci/engine/state.h"
@ -254,7 +255,19 @@ Common::Error SciEngine::run() {
return Common::kNoError;
}
// Invoked by error() when a severe error occurs
GUI::Debugger *SciEngine::getDebugger() {
ExecStack *xs = &(_gamestate->_executionStack.back());
debugState.runningStep = 0; // Stop multiple execution
debugState.seeking = kDebugSeekNothing; // Stop special seeks
xs->addr.pc.offset = debugState.old_pc_offset;
xs->sp = debugState.old_sp;
return _console;
}
// Used to obtain the engine's console in order to print messages to it
Console *SciEngine::getSciDebugger() {
return _console;
}

View File

@ -142,6 +142,7 @@ public:
virtual Common::Error run();
void pauseEngineIntern(bool pause);
virtual GUI::Debugger *getDebugger();
Console *getSciDebugger();
const char* getGameID() const;
int getResourceVersion() const;

View File

@ -70,7 +70,7 @@ void sciprintf(const char *fmt, ...) {
// Display the result suitably
if (g_redirect_sciprintf_to_gui)
((SciEngine *)g_engine)->getDebugger()->DebugPrintf("%s", buf);
((SciEngine *)g_engine)->getSciDebugger()->DebugPrintf("%s", buf);
printf("%s", buf);
free(buf);

View File

@ -438,7 +438,7 @@ bool Vocabulary::tokenizeString(ResultWordList &retval, const char *sentence, ch
void Vocabulary::printSuffixes() const {
char word_buf[256], alt_buf[256];
GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
Console *con = ((SciEngine *)g_engine)->getSciDebugger();
int i = 0;
for (SuffixList::const_iterator suf = _parserSuffixes.begin(); suf != _parserSuffixes.end(); ++suf) {
@ -453,7 +453,7 @@ void Vocabulary::printSuffixes() const {
}
void Vocabulary::printParserWords() const {
GUI::Debugger *con = ((SciEngine *)g_engine)->getDebugger();
Console *con = ((SciEngine *)g_engine)->getSciDebugger();
int j = 0;
for (WordMap::iterator i = _parserWords.begin(); i != _parserWords.end(); ++i) {