Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dyndbg: add source filename to prefix

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>

authored by

Thomas Weißschuh and committed by
Greg Kroah-Hartman
31ed379b 3bdaf739

+10 -3
+3 -2
Documentation/admin-guide/dynamic-debug-howto.rst
··· 216 216 t Include thread ID, or <intr> 217 217 m Include module name 218 218 f Include the function name 219 + s Include the source file name 219 220 l Include line number 220 221 221 222 For ``print_hex_dump_debug()`` and ``print_hex_dump_bytes()``, only 222 223 the ``p`` flag has meaning, other flags are ignored. 223 224 224 - Note the regexp ``^[-+=][flmpt_]+$`` matches a flags specification. 225 - To clear all flags at once, use ``=_`` or ``-flmpt``. 225 + Note the regexp ``^[-+=][fslmpt_]+$`` matches a flags specification. 226 + To clear all flags at once, use ``=_`` or ``-fslmpt``. 226 227 227 228 228 229 Debug messages during Boot Process
+3 -1
include/linux/dynamic_debug.h
··· 37 37 #define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2) 38 38 #define _DPRINTK_FLAGS_INCL_LINENO (1<<3) 39 39 #define _DPRINTK_FLAGS_INCL_TID (1<<4) 40 + #define _DPRINTK_FLAGS_INCL_SOURCENAME (1<<5) 40 41 41 42 #define _DPRINTK_FLAGS_INCL_ANY \ 42 43 (_DPRINTK_FLAGS_INCL_MODNAME | _DPRINTK_FLAGS_INCL_FUNCNAME |\ 43 - _DPRINTK_FLAGS_INCL_LINENO | _DPRINTK_FLAGS_INCL_TID) 44 + _DPRINTK_FLAGS_INCL_LINENO | _DPRINTK_FLAGS_INCL_TID |\ 45 + _DPRINTK_FLAGS_INCL_SOURCENAME) 44 46 45 47 #if defined DEBUG 46 48 #define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
+4
lib/dynamic_debug.c
··· 92 92 { _DPRINTK_FLAGS_PRINT, 'p' }, 93 93 { _DPRINTK_FLAGS_INCL_MODNAME, 'm' }, 94 94 { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' }, 95 + { _DPRINTK_FLAGS_INCL_SOURCENAME, 's' }, 95 96 { _DPRINTK_FLAGS_INCL_LINENO, 'l' }, 96 97 { _DPRINTK_FLAGS_INCL_TID, 't' }, 97 98 { _DPRINTK_FLAGS_NONE, '_' }, ··· 837 836 if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) 838 837 pos += snprintf(buf + pos, remaining(pos), "%s:", 839 838 desc->function); 839 + if (desc->flags & _DPRINTK_FLAGS_INCL_SOURCENAME) 840 + pos += snprintf(buf + pos, remaining(pos), "%s:", 841 + trim_prefix(desc->filename)); 840 842 if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) 841 843 pos += snprintf(buf + pos, remaining(pos), "%d:", 842 844 desc->lineno);