diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index e699e4a5e..7ed0f6a69 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -126,6 +126,10 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[]) else if (std::strcmp(argv[i], "--debug") == 0) _settings->debug = _settings->debugwarnings = true; + // Show --debug output after the first simplifications + else if (std::strcmp(argv[i], "--debug-normal") == 0) + _settings->debugnormal = true; + // Show debug warnings else if (std::strcmp(argv[i], "--debug-warnings") == 0) _settings->debugwarnings = true; diff --git a/lib/settings.cpp b/lib/settings.cpp index e728685a9..a867b93af 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -27,6 +27,7 @@ Settings::Settings() : _terminate(false), debug(false), + debugnormal(false), debugwarnings(false), debugFalsePositive(false), dump(false), diff --git a/lib/settings.h b/lib/settings.h index 214d62244..eb5b65113 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -57,6 +57,9 @@ public: /** @brief Is --debug given? */ bool debug; + /** @brief Is --debug-normal given? */ + bool debugnormal; + /** @brief Is --debug-warnings given? */ bool debugwarnings; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b012a1b87..b7d71fdfb 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1757,6 +1757,8 @@ bool Tokenizer::tokenize(std::istream &code, ValueFlow::setValues(&list, _symbolDatabase, _errorLogger, _settings); } + printDebugOutput(1); + return true; } return false; @@ -3785,15 +3787,18 @@ bool Tokenizer::simplifyTokenList2() if (_settings->terminated()) return false; - printDebugOutput(); + printDebugOutput(2); return true; } //--------------------------------------------------------------------------- -void Tokenizer::printDebugOutput() const +void Tokenizer::printDebugOutput(unsigned int simplification) const { - if (_settings->debug) { + const bool debug = (simplification != 1U && _settings->debug) || + (simplification != 2U && _settings->debugnormal); + + if (debug) { list.front()->printOut(0, list.getFiles()); if (_settings->_xml) @@ -3815,7 +3820,7 @@ void Tokenizer::printDebugOutput() const std::cout << "" << std::endl; } - if (_settings->debugwarnings) { + if (simplification == 2U && _settings->debugwarnings) { printUnknownTypes(); // #5054 - the typeStartToken() should come before typeEndToken() @@ -8235,13 +8240,13 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end) void Tokenizer::syntaxError(const Token *tok) const { - printDebugOutput(); + printDebugOutput(0); throw InternalError(tok, "syntax error", InternalError::SYNTAX); } void Tokenizer::syntaxError(const Token *tok, char c) const { - printDebugOutput(); + printDebugOutput(0); throw InternalError(tok, std::string("Invalid number of character (") + c + ") " + "when these macros are defined: '" + _configuration + "'.", @@ -8262,7 +8267,7 @@ void Tokenizer::unhandled_macro_class_x_y(const Token *tok) const void Tokenizer::cppcheckError(const Token *tok) const { - printDebugOutput(); + printDebugOutput(0); throw InternalError(tok, "Analysis failed. If the code is valid then please report this failure.", InternalError::INTERNAL); } /** diff --git a/lib/tokenize.h b/lib/tokenize.h index 6f4ad5c3f..5eb64a8f9 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -755,7 +755,12 @@ public: void createSymbolDatabase(); void deleteSymbolDatabase(); - void printDebugOutput() const; + /** print --debug output if debug flags match the simplification: + * 0=unknown/both simplifications + * 1=1st simplifications + * 2=2nd simplifications + */ + void printDebugOutput(unsigned int simplification) const; void dump(std::ostream &out) const;