ssnetsim / supersim

A flexible event-driven cycle-accurate network simulator
Apache License 2.0
8 stars 1 forks source link

Attach debug messages to assertion failures #25

Open knrafto opened 4 years ago

knrafto commented 4 years ago

I've noticed if I do a dbgprintf and then an assert(false), sometimes the debug message isn't printed before the program dies. I'm not sure why. Compiler optimization? Stream not getting flushed?

I would appreciate it if there was a function like

dbgassert(bool, const char* _format, ...)

where I could add a nice debugging message for why the assertion failed (similar to LOG(FATAL) or CHECK() at Google), and also log the component info like dbgprintf() does.

nicmcd commented 4 years ago

Would a valid macro expansion be:

if (!condition) { fprintf(stderr, _format, ...); fflush(stderr); assert(false); }

knrafto commented 4 years ago

s/fprintf/dbgprintf, so it shows the component info and the original file/line. But it would be nice to flag it as "this is an assertion failure!" instead of being a normal log line. If we have that, then we can use abort() instead of assert(false)