• Benjamin Peterson's avatar
    perf trace beauty ioctl: Fix off-by-one error in cmd->string table · b92675f4
    Benjamin Peterson authored
    While tracing a program that calls isatty(3), I noticed that strace
    reported TCGETS for the request argument of the underlying ioctl(2)
    syscall while perf trace reported TCSETS. strace is corrrect. The bug in
    perf was due to the tty ioctl beauty table starting at 0x5400 rather
    than 0x5401.
    
    Committer testing:
    
      Using augmented_raw_syscalls.o and settings to make 'perf trace'
      use strace formatting, i.e. with this in ~/.perfconfig
    
      # cat ~/.perfconfig
      [trace]
    	add_events = /home/acme/git/linux/tools/perf/examples/bpf/augmented_raw_syscalls.c
    	show_zeros = yes
    	show_duration = no
    	no_inherit = yes
    	show_timestamp = no
    	show_arg_names = no
    	args_alignment = 40
    	show_prefix = yes
    
      # strace -e ioctl stty > /dev/null
      ioctl(0, TCGETS, {B38400 opost isig icanon echo ...}) = 0
      ioctl(1, TIOCGWINSZ, 0x7fff8a9b0860)    = -1 ENOTTY (Inappropriate ioctl for device)
      ioctl(1, TCGETS, 0x7fff8a9b0540)        = -1 ENOTTY (Inappropriate ioctl for device)
      +++ exited with 0 +++
      #
    
    Before:
    
      # perf trace -e ioctl stty > /dev/null
      ioctl(0, TCSETS, 0x7fff2cf79f20)        = 0
      ioctl(1, TIOCSWINSZ, 0x7fff2cf79f40)    = -1 ENOTTY (Inappropriate ioctl for device)
      ioctl(1, TCSETS, 0x7fff2cf79c20)        = -1 ENOTTY (Inappropriate ioctl for device)
      #
    
    After:
    
      # perf trace -e ioctl stty > /dev/null
      ioctl(0, TCGETS, 0x7ffed0763920)        = 0
      ioctl(1, TIOCGWINSZ, 0x7ffed0763940)    = -1 ENOTTY (Inappropriate ioctl for device)
      ioctl(1, TCGETS, 0x7ffed0763620)        = -1 ENOTTY (Inappropriate ioctl for device)
      #
    Signed-off-by: default avatarBenjamin Peterson <benjamin@python.org>
    Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Fixes: 1cc47f2d ("perf trace beauty ioctl: Improve 'cmd' beautifier")
    Link: http://lkml.kernel.org/r/20190823033625.18814-1-benjamin@python.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
    b92675f4
ioctl.c 7.42 KB