[llvm] [docs] Update logging section of the programmer manual to include LDBG() (NFC) (PR #156235)
Jacques Pienaar via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 1 05:32:29 PDT 2025
================
@@ -1199,52 +1228,74 @@ follows:
.. code-block:: c++
#define DEBUG_TYPE "foo"
- LLVM_DEBUG(dbgs() << "'foo' debug type\n");
- #undef DEBUG_TYPE
- #define DEBUG_TYPE "bar"
- LLVM_DEBUG(dbgs() << "'bar' debug type\n");
- #undef DEBUG_TYPE
+ LDBG(2) << "Hello,";
+ // DEBUG_TYPE can be overridden locally, here with "bar"
+ LDBG("bar", 3) << "'bar' debug type";
+
-Then you can run your pass like this:
+A more fine-grained control can be achieved by passing the ``-debug-only``
+command line argument:
.. code-block:: none
- $ opt < a.bc > /dev/null -mypass
- <no output>
- $ opt < a.bc > /dev/null -mypass -debug
- 'foo' debug type
- 'bar' debug type
$ opt < a.bc > /dev/null -mypass -debug-only=foo
- 'foo' debug type
- $ opt < a.bc > /dev/null -mypass -debug-only=bar
- 'bar' debug type
+ [foo:2] MyPass.cpp:123 Hello,
$ opt < a.bc > /dev/null -mypass -debug-only=foo,bar
- 'foo' debug type
- 'bar' debug type
-
-Of course, in practice, you should only set ``DEBUG_TYPE`` at the top of a file,
-to specify the debug type for the entire module. Be careful that you only do
-this after including ``Debug.h`` and not around any #include of headers. Also, you
-should use names more meaningful than "foo" and "bar", because there is no
-system in place to ensure that names do not conflict. If two different modules
-use the same string, they will all be turned on when the name is specified.
+ [foo:2] MyPass.cpp:123 Hello,
+ [bar:3] MyPass.cpp:124 World!
+ $ opt < a.bc > /dev/null -mypass -debug-only=bar
+ [bar:3] MyPass.cpp:124 World!
+
+The debug-only argument is a comma separated list of debug types and levels.
+The level is an optional integer setting the maximum debug level to enable:
+
+.. code-block:: none
+
+ $ opt < a.bc > /dev/null -mypass -debug-only=foo:2,bar:2
+ [foo:2] MyPass.cpp:123 Hello,
+ $ opt < a.bc > /dev/null -mypass -debug-only=foo:1,bar:3
+ [bar:3] MyPass.cpp:124 World!
+
+Instead of opting in specific debug types, the ``-debug-only`` option also
+works to filter out debug output for specific debug types, by omitting the
+level (or setting it to 0):
+
+.. code-block:: none
+
+ $ opt < a.bc > /dev/null -mypass -debug-only=foo:
+ [bar:3] MyPass.cpp:124 World!
+ $ opt < a.bc > /dev/null -mypass -debug-only=bar:0,foo:
+
+
+In practice, you should only set ``DEBUG_TYPE`` at the top of a file, to
+specify the debug type for the entire module. Be careful that you only do
+this after including ``DebugLog.h`` and not around any #include of headers.
----------------
jpienaar wrote:
``Debug.h`` and/or ``DebugLoc.h`` ?
https://github.com/llvm/llvm-project/pull/156235
More information about the llvm-commits
mailing list