custom printing messages with your assertion trips #14466
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
I kept rewriting assertions into
if(assert condition) { print something; trip assertion; }
and went "this probably works".So now I want to see if the CI explodes on Debian 8 or something.
(Before merge I'd probably refactor the non-f versions into being in terms of the f versions, but this way I can test a much smaller blast radius at a time...also suggestions for better naming welcome.)
(...I also flattened freebsd's debug.h and linux's after noticing they were more or less the same file, but that's mostly orthogonal and just in here because I also want to make sure that compiles everywhere.)
Description
Gives all the ASSERT/VERIFY macros an "f" suffix variant that adds "STR, ..." arguments such that you could do, say
ASSERT3Pf(hdr->b_l1hdr.b_pabd, !=, NULL, "hdr %px buf %px", hdr, buf);
and get an error trip like
VERIFY3(hdr->b_l1hdr.b_pabd != NULL) failed (0000000000000000 != 0000000000000000) hdr 0000000000000000 buf 0000000000000000
The only big caveat is I don't think you can do something like
((void) __VA_ARGS__)
so the print varargs won't always get executed, so don't put side effect things in there you need to always run...but that's not a reason not to have it, just a warning.How Has This Been Tested?
I mean, I compiled it once, what could go wrong, right?
Types of changes
Checklist:
Signed-off-by
.