Date: Sun, 24 May 2009 19:20:05 GMT From: Steven Hartland <steven.hartland@multiplay.co.uk> To: freebsd-gnats-submit@FreeBSD.org Subject: misc/134919: Additional detail for truss when tracing linux apps Message-ID: <200905241920.n4OJK5qm037767@www.freebsd.org> Resent-Message-ID: <200905241930.n4OJU1pU046582@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 134919 >Category: misc >Synopsis: Additional detail for truss when tracing linux apps >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: update >Submitter-Id: current-users >Arrival-Date: Sun May 24 19:30:01 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Steven Hartland >Release: 7.2 >Organization: Multiplay >Environment: FreeBSD ftp1.multiplay.co.uk 7.2-RELEASE FreeBSD 7.2-RELEASE #0: Sun May 24 19:21:08 BST 2009 root@ftp1.multiplay.co.uk:/usr/obj/usr/src/sys/MULTIPLAY i386 >Description: The following patch adds a number of additional tracing options for linux apps to truss >How-To-Repeat: >Fix: Apply the attached patch :) Patch attached with submission follows: --- /usr/src/usr.bin/truss/syscall.h.orig 2007-04-10 05:03:34.000000000 +0100 +++ /usr/src/usr.bin/truss/syscall.h 2008-06-30 13:16:01.000000000 +0100 @@ -41,5 +41,5 @@ Umtx, Sigset, Sigprocmask, Kevent, Sockdomain, Socktype, Open, Fcntlflag, Rusage, BinString, Shutdown, Resource, Rlimit, Timeval2, - Pathconf }; + Pathconf, LinuxSockArgs }; #define ARG_MASK 0xff @@ -65,2 +65,49 @@ void print_syscall_ret(struct trussinfo *, const char *, int, char **, int, long); + +/* + * Linux Socket defines + */ +#define LINUX_SOCKET 1 +#define LINUX_BIND 2 +#define LINUX_CONNECT 3 +#define LINUX_LISTEN 4 +#define LINUX_ACCEPT 5 +#define LINUX_GETSOCKNAME 6 +#define LINUX_GETPEERNAME 7 +#define LINUX_SOCKETPAIR 8 +#define LINUX_SEND 9 +#define LINUX_RECV 10 +#define LINUX_SENDTO 11 +#define LINUX_RECVFROM 12 +#define LINUX_SHUTDOWN 13 +#define LINUX_SETSOCKOPT 14 +#define LINUX_GETSOCKOPT 15 +#define LINUX_SENDMSG 16 +#define LINUX_RECVMSG 17 + +#define PAD_(t) (sizeof(register_t) <= sizeof(t) ? \ + 0 : sizeof(register_t) - sizeof(t)) + +#if BYTE_ORDER == LITTLE_ENDIAN +#define PADL_(t) 0 +#define PADR_(t) PAD_(t) +#else +#define PADL_(t) PAD_(t) +#define PADR_(t) 0 +#endif + +typedef int l_int; +typedef uint32_t l_ulong; + +struct linux_socketcall_args { + char what_l_[PADL_(l_int)]; l_int what; char what_r_[PADR_(l_int)]; + char args_l_[PADL_(l_ulong)]; l_ulong args; char args_r_[PADR_(l_ulong)]; +}; + +/* +struct linux_socketcall_args { + l_int what; + l_ulong args; +}; +*/ --- syscalls.c.orig 2008-07-13 22:34:30.000000000 +0100 +++ syscalls.c 2008-11-22 02:27:12.000000000 +0000 @@ -96,4 +96,8 @@ { "readlink", 1, 3, { { Name, 0 } , { Readlinkres | OUT, 1 }, { Int, 2 }}}, + { "linux_readlink", 1, 3, + { { Name, 0 } , { Name | OUT, 1 }, { Int, 2 }}}, + { "linux_socketcall", 1, 2, + { { Int, 0 } , { LinuxSockArgs, 1 }}}, { "lseek", 2, 3, { {Int, 0}, {Quad, 1 + QUAD_ALIGN}, @@ -112,4 +116,6 @@ { "linux_open", 1, 3, { { Name, 0 }, { Hex, 1}, { Octal, 2 }}}, + { "linux_mkdir", 1, 2, + { { Name | IN, 0} , {Int, 1}}}, { "close", 1, 1, { { Int, 0 } } }, @@ -136,4 +142,6 @@ { "stat", 1, 2, { { Name | IN, 0 }, { Stat | OUT, 1 }}}, + { "linux_stat64", 1, 3, + { { Name | IN, 0 }, { Ptr | OUT, 1 }, { Ptr | IN, 1 }}}, { "lstat", 1, 2, { { Name | IN, 0 }, { Stat | OUT, 1 }}}, @@ -149,4 +157,5 @@ { "exit", 0, 1, { { Hex, 0 }}}, { "access", 1, 2, { { Name | IN, 0 }, { Int, 1 }}}, + { "linux_access", 1, 2, { { Name, 0 }, { Int, 1 }}}, { "sigaction", 1, 3, { { Signal, 0 }, { Sigaction | IN, 1 }, { Sigaction | OUT, 2 }}}, @@ -667,4 +676,75 @@ break; case Itimerval: + case LinuxSockArgs: + { + + 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 ); + } + break; { struct itimerval itv; >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905241920.n4OJK5qm037767>