Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.cppHeaderProbe = true;
}

else if (std::strcmp(argv[i], "--debug-ast") == 0)
mSettings.debugast = true;

// Show debug warnings for lookup for configuration files
else if (std::strcmp(argv[i], "--debug-clang-output") == 0)
mSettings.debugClangOutput = true;
Expand Down Expand Up @@ -687,10 +690,16 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
else if (std::strcmp(argv[i], "--debug-simplified") == 0)
mSettings.debugSimplified = true;

else if (std::strcmp(argv[i], "--debug-symdb") == 0)
mSettings.debugsymdb = true;

// Show template information
else if (std::strcmp(argv[i], "--debug-template") == 0)
mSettings.debugtemplate = true;

else if (std::strcmp(argv[i], "--debug-valueflow") == 0)
mSettings.debugvalueflow = true;

// Show debug warnings
else if (std::strcmp(argv[i], "--debug-warnings") == 0)
mSettings.debugwarnings = true;
Expand Down
3 changes: 1 addition & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
mErrorLogger,
mSettings,
&s_timerResults);
if (mSettings.debugnormal)
tokenizer.printDebugOutput(1, std::cout);
tokenizer.printDebugOutput(std::cout);
checkNormalTokens(tokenizer, nullptr); // TODO: provide analyzer information

// create dumpfile
Expand Down
9 changes: 9 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief Are we running from DACA script? */
bool daca{};

/** @brief Is --debug-ast given? */
bool debugast{};

/** @brief Is --debug-clang-output given? */
bool debugClangOutput{};

Expand Down Expand Up @@ -215,9 +218,15 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief Is --debug-simplified given? */
bool debugSimplified{};

/** @brief Is --debug-symdb given? */
bool debugsymdb{};

/** @brief Is --debug-template given? */
bool debugtemplate{};

/** @brief Is --debug-valueflow given? */
bool debugvalueflow{};

/** @brief Is --debug-warnings given? */
bool debugwarnings{};

Expand Down
64 changes: 34 additions & 30 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3441,7 +3441,7 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
mSymbolDatabase->setArrayDimensionsUsingValueFlow();
}

printDebugOutput(1, std::cout);
printDebugOutput(std::cout);

return true;
}
Expand Down Expand Up @@ -5890,39 +5890,39 @@ bool Tokenizer::simplifyTokenList1(const char FileName[])
}
//---------------------------------------------------------------------------

void Tokenizer::printDebugOutput(int simplification, std::ostream &out) const
// TODO: do not depend on --verbose
void Tokenizer::printDebugOutput(std::ostream &out) const
{
const bool debug = (simplification != 1U && mSettings.debugSimplified) ||
(simplification != 2U && mSettings.debugnormal);
if (!list.front())
return;

if (debug && list.front()) {
const bool xml = (mSettings.outputFormat == Settings::OutputFormat::xml);
const bool debug = mSettings.debugSimplified || mSettings.debugnormal || mSettings.debugsymdb || mSettings.debugast || mSettings.debugvalueflow;
if (!debug)
return;

if (!xml)
list.front()->printOut(out, xml, nullptr, list.getFiles());
const bool xml = (mSettings.outputFormat == Settings::OutputFormat::xml);

if (xml)
{
out << "<debug>" << std::endl;
list.front()->printOut(out, xml, nullptr, list.getFiles());
}
if (xml)
out << "<debug>" << std::endl;

if (mSymbolDatabase) {
if (xml)
mSymbolDatabase->printXml(out);
else if (mSettings.verbose) {
mSymbolDatabase->printOut("Symbol database");
}
}
if (mSettings.debugSimplified || mSettings.debugnormal)
list.front()->printOut(out, xml, nullptr, list.getFiles());

if (mSymbolDatabase) {
if (xml)
mSymbolDatabase->printXml(out);
else if (mSettings.debugsymdb || (mSettings.debugnormal && mSettings.verbose))
mSymbolDatabase->printOut("Symbol database");
}

if (mSettings.verbose)
list.front()->printAst(mSettings.verbose, xml, list.getFiles(), out);
if (mSettings.debugast || (mSettings.debugnormal && mSettings.verbose))
list.front()->printAst(mSettings.verbose, xml, list.getFiles(), out);

if (mSettings.debugnormal || mSettings.debugvalueflow)
list.front()->printValueFlow(list.getFiles(), xml, out);

if (xml)
out << "</debug>" << std::endl;
}
if (xml)
out << "</debug>" << std::endl;
}

