diff options
-rw-r--r-- | common/debug.cpp | 58 | ||||
-rw-r--r-- | common/debug.h | 55 | ||||
-rw-r--r-- | engines/groovie/script.cpp | 7 | ||||
-rw-r--r-- | engines/groovie/vdx.cpp | 3 | ||||
-rw-r--r-- | engines/scumm/debugger.cpp | 62 | ||||
-rw-r--r-- | gui/debugger.cpp | 8 |
6 files changed, 102 insertions, 91 deletions
diff --git a/common/debug.cpp b/common/debug.cpp index 6c8d94a829..af3e6d8018 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -57,35 +57,35 @@ namespace Common { namespace { -DebugLevelContainer gDebugLevels; +SpecialDebugLevelList gDebugLevels; uint32 gDebugLevelsEnabled = 0; struct DebugLevelSort { - bool operator()(const EngineDebugLevel &l, const EngineDebugLevel &r) { - return (l.option.compareToIgnoreCase(r.option) < 0); + bool operator()(const SpecialDebugLevel &l, const SpecialDebugLevel &r) { + return (l.name.compareToIgnoreCase(r.name) < 0); } }; struct DebugLevelSearch { - const String &_option; + const String &_name; - DebugLevelSearch(const String &option) : _option(option) {} + DebugLevelSearch(const String &name) : _name(name) {} - bool operator()(const EngineDebugLevel &l) { - return _option.equalsIgnoreCase(l.option); + bool operator()(const SpecialDebugLevel &l) { + return _name.equalsIgnoreCase(l.name); } }; } -bool addSpecialDebugLevel(uint32 level, const String &option, const String &description) { - DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); +bool addSpecialDebugLevel(uint32 level, const String &name, const String &description) { + SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name)); if (i != gDebugLevels.end()) { - warning("Declared engine debug level '%s' again", option.c_str()); - *i = EngineDebugLevel(level, option, description); + warning("Declared engine debug level '%s' again", name.c_str()); + *i = SpecialDebugLevel(level, name, description); } else { - gDebugLevels.push_back(EngineDebugLevel(level, option, description)); + gDebugLevels.push_back(SpecialDebugLevel(level, name, description)); sort(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSort()); } @@ -97,8 +97,8 @@ void clearAllSpecialDebugLevels() { gDebugLevels.clear(); } -bool enableSpecialDebugLevel(const String &option) { - DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); +bool enableSpecialDebugLevel(const String &name) { + SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name)); if (i != gDebugLevels.end()) { gDebugLevelsEnabled |= i->level; @@ -110,8 +110,8 @@ bool enableSpecialDebugLevel(const String &option) { } } -void enableSpecialDebugLevelList(const String &option) { - StringTokenizer tokenizer(option, " ,"); +void enableSpecialDebugLevelList(const String &names) { + StringTokenizer tokenizer(names, " ,"); String token; while (!tokenizer.empty()) { @@ -122,7 +122,7 @@ void enableSpecialDebugLevelList(const String &option) { } bool disableSpecialDebugLevel(const String &option) { - DebugLevelContainer::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); + SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(option)); if (i != gDebugLevels.end()) { gDebugLevelsEnabled &= ~i->level; @@ -134,7 +134,7 @@ bool disableSpecialDebugLevel(const String &option) { } } -const DebugLevelContainer &listSpecialDebugLevels() { +const SpecialDebugLevelList &listSpecialDebugLevels() { return gDebugLevels; } @@ -142,6 +142,27 @@ uint32 getEnabledSpecialDebugLevels() { return gDebugLevelsEnabled; } +bool isSpecialDebugLevelEnabled(uint32 level) { + // FIXME: Seems gDebugLevel 11 has a special meaning? Document that! + if (gDebugLevel == 11) + return true; +// return gDebugLevelsEnabled & (1 << level); + return gDebugLevelsEnabled & level; +} + +bool isSpecialDebugLevelEnabled(const String &name) { + // FIXME: Seems gDebugLevel 11 has a special meaning? Document that! + if (gDebugLevel == 11) + return true; + + // Search for the debug level with the given name and check if it is enabled + SpecialDebugLevelList::iterator i = find_if(gDebugLevels.begin(), gDebugLevels.end(), DebugLevelSearch(name)); + if (i != gDebugLevels.end()) + return gDebugLevelsEnabled & i->level; + return false; +} + + } // End of namespace Common @@ -217,6 +238,7 @@ void debugN(int level, const char *s, ...) { void debugC(int level, uint32 engine_level, const char *s, ...) { va_list va; + // FIXME: Seems gDebugLevel 11 has a special meaning? Document that! if (gDebugLevel != 11) if (level > gDebugLevel || !(Common::gDebugLevelsEnabled & engine_level)) return; diff --git a/common/debug.h b/common/debug.h index d446a53d0e..8d01cde539 100644 --- a/common/debug.h +++ b/common/debug.h @@ -33,12 +33,12 @@ namespace Common { -struct EngineDebugLevel { - EngineDebugLevel() : option(""), description(""), level(0), enabled(false) {} - EngineDebugLevel(uint32 l, const String &o, const String &d) - : option(o), description(d), level(l), enabled(false) {} +struct SpecialDebugLevel { + SpecialDebugLevel() : level(0), enabled(false) {} + SpecialDebugLevel(uint32 l, const String &n, const String &d) + : name(n), description(d), level(l), enabled(false) {} - String option; + String name; String description; uint32 level; @@ -48,42 +48,46 @@ struct EngineDebugLevel { /** * Adds a engine debug level. * @param level the level flag (should be OR-able i.e. first one should be 1 than 2,4,...) - * @param option the option name which is used in the debugger/on the command line to enable + * @param name the option name which is used in the debugger/on the command line to enable * this special debug level, the option will be compared case !insentiv! later * @param description the description which shows up in the debugger * @return true on success false on failure */ -bool addSpecialDebugLevel(uint32 level, const String &option, const String &description); +bool addSpecialDebugLevel(uint32 level, const String &name, const String &description); /** - * Resets all engine debug levels + * Resets all engine debug levels. */ void clearAllSpecialDebugLevels(); /** - * Enables a engine debug level - * @param option the option which should be enabled - * @return true on success false on failure + * Enables an engine debug level. + * @param name the name of the debug level to enable + * @return true on success, false on failure */ -bool enableSpecialDebugLevel(const String &option); +bool enableSpecialDebugLevel(const String &name); -// only used for parsing the levels from the commandline -void enableSpecialDebugLevelList(const String &option); +/** + * Enables a list of engine debug levels, given as a comma-separated list + * of level names. + * @param name the list of names of debug levels to enable + */ +void enableSpecialDebugLevelList(const String &names); /** - * Disables a engine debug level - * @param option the option to disable - * @return true on success false on failure + * Disables an engine debug level + * @param name the name of the debug level to disable + * @return true on success, false on failure */ -bool disableSpecialDebugLevel(const String &option); +bool disableSpecialDebugLevel(const String &name); -typedef List<EngineDebugLevel> DebugLevelContainer; +typedef List<SpecialDebugLevel> SpecialDebugLevelList; /** * Lists all debug levels * @return returns a arry with all debug levels */ -const DebugLevelContainer &listSpecialDebugLevels(); +const SpecialDebugLevelList &listSpecialDebugLevels(); /** * Return the active debug flag mask (i.e. all active debug flags ORed @@ -92,6 +96,17 @@ const DebugLevelContainer &listSpecialDebugLevels(); uint32 getEnabledSpecialDebugLevels(); +/** + * Test whether the given debug level is enabled. + */ +bool isSpecialDebugLevelEnabled(uint32 level); + +/** + * Test whether the given debug level is enabled. + */ +bool isSpecialDebugLevelEnabled(const String &name); + + } // End of namespace Common diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp index a8feda0805..e1912d2737 100644 --- a/engines/groovie/script.cpp +++ b/engines/groovie/script.cpp @@ -42,11 +42,8 @@ void debugScript(int level, bool nl, const char *s, ...) { char buf[STRINGBUFLEN]; va_list va; - uint32 engine_level = kGroovieDebugScript | kGroovieDebugAll; - - if (gDebugLevel != 11) - if (!(Common::getEnabledSpecialDebugLevels() & engine_level)) - return; + if (!Common::isSpecialDebugLevelEnabled(kGroovieDebugScript | kGroovieDebugAll)) + return; va_start(va, s); vsnprintf(buf, STRINGBUFLEN, s, va); diff --git a/engines/groovie/vdx.cpp b/engines/groovie/vdx.cpp index 247d2c885e..aa5196c5c9 100644 --- a/engines/groovie/vdx.cpp +++ b/engines/groovie/vdx.cpp @@ -49,8 +49,7 @@ void VDXPlayer::setOrigin(int16 x, int16 y) { } uint16 VDXPlayer::loadInternal() { - uint32 engine_level = kGroovieDebugVideo | kGroovieDebugAll; - if ((gDebugLevel == 11) || (Common::getEnabledSpecialDebugLevels() & engine_level)) { + if (Common::isSpecialDebugLevelEnabled(kGroovieDebugVideo | kGroovieDebugAll)) { int8 i; debugN(1, "Groovie::VDX: New VDX: bitflags are "); for (i = 15; i >= 0; i--) { diff --git a/engines/scumm/debugger.cpp b/engines/scumm/debugger.cpp index 891b5c0135..78c2c410e0 100644 --- a/engines/scumm/debugger.cpp +++ b/engines/scumm/debugger.cpp @@ -498,59 +498,35 @@ bool ScummDebugger::Cmd_Object(int argc, const char **argv) { } bool ScummDebugger::Cmd_Debug(int argc, const char **argv) { - const Common::DebugLevelContainer &lvls = Common::listSpecialDebugLevels(); - - bool setFlag = false; // Remove or add debug channel? - - if ((argc == 1) && (Common::getEnabledSpecialDebugLevels() == 0)) { - DebugPrintf("No debug flags are enabled\n"); - DebugPrintf("Available Channels: "); - for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) { - DebugPrintf("%s, ", i->option.c_str()); - } - DebugPrintf("\n"); - return true; - } - - if ((argc == 1) && (Common::getEnabledSpecialDebugLevels() > 0)) { - for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) { - if (i->enabled) - DebugPrintf("%s - %s\n", i->option.c_str(), i->description.c_str()); + const Common::SpecialDebugLevelList &lvls = Common::listSpecialDebugLevels(); + + // No parameters given: Print out a list of all channels and their status + if (argc <= 1) { + DebugPrintf("Available debug channels: "); + for (Common::SpecialDebugLevelList::iterator i = lvls.begin(); i != lvls.end(); ++i) { + DebugPrintf("%c%s - %s (%s)\n", i->enabled ? '+' : ' ', + i->name.c_str(), i->description.c_str(), + i->enabled ? "enabled" : "disabled"); } return true; } // Enable or disable channel? + bool result = false; if (argv[1][0] == '+') { - setFlag = true; + result = Common::enableSpecialDebugLevel(argv[1] + 1); } else if (argv[1][0] == '-') { - setFlag = false; - } else { - DebugPrintf("Syntax: Debug +CHANNEL, or Debug -CHANNEL\n"); - DebugPrintf("Available Channels: "); - for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) { - DebugPrintf("%s\n", i->option.c_str()); - } + result = Common::disableSpecialDebugLevel(argv[1] + 1); } - - // Identify flag - const char *realFlag = argv[1] + 1; - for (Common::DebugLevelContainer::iterator i = lvls.begin(); i != lvls.end(); ++i) { - if (i->option.equalsIgnoreCase(realFlag)) { - if (setFlag) { - enableSpecialDebugLevel(i->option); - DebugPrintf("Enable "); - } else { - disableSpecialDebugLevel(i->option); - DebugPrintf("Disable "); - } - - DebugPrintf("%s\n", i->description.c_str()); - return true; - } + + if (result) { + DebugPrintf("%s %s\n", (argv[1][0] == '+') ? "Enabled" : "Disabled", argv[1] + 1); + } else { + DebugPrintf("Usage: debug [+CHANNEL|-CHANNEL]\n"); + DebugPrintf("Enables or disables the given debug channel.\n"); + DebugPrintf("When used without parameters, lists all avaiable debug channels and their status.\n"); } - DebugPrintf("Unknown flag. Type 'Debug ?' for syntax\n"); return true; } diff --git a/gui/debugger.cpp b/gui/debugger.cpp index 8ec7949ab2..39e07a28f3 100644 --- a/gui/debugger.cpp +++ b/gui/debugger.cpp @@ -406,7 +406,7 @@ bool Debugger::Cmd_Help(int argc, const char **argv) { } bool Debugger::Cmd_DebugFlagsList(int argc, const char **argv) { - const Common::DebugLevelContainer &debugLevels = Common::listSpecialDebugLevels(); + const Common::SpecialDebugLevelList &debugLevels = Common::listSpecialDebugLevels(); DebugPrintf("Engine debug levels:\n"); DebugPrintf("--------------------\n"); @@ -414,8 +414,10 @@ bool Debugger::Cmd_DebugFlagsList(int argc, const char **argv) { DebugPrintf("No engine debug levels\n"); return true; } - for (Common::DebugLevelContainer::const_iterator i = debugLevels.begin(); i != debugLevels.end(); ++i) { - DebugPrintf("'%s' - Description: %s\n", i->option.c_str(), i->description.c_str()); + for (Common::SpecialDebugLevelList::const_iterator i = debugLevels.begin(); i != debugLevels.end(); ++i) { + DebugPrintf("%c%s - %s (%s)\n", i->enabled ? '+' : ' ', + i->name.c_str(), i->description.c_str(), + i->enabled ? "enabled" : "disabled"); } DebugPrintf("\n"); return true; |