tracing library calls in Solaris with truss

It is possible to trace systemcalls with truss in Solaris as well known, but it is also possible to trace calls in a shared object. As the example below shows, all calls in the libc Library are traced. It is also possible to trace only a specified function like


truss -u libc::memcpy


bash-3.2$ truss -u libc:: ls
execve("/usr/bin/ls", 0x0804705C, 0x08047064) argc = 1
mmap(0x00000000, 4096, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON, -1, 0) = 0xCEBF0000
resolvepath("/usr/lib/ld.so.1", "/lib/ld.so.1", 1023) = 12
resolvepath("/usr/bin/ls", "/usr/bin/ls", 1023) = 11
xstat(2, "/usr/bin/ls", 0x08046D08) = 0
open("/var/ld/ld.config", O_RDONLY) Err#2 ENOENT
sysconfig(_CONFIG_PAGESIZE) = 4096
xstat(2, "/lib/libc.so.1", 0x08046468) = 0
resolvepath("/lib/libc.so.1", "/lib/libc.so.1", 1023) = 14
open("/lib/libc.so.1", O_RDONLY) = 3
mmap(0x00010000, 32768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_ALIGN, 3, 0) = 0xCEBB0000
mmap(0x00010000, 1368064, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xCEA60000
mmap(0xCEA60000, 1258857, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_TEXT, 3, 0) = 0xCEA60000
mmap(0xCEBA4000, 30506, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_INITDATA, 3, 1261568) = 0xCEBA4000
mmap(0xCEBAC000, 4416, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANON, -1, 0) = 0xCEBAC000
munmap(0xCEB94000, 65536) = 0
memcntl(0xCEA60000, 202492, MC_ADVISE, MADV_WILLNEED, 0, 0) = 0
close(3) = 0
/1: -> libc:__tls_static_mods(0xcebf0308, 0x200)
/1: -> libc:lmalloc(0x200)
/1: -> libc:getbucketnum(0x200)
/1: <- libc:getbucketnum() = 3 /1: -> libc:initial_allocation(0xceba9c40)
/1: -> libc:__systemcall(0x8046c38, 0x73, 0x10000, 0x6000)
/1: mmap(0x00010000, 24576, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON|MAP_ALIGN, -1, 0) = 0xCEA50000
/1: <- libc:__systemcall() = 0 /1: <- libc:initial_allocation() = 0xceba9dc0 /1: <- libc:lmalloc() = 0xcea51800 /1: -> libc:tls_modinfo_alloc(0xceba9f40, 0x0)
/1: -> libc:lmalloc(0x400)
/1: -> libc:getbucketnum(0x400)
/1: <- libc:getbucketnum() = 4 /1: <- libc:lmalloc() = 0xcea52000 /1: <- libc:tls_modinfo_alloc() = 0xcea52000 /1: <- libc:__tls_static_mods() = 0 /1: munmap(0xCEBB0000, 32768) = 0 /1: -> libc:libc_init()
/1: -> libc:atexit(0xceae51e0)
/1: -> libc:lmalloc(0x8)
/1: -> libc:getbucketnum(0x8)
/1: <- libc:getbucketnum() = 0 /1: <- libc:lmalloc() = 0xcea50000 /1: <- libc:atexit() = 0 /1: -> libc:__getcontext(0x8046ab0)
/1: getcontext(0x08046AB0)
/1: <- libc:__getcontext() = 0 /1: -> libc:lmalloc(0x460)
/1: -> libc:getbucketnum(0x460)
/1: <- libc:getbucketnum() = 5 /1: <- libc:lmalloc() = 0xcea52800 /1: -> libc:getrlimit(0x3, 0x8046aa8)
/1: getrlimit(RLIMIT_STACK, 0x08046AA8) = 0
/1: <- libc:getrlimit() = 0 /1@1: -> libc:getpid()
/1: getpid() = 1916 [1915]
/1@1: <- libc:getpid() = 1916 /1@1: -> libc:lmalloc(0x4)
/1@1: -> libc:getbucketnum(0x4)
/1@1: <- libc:getbucketnum() = 0 /1@1: <- libc:lmalloc() = 0xcea50040 /1@1: -> libc:___lwp_private(0x0, 0x1, 0xcea52a00)
/1: lwp_private(0, 1, 0xCEA52A00) = 0x000001C3
/1@1: <- libc:___lwp_private() = 451 /1@1: -> libc:set_curthread(0xcea52a00)
/1@1: <- libc:set_curthread() = 0xcea52a00 /1@1: -> libc:mutex_setup()
/1@1: <- libc:mutex_setup() = 0xcea52a00 /1@1: -> libc:atfork_init()
/1@1: -> libc:pthread_atfork(0xceac8240, 0xceac8290, 0xceac8265)
/1@1: -> libc:mutex_lock(0xceba8300)
/1@1: -> libc:mutex_lock_impl(0xceba8300, 0x0)
/1@1: <- libc:mutex_lock_impl() = 0 /1@1: <- libc:mutex_lock() = 0