Bug 214885 - [patch] add missing system calls to truss
Summary: [patch] add missing system calls to truss
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.0-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: John Baldwin
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-11-27 17:23 UTC by Jonathan de Boyne Pollard
Modified: 2017-11-21 02:11 UTC (History)
2 users (show)

See Also:
jhb: mfc-stable11+


Attachments
patch to usr.sbin/truss/syscalls.c (2.91 KB, patch)
2016-11-27 17:23 UTC, Jonathan de Boyne Pollard
no flags Details | Diff
bigger patch to usr.sbin/truss/syscalls.c (6.09 KB, patch)
2016-12-29 17:33 UTC, Jonathan de Boyne Pollard
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan de Boyne Pollard 2016-11-27 17:23:22 UTC
Created attachment 177455 [details]
patch to usr.sbin/truss/syscalls.c

truss does not usefully display the parameters to a lot of relatively new system calls that are now in common use by softwares ranging from uhidd to evilvte, and a few old ones.  This patch adds a few of them.  There are more yet to cover.
Comment 1 Jonathan de Boyne Pollard 2016-12-29 17:33:32 UTC
Created attachment 178382 [details]
bigger patch to usr.sbin/truss/syscalls.c

I have added some more system call coverage.
Comment 2 John Baldwin freebsd_committer freebsd_triage 2017-01-12 18:03:00 UTC
What version is this against?  Several of the new system calls are already handled in truss in stable/11:

> egrep '(openat|mkdirat|unlinkat|[lf]chmod|getdirentries|fstatat|pwrite|pipe2|pread|symlinkat)' syscalls.c
        { .name = "fchmod", .ret_type = 1, .nargs = 2,
        { .name = "fchmodat", .ret_type = 1, .nargs = 4,
        { .name = "fstatat", .ret_type = 1, .nargs = 4,
        { .name = "lchmod", .ret_type = 1, .nargs = 2,
        { .name = "mkdirat", .ret_type = 1, .nargs = 3,
        { .name = "openat", .ret_type = 1, .nargs = 4,
        { .name = "pipe2", .ret_type = 1, .nargs = 2,
        { .name = "symlinkat", .ret_type = 1, .nargs = 3,
        { .name = "unlinkat", .ret_type = 1, .nargs = 3,
                print_mask_arg(sysdecode_pipe2_flags, fp, args[sc->offset]);

In addition, due to the recent ptrace changes to return an accurate system call argument count, system calls that accept no arguments or only plain integer arguments (issetugid, dup, dup2, kqueue) should not need explicit descriptions just to limit the number of arguments printed.
Comment 3 John Baldwin freebsd_committer freebsd_triage 2017-06-03 16:03:58 UTC
Still relevant to add from this patch:
- dup
- dup2
- getdirentries
- pread
- pwrite

The rest are either already added or were syscalls taking no args that do not require explicit entries in modern truss.
Comment 4 commit-hook freebsd_committer 2017-06-05 05:26:50 UTC
A commit references this bug:

Author: jhb
Date: Mon Jun  5 05:25:50 UTC 2017
New revision: 319595
URL: https://svnweb.freebsd.org/changeset/base/319595

Log:
  Decode arguments to dup, dup2, getdirentries, pread, and pwrite.

  - dup and dup2 print fd arguments in decimal.
  - pread and pwrite are similar to read and write with the addition of the
    file offset.
  - getdirentries displays the output entries as a string for now and also
    prints the value returned in *basep.  Eventually the buffer for
    getdirentries should perhaps be decoded as an array of dirent
    structures.

  PR:		214885
  Submitted by:	Jonathan de Boyne Pollard <J.deBoynePollard-newsgroups@NTLWorld.COM>

Changes:
  head/usr.bin/truss/syscall.h
  head/usr.bin/truss/syscalls.c
Comment 5 commit-hook freebsd_committer 2017-11-21 02:11:06 UTC
A commit references this bug:

Author: jhb
Date: Tue Nov 21 02:10:00 UTC 2017
New revision: 326044
URL: https://svnweb.freebsd.org/changeset/base/326044

Log:
  MFC 319493,319509,319520,319595,319677,319679-319681,319688,319689,
  319761-319768,320010,322899,322959,323020,323021,323151:

  Sync libsysdecode, kdump, and truss with head (aside from changes such
  as ino64 that are not applicable to 11).

  319493:
  Decode the arguments passed to __cap_rights_get() and cap_rights_limit().

  319509:
  Decode the argument passed to cap_getmode().

  The returned integer value is output.

  319520:
  Decode the 'who' argument passed to getrusage().

  Add a new sysdecode_getrusage_who() which decodes the RUSAGE_* constant
  passed as the first argument to getrusage().  Use this function in both
  kdump and truss to decode the first argument to getrusage().

  319595:
  Decode arguments to dup, dup2, getdirentries, pread, and pwrite.

  - dup and dup2 print fd arguments in decimal.
  - pread and pwrite are similar to read and write with the addition of the
    file offset.
  - getdirentries displays the output entries as a string for now and also
    prints the value returned in *basep.  Eventually the buffer for
    getdirentries should perhaps be decoded as an array of dirent
    structures.

  319677:
  Decode arguments to ACL related system calls.

  This only decodes the raw arguments but not the contents of the struct acl
  objects.

  319679:
  Decode arguments passed to extended attribute related system calls.

  The cmd argument passed to extattrctl() is not decoded as a string constant
  but is just printed in hex.  The value is filesystem-specific but in
  practice is only used with UFS1 filesystems.

  319680:
  Decode arguments to minherit().

  319681:
  Decode arguments to mlock(), mlockall(), and munlock().

  319688:
  Decode flags passed to mount(), nmount(), and unmount().

  319689:
  Decode arguments passed to msync().

  319761:
  Fix decoding of setpriority() arguments.

  The PRIO_* 'which' value is stored in the first argument to setpriority(2),
  not the last.  While here, decode the arguments to getpriority(2).

  319762:
  Decode arguments to getpriority() and setpriority().

  319763:
  Decode the arguments to ptrace().

  This does not decode structures returned by ptrace().

  319764:
  Decode the arguments to quotactl().

  319765:
  Improve decoding of RB_AUTOBOOT in the 'howto' argument to reboot().

  The reboot() system call accepts a mode (RB_AUTOBOOT, RB_HALT, RB_POWEROFF,
  or RB_REROOT) as well as zero or more optional flags in 'howto'.
  However, RB_AUTOBOOT was only displayed if 'howto' was exactly 0.
  Combinations like 'RB_AUTOBOOT | RB_DUMP' were decoded as 'RB_DUMP'.
  Instead, imply that RB_AUTOBOOT was specified if none of the other "mode"
  flags were specified.

  319766:
  Decode the 'howto' argument to reboot().

  319767:
  Decode arguments to rtprio_thread() (same as rtprio()).

  319768:
  Decode arguments to rtprio() and rtprio_thread().

  320010:
  Decode arguments to sched_* family of system calls.

  This includes decoding both scheduler policy constants and the sched_param
  structure for sched_get_priority_max(), sched_get_priority_min(),
  sched_getparam(), sched_getscheduler(), sched_rr_get_interval(),
  sched_setparam(), and sched_setscheduler().

  322899:
  Decode arguments passed to thr_set_name().

  322959:
  Decode extra signal information for caught signals.

  Decode fields from the siginfo_t stored in the PT_LWPINFO structure when a
  signal is caught by a traced process.  This includes the signal code
  (si_code) as well as additional members such as si_addr, si_pid, etc.

  323020:
  Trim stale prototype for ioctlname().

  323021:
  Decode signal information returned by system calls.

  Specifically, decode the siginfo structure returned by sigtimedwait(),
  sigwaitinfo(), and wait6().  While here, also decode the signal number
  returned in the second argument to sigwait().

  323151:
  Decode pathconf() names, *at() flags, and sysarch() numbers in libsysdecode.

  Move tables that were previously in truss over to libsysdecode.  truss
  output is unchanged, but kdump has been updated to decode these fields.
  In addition, sysdecode_sysarch_number() should support all platforms
  whereas the old table in truss only supported x86.

  PR:		214885, 215448

Changes:
_U  stable/11/
  stable/11/lib/libsysdecode/Makefile
  stable/11/lib/libsysdecode/flags.c
  stable/11/lib/libsysdecode/mktables
  stable/11/lib/libsysdecode/sysdecode.h
  stable/11/lib/libsysdecode/sysdecode_enum.3
  stable/11/lib/libsysdecode/sysdecode_mask.3
  stable/11/usr.bin/kdump/kdump.c
  stable/11/usr.bin/truss/extern.h
  stable/11/usr.bin/truss/setup.c
  stable/11/usr.bin/truss/syscall.h
  stable/11/usr.bin/truss/syscalls.c