void Tokenizer::dump(std::ostream &out) const
Expand Down Expand Up @@ -8077,27 +8077,31 @@ bool Tokenizer::isScopeNoReturn(const Token *endScopeToken, bool *unknown) const

void Tokenizer::syntaxError(const Token *tok, const std::string &code) const
{
printDebugOutput(0, std::cout);
if (mSettings.debugSimplified || mSettings.debugnormal)
printDebugOutput(std::cout);
throw InternalError(tok, code.empty() ? "syntax error" : "syntax error: " + code, InternalError::SYNTAX);
}

void Tokenizer::unmatchedToken(const Token *tok) const
{
printDebugOutput(0, std::cout);
if (mSettings.debugSimplified || mSettings.debugnormal)
printDebugOutput(std::cout);
throw InternalError(tok,
"Unmatched '" + tok->str() + "'. Configuration: '" + mConfiguration + "'.",
InternalError::SYNTAX);
}

void Tokenizer::syntaxErrorC(const Token *tok, const std::string &what) const
{
printDebugOutput(0, std::cout);
if (mSettings.debugSimplified || mSettings.debugnormal)
printDebugOutput(std::cout);
throw InternalError(tok, "Code '"+what+"' is invalid C code.", "Use --std, -x or --language to enforce C++. Or --cpp-header-probe to identify C++ headers via the Emacs marker.", InternalError::SYNTAX);
}

void Tokenizer::unknownMacroError(const Token *tok1) const
{
printDebugOutput(0, std::cout);
if (mSettings.debugSimplified || mSettings.debugnormal)
printDebugOutput(std::cout);
throw InternalError(tok1, "There is an unknown macro here somewhere. Configuration is required. If " + tok1->str() + " is a macro then please configure it.", InternalError::UNKNOWN_MACRO);
}

Expand Down Expand Up @@ -8131,7 +8135,7 @@ void Tokenizer::invalidConstFunctionTypeError(const Token *tok) const

void Tokenizer::cppcheckError(const Token *tok) const
{
printDebugOutput(0, std::cout);
printDebugOutput(std::cout);
throw InternalError(tok, "Analysis failed. If the code is valid then please report this failure.", InternalError::INTERNAL);
}

Expand Down
5 changes: 1 addition & 4 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,8 @@ class CPPCHECKLIB Tokenizer {
void createSymbolDatabase();

/** print --debug output if debug flags match the simplification:
* 0=unknown/both simplifications
* 1=1st simplifications
* 2=2nd simplifications
*/
void printDebugOutput(int simplification, std::ostream &out) const;
void printDebugOutput(std::ostream &out) const;

void dump(std::ostream &out) const;

Expand Down
8 changes: 4 additions & 4 deletions test/cli/clang-import_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def __check_symbol_database(tmpdir, code):
testfile = os.path.join(tmpdir, 'test.cpp')
with open(testfile, 'w+t') as f:
f.write(code)
ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile])
ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile])
ret1, stdout1, _ = cppcheck(['--clang', '--debug-symdb', testfile])
ret2, stdout2, _ = cppcheck(['--debug-symdb', testfile])
assert 0 == ret1, stdout1
assert 0 == ret2, stdout2
assert __get_debug_section('### Symbol database', stdout1) == __get_debug_section('### Symbol database', stdout2)
Expand All @@ -58,8 +58,8 @@ def __check_ast(tmpdir, code):
testfile = os.path.join(tmpdir, 'test.cpp')
with open(testfile, 'w+t') as f:
f.write(code)
ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile])
ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile])
ret1, stdout1, _ = cppcheck(['--clang', '--debug-ast', testfile])
ret2, stdout2, _ = cppcheck(['--debug-ast', testfile])
assert 0 == ret1, stdout1
assert 0 == ret2, stdout1
assert __get_debug_section('##AST', stdout1) == __get_debug_section('##AST', stdout2)
Expand Down
Loading
Loading