From a7ecfcac5413dc4d0d69986acfbe52a5e8ecb48f Mon Sep 17 00:00:00 2001 From: jhb Date: Mon, 17 Aug 2015 18:47:39 +0000 Subject: Tidy the linux_socketcall decoding: - Don't exit if get_struct() fails, instead print the raw pointer value to match all other argument decoding cases. - Use an xlat table instead of a home-rolled switch for the operation name. - Display the nested socketcall args structure as a structure instead of as two inline arguments. --- usr.bin/truss/syscalls.c | 81 ++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 65 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c index 26c90b8..3132f21 100644 --- a/usr.bin/truss/syscalls.c +++ b/usr.bin/truss/syscalls.c @@ -545,6 +545,16 @@ static struct xlat sysarch_ops[] = { #endif XEND }; + +static struct xlat linux_socketcall_ops[] = { + X(LINUX_SOCKET) X(LINUX_BIND) X(LINUX_CONNECT) X(LINUX_LISTEN) + X(LINUX_ACCEPT) X(LINUX_GETSOCKNAME) X(LINUX_GETPEERNAME) + X(LINUX_SOCKETPAIR) X(LINUX_SEND) X(LINUX_RECV) X(LINUX_SENDTO) + X(LINUX_RECVFROM) X(LINUX_SHUTDOWN) X(LINUX_SETSOCKOPT) + X(LINUX_GETSOCKOPT) X(LINUX_SENDMSG) X(LINUX_RECVMSG) + XEND +}; + #undef X #undef XEND @@ -962,71 +972,12 @@ print_arg(struct syscall_args *sc, unsigned long *args, long retval, { struct linux_socketcall_args largs; if (get_struct(pid, (void *)args[sc->offset], (void *)&largs, - sizeof(largs)) == -1) { - err(1, "get_struct %p", (void *)args[sc->offset]); - } - const char *what; - char buf[30]; - - switch (largs.what) { - case LINUX_SOCKET: - what = "LINUX_SOCKET"; - break; - case LINUX_BIND: - what = "LINUX_BIND"; - break; - case LINUX_CONNECT: - what = "LINUX_CONNECT"; - break; - case LINUX_LISTEN: - what = "LINUX_LISTEN"; - break; - case LINUX_ACCEPT: - what = "LINUX_ACCEPT"; - break; - case LINUX_GETSOCKNAME: - what = "LINUX_GETSOCKNAME"; - break; - case LINUX_GETPEERNAME: - what = "LINUX_GETPEERNAME"; - break; - case LINUX_SOCKETPAIR: - what = "LINUX_SOCKETPAIR"; - break; - case LINUX_SEND: - what = "LINUX_SEND"; - break; - case LINUX_RECV: - what = "LINUX_RECV"; - break; - case LINUX_SENDTO: - what = "LINUX_SENDTO"; - break; - case LINUX_RECVFROM: - what = "LINUX_RECVFROM"; - break; - case LINUX_SHUTDOWN: - what = "LINUX_SHUTDOWN"; - break; - case LINUX_SETSOCKOPT: - what = "LINUX_SETSOCKOPT"; - break; - case LINUX_GETSOCKOPT: - what = "LINUX_GETSOCKOPT"; - break; - case LINUX_SENDMSG: - what = "LINUX_SENDMSG"; - break; - case LINUX_RECVMSG: - what = "LINUX_RECVMSG"; - break; - default: - sprintf(buf, "%d", largs.what); - what = buf; - break; - } - asprintf(&tmp, "(0x%lx)%s, 0x%lx", args[sc->offset], what, - (long unsigned int)largs.args); + sizeof(largs)) != -1) + asprintf(&tmp, "{ %s, 0x%lx }", + lookup(linux_socketcall_ops, largs.what, 10), + (long unsigned int)largs.args); + else + asprintf(&tmp, "0x%lx", args[sc->offset]); break; } case Pollfd: { -- cgit v1.1