Skip to content

Commit 650577d

Browse files
committed
Add debug logging for piped_process failures
1 parent ded72ee commit 650577d

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/solvers/smt2_incremental/smt_solver_process.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ smt_piped_solver_processt::smt_piped_solver_processt(
1313
std::string command_line,
1414
message_handlert &message_handler)
1515
: command_line_description{"\"" + command_line + "\""},
16-
process{split_string(command_line, ' ', false, true)},
16+
process{split_string(command_line, ' ', false, true),
17+
&message_handler},
1718
log{message_handler}
1819
{
1920
}

src/util/piped_process.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,22 @@ prepare_windows_command_line(const std::vector<std::string> &commandvec)
124124
}
125125
#endif
126126

127-
piped_processt::piped_processt(const std::vector<std::string> &commandvec)
127+
messaget piped_processt::make_log(message_handlert *message_handler)
128+
{
129+
if(message_handler)
130+
{
131+
return messaget{*message_handler};
132+
}
133+
else
134+
{
135+
null_handler = util_make_unique<null_message_handlert>();
136+
return messaget{*null_handler};
137+
}
138+
}
139+
140+
piped_processt::piped_processt(const std::vector<std::string> &commandvec,
141+
message_handlert *message_handler)
142+
: log{make_log(message_handler)}
128143
{
129144
# ifdef _WIN32
130145
// Security attributes for pipe creation
@@ -365,12 +380,16 @@ piped_processt::send_responset piped_processt::send(const std::string &message)
365380
if(!WriteFile(
366381
child_std_IN_Wr, message.c_str(), message_size, &bytes_written, NULL))
367382
{
368-
// Error handling with GetLastError ?
383+
const DWORD error_code = GetLastError();
384+
log.debug() << "Last error code is " + std::to_string(error_code) << messaget::eom;
369385
return send_responset::FAILED;
370386
}
371387
if(bytes_written != 0)
372388
break;
373389
// Give the sub-process chance to read the waiting message(s).
390+
const auto wait_milliseconds = narrow<DWORD>(1 << send_attempts);
391+
log.debug() << "Zero bytes send to sub process. Retrying in "
392+
<< wait_milliseconds << " milliseconds." << messaget::eom;
374393
FlushFileBuffers(child_std_IN_Wr);
375394
Sleep(1 << send_attempts);
376395
}

src/util/piped_process.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef void *HANDLE; // NOLINT
1515

1616
#include "nodiscard.h"
1717
#include "optional.h"
18+
#include "message.h"
1819
#include <vector>
1920

2021
#define PIPED_PROCESS_INFINITE_TIMEOUT \
@@ -79,7 +80,9 @@ class piped_processt
7980
/// Initiate a new subprocess with pipes supporting communication
8081
/// between the parent (this process) and the child.
8182
/// \param commandvec The command and arguments to create the process
82-
explicit piped_processt(const std::vector<std::string> &commandvec);
83+
/// \param message_handler Optional message handler for logging debug messages
84+
explicit piped_processt(const std::vector<std::string> &commandvec,
85+
message_handlert *message_handler = nullptr);
8386

8487
// Deleted due to declaring an explicit destructor and not wanting copy
8588
// constructors to be implemented.
@@ -108,6 +111,10 @@ class piped_processt
108111
int pipe_output[2];
109112
#endif
110113
statet process_state;
114+
115+
messaget make_log(message_handlert *message_handler);
116+
std::unique_ptr<null_message_handlert> null_handler;
117+
messaget log;
111118
};
112119

113120
#endif // endifndef CPROVER_UTIL_PIPED_PROCESS_H

0 commit comments

Comments
 (0)