From owner-freebsd-dtrace@FreeBSD.ORG Mon Nov 4 04:11:56 2013 Return-Path: Delivered-To: freebsd-dtrace@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 965A4E6F; Mon, 4 Nov 2013 04:11:56 +0000 (UTC) (envelope-from john.37@gmail.com) Received: from mail-ob0-x234.google.com (mail-ob0-x234.google.com [IPv6:2607:f8b0:4003:c01::234]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 57E1C2631; Mon, 4 Nov 2013 04:11:56 +0000 (UTC) Received: by mail-ob0-f180.google.com with SMTP id wo20so6540690obc.25 for ; Sun, 03 Nov 2013 20:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ITURlHVkHbSeuwoSk5vKMOLUgtU8O50fUfqhRBS1Ssc=; b=yT5ZpsrJ/F+4civaHF9j+3UR1HQUVFS377zkaHufiqqoMTFBmz+obVc5cP2zvPCMzF Uy/q//QEHcVhZYEuiOZvzJai1eF+LbXm32hDQg05LRy5rphrfvD0KHPemhr3F1Xv6NC3 kBb2DODB/V1O/b+9Dh0boDkwoF8Xmg9QAy+i0dSz//a01Wq0M8z+G8+adfp22YWQ6Y8x EFrKm3AeKVZEDJk7BYdGIppZrUoiD5LopLLOaZnbeeemAbalqQsdaOgrVn1XeITf4ORY p+V7Haum41U7GfDPuKKa1Gv8cv1QUG27tUR6WTHU7YhHT1/UXeRmDRqDzSXD2GezZX0W RnvA== MIME-Version: 1.0 X-Received: by 10.60.116.230 with SMTP id jz6mr12959874oeb.21.1383538315533; Sun, 03 Nov 2013 20:11:55 -0800 (PST) Received: by 10.60.35.74 with HTTP; Sun, 3 Nov 2013 20:11:55 -0800 (PST) In-Reply-To: <20131103235936.GB15661@raichu> References: <20131103235936.GB15661@raichu> Date: Mon, 4 Nov 2013 12:11:55 +0800 Message-ID: Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD 9.1-RELEASE From: John Luk To: Mark Johnston Content-Type: text/plain; charset=UTF-8 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: Mon, 04 Nov 2013 04:11:56 -0000 Thanks, Mark. But I still got nothing :( The line number of your patch wasn't match with mine, I patched it on hand. Was it because I was on an older version of src? The head of proc_sym.c shows: $FreeBSD: release/9.1.0/lib/libproc/proc_sym.c 211184 2010-08-11 17:33:26Z rpaulo And the patch of mine is include below, is it correct? Cheers, spin6lock diff --git a/proc_sym.c b/proc_sym.c index baa7f98..1969d7e 100644 --- a/proc_sym.c +++ b/proc_sym.c @@ -439,7 +439,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; } @@ -484,6 +486,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; @@ -500,6 +503,10 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, warn("ERROR: elf_begin() failed"); goto err1; } + if (gelf_getehdr(e, &ehdr) == NULL) { + warn("ERROR: gelf_getehdr() failed"); + goto err2; + } /* * Find the section we are looking for. */ @@ -551,6 +558,9 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, 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; + sym.st_value += map->pr_vaddr; (*func)(cd, &sym, s); } error = 0; 2013/11/4 Mark Johnston : > 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;