[llvm] Introduce LDBG_OS() macro as a variant of LDBG() (PR #157194)

Andrzej WarzyƄski via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 8 02:43:34 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());
----------------
banach-space wrote:

I don't quite follow this check - where do we tie `DebugOs` and `RefOs`? Does `RefOs` means "reference" ? As in, the expected output?

https://github.com/llvm/llvm-project/pull/157194


More information about the llvm-commits mailing list