Skip to content

Commit 781a667

Browse files
committed
Add debug logging for piped_process failures
1 parent cd29b67 commit 781a667

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/solvers/smt2_incremental/smt_solver_process.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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), &message_handler},
1717
log{message_handler}
1818
{
1919
}

src/util/piped_process.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
# include "run.h" // for Windows arg quoting
8080
# include "unicode.h" // for widen function
8181
# include <tchar.h> // library for _tcscpy function
82-
# include <util/make_unique.h>
8382
# include <windows.h>
8483
#else
8584
# include <fcntl.h> // library for fcntl function
@@ -90,6 +89,7 @@
9089

9190
#include <util/exception_utils.h>
9291
#include <util/invariant.h>
92+
#include <util/make_unique.h>
9393
#include <util/narrow.h>
9494
#include <util/optional.h>
9595
#include <util/piped_process.h>
@@ -124,7 +124,23 @@ 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(
141+
const std::vector<std::string> &commandvec,
142+
message_handlert *message_handler)
143+
: log{make_log(message_handler)}
128144
{
129145
# ifdef _WIN32
130146
// Security attributes for pipe creation
@@ -365,12 +381,17 @@ piped_processt::send_responset piped_processt::send(const std::string &message)
365381
if(!WriteFile(
366382
child_std_IN_Wr, message.c_str(), message_size, &bytes_written, NULL))
367383
{
368-
// Error handling with GetLastError ?
384+
const DWORD error_code = GetLastError();
385+
log.debug() << "Last error code is " + std::to_string(error_code)
386+
<< messaget::eom;
369387
return send_responset::FAILED;
370388
}
371389
if(bytes_written != 0)
372390
break;
373391
// Give the sub-process chance to read the waiting message(s).
392+
const auto wait_milliseconds = narrow<DWORD>(1 << send_attempts);
393+
log.debug() << "Zero bytes send to sub process. Retrying in "
394+
<< wait_milliseconds << " milliseconds." << messaget::eom;
374395
FlushFileBuffers(child_std_IN_Wr);
375396
Sleep(1 << send_attempts);
376397
}

src/util/piped_process.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
#define CPROVER_UTIL_PIPED_PROCESS_H
77

88
#ifdef _WIN32
9-
# include <memory>
109
// The below are forward declarations for Windows APIs
1110
struct _PROCESS_INFORMATION; // NOLINT
1211
typedef struct _PROCESS_INFORMATION PROCESS_INFORMATION; // NOLINT
1312
typedef void *HANDLE; // NOLINT
1413
#endif
1514

15+
#include <util/message.h>
1616
#include <util/nodiscard.h>
1717
#include <util/optional.h>
1818

19+
#include <memory>
1920
#include <vector>
2021

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

8589
// Deleted due to declaring an explicit destructor and not wanting copy
8690
// constructors to be implemented.
@@ -109,6 +113,10 @@ class piped_processt
109113
int pipe_output[2];
110114
#endif
111115
statet process_state;
116+
117+
messaget make_log(message_handlert *message_handler);
118+
std::unique_ptr<null_message_handlert> null_handler;
119+
messaget log;
112120
};
113121

114122
#endif // endifndef CPROVER_UTIL_PIPED_PROCESS_H

0 commit comments

Comments
 (0)