-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Do not evaluate hidden LogPrint arguments #9417
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
Conversation
|
@sipa Thanks - I was just about to look into coding something similar so you have saved me the job. In the similar way that GetBoolArg() works, I wondered if perhaps we could have a boolean check for whether various debug are set, or perhaps even a scenario where we can say log this if debug=tx OR debug=mempool is set since I have some debug lines from mempool and tx functions merged, perhaps something like Looking at the code it looks like the boolean function exists already, but the 2nd part (the "this category or that category" would still be nice). |
|
ACK. Additional benefit: if evaluation of an argument would crash the software, e.g. via evaluating vector[0] without checking the size, that won't happen if the debugging is not actually turned on. Not all side effects are good. :) |
|
Makes sense. It's unfortunate that this needs a macro solution.
utACK 407cdd6 |
407cdd6 Do not evaluate hidden LogPrint arguments (Pieter Wuille)
|
I looked this up. I find mentions that C++11 mandates support for vararg
macros, however, it's not even listed in GCC's C++11 support pages. Perhaps
it's been supported for so long that they didn't bother listing it? Then I
noticed we're already using vararg templates in the codebase, so I stopped
worrying.
|
407cdd6 Do not evaluate hidden LogPrint arguments (Pieter Wuille)
407cdd6 Do not evaluate hidden LogPrint arguments (Pieter Wuille)
407cdd6 Do not evaluate hidden LogPrint arguments (Pieter Wuille)
407cdd6 Do not evaluate hidden LogPrint arguments (Pieter Wuille)
9fb0a43 util: Throw tinyformat::format_error on formatting error (random-zebra) 67eb699 util: Properly handle errors during log message formatting (random-zebra) 66ec97b Do not evaluate hidden LogPrint arguments (random-zebra) 2713458 util: Remove zero-argument versions of LogPrint and error (random-zebra) 500dfee util: Update tinyformat (random-zebra) 6837887 util: switch LogPrint and error to variadic templates (random-zebra) 0fa578f tinyformat: force USE_VARIADIC_TEMPLATES (random-zebra) Pull request description: this backports the following pull requests from upstream bitcoin: - bitcoin#8000 (0fa578f, 6837887) > Now that we started using c++11, force use of variadic templates. The autodetection may be wonky on some compilers, see discussion here and is unnecessary for us anyhow. - bitcoin#8274 (500dfee, 2713458) > Updates tinyformat.h to commit c42f/tinyformat@3a33bbf upstream. - bitcoin#9417 (66ec97b) > There are a few cases where hashes are computed inside LogPrint arguments - where they usually go unused. As LogPrint statements should never have side effects besides printing something, we can avoid the evaluation in this case. Advantage: perhaps a small performance improvement; I haven't benchmarked. Disadvantage: if we would have statements with side-effects, this could make this a bit harder to debug. - bitcoin#9963 (67eb699, 9fb0a43) > Instead of having an exception propagate into the program (which at worst causes a crash) when an error happens while formatting a log message, just print a message to the log. This message clearly indicates what log message was formatted wrongly, and what error happened during formatting it. ACKs for top commit: Fuzzbawls: ACK 9fb0a43 furszy: cool, utACK 9fb0a43 . Tree-SHA512: 29a902bb712612ca093a8fe863e9eff1c17d40955bbc37a5ceb6f057068ac6150dfcffd6836a6b0bd6295aa9bffd0925eb69e50f82ccaa7d84215efc274a59a4
9fb0a43 util: Throw tinyformat::format_error on formatting error (random-zebra) 67eb699 util: Properly handle errors during log message formatting (random-zebra) 66ec97b Do not evaluate hidden LogPrint arguments (random-zebra) 2713458 util: Remove zero-argument versions of LogPrint and error (random-zebra) 500dfee util: Update tinyformat (random-zebra) 6837887 util: switch LogPrint and error to variadic templates (random-zebra) 0fa578f tinyformat: force USE_VARIADIC_TEMPLATES (random-zebra) Pull request description: this backports the following pull requests from upstream bitcoin: - bitcoin#8000 (0fa578f, 6837887) > Now that we started using c++11, force use of variadic templates. The autodetection may be wonky on some compilers, see discussion here and is unnecessary for us anyhow. - bitcoin#8274 (500dfee, 2713458) > Updates tinyformat.h to commit c42f/tinyformat@3a33bbf upstream. - bitcoin#9417 (66ec97b) > There are a few cases where hashes are computed inside LogPrint arguments - where they usually go unused. As LogPrint statements should never have side effects besides printing something, we can avoid the evaluation in this case. Advantage: perhaps a small performance improvement; I haven't benchmarked. Disadvantage: if we would have statements with side-effects, this could make this a bit harder to debug. - bitcoin#9963 (67eb699, 9fb0a43) > Instead of having an exception propagate into the program (which at worst causes a crash) when an error happens while formatting a log message, just print a message to the log. This message clearly indicates what log message was formatted wrongly, and what error happened during formatting it. ACKs for top commit: Fuzzbawls: ACK 9fb0a43 furszy: cool, utACK 9fb0a43 . Tree-SHA512: 29a902bb712612ca093a8fe863e9eff1c17d40955bbc37a5ceb6f057068ac6150dfcffd6836a6b0bd6295aa9bffd0925eb69e50f82ccaa7d84215efc274a59a4
There are a few cases where hashes are computed inside LogPrint arguments - where they usually go unused. As LogPrint statements should never have side effects besides printing something, we can avoid the evaluation in this case.
Advantage: perhaps a small performance improvement; I haven't benchmarked.
Disadvantage: if we would have statements with side-effects, this could make this a bit harder to debug.