Skip to content

Commit 05052d7

Browse files
committed
added CLI option --debug-ipc to log ProcessExecutor IPC communication [skip ci]
1 parent efae8c0 commit 05052d7

6 files changed

Lines changed: 49 additions & 3 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
631631
else if (std::strcmp(argv[i], "--debug-ignore") == 0)
632632
mSettings.debugignore = true;
633633

634+
else if (std::strcmp(argv[i], "--debug-ipc") == 0)
635+
mSettings.debugipc = true;
636+
634637
// Show --debug output after the first simplifications
635638
else if (std::strcmp(argv[i], "--debug") == 0 ||
636639
std::strcmp(argv[i], "--debug-normal") == 0)

cli/processexecutor.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace {
8080
public:
8181
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'};
8282

83-
explicit PipeWriter(int pipe) : mWpipe(pipe) {}
83+
explicit PipeWriter(int pipe, bool debug) : mWpipe(pipe), mDebug(debug) {}
8484

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

154154
void writeToPipe(PipeSignal type, const std::string &data) const
155155
{
156+
if (mDebug)
157+
std::cout << "writeToPipe - " << type << " - " << data << std::endl;
158+
156159
{
157160
const auto t = static_cast<char>(type);
158161
writeToPipeInternal(type, &t, 1);
@@ -169,6 +172,7 @@ namespace {
169172
}
170173

171174
const int mWpipe;
175+
const bool mDebug;
172176
};
173177
}
174178

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

242+
if (mSettings.debugipc)
243+
std::cout << "handleRead - " << type << " - " << buf << std::endl;
244+
238245
bool res = true;
239246
if (type == PipeWriter::REPORT_OUT) {
240247
// the first character is the color
@@ -378,7 +385,7 @@ unsigned int ProcessExecutor::check()
378385
mTimerResults->reset();
379386
// TODO: how to "reset" mSuppressions?
380387

381-
PipeWriter pipewriter(pipes[1]);
388+
PipeWriter pipewriter(pipes[1], mSettings.debugipc);
382389
CppCheck fileChecker(mSettings, mSuppressions, pipewriter, mTimerResults, false, mExecuteCommand);
383390
unsigned int resultOfCheck = 0;
384391

lib/check.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ ErrorPath Check::getErrorPath(const Token* errtok, const ValueFlow::Value* value
130130

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

lib/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
202202
/** @brief Is --debug-ignore given? */
203203
bool debugignore{};
204204

205+
/** @brief Is --debug-ipc given? */
206+
bool debugipc{};
207+
205208
/** @brief Internal: Is --debug-lookup or --debug-lookup=all given? */
206209
bool debuglookup{};
207210

test/cli/other_test.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4633,4 +4633,28 @@ def test_dui_include_absolute_missing(tmp_path): # #14675
46334633
assert stdout == ''
46344634
assert stderr.splitlines() == [
46354635
f"{test_file}:0:0: error: Can not open include file '/share/include/missing.h' that is explicitly included. [missingIncludeExplicit]"
4636-
]
4636+
]
4637+
4638+
4639+
@pytest.mark.xfail(strict=True) # TODO: should not report logChecker when not required
4640+
@pytest.mark.skipif(sys.platform == 'win32', reason="requires ProcessExecutor")
4641+
def test_ipc_log_checker(tmp_path):
4642+
test_file = tmp_path / 'test.c'
4643+
with open(test_file, "w") as f:
4644+
f.write('void f() {}')
4645+
4646+
args = [
4647+
'-q',
4648+
'--debug-ipc',
4649+
'-j2',
4650+
'--executor=process',
4651+
str(test_file)
4652+
]
4653+
4654+
exitcode, stdout, stderr = cppcheck(args)
4655+
assert exitcode == 0
4656+
assert stdout.splitlines() == [
4657+
'writeToPipe - 5 - 0',
4658+
'handleRead - 5 - 0'
4659+
]
4660+
assert stderr.splitlines() == []

test/testcmdlineparser.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class TestCmdlineParser : public TestFixture {
498498
TEST_CASE(noSafety);
499499
TEST_CASE(noSafetyOverride);
500500
TEST_CASE(debugAnalyzerinfo);
501+
TEST_CASE(debugIpc);
501502

502503
TEST_CASE(ignorepaths1);
503504
TEST_CASE(ignorepaths2);
@@ -3479,6 +3480,13 @@ class TestCmdlineParser : public TestFixture {
34793480
ASSERT_EQUALS(true, settings->debugainfo);
34803481
}
34813482

3483+
void debugIpc() {
3484+
REDIRECT;
3485+
const char * const argv[] = {"cppcheck", "--debug-ipc", "file.cpp"};
3486+
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
3487+
ASSERT_EQUALS(true, settings->debugipc);
3488+
}
3489+
34823490
void ignorepaths1() {
34833491
REDIRECT;
34843492
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};

0 commit comments

Comments
 (0)