[llvm] Introduce LDBG_OS() macro as a variant of LDBG() (PR #157194)
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 10:12:49 PDT 2025
================
@@ -128,6 +128,131 @@ TEST(DebugLogTest, DestructorPrefix) {
// After destructors, nothing should have been printed.
EXPECT_EQ(os.str(), "");
}
+
+TEST(DebugLogTest, LDBG_MACROS) {
+ llvm::DebugFlag = true;
+ static const char *DT[] = {"A:3", "B:2"};
+ setCurrentDebugTypes(DT, sizeof(DT) / sizeof(DT[0]));
+ std::string Str;
+ raw_string_ostream DebugOs(Str);
+ std::string StrRef;
+ raw_string_ostream RefOs(StrRef);
+#undef LDBG_STREAM
+#define LDBG_STREAM DebugOs
+#define DEBUG_TYPE "A"
+ LDBG() << "Hello, world!";
+ RefOs << "[A:1] " << __LLVM_FILE_NAME__ << ":" << (__LINE__ - 1)
+ << " Hello, world!\n";
+ EXPECT_EQ(DebugOs.str(), RefOs.str());
----------------
joker-eph wrote:
DebugOS is where LDBG() is streaming. We generate the string we expect directly in RefOS, that is we construct the expected output of LDBG().
I could hardcode it but LDBG() depends on the current line number which makes it fragile.
https://github.com/llvm/llvm-project/pull/157194
More information about the llvm-commits
mailing list