Skip to content
Draft
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
3 changes: 3 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
else if (std::strcmp(argv[i], "--debug-ignore") == 0)
mSettings.debugignore = true;

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

// Show --debug output after the first simplifications
else if (std::strcmp(argv[i], "--debug") == 0 ||
std::strcmp(argv[i], "--debug-normal") == 0)
Expand Down
11 changes: 9 additions & 2 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace {
public:
enum PipeSignal : std::uint8_t {REPORT_OUT='1',REPORT_ERROR='2',REPORT_SUPPR_INLINE='3',REPORT_SUPPR='4',CHILD_END='5',REPORT_METRIC='6',REPORT_TIMER='7'};

explicit PipeWriter(int pipe) : mWpipe(pipe) {}
explicit PipeWriter(int pipe, bool debug) : mWpipe(pipe), mDebug(debug) {}

void reportOut(const std::string &outmsg, Color c) override {
writeToPipe(REPORT_OUT, static_cast<char>(c) + outmsg);
Expand Down Expand Up @@ -153,6 +153,9 @@ namespace {

void writeToPipe(PipeSignal type, const std::string &data) const
{
if (mDebug)
std::cout << "writeToPipe - " << type << " - " << data << std::endl;

{
const auto t = static_cast<char>(type);
writeToPipeInternal(type, &t, 1);
Expand All @@ -169,6 +172,7 @@ namespace {
}

const int mWpipe;
const bool mDebug;
};
}

Expand Down Expand Up @@ -235,6 +239,9 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
} while (bytes_to_read != 0);
}

if (mSettings.debugipc)
std::cout << "handleRead - " << type << " - " << buf << std::endl;

bool res = true;
if (type == PipeWriter::REPORT_OUT) {
// the first character is the color
Expand Down Expand Up @@ -378,7 +385,7 @@ unsigned int ProcessExecutor::check()
mTimerResults->reset();
// TODO: how to "reset" mSuppressions?

PipeWriter pipewriter(pipes[1]);
PipeWriter pipewriter(pipes[1], mSettings.debugipc);
CppCheck fileChecker(mSettings, mSuppressions, pipewriter, mTimerResults, false, mExecuteCommand);
unsigned int resultOfCheck = 0;

Expand Down
1 change: 1 addition & 0 deletions lib/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ ErrorPath Check::getErrorPath(const Token* errtok, const ValueFlow::Value* value

void Check::logChecker(const char id[])
{
// TODO: only issue when we would actually use it later on
reportError(nullptr, Severity::internal, "logChecker", id);
}

3 changes: 3 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief Is --debug-ignore given? */
bool debugignore{};

/** @brief Is --debug-ipc given? */
bool debugipc{};

/** @brief Internal: Is --debug-lookup or --debug-lookup=all given? */
bool debuglookup{};

Expand Down
26 changes: 25 additions & 1 deletion test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4633,4 +4633,28 @@ def test_dui_include_absolute_missing(tmp_path): # #14675
assert stdout == ''
assert stderr.splitlines() == [
f"{test_file}:0:0: error: Can not open include file '/share/include/missing.h' that is explicitly included. [missingIncludeExplicit]"
]
]


@pytest.mark.xfail(strict=True) # TODO: should not report logChecker when not required
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
def test_ipc_log_checker(tmp_path):
test_file = tmp_path / 'test.c'
with open(test_file, "w") as f:
f.write('void f() {}')

args = [
'-q',
'--debug-ipc',
'-j2',
'--executor=process',
str(test_file)
]

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0
assert stdout.splitlines() == [
'writeToPipe - 5 - 0',
'handleRead - 5 - 0'
]
assert stderr.splitlines() == []
8 changes: 8 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(noSafety);
TEST_CASE(noSafetyOverride);
TEST_CASE(debugAnalyzerinfo);
TEST_CASE(debugIpc);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -3479,6 +3480,13 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS(true, settings->debugainfo);
}

void debugIpc() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--debug-ipc", "file.cpp"};
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
ASSERT_EQUALS(true, settings->debugipc);
}

void ignorepaths1() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
Expand Down