Subject: Re: truss ?
To: Brian Buhrow <buhrow@cats.ucsc.edu>
From: Darren Reed <darrenr@cyber.com.au>
List: tech-kern
Date: 02/08/1998 15:36:23
In some mail I received from Brian Buhrow, sie wrote
> 
> 	What does truss provide that ktrace doesn't?  I use both and find I
> like ktrace better.  But there might be something I don't know.
> -Brian
> 
> On Feb 6,  9:40pm, Darren Reed wrote:
> } Subject: truss ?
> } 
> } Can we put "truss" on the projects list, maybe even for 1.4, please ?
> } I was passed on this URL, if it helps, for at least one implementation
> } of truss on BSD:
> } http://www.ddj.com/ftp/1998/1998_03/
> } 
> } Darren

Example:
*** truss ***
% echo 'main(){printf("Hello world\n");}' > hello.c
% gcc hello.c
% truss a.out 
execve("./a.out", 0xEFFFF9C8, 0xEFFFF9D0)  argc = 1
open("/dev/zero", O_RDONLY)                     = 3
mmap(0x00000000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0xEF7C0000
open("/usr/lib/libc.so.1", O_RDONLY)            = 4
fstat(4, 0xEFFFF67C)                            = 0
mmap(0x00000000, 4096, PROT_READ|PROT_EXEC, MAP_SHARED, 4, 0) = 0xEF7B0000
mmap(0x00000000, 618496, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) = 0xEF700000
munmap(0xEF77F000, 61440)                       = 0
mmap(0xEF78E000, 27856, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 4, 516096) = 0xEF78E000
mmap(0xEF795000, 7968, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0) = 0xEF795000
close(4)                                        = 0
open("/usr/lib/libdl.so.1", O_RDONLY)           = 4
fstat(4, 0xEFFFF67C)                            = 0
mmap(0xEF7B0000, 4096, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, 4, 0) = 0xEF7B0000
close(4)                                        = 0
open("/usr/platform/SUNW,SPARCstation-5/lib/libc_psr.so.1", O_RDONLY) Err#2 ENOENT
close(3)                                        = 0
ioctl(1, TCGETA, 0xEFFFEB84)                    = 0
Hello World
write(1, " H e l l o   W o r l d\n", 12)        = 12
lseek(0, 0, SEEK_CUR)                           = 22531
_exit(1)

*** ktrace ***
% echo 'main(){printf("Hello world\n");}' > hello.c
% gcc hello.c
% ktrace a.out 
Hello world
% kdump
   278 ktrace   RET   ktrace 0
   278 ktrace   CALL  readlink(0x1006ba4a,0xefbfcff8,0x3f)
   278 ktrace   NAMI  "/etc/malloc.conf"
   278 ktrace   RET   readlink -1 errno 2 No such file or directory
   278 ktrace   CALL  mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0)
   278 ktrace   RET   mmap 268546048/0x1001b000
   278 ktrace   CALL  break(0x5000)
   278 ktrace   RET   break 0
   278 ktrace   CALL  break(0x6000)
   278 ktrace   RET   break 0
   278 ktrace   CALL  execve(0xefbfd0a8,0xefbfd568,0xefbfd570)
   278 ktrace   NAMI  "./a.out"
   278 a.out    RET   execve 0
   278 a.out    CALL  open(0x109c,0,0)
   278 a.out    NAMI  "/usr/libexec/ld.so"
   278 a.out    RET   open 3
   278 a.out    CALL  read(0x3,0xefbfd510,0x20)
   278 a.out    GIO   fd 3 read 32 bytes
       "\M-L\0\M^F\M-@\0\M-`\0\0\0 \0\0$\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0"
   278 a.out    RET   read 32/0x20
   278 a.out    CALL  mmap(0,0xe000,0x5,0x2,0x3,0,0,0)
   278 a.out    RET   mmap 268443648/0x10002000
   278 a.out    CALL  mmap(0x10010000,0x2000,0x3,0x12,0x3,0,0xe000,0)
   278 a.out    RET   mmap 268500992/0x10010000
   278 a.out    CALL  mmap(0x10012000,0x24,0x3,0x1012,0xffffffff,0,0,0)
   278 a.out    RET   mmap 268509184/0x10012000
   278 a.out    CALL  getuid
   278 a.out    RET   getuid 1013/0x3f5
   278 a.out    CALL  geteuid
   278 a.out    RET   geteuid 1013/0x3f5
   278 a.out    CALL  getgid
   278 a.out    RET   getgid 2000/0x7d0
   278 a.out    CALL  getegid
   278 a.out    RET   getegid 2000/0x7d0
   278 a.out    CALL  __sysctl(0xefbfd468,0x2,0x100118ec,0xefbfd470,0,0)
   278 a.out    RET   __sysctl 0
   278 a.out    CALL  mmap(0,0x8000,0x3,0x1002,0xffffffff,0,0,0)
   278 a.out    RET   mmap 268513280/0x10013000
   278 a.out    CALL  open(0x10003b06,0,0)
   278 a.out    NAMI  "/var/run/ld.so.hints"
   278 a.out    RET   open 4
   278 a.out    CALL  read(0x4,0xefbfd458,0x20)
   278 a.out    GIO   fd 4 read 32 bytes
       "iHDL\^B\0\0\0 \0\0\0W\0\0\0p\^P\0\0\M^G\v\0\0\M-w\^[\0\0P\v\0\0"
   278 a.out    RET   read 32/0x20
   278 a.out    CALL  mmap(0,0x1bf7,0x1,0x1,0x4,0,0,0)
   278 a.out    RET   mmap 268546048/0x1001b000
   278 a.out    CALL  close(0x4)
   278 a.out    RET   close 0
   278 a.out    CALL  stat(0x1001c321,0xefbfd40c)
   278 a.out    NAMI  "/usr/lib/libc.so.3.0"
   278 a.out    RET   stat 0
   278 a.out    CALL  stat(0x100160a0,0xefbfd434)
   278 a.out    NAMI  "/usr/lib/libc.so.3.0"
   278 a.out    RET   stat 0
   278 a.out    CALL  open(0x100160a0,0,0)
   278 a.out    NAMI  "/usr/lib/libc.so.3.0"
   278 a.out    RET   open 4
   278 a.out    CALL  read(0x4,0xefbfd414,0x20)
   278 a.out    GIO   fd 4 read 32 bytes
       "\M-L\0\M^F\M-@\0\M-@\^E\0\0@\0\0\M-0\M-J\0\0$3\0\0 \0\0\0\0\0\0\0\0\0\
        \0\0"
   278 a.out    RET   read 32/0x20
   278 a.out    CALL  mmap(0,0x6cab0,0x5,0x2,0x4,0,0,0)
   278 a.out    RET   mmap 268554240/0x1001d000
   278 a.out    CALL  close(0x4)
   278 a.out    RET   close 0
   278 a.out    CALL  mprotect(0x10079000,0x4000,0x7)
   278 a.out    RET   mprotect 0
   278 a.out    CALL  mmap(0x1007d000,0xcab0,0x7,0x1012,0xffffffff,0,0,0)
   278 a.out    RET   mmap 268947456/0x1007d000
   278 a.out    CALL  munmap(0x1001a000,0x1000)
   278 a.out    RET   munmap 0
   278 a.out    CALL  mmap(0,0xa000,0x3,0x1002,0xffffffff,0,0,0)
   278 a.out    RET   mmap 269000704/0x1008a000
   278 a.out    CALL  munmap(0x1001b000,0x1bf7)
   278 a.out    RET   munmap 0
   278 a.out    CALL  close(0x3)
   278 a.out    RET   close 0
   278 a.out    CALL  fstat(0x1,0xefbfd1f8)
   278 a.out    RET   fstat 0
   278 a.out    CALL  readlink(0x1006aa4a,0xefbfd1f4,0x3f)
   278 a.out    NAMI  "/etc/malloc.conf"
   278 a.out    RET   readlink -1 errno 2 No such file or directory
   278 a.out    CALL  mmap(0,0x1000,0x3,0x1002,0xffffffff,0,0,0)
   278 a.out    RET   mmap 268541952/0x1001a000
   278 a.out    CALL  break(0x4000)
   278 a.out    RET   break 0
   278 a.out    CALL  break(0x14000)
   278 a.out    RET   break 0
   278 a.out    CALL  ioctl(0x1,TIOCGETA,0xefbfd234)
   278 a.out    RET   ioctl 0
   278 a.out    CALL  write(0x1,0x4000,0xc)
   278 a.out    GIO   fd 1 wrote 12 bytes
       "Hello world
       "
   278 a.out    RET   write 12/0xc
   278 a.out    CALL  exit(0xc)

Just one thing: that's ktrace/kdump from FreeBSD 2.2.5 (not NetBSD),
although I think they're much the same.

The single biggest difference is that truss is "realtime".

Darren