Add specific error messages around gdb RSP handshake failures

Report timeout exceeded and connection lost error messages
when sending the initial handshake packet in a gdb remote
serial protocol connection, an especially fragile time.

Differential Revision: https://reviews.llvm.org/D108888
This commit is contained in:
Jason Molenda 2021-09-09 17:02:42 -07:00
parent 766afbc804
commit f3472ad5c5
1 changed files with 20 additions and 2 deletions

View File

@ -82,6 +82,8 @@ bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
// Start the read thread after we send the handshake ack since if we fail to // Start the read thread after we send the handshake ack since if we fail to
// send the handshake ack, there is no reason to continue... // send the handshake ack, there is no reason to continue...
std::chrono::steady_clock::time_point start_of_handshake =
std::chrono::steady_clock::now();
if (SendAck()) { if (SendAck()) {
// Wait for any responses that might have been queued up in the remote // Wait for any responses that might have been queued up in the remote
// GDB server and flush them all // GDB server and flush them all
@ -97,8 +99,24 @@ bool GDBRemoteCommunicationClient::HandshakeWithServer(Status *error_ptr) {
if (QueryNoAckModeSupported()) { if (QueryNoAckModeSupported()) {
return true; return true;
} else { } else {
if (error_ptr) std::chrono::steady_clock::time_point end_of_handshake =
error_ptr->SetErrorString("failed to get reply to handshake packet"); std::chrono::steady_clock::now();
auto handshake_timeout =
std::chrono::duration<double>(end_of_handshake - start_of_handshake)
.count();
if (error_ptr) {
if (packet_result == PacketResult::ErrorDisconnected)
error_ptr->SetErrorString("Connection shut down by remote side "
"while waiting for reply to initial "
"handshake packet");
else if (packet_result == PacketResult::ErrorReplyTimeout)
error_ptr->SetErrorStringWithFormat(
"failed to get reply to handshake packet within timeout of "
"%.1f seconds",
handshake_timeout);
else
error_ptr->SetErrorString("failed to get reply to handshake packet");
}
} }
} else { } else {
if (error_ptr) if (error_ptr)