dyndbg: pr_fmt(fmt) with additional arguments?
Subsystems (2)
Hello Jason, hello Jim,
I've been using the following in my modules to prefix all messages with the module and function name:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
This worked nicely until pr_debug_ratelimit() is used: The additional arguments breaks DEFINE_DYNAMIC_DEBUG_METADATA_CLS:
#define pr_debug_ratelimited(fmt, ...) \
DEFINE_DYNAMIC_DEBUG_METADATA(…, pr_fmt(fmt)); \
#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, …, fmt)
#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \
static struct _ddebug __aligned(8) \
__section("__dyndbg") name = { \
… \
.format = (fmt), \This could be fixed easily by adding an additional '...' to it to slurp any additional argument which pr_fmt might add.
Would this be okay or do I miss something?
For testing I have recompiled current 7.0.0-rc1 for x86_64 with no compile failures.
Philipp Hahn
From 545173a75e3928ec000b1127bfc99439b7fa2f8b Mon Sep 17 00:00:00 2001
Message-ID: <545173a75e3928ec000b1127bfc99439b7fa2f8b.1772186702.git.p.hahn@avm.de>
From: Philipp Hahn <[email protected]>
Date: Fri, 27 Feb 2026 10:53:04 +0100
Subject: [PATCH] dyndbg: Ignore additional arguments from pr_fmt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: FRITZ! Technology GmbH, Berlin, Germany
pr_fmt can be used to add a common prefix to any output from a module:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
But adding additional arguments breaks dynamic debug:
Quoted 7 lines
error: macro "
DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
|pr_debug_ratelimited("%s", "Hello world!");
| ^
note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
| #defineDEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)\
|
error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)
Quoted 8 lines
| DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’
| DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of macro ‘pr_debug_ratelimited’
| pr_debug_ratelimited("%s", "Hello world!");
| ^~~~~~~~~~~~~~~~~~~~Add an additional ', ...' to DEFINE_DYNAMIC_DEBUG_METADATA_CLS to slurp any additional argument, which pr_fmt might add.
--- include/linux/dynamic_debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/dynamic_debug.h +1 -1
@@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,dump_stack (); \ } -#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS (name, cls, fmt) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS (name, cls, fmt, ...) \ static struct _ddebug __aligned(8) \ __section("__dyndbg") name = { \ .modname = KBUILD_MODNAME, \
Signature · 1 line
2.43.0
Hello,
Am Fri, Feb 27, 2026 at 12:33:18PM +0100 schrieb Philipp Hahn:
Quoted 3 lines
I've been using the following in my modules to prefix all messages with the module and function name:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
<https://docs.kernel.org/core-api/printk-basics.html> itself has the following example:
Quoted 1 line
#define
pr_fmt(fmt)"%s:%s: " fmt,KBUILD_MODNAME,__func__
This breaks pr_debug_ratelimited().
Quoted 8 lines
This could be fixed easily by adding an additional '...' to
DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)to slurp any additional argument whichpr_fmtmight add.Would this be okay or do I miss something?
For testing I have recompiled current 7.0.0-rc1 for
x86_64with no compile failures.
Ping?
Philipp Hahn
Quoted 54 lines
From
545173a75e3928ec000b1127bfc99439b7fa2f8bMon Sep 17 00:00:00 2001
Message-ID: <545173a75e3928ec000b1127bfc99439b7fa2f8b.1772186702.git.p.hahn@avm.de>
From: Philipp Hahn <[email protected]>
Date: Fri, 27 Feb 2026 10:53:04 +0100
Subject: [PATCH] dyndbg: Ignore additional arguments frompr_fmt
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: FRITZ! Technology GmbH, Berlin, Germany
pr_fmtcan be used to add a common prefix to any output from a module:#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__But adding additional arguments breaks dynamic debug:
Quoted 7 lines
error: macro "
DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
|pr_debug_ratelimited("%s", "Hello world!");
| ^
note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
| #defineDEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)\
|
error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)Quoted 8 lines
| DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’ | DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ note: in expansion of macro ‘pr_debug_ratelimited’ | pr_debug_ratelimited("%s", "Hello world!"); | ^~~~~~~~~~~~~~~~~~~~Add an additional ', ...' to
DEFINE_DYNAMIC_DEBUG_METADATA_CLSto slurp any additional argument, whichpr_fmtmight add.Signed-off-by Philipp Hahn <[email protected]>--- include/linux/dynamic_debug.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/dynamic_debug.h +1
-1@@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,dump_stack (); \ } -#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS (name, cls, fmt) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS (name, cls, fmt, ...) \ static struct _ddebug __aligned(8) \ __section("__dyndbg") name = { \ .modname = KBUILD_MODNAME, \Signature · 1 line
2.43.0
Quoted 6 lines · Philipp Hahn
Hello Jason, hello Jim,
I've been using the following in my modules to prefix all messages with the module and function name:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__
Your example loses the fmt, so is not actually useful.
but that said, the compile err is real, I hit it once I changed
1 - the pr_debug("exited") call in test_dynamic_debug.c
to pr_debug_ratelimited.
2- the pr_fmt in same:
#if defined(TEST_DYNAMIC_DEBUG_SUBMOD)
- #define pr_fmt(fmt) "test_dd_submod: " fmt
+ #define pr_fmt(fmt) KBUILD_MODNAME " test_dd_submod: %s" fmt, __func__
2 was my test-case, on my latest branch, yours (on master) will be different.
please add that test to your patch, and my
Quoted 19 lines
This worked nicely until
pr_debug_ratelimit()is used: The additional arguments breaksDEFINE_DYNAMIC_DEBUG_METADATA_CLS:#define pr_debug_ratelimited(fmt, ...) \ DEFINE_DYNAMIC_DEBUG_METADATA(…, pr_fmt(fmt)); \ #define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \ DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, …, fmt) #define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt) \ static struct _ddebug __aligned(8) \ __section("__dyndbg") name = { \ … \ .format = (fmt), \This could be fixed easily by adding an additional '...' to it to slurp any additional argument which
pr_fmtmight add.
Quoted 6 lines
Would this be okay or do I miss something?
For testing I have recompiled current 7.0.0-rc1 for
x86_64with no compile failures.Philipp Hahn
I tried this locally, it built and ran w/o errors.
Hello Jim,
Am Sun, Mar 15, 2026 at 05:30:43PM -0600 schrieb [email protected]:
Quoted 9 lines · Philipp Hahn
Quoted 6 lines
Hello Jason, hello Jim,
I've been using the following in my modules to prefix all messages with the module and function name:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s ", __func__Your example loses the fmt, so is not actually useful.
Yes, somehow that 'fmt' got lost; I've re-added it.
Quoted 10 lines
but that said, the compile err is real, I hit it once I changed
1 - the
pr_debug("exited")call intest_dynamic_debug.c
topr_debug_ratelimited.2- the
pr_fmtin same:
#ifdefined(TEST_DYNAMIC_DEBUG_SUBMOD)(quoted diff) +1
-1- #define pr_fmt(fmt) "test_dd_submod: " fmt + #define pr_fmt(fmt) KBUILD_MODNAME " test_dd_submod: %s" fmt, __func__
Quoted 4 lines
2 was my test-case, on my latest branch, yours (on master) will be different.
please add that test to your patch, and my
Acked-by Jim Cromie <[email protected]>
I did both; v2 is on it's way. Thank you for your review.
Philipp Hahn
PATCH v2 1/1 dyndbg: Ignore additional arguments from pr_fmt
In reply to Philipp Hahnpr_fmt can be used to add a common prefix to any output from a module:
#define pr_fmt(fmt) KBUILD_MODNAME ".%s " fmt, __func__
But adding additional arguments breaks dynamic debug:
Quoted 7 lines
error: macro "
DEFINE_DYNAMIC_DEBUG_METADATA_CLS" passed 4 arguments, but takes just 3
|pr_debug_ratelimited("%s", "Hello world!");
| ^
note: macro "DEFINE_DYNAMIC_DEBUG_METADATA_CLS" defined here
| #defineDEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)\
|
error: ‘DEFINE_DYNAMIC_DEBUG_METADATA_CLS’ undeclared (first use in this function)
Quoted 8 lines
| DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of macro ‘DEFINE_DYNAMIC_DEBUG_METADATA’
| DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, pr_fmt(fmt)); \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: in expansion of macro ‘pr_debug_ratelimited’
| pr_debug_ratelimited("%s", "Hello world!");
| ^~~~~~~~~~~~~~~~~~~~Add an additional ', ...' to DEFINE_DYNAMIC_DEBUG_METADATA_CLS to slurp any additional argument, which pr_fmt might add.
--- include/linux/dynamic_debug.h | 2 +- lib/test_dynamic_debug.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
include/linux/dynamic_debug.h +1 -1
@@ -167,7 +167,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,dump_stack (); \ } -#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS (name, cls, fmt) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS (name, cls, fmt, ...) \ static struct _ddebug __aligned(8) \ __section("__dyndbg") name = { \ .modname = KBUILD_MODNAME, \
lib/test_dynamic_debug.c +2 -2
@@ -6,7 +6,7 @@* Jim Cromie <[email protected]> */ -#define pr_fmt (fmt) "test_dd: " fmt +#define pr_fmt (fmt) "test_dd: %s " fmt, __func__#include <linux/module.h>
@@ -155,7 +155,7 @@ static int __init test_dynamic_debug_init(void) static void __exit test_dynamic_debug_exit(void) { -pr_debug ("exited\n" ); +pr_debug_ratelimited ("exited\n" ); }module_init (test_dynamic_debug_init);
Signature · 1 line
2.43.0