Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach debug messages to assertion failures #25

Open
knrafto opened this issue Apr 15, 2020 · 2 comments
Open

Attach debug messages to assertion failures #25

knrafto opened this issue Apr 15, 2020 · 2 comments

Comments

@knrafto
Copy link
Contributor

knrafto commented Apr 15, 2020

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
Copy link
Member

nicmcd commented Apr 15, 2020

Would a valid macro expansion be:

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

@knrafto
Copy link
Contributor Author

knrafto commented Apr 15, 2020

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants