tracing/probe: add a char type to print the character value of traced arguments

Message ID 20221213115304.3964458-1-dolinux.peng@gmail.com
State New
Headers
Series tracing/probe: add a char type to print the character value of traced arguments |

Commit Message

Donglin Peng Dec. 13, 2022, 11:53 a.m. UTC
  There are scenes that we want to show the character value of traced
arguments other than a decimal or hexadecimal or string value for debug
convinience. Add a new type named 'char' to do it.

For example:

echo 'p:myprobe xxxx $arg1:char' > kprobe_events

Signed-off-by: Donglin Peng <dolinux.peng@gmail.com>
---
 Documentation/trace/kprobetrace.rst | 3 ++-
 kernel/trace/trace_probe.c          | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
  

Comments

kernel test robot Dec. 13, 2022, 3:57 p.m. UTC | #1
Hi Donglin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on rostedt-trace/for-next v6.1 next-20221213]
[cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Donglin-Peng/tracing-probe-add-a-char-type-to-print-the-character-value-of-traced-arguments/20221213-195552
patch link:    https://lore.kernel.org/r/20221213115304.3964458-1-dolinux.peng%40gmail.com
patch subject: [PATCH] tracing/probe: add a char type to print the character value of traced arguments
config: parisc-allyesconfig
compiler: hppa-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/c09eb24f0c2c27ce649aed5360dcf3299b636de6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Donglin-Peng/tracing-probe-add-a-char-type-to-print-the-character-value-of-traced-arguments/20221213-195552
        git checkout c09eb24f0c2c27ce649aed5360dcf3299b636de6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=parisc SHELL=/bin/bash kernel/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from kernel/trace/trace_probe.c:14:
>> kernel/trace/trace_probe.h:146:41: warning: no previous prototype for 'print_type_char' [-Wmissing-prototypes]
     146 | #define PRINT_TYPE_FUNC_NAME(type)      print_type_##type
         |                                         ^~~~~~~~~~~
   kernel/trace/trace_probe.c:34:5: note: in expansion of macro 'PRINT_TYPE_FUNC_NAME'
      34 | int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\
         |     ^~~~~~~~~~~~~~~~~~~~
   kernel/trace/trace_probe.c:53:1: note: in expansion of macro 'DEFINE_BASIC_PRINT_TYPE_FUNC'
      53 | DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "%c")
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/print_type_char +146 kernel/trace/trace_probe.h

34fee3a104cea1 Namhyung Kim 2013-11-26  145  
b26c74e116ad84 Namhyung Kim 2013-11-26 @146  #define PRINT_TYPE_FUNC_NAME(type)	print_type_##type
b26c74e116ad84 Namhyung Kim 2013-11-26  147  #define PRINT_TYPE_FMT_NAME(type)	print_type_format_##type
b26c74e116ad84 Namhyung Kim 2013-11-26  148
  
kernel test robot Dec. 13, 2022, 9:51 p.m. UTC | #2
Hi Donglin,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on rostedt-trace/for-next]
[cannot apply to rostedt-trace/for-next-urgent]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Donglin-Peng/tracing-probe-add-a-char-type-to-print-the-character-value-of-traced-arguments/20221213-195552
patch link:    https://lore.kernel.org/r/20221213115304.3964458-1-dolinux.peng%40gmail.com
patch subject: [PATCH] tracing/probe: add a char type to print the character value of traced arguments
config: s390-randconfig-r044-20221213
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install s390 cross compiling tool for clang build
        # apt-get install binutils-s390x-linux-gnu
        # https://github.com/intel-lab-lkp/linux/commit/c09eb24f0c2c27ce649aed5360dcf3299b636de6
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Donglin-Peng/tracing-probe-add-a-char-type-to-print-the-character-value-of-traced-arguments/20221213-195552
        git checkout c09eb24f0c2c27ce649aed5360dcf3299b636de6
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash kernel/trace/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   In file included from kernel/trace/trace_probe.c:14:
   In file included from kernel/trace/trace_probe.h:28:
   In file included from kernel/trace/trace.h:9:
   In file included from include/linux/clocksource.h:22:
   In file included from arch/s390/include/asm/io.h:75:
   include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __raw_readb(PCI_IOBASE + addr);
                             ~~~~~~~~~~ ^
   include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:37:59: note: expanded from macro '__le16_to_cpu'
   #define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
                                                             ^
   include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
   #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
                                                        ^
   In file included from kernel/trace/trace_probe.c:14:
   In file included from kernel/trace/trace_probe.h:28:
   In file included from kernel/trace/trace.h:9:
   In file included from include/linux/clocksource.h:22:
   In file included from arch/s390/include/asm/io.h:75:
   include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:35:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
   #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
                                                        ^
   In file included from kernel/trace/trace_probe.c:14:
   In file included from kernel/trace/trace_probe.h:28:
   In file included from kernel/trace/trace.h:9:
   In file included from include/linux/clocksource.h:22:
   In file included from arch/s390/include/asm/io.h:75:
   include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsb(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsw(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsl(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesb(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesw(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesl(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
>> kernel/trace/trace_probe.c:53:1: warning: no previous prototype for function 'print_type_char' [-Wmissing-prototypes]
   DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "%c")
   ^
   kernel/trace/trace_probe.c:34:5: note: expanded from macro 'DEFINE_BASIC_PRINT_TYPE_FUNC'
   int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\
       ^
   kernel/trace/trace_probe.h:146:36: note: expanded from macro 'PRINT_TYPE_FUNC_NAME'
   #define PRINT_TYPE_FUNC_NAME(type)      print_type_##type
                                           ^
   <scratch space>:93:1: note: expanded from here
   print_type_char
   ^
   kernel/trace/trace_probe.c:53:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "%c")
   ^
   static 
   kernel/trace/trace_probe.c:33:58: note: expanded from macro 'DEFINE_BASIC_PRINT_TYPE_FUNC'
   #define DEFINE_BASIC_PRINT_TYPE_FUNC(tname, type, fmt)                  \
                                                                           ^
   13 warnings generated.


vim +/print_type_char +53 kernel/trace/trace_probe.c

    40	
    41	DEFINE_BASIC_PRINT_TYPE_FUNC(u8,  u8,  "%u")
    42	DEFINE_BASIC_PRINT_TYPE_FUNC(u16, u16, "%u")
    43	DEFINE_BASIC_PRINT_TYPE_FUNC(u32, u32, "%u")
    44	DEFINE_BASIC_PRINT_TYPE_FUNC(u64, u64, "%Lu")
    45	DEFINE_BASIC_PRINT_TYPE_FUNC(s8,  s8,  "%d")
    46	DEFINE_BASIC_PRINT_TYPE_FUNC(s16, s16, "%d")
    47	DEFINE_BASIC_PRINT_TYPE_FUNC(s32, s32, "%d")
    48	DEFINE_BASIC_PRINT_TYPE_FUNC(s64, s64, "%Ld")
    49	DEFINE_BASIC_PRINT_TYPE_FUNC(x8,  u8,  "0x%x")
    50	DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
    51	DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
    52	DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
  > 53	DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "%c")
    54
  

Patch

diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst
index 4274cc6a2f94..007972a3c5c4 100644
--- a/Documentation/trace/kprobetrace.rst
+++ b/Documentation/trace/kprobetrace.rst
@@ -58,7 +58,7 @@  Synopsis of kprobe_events
   NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
   FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
 		  (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types
-		  (x8/x16/x32/x64), "string", "ustring" and bitfield
+		  (x8/x16/x32/x64), "char", "string", "ustring" and bitfield
 		  are supported.
 
   (\*1) only for the probe on function entry (offs == 0).
@@ -80,6 +80,7 @@  E.g. 'x16[4]' means an array of x16 (2bytes hex) with 4 elements.
 Note that the array can be applied to memory type fetchargs, you can not
 apply it to registers/stack-entries etc. (for example, '$stack1:x8[8]' is
 wrong, but '+8($stack):x8[8]' is OK.)
+Char type can be used to show the character value of traced arguments.
 String type is a special type, which fetches a "null-terminated" string from
 kernel space. This means it will fail and store NULL if the string container
 has been paged out. "ustring" type is an alternative of string for user-space.
diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c
index 36dff277de46..a4abf7f6c295 100644
--- a/kernel/trace/trace_probe.c
+++ b/kernel/trace/trace_probe.c
@@ -50,6 +50,7 @@  DEFINE_BASIC_PRINT_TYPE_FUNC(x8,  u8,  "0x%x")
 DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x")
 DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")
 DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx")
+DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "%c")
 
 int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent)
 {
@@ -93,6 +94,7 @@  static const struct fetch_type probe_fetch_types[] = {
 	ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0),
 	ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0),
 	ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0),
+	ASSIGN_FETCH_TYPE_ALIAS(char, u8, u8,  0),
 	ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0),
 
 	ASSIGN_FETCH_TYPE_END