-
Notifications
You must be signed in to change notification settings - Fork 108
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
Source location in Debug #55
Conversation
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
=========================================
+ Coverage 97.49% 97.5% +<.01%
=========================================
Files 87 81 -6
Lines 5796 5442 -354
=========================================
- Hits 5651 5306 -345
+ Misses 145 136 -9
Continue to review full report at Codecov.
|
Rust 1.35 has an empty dbg! macro to print just the file & line. Added that to the list above. |
Invented a much better version that's opt-in, easy to use and doesn't bloat the binary when not used. The last remaining blocker is |
To have this working on both Clang and GCC, I'll probably change to using the compiler builtins, and that'll solve the |
Supported on GCC 8.1+ and Clang 9+.
e4c1361
to
3872b3c
Compare
You're the constant source of PAIN in my life.
MSVC builtins seem to be implemented in upcoming 16.6: microsoft/STL#54 (comment) |
Similarly to the new
dbg!
macro in Rust, this implements source location for Debug using std::experiemntal::source_location. At the moment this feature is present only in GCC 8.1 / libstdc++ and up and a builtin in Clang 9:no traces ofusing the builtins insteadstd::source_location
in libc++ yet as of November: https://github.com/llvm-mirror/libcxx/tree/master/include/experimentalThis is an experiment that needs further design iterations:
At the moment, allDebug{}
,Error{}
etc. constructors are acquiring the source location and saving it even if it might not be used, which means extreme increase in binary sizes. While this is convenient and doesn't require changes on the user side (it's just enabling a flag and then all following debug statements in the same scope get source location), it's not efficient. Some ideas:Provide a dedicated function such asdebug()
that instantiatesDebug
and with source location (bad, it requires users to learn a new thing, also we would need to do anerror()
,fatal()
etc. and there's a high chance these names will clash with user code)Provide a constructor tag such asDebug{Debug::SourceLocation}
(again kinda bad, since it's verbose to say every time)Save source file name only at the point of enabling the debug output but save line in every constructor (would need some way to detect what file we are in in order to not print file info from unrelated files, maybe abusing unnamed namespaces?)Provide a constructor tag that explicitly does not use source location and then use that in all the library internals to minimize the impact (goes against "don't pay for what you don't use", doesn't really help users)!Debug{}
The Rustnot sure howdbg!
macro works insideif()
as well, provide something like that too?I'm working around that by-- using the builtins directly#undef constexpr
for C++11 (which is insane), submit a PR to libstdc++ that uses some C++14 constexpr instead?The file+line info output format is probably not the best (use colors? wrap inpostponed, will be done together with arbitrary line prefixing[]
like Rust does? make itformat()
able, allowing stuff like column, date and other things there?)Obligatory docs:
Further design ideas welcome! :)