dyndbg: add source filename to prefix
authorThomas Weißschuh <linux@weissschuh.net>
Sun, 9 Jul 2023 21:18:00 +0000 (23:18 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Aug 2023 13:28:41 +0000 (15:28 +0200)
Printing the line number without the file is of limited usefulness.

Knowing the filename also makes it also easier to relate the logged
information to the controlfile.

Example:

    # modprobe test_dynamic_debug
    # echo 'file test_dynamic_debug.c =pfsl' > /proc/dynamic_debug/control
    # echo 1 > /sys/module/test_dynamic_debug/parameters/do_prints
    # dmesg | tail -2
    [   71.802212] do_cats:lib/test_dynamic_debug.c:103: test_dd: doing categories
    [   71.802227] do_levels:lib/test_dynamic_debug.c:123: test_dd: doing levels

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Jim Cromie <jim.cromie@gmail.com>
Acked-by: Jason Baron <jbaron@akamai.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20230709-dyndbg-filename-v2-3-fd83beef0925@weissschuh.net
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/admin-guide/dynamic-debug-howto.rst
include/linux/dynamic_debug.h
lib/dynamic_debug.c

index 8dc668cc1216e453ed4c5ca7e50f6dd3fdf06d4c..0b3d39c610d9c7dbbcde2894507ea4d399106e6c 100644 (file)
@@ -216,13 +216,14 @@ The flags are::
   t    Include thread ID, or <intr>
   m    Include module name
   f    Include the function name
+  s    Include the source file name
   l    Include line number
 
 For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only
 the ``p`` flag has meaning, other flags are ignored.
 
-Note the regexp ``^[-+=][flmpt_]+$`` matches a flags specification.
-To clear all flags at once, use ``=_`` or ``-flmpt``.
+Note the regexp ``^[-+=][fslmpt_]+$`` matches a flags specification.
+To clear all flags at once, use ``=_`` or ``-fslmpt``.
 
 
 Debug messages during Boot Process
index 061dd84d09f30625ae41d21720783e03f51bfaef..4fcbf4d4fd0a29d11c550805e0e4dd99aae0ac44 100644 (file)
@@ -37,10 +37,12 @@ struct _ddebug {
 #define _DPRINTK_FLAGS_INCL_FUNCNAME   (1<<2)
 #define _DPRINTK_FLAGS_INCL_LINENO     (1<<3)
 #define _DPRINTK_FLAGS_INCL_TID                (1<<4)
+#define _DPRINTK_FLAGS_INCL_SOURCENAME (1<<5)
 
 #define _DPRINTK_FLAGS_INCL_ANY                \
        (_DPRINTK_FLAGS_INCL_MODNAME | _DPRINTK_FLAGS_INCL_FUNCNAME |\
-        _DPRINTK_FLAGS_INCL_LINENO  | _DPRINTK_FLAGS_INCL_TID)
+        _DPRINTK_FLAGS_INCL_LINENO  | _DPRINTK_FLAGS_INCL_TID |\
+        _DPRINTK_FLAGS_INCL_SOURCENAME)
 
 #if defined DEBUG
 #define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
index 166229dfe171d2a7b3de6e5d6a689c1eb47bd088..6fba6423cc10b512acdfac38cc44887a626c8096 100644 (file)
@@ -92,6 +92,7 @@ static const struct { unsigned flag:8; char opt_char; } opt_array[] = {
        { _DPRINTK_FLAGS_PRINT, 'p' },
        { _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
        { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
+       { _DPRINTK_FLAGS_INCL_SOURCENAME, 's' },
        { _DPRINTK_FLAGS_INCL_LINENO, 'l' },
        { _DPRINTK_FLAGS_INCL_TID, 't' },
        { _DPRINTK_FLAGS_NONE, '_' },
@@ -836,6 +837,9 @@ static char *__dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
        if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
                pos += snprintf(buf + pos, remaining(pos), "%s:",
                                desc->function);
+       if (desc->flags & _DPRINTK_FLAGS_INCL_SOURCENAME)
+               pos += snprintf(buf + pos, remaining(pos), "%s:",
+                               trim_prefix(desc->filename));
        if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
                pos += snprintf(buf + pos, remaining(pos), "%d:",
                                desc->lineno);