[lldb] Improve assert in GDBRemoteCommunicationReplayServer
authorJonas Devlieghere <jonas@devlieghere.com>
Thu, 7 Nov 2019 19:13:47 +0000 (11:13 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Thu, 7 Nov 2019 20:43:59 +0000 (12:43 -0800)
While investigating an issue where a different packet was sent during
replay I noticed how annoying it is that the existing assert doesn't
specify what packet is actually different. It's printed to the log, but
enabling logging has the potential to change LLDB's behavior. The same
is true when debugging LLDB while it's replaying the reproducer.

I replaced the assert with a printf of the unexpected packet followed by
a fatal_error wrapped in ifndef NDEBUG. The behavior is the same as the
previous assert, just with more/better context.

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp

index 2d26c55..3a01df0 100644 (file)
@@ -143,7 +143,14 @@ GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
                  entry.packet.data);
         LLDB_LOG(log, "GDBRemoteCommunicationReplayServer actual packet: '{0}'",
                  packet.GetStringRef());
-        assert(false && "Encountered unexpected packet during replay");
+#ifndef NDEBUG
+        // This behaves like a regular assert, but prints the expected and
+        // received packet before aborting.
+        printf("Reproducer expected packet: '%s'\n", entry.packet.data.c_str());
+        printf("Reproducer received packet: '%s'\n",
+               packet.GetStringRef().data());
+        llvm::report_fatal_error("Encountered unexpected packet during replay");
+#endif
         return PacketResult::ErrorSendFailed;
       }