* script compilation fails at 'Pass 4' @ 2012-12-06 9:38 Mehul Choube 2012-12-06 14:43 ` David Smith 2012-12-06 23:11 ` Frank Ch. Eigler 0 siblings, 2 replies; 6+ messages in thread From: Mehul Choube @ 2012-12-06 9:38 UTC (permalink / raw) To: systemtap Hi, Whenever a syscall.connect returns I want to print the socket name (getsockname()) Error: ======= run start ======= [root@rhel5-stap stps]# stap -g strace-connect.stp -c "curl www.google.com" Pass 4: compilation failed. Try again with another '--vp 0001' option. [root@rhel5-stap stps]# stap -g --vp 0001 strace-connect.stp -c "curl www.google.com" Pass 4: compiled C into "stap_b7800dfc97ca81afbd4921aaa452d856_6437.ko" in 740usr/190sys/932real ms. Pass 4: compilation failed. Try again with another '--vp 0001' option. [root@rhel5-stap ~]# uname -a Linux rhel5-stap 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux ======= run end ======= The script and the C code is at: http://pastebin.com/ZspDG6qx Thanks, Mehul ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script compilation fails at 'Pass 4' 2012-12-06 9:38 script compilation fails at 'Pass 4' Mehul Choube @ 2012-12-06 14:43 ` David Smith 2012-12-06 16:01 ` Mehul Choube 2012-12-06 23:11 ` Frank Ch. Eigler 1 sibling, 1 reply; 6+ messages in thread From: David Smith @ 2012-12-06 14:43 UTC (permalink / raw) To: Mehul Choube; +Cc: systemtap On 12/06/2012 03:38 AM, Mehul Choube wrote: > Hi, > > Whenever a syscall.connect returns I want to print the socket name (getsockname()) > > Error: > > ======= run start ======= > > [root@rhel5-stap stps]# stap -g strace-connect.stp -c "curl www.google.com" > Pass 4: compilation failed. Try again with another '--vp 0001' option. > > [root@rhel5-stap stps]# stap -g --vp 0001 strace-connect.stp -c "curl www.google.com" > Pass 4: compiled C into "stap_b7800dfc97ca81afbd4921aaa452d856_6437.ko" in 740usr/190sys/932real ms. > Pass 4: compilation failed. Try again with another '--vp 0001' option. > > [root@rhel5-stap ~]# uname -a > Linux rhel5-stap 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux > > ======= run end ======= > > The script and the C code is at: http://pastebin.com/ZspDG6qx Mehul, I'm not sure why you aren't getting any error messages out of stap. What version of systemtap are you running? Here's what I get with systemtap HEAD: ==== # stap -gv ./strace-connect.stp -c "curl www.google.com" Checking "/lib/modules/2.6.18-308.20.1.el5/build/System.map" failed with error: No such file or directory Ensure kernel development headers & makefiles are installed Pass 1: parsed user script and 90 library script(s) using 148624virt/23228res/2904shr/21132data kb, in 180usr/20sys/202real ms. Pass 2: analyzed script: 1 probe(s), 2 function(s), 3 embed(s), 0 global(s) using 226460virt/81232res/45132shr/36912data kb, in 370usr/20sys/394real ms. Pass 3: translated to C into "/tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c" using 226460virt/81476res/45376shr/36912data kb, in 10usr/0sys/8real ms. /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c:22:20: error: stdlib.h: No such file or directory /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c:23:24: error: sys/socket.h: No such file or directory /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c: In function ‘function_sockname’: /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c:501: error: implicit declaration of function ‘malloc’ cc1: warnings being treated as errors /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c:501: warning: incompatible implicit declaration of built-in function ‘malloc’ /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c:501: error: invalid application of ‘sizeof’ to incomplete type ‘struct sockaddr’ /tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.c:502: error: expected ‘,’ or ‘;’ before ‘if’ make[1]: *** [/tmp/stapg3uHUN/stap_548b6f815eca69cfd5a759e9b2e12233_7447_src.o] Error 1 make: *** [_module_/tmp/stapg3uHUN] Error 2 WARNING: kbuild exited with status: 2 Pass 4: compiled C into "stap_548b6f815eca69cfd5a759e9b2e12233_7447.ko" in 380usr/190sys/588real ms. Pass 4: compilation failed. Try again with another '--vp 0001' option. ==== There are several misconceptions with your script. The main one being that the embedded C code in your script isn't user code, it is kernel code. So, for instance you can't call malloc(), header files don't come from /usr/include, etc. Perhaps you could back up a bit and tell us what you are really trying to do? -- David Smith dsmith@redhat.com Red Hat http://www.redhat.com 256.217.0141 (direct) 256.837.0057 (fax) ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: script compilation fails at 'Pass 4' 2012-12-06 14:43 ` David Smith @ 2012-12-06 16:01 ` Mehul Choube 0 siblings, 0 replies; 6+ messages in thread From: Mehul Choube @ 2012-12-06 16:01 UTC (permalink / raw) To: systemtap On Thu, 6 Dec 2012, David Smith wrote: > > Perhaps you could back up a bit and tell us what you are really trying > to do? our product have ~60 daemons running plus occasionally we spawn ephemeral processes. Using systemtap I want to find out who connects to whom for servicing a request. output something like: A (pid) <-- Socket --> B (pid) B (pid) <-- Shared memory --> D (pid) D (pid) <-- Message queue --> C (pid) and so on... I want to match local address+localport from connect() to remote address+remote port in accept(). Thanks, Mehul ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script compilation fails at 'Pass 4' 2012-12-06 9:38 script compilation fails at 'Pass 4' Mehul Choube 2012-12-06 14:43 ` David Smith @ 2012-12-06 23:11 ` Frank Ch. Eigler 2012-12-10 15:50 ` Mehul Choube 1 sibling, 1 reply; 6+ messages in thread From: Frank Ch. Eigler @ 2012-12-06 23:11 UTC (permalink / raw) To: Mehul Choube; +Cc: systemtap Mehul_Choube wrote: > http://pastebin.com/vyKHBGd0 sockname() can't work like that. Systemtap embedded-C code runs within the kernel, and can't call userspace glibc functions or system calls like that. Try instead: ######################################################################## function print_fd(fd) { task = task_current() sock = task_file_handle_socket(task,fd) if (sock) { fam = socket_family(sock) if (fam == %{ AF_INET %}) { printf("%s[%d] fd %d: %s\n", execname(), tid(), fd, socket_ipv4_sockname(sock)) return 0 } /* other cases as per pfiles.stp */ } } probe syscall.connect.return { if ($return >= 0) print_fd($return) } /* the rest verbatim from pfiles.stp */ %{ #include <linux/file.h> #include <net/sock.h> #include <linux/un.h> #include <linux/tcp.h> #include <linux/in.h> %} function task_file_handle_socket:long (task:long, fd:long) %{ /* pure */ struct task_struct *p = (struct task_struct *)((long)STAP_ARG_task); struct files_struct *files; struct file *filp; struct dentry *dentry; struct inode *inode; rcu_read_lock(); if ((files = kread(&p->files)) && (filp = fcheck_files(files, STAP_ARG_fd)) && (dentry = kread(&filp->f_dentry)) && (inode = kread(&filp->f_dentry->d_inode))) { if (S_ISSOCK(kread(&inode->i_mode))) STAP_RETVALUE = (long)SOCKET_I(inode); } CATCH_DEREF_FAULT(); rcu_read_unlock(); %} function socket_family:long (sock:long) %{ /* pure */ struct socket *sock = (struct socket *)((long)STAP_ARG_sock); const struct proto_ops *ops = kread(&sock->ops); STAP_RETVALUE = (long)kread(&ops->family); CATCH_DEREF_FAULT(); %} function socket_ipv4_sockname:string (sock:long) %{ /* pure */ struct socket *sock = (struct socket *)((long)STAP_ARG_sock); const struct proto_ops *ops = kread(&sock->ops); struct sockaddr_in in_addr; __be32 addr, port; int err, len; err = ops->getname (sock, (struct sockaddr*)(&in_addr), &len, 0); if (!err) { addr = in_addr.sin_addr.s_addr; port = htons(in_addr.sin_port); snprintf(STAP_RETVALUE, MAXSTRINGLEN, " sockname: AF_INET " NIPQUAD_FMT " port: %d", NIPQUAD(addr), port); } CATCH_DEREF_FAULT(); %} ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: script compilation fails at 'Pass 4' 2012-12-06 23:11 ` Frank Ch. Eigler @ 2012-12-10 15:50 ` Mehul Choube 2012-12-10 17:47 ` Frank Ch. Eigler 0 siblings, 1 reply; 6+ messages in thread From: Mehul Choube @ 2012-12-10 15:50 UTC (permalink / raw) To: systemtap On Thu, 6 Dec 2012, Frank Ch. Eigler wrote: > > Mehul_Choube wrote: > >> http://pastebin.com/vyKHBGd0 > > sockname() can't work like that. Systemtap embedded-C code runs > within the kernel, and can't call userspace glibc functions or > system calls like that. > > Try instead: > > ######################################################################## > function print_fd(fd) { > task = task_current() > sock = task_file_handle_socket(task,fd) > if (sock) { > fam = socket_family(sock) > if (fam == %{ AF_INET %}) { > printf("%s[%d] fd %d: %s\n", execname(), tid(), fd, > socket_ipv4_sockname(sock)) > return 0 > } /* other cases as per pfiles.stp */ > } > } > > probe syscall.connect.return { > if ($return >= 0) print_fd($return) > } > > > /* the rest verbatim from pfiles.stp */ > > %{ > #include <linux/file.h> > #include <net/sock.h> > #include <linux/un.h> > #include <linux/tcp.h> > #include <linux/in.h> > %} > > function task_file_handle_socket:long (task:long, fd:long) %{ /* pure */ > struct task_struct *p = (struct task_struct *)((long)STAP_ARG_task); > struct files_struct *files; > struct file *filp; > struct dentry *dentry; > struct inode *inode; > > rcu_read_lock(); > if ((files = kread(&p->files)) && > (filp = fcheck_files(files, STAP_ARG_fd)) && > (dentry = kread(&filp->f_dentry)) && > (inode = kread(&filp->f_dentry->d_inode))) { > if (S_ISSOCK(kread(&inode->i_mode))) > STAP_RETVALUE = (long)SOCKET_I(inode); > } > > CATCH_DEREF_FAULT(); > rcu_read_unlock(); > %} > > function socket_family:long (sock:long) %{ /* pure */ > struct socket *sock = (struct socket *)((long)STAP_ARG_sock); > const struct proto_ops *ops = kread(&sock->ops); > STAP_RETVALUE = (long)kread(&ops->family); > CATCH_DEREF_FAULT(); > %} > > function socket_ipv4_sockname:string (sock:long) %{ /* pure */ > struct socket *sock = (struct socket *)((long)STAP_ARG_sock); > const struct proto_ops *ops = kread(&sock->ops); > struct sockaddr_in in_addr; > __be32 addr, port; > int err, len; > > err = ops->getname (sock, (struct sockaddr*)(&in_addr), &len, 0); > if (!err) { > addr = in_addr.sin_addr.s_addr; > port = htons(in_addr.sin_port); > snprintf(STAP_RETVALUE, MAXSTRINGLEN, > " sockname: AF_INET " NIPQUAD_FMT " port: %d", > NIPQUAD(addr), port); > } > CATCH_DEREF_FAULT(); > %} > > Now it fails with: error: 'STAP_ARG_sock' undeclared (first use in this function) please check: http://pastebin.com/wvZFu02g Thanks, Mehul ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: script compilation fails at 'Pass 4' 2012-12-10 15:50 ` Mehul Choube @ 2012-12-10 17:47 ` Frank Ch. Eigler 0 siblings, 0 replies; 6+ messages in thread From: Frank Ch. Eigler @ 2012-12-10 17:47 UTC (permalink / raw) To: Mehul Choube; +Cc: systemtap Mehul Choube <Mehul_Choube@symantec.com> writes: > [...] > Now it fails with: > error: 'STAP_ARG_sock' undeclared (first use in this function) OK, so you must be running a systemtap version older than 1.8. In that case, you would need to use THIS->sock instead of STAP_ARG_sock and THIS->__retvalue for STAP_RETVALUE etc. in the embedded-C blocks. You might also need to copy the NIPQUAD* related embedded-C block from <http://sourceware.org/systemtap/examples/process/pfiles.stp>. - FChE ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-12-10 17:47 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-12-06 9:38 script compilation fails at 'Pass 4' Mehul Choube 2012-12-06 14:43 ` David Smith 2012-12-06 16:01 ` Mehul Choube 2012-12-06 23:11 ` Frank Ch. Eigler 2012-12-10 15:50 ` Mehul Choube 2012-12-10 17:47 ` Frank Ch. Eigler
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).