Solved truss question about how strings are displayed

Hello,

I'm recently arrived to FreeBSD from too many years working with Linux and I'm trying to put the things right with my new FreeBSD :).

A very good tool for me was strace, because you can understand what are happening behind the scenes, so I decided to use truss to understand how FreeBSD works (probably dtrace is the best way but I'm going step by step). Using truss I found something annoying (for me):

Code:
$ truss head -1 /etc/passwd 2>&1 | grep open
openat(0xffffff9c,0x800622000,0x100000,0x0,0xfffffffffffffc00,0x400308) = 3 (0x3)
openat(0xffffff9c,0x800618703,0x100000,0x0,0xfffffffffffffc00,0x0) = 3 (0x3)
openat(0xffffff9c,0x80061f060,0x100000,0x0,0x101010101010101,0x8080808080808080) = 3 (0x3)
open("/etc/passwd",O_RDONLY,0666)  = 3 (0x3)
$

Is there any reason which truss does not display openat strings arguments? It's impossible that nobody have realized about it because it's hard to find a process not executing openat, so I supposed there is a good reason.
 
I would guess the implementation is such that the information about the argument types for system calls is not available so truss(1) sees the second argument to openat(2) as a number but it doesn't know that it's in fact a pointer, char *.

The manual page says that it's modeled after similar tools from System V and SunOS so I'd guess those operated the same.
 
Someone obviously thought about implementing such features. The -f option turns on string expansion for the execve(2) system call but only for that one system call:

Code:
freebsd10 ~ % truss -af env head -1 /etc/passwd 2>&1 | grep exec
8592: execve("/sbin/head", [ "head", "-1", "/etc/passwd" ],<missing argument>) ERR#2 'No such file or directory'
8592: execve("/bin/head", [ "head", "-1", "/etc/passwd" ],<missing argument>) ERR#2 'No such file or directory'
8592: execve("/usr/sbin/head", [ "head", "-1", "/etc/passwd" ],<missing argument>) ERR#2 'No such file or directory'
8592: execve("/usr/bin/head", [ "head", "-1", "/etc/passwd" ],<missing argument>) = 0 (0x0)
freebsd10 ~ %
 
It has it's own table
Code:
$ grep open /usr/src/usr.bin/truss/syscalls.c
  { .name = "open", .ret_type = 1, .nargs = 3,
  { .name = "linux_open", .ret_type = 1, .nargs = 3,
  { .name = "posix_openpt", .ret_type = 1, .nargs = 1,

Juha
 
Yep,

Adding this
Code:
  { .name = "openat", .ret_type = 1, .nargs = 4,
  .args = { {Int, 0}, { Name | IN, 1 } , { Open, 2 }, { Octal, 3 } } },

Works fine:

Code:
$ truss head -1 /etc/passwd 2>&1 | grep open
openat(-100,"/etc/libmap.conf",O_CLOEXEC,00)  = 3 (0x3)
openat(-100,"/var/run/ld-elf.so.hints",O_CLOEXEC,00) = 3 (0x3)
openat(-100,"/lib/libc.so.7",O_CLOEXEC,00)  = 3 (0x3)
open("/etc/passwd",O_RDONLY,0666)  = 3 (0x3)
$
 
In FreeBSD-CURRENT it's already added to the table as:

Code:
  { .name = "openat", .ret_type = 1, .nargs = 4,
  .args = { { Atfd, 0 }, { Name | IN, 1 }, { Open, 2 },
  { Octal, 3 } } },
 
Back
Top