From owner-freebsd-dtrace@FreeBSD.ORG Sun Nov 3 23:59:40 2013 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 32F3DDFF for ; Sun, 3 Nov 2013 23:59:40 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-ie0-x234.google.com (mail-ie0-x234.google.com [IPv6:2607:f8b0:4001:c03::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 024982B2C for ; Sun, 3 Nov 2013 23:59:39 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e14so10846659iej.25 for ; Sun, 03 Nov 2013 15:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=VA7y6+jx28vDJEIW0FSuhhS8OVOWmqbGAnGZ7RGgJG8=; b=noAK+1PmP63KR+4lOJ97QlMZUaAP+Ux76m0axuf3/THGjVtCNQ29/J97RHrT9swqyH vk2iDQiZch/aUhEKXH/PH5fiNH5EgjSUoDu8DgMfOoP0fA7KZRiKICagct5NqZ71WqdQ 4lzrNUmYHBTNd4GgwqgLuYyM/HJ/qJNYnESpbbo03ifWDOTT9dOc2l53kANqjP9EHuYr YlKAvQdVHBbgUtFIscX97FtFZXtxTmFGPtdOod9daN1uO1ZrwbnxplWub9O2b7Ociqc5 scKU91EVUfuhDtdWuTN9hEMfQ9OKQFFbioeEMBw+ar+CmFYHw2wm8Bt2vUEgatLer2la 9obg== X-Received: by 10.50.130.46 with SMTP id ob14mr9915247igb.22.1383523179301; Sun, 03 Nov 2013 15:59:39 -0800 (PST) Received: from raichu (24-212-218-13.cable.teksavvy.com. [24.212.218.13]) by mx.google.com with ESMTPSA id f5sm18988360igc.4.2013.11.03.15.59.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 Nov 2013 15:59:38 -0800 (PST) Sender: Mark Johnston Date: Sun, 3 Nov 2013 18:59:36 -0500 From: Mark Johnston To: John Luk Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD 9.1-RELEASE Message-ID: <20131103235936.GB15661@raichu> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-dtrace@freebsd.org X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Nov 2013 23:59:40 -0000 On Sat, Nov 02, 2013 at 11:56:49AM +0800, John Luk wrote: > Hi all, > I'm a newbie in dtrace, and I following this tutorial from Oracle: > http://docs.oracle.com/cd/E19205-01/820-4221/ to learn dtrace. In the > example of test.c and ufunc.d, I expected output like this: > > % dtrace -s ufunc.d -c ./a.out a.out > > dtrace: script 'ufunc.d' matched 5 probes > dtrace: pid 27210 has exited > > inet_makeaddr 1 > foo1 1 > foo 1 > main 1 > __fsr 1 > > > But I got this instead: > > # dtrace -s ufunc.d -c ./a.out a.out > dtrace: script 'ufunc.d' matched 5 probes > dtrace: pid 86498 has exited > > # > > My system info: > root@home:/home/spin6lock/test # dtrace -V > dtrace: Sun D 1.7 > root@home:/home/spin6lock/test # uname -a > FreeBSD 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Mon Oct 28 20:52:03 CST > 2013 root@xiangling:/usr/obj/usr/src/sys/DTRACE amd64 > > Any clues? Thanks in advanced. This seems to be the result of a bug in libproc. I've included a patch below; could you apply it and verify that it fixes the problem? Once you've applied the patch, libproc can be rebuilt with # cd $SRCBASE/lib/libproc # make && make install Thanks, -Mark diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c index 87ac471..73e9742 100644 --- a/lib/libproc/proc_sym.c +++ b/lib/libproc/proc_sym.c @@ -465,7 +465,9 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol, s = elf_strptr(e, dynsymstridx, sym.st_name); if (s && strcmp(s, symbol) == 0) { memcpy(symcopy, &sym, sizeof(sym)); - symcopy->st_value = map->pr_vaddr + sym.st_value; + if (ehdr.e_type != ET_EXEC) + symcopy->st_value = map->pr_vaddr + + sym.st_value; error = 0; goto out; } @@ -509,6 +511,7 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, prmap_t *map; Elf_Scn *scn, *foundscn = NULL; Elf_Data *data; + GElf_Ehdr ehdr; GElf_Shdr shdr; GElf_Sym sym; unsigned long stridx = -1; @@ -525,6 +528,10 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, DPRINTFX("ERROR: elf_begin() failed: %s", elf_errmsg(-1)); goto err1; } + if (gelf_getehdr(e, &ehdr) == NULL) { + DPRINTFX("ERROR: gelf_getehdr() failed: %s", elf_errmsg(-1)); + goto err2; + } /* * Find the section we are looking for. */ @@ -575,7 +582,8 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, (mask & TYPE_FILE) == 0) continue; s = elf_strptr(e, stridx, sym.st_name); - sym.st_value += map->pr_vaddr; + if (ehdr.e_type != ET_EXEC) + sym.st_value += map->pr_vaddr; (*func)(cd, &sym, s); } error = 0;