[llvm] [llvm][support] Add LDBG macro. (PR #143704)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 25 05:00:57 PDT 2025


================
@@ -0,0 +1,68 @@
+//===- llvm/Support/DebugLog.h - Logging like debug output ------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// This file contains macros for logging like debug output. It builds upon the
+// support in Debug.h but provides a utility function for common debug output
+// style.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_DEBUGLOG_H
+#define LLVM_SUPPORT_DEBUGLOG_H
+
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+#ifndef NDEBUG
+
+// Output with given inputs and trailing newline. E.g.,
+//   LDBG() << "Bitset contains: " << Bitset;
+// is equivalent to
+//   LLVM_DEBUG(dbgs() << DEBUG_TYPE << " [" << __FILE__ << ":" << __LINE__
+//              << "] " << "Bitset contains: " << Bitset << "\n");
+#define LDBG() DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE)
----------------
kuhar wrote:

Should we prefix this with `LLVM_`? In the past, we used `DEBUG` instead of `LLVM_DEBUG` which caused naming collisions downstream: https://discourse.llvm.org/t/rfc-change-debug-macro-to-llvm-debug/48092 . I wonder if LDBG may be terse enough to run into similar issues.

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


More information about the llvm-commits mailing list