[llvm] Implement a custom stream for LDBG macro to handle newlines (PR #150750)
Jacques Pienaar via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 26 23:47:55 PDT 2025
================
@@ -30,37 +30,95 @@ namespace llvm {
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
_c = false) \
- ::llvm::impl::LogWithNewline(TYPE, __SHORT_FILE__, __LINE__, (STREAM))
+ ::llvm::impl::LogWithNewline(TYPE, __SHORT_FILE__, __LINE__, (STREAM)) \
+ .stream()
#else
#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
_c = false) \
- ::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM))
+ ::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM)).stream()
#endif
namespace impl {
-class LogWithNewline {
+
+/// A raw_ostream that tracks `\n` and print the prefix.
+class LLVM_ABI raw_ldbg_ostream final : public raw_ostream {
+ std::string Prefix;
----------------
jpienaar wrote:
Should we perhaps just merge LogWithNewline and this into one? (means we don't need the .stream() above and this is just how it behaves, it has special treatment for newlines and adds one).
https://github.com/llvm/llvm-project/pull/150750
More information about the llvm-commits
mailing list