Validate flatbuffers before printing in aos_dump, log_cat, and simulated_event_loop
We had a corrupted flatbuffer being logged, and the error was very poor
when it was being printed. Let's try to catch this a lot earlier.
Fix 1: log_cat should validate before printing. That'll prevent us
from wasting time debugging why it is crashing and point the finger a
lot better.
Fix 2: aos_dump should do the same. That'll save us from nasty crashes
there too and focus attention a lot better.
Fix 3: SimulatedEventLoop sender Send should also validate in debug
mode. This will avoid too big a performance hit in the fast path, but
will catch corrupted flatbuffers in any simulations we do, or any log
replay that gets done with debug turned on.
This caught a couple of places where we were missing schemas, so add
those in too.
Change-Id: I1873ddd592d33fe4e64210a2e08aa9b937d61ab8
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/simulated_event_loop.cc b/aos/events/simulated_event_loop.cc
index ef34839..51021b6 100644
--- a/aos/events/simulated_event_loop.cc
+++ b/aos/events/simulated_event_loop.cc
@@ -806,6 +806,17 @@
message->context.queue_index = queue_index;
message->context.data = message->data(channel()->max_size()) +
channel()->max_size() - message->context.size;
+
+ DCHECK(channel()->has_schema())
+ << ": Missing schema for channel "
+ << configuration::StrippedChannelToString(channel());
+ DCHECK(flatbuffers::Verify(
+ *channel()->schema(), *channel()->schema()->root_table(),
+ static_cast<const uint8_t *>(message->context.data),
+ message->context.size))
+ << ": Corrupted flatbuffer on " << channel()->name()->c_str() << " "
+ << channel()->type()->c_str();
+
next_queue_index_ = next_queue_index_.Increment();
latest_message_ = message;