decoding of input/output args ?

Mike Frysinger vapier at gentoo.org
Wed Aug 19 20:59:38 UTC 2015


On 19 Aug 2015 22:36, Dmitry V. Levin wrote:
> On Wed, Aug 19, 2015 at 03:17:39PM -0400, Mike Frysinger wrote:
> > some syscalls have arguments that are read/write.  for example, getsockopt 
> > passes in a pointer to a length that has to be set correctly first, and then
> > the kernel will adjust it when returning.  being able to see both values is
> > important when getting an error so you can see what the user sent up and what
> > the kernel sent back.
> > 
> > are there examples in strace to look at ?  perhaps something like:
> > getsockopt(4, SOL_IP, IPT_SO_GET_ENTRIES, "...", [2900->2804]) = 0
> > and when you get an error it'd be:
> > getsockopt(4, SOL_IP, IPT_SO_GET_ENTRIES, 0x12345, [2900->2900]) = EINVAL
> 
> I think there is no need to print it in case of an error,
> when it's known to be unchanged.
> 
> We have several examples in the code:
> $ git grep '[^a-z] => ' *.c
> mtd.c:			tprints(" => ");
> mtd.c:			tprints(" => ");
> sendfile.c:			tprints(" => ");
> sendfile.c:			tprints(" => ");
> sock.c:	tprints(" => ");
> v4l2.c:			tprints(exiting(tcp) && code != VIDIOC_G_FMT ? " => " : ", ");
> v4l2.c:		tprints(exiting(tcp) && code == VIDIOC_S_PARM ? " => {" : ", {");
> v4l2.c:			tprints(exiting(tcp) ? " => " : ", {id=");
> v4l2.c:		tprints(code != VIDIOC_G_EXT_CTRLS && exiting(tcp) ? " => " : ", ");
> 
> The most recent one is from commits v4.10-319-g22f8b27 and
> v4.10-320-g4918285.

output format looks fine.  but there's another wrinkle here :).  sendfile is 
easy -- the leading args are input only, and the last one is input/output,
so incremental output is not an issue.  getsockopt is inputs, then output,
then input/output.  so i can't print the last input in the entering code path
and then print the output in the exiting code path.  i need to read the curr
value, save it in the tcp structure somehow (?), and then read that back out
in the exiting code path.

	int getsockopt(int sockfd, int level, int optname,
	               void *optval, socklen_t *optlen);

	if (entering(tcp)) {
		... print sockfd/level/optname ...
		tprintf("%i, %i, %i, ", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
		... save current *optlen value ...
		umove(tcp, tcp->u_arg[4], &tcp->scratch);
	} else {
		... print optval output ...
		print_getsockopt(... tcp->u_arg[3] ...);
		... print the *optlen value ...
		umove(tcp, tcp->u_arg[4], &len);
		tprintf("[%d]", tcp->scratch);
		if (tcp->scratch != len)
			tprintf(" => [%d]", len);
	}

tips ?
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20150819/5eb027eb/attachment.bin>


More information about the Strace-devel mailing list