From owner-freebsd-dtrace@FreeBSD.ORG  Sun Nov  3 23:59:40 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 <freebsd-dtrace@freebsd.org>; 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 <freebsd-dtrace@freebsd.org>; Sun,  3 Nov 2013 23:59:39 +0000 (UTC)
Received: by mail-ie0-f180.google.com with SMTP id e14so10846659iej.25
 for <freebsd-dtrace@freebsd.org>; 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 <multiple recipients>
 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
 Sun, 03 Nov 2013 15:59:38 -0800 (PST)
Sender: Mark Johnston <markjdb@gmail.com>
Date: Sun, 3 Nov 2013 18:59:36 -0500
From: Mark Johnston <markj@freebsd.org>
To: John Luk <john.37@gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
Message-ID: <20131103235936.GB15661@raichu>
References: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=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;

From owner-freebsd-dtrace@FreeBSD.ORG  Mon Nov  4 04:11:56 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 <multiple recipients>; 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: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
 <20131103235936.GB15661@raichu>
Date: Mon, 4 Nov 2013 12:11:55 +0800
Message-ID: <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
From: John Luk <john.37@gmail.com>
To: Mark Johnston <markj@freebsd.org>
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=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 <markj@freebsd.org>:
> 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;

From owner-freebsd-dtrace@FreeBSD.ORG  Mon Nov  4 04:35:23 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 05D9FFF8
 for <freebsd-dtrace@freebsd.org>; Mon,  4 Nov 2013 04:35:23 +0000 (UTC)
 (envelope-from markjdb@gmail.com)
Received: from mail-ie0-x230.google.com (mail-ie0-x230.google.com
 [IPv6:2607:f8b0:4001:c03::230])
 (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id C88BC2705
 for <freebsd-dtrace@freebsd.org>; Mon,  4 Nov 2013 04:35:22 +0000 (UTC)
Received: by mail-ie0-f176.google.com with SMTP id u16so11772992iet.35
 for <freebsd-dtrace@freebsd.org>; Sun, 03 Nov 2013 20:35:22 -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=sYn+xsQ9sxV1T3465y/vTvWA+KVAD2RsjHGbcqZCyBY=;
 b=bFgt3lXKvfWuQwZ46SsXokkY6WoNSuUBlmZ3t9pU91vNoMNwaMWr9ffFKhbyGCFZg3
 6nyPyXUBwpMEB+7mMdQ5tcVS3ndM9NPtAlfR6y1je7Nchxq8wYsQvasx5olOD+H2itwv
 hx+LnFHJ6Nyd/nwQtgbpd/UT+7jujfrl1JCR14VByBAdcwvgfqBmNhDkY942V11RgDYS
 3uckSCjsTPHD9PXj4ah9zhglR1v0w5ZGpsP3lV/2VUPjTkcaurrLGdkDklIqQnkMuXcg
 BIwA/WWVqsFpQUxllsAf9NuvBR36W48u5y6K5bTitfShMTE7aYjnZPunG2PTHtD8c+ts
 3lQQ==
X-Received: by 10.51.16.35 with SMTP id ft3mr10308172igd.46.1383539722346;
 Sun, 03 Nov 2013 20:35:22 -0800 (PST)
Received: from raichu (24-212-218-13.cable.teksavvy.com. [24.212.218.13])
 by mx.google.com with ESMTPSA id ft2sm20271501igb.5.2013.11.03.20.35.21
 for <multiple recipients>
 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
 Sun, 03 Nov 2013 20:35:21 -0800 (PST)
Sender: Mark Johnston <markjdb@gmail.com>
Date: Sun, 3 Nov 2013 23:35:19 -0500
From: Mark Johnston <markj@freebsd.org>
To: John Luk <john.37@gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
Message-ID: <20131104043519.GB8007@raichu>
References: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
 <20131103235936.GB15661@raichu>
 <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Nov 2013 04:35:23 -0000

On Mon, Nov 04, 2013 at 12:11:55PM +0800, John Luk wrote:
> 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?

Sorry, I missed that you were on 9.1. The patch you pasted had a mistake
in it; can you instead try applying the patch here:

http://people.freebsd.org/~markj/patches/libproc_sym_lookup-9.1.diff

I created it against the 9.1 tree, so it should apply cleanly. I built and
installed the patched 9.1 libproc on a machine running head, and got the
expected behaviour:

    mark@raichu: ~/src/dtrace/ufunc $ sudo dtrace -s ufunc.d -c ./test test
    dtrace: script 'ufunc.d' matched 9 probes
    dtrace: pid 11555 has exited

      __do_global_dtors_aux                                             1
      foo                                                               1
      foo1                                                              1
      inet_makeaddr                                                     1
      main                                                              1

    mark@raichu: ~/src/dtrace/ufunc $

I don't think that this will be the final patch; checking for ET_EXEC to
determine whether to add a relocation offset seems a bit dubious; I'm
pretty sure it won't work for position-independent executables.

Thanks,
-Mark

> 
> [...]
>

From owner-freebsd-dtrace@FreeBSD.ORG  Mon Nov  4 08:56:45 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 18502E22;
 Mon,  4 Nov 2013 08:56:45 +0000 (UTC)
 (envelope-from john.37@gmail.com)
Received: from mail-oa0-x234.google.com (mail-oa0-x234.google.com
 [IPv6:2607:f8b0:4003:c02::234])
 (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id CAF05256A;
 Mon,  4 Nov 2013 08:56:44 +0000 (UTC)
Received: by mail-oa0-f52.google.com with SMTP id j1so6745773oag.25
 for <multiple recipients>; Mon, 04 Nov 2013 00:56:43 -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
 :content-type; bh=VtknrrksCNaFip/BKlAlzg6g3UWuECo3AylTsxhMyKU=;
 b=KgGv4M74S8UpEYQczasFDJ/nIjH5cxUEXaNzh4R0WZ5+vBVIbfLs2p5sPEUdEGmSHo
 VHB9z6Uj2gZK7Iaj8XI0fN9qFnD2s30B+dlRTySK3LMQTxK2KfByOZcGHTunygGbcrzy
 ItRhhqegmCRv+ZBkdjBcsRb5k0dYwa/G0VaBxyBUaHO+39nF3yBMrYTH4lzTek9aDRCN
 w8PO/qTPtbFG0HbwpoiC6VLC8ypAOL7a/4mzNBurcDY5AfhoCHr/qmm2AqWhYvvp0tKm
 QYrkBIwbrKg0Q4o+nX6VsXN9dclqJ3aVFgpK8qjnM4/ua222MFSfWignLGvHyIz+OKYV
 wpmg==
MIME-Version: 1.0
X-Received: by 10.182.129.201 with SMTP id ny9mr13537142obb.0.1383555403684;
 Mon, 04 Nov 2013 00:56:43 -0800 (PST)
Received: by 10.60.35.74 with HTTP; Mon, 4 Nov 2013 00:56:43 -0800 (PST)
In-Reply-To: <CAHkCX6h312PJvukGo_MNowNpENDLT=hvmXymZRsDFW+tzYNPug@mail.gmail.com>
References: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
 <20131103235936.GB15661@raichu>
 <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
 <20131104043519.GB8007@raichu>
 <CAHkCX6h312PJvukGo_MNowNpENDLT=hvmXymZRsDFW+tzYNPug@mail.gmail.com>
Date: Mon, 4 Nov 2013 16:56:43 +0800
Message-ID: <CAHkCX6iT2MKMRwQDQrWLLjMXx9kiiYneT4J_qirxn1EwshmGng@mail.gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
From: John Luk <john.37@gmail.com>
To: Mark Johnston <markj@freebsd.org>, freebsd-dtrace@freebsd.org
Content-Type: text/plain; charset=UTF-8
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Nov 2013 08:56:45 -0000

EDIT:Apologies for miss-sent mail.

Great! Seems that we're on the right way, I got the output below:

# dtrace -s ufunc.d -c ./a.out a.out
dtrace: script 'ufunc.d' matched 5 probes
^C

  foo                                                               1
  foo1                                                              1
  main                                                              1

through the inet_makeaddr was missing. I applied the patch with:

patch < libproc_sym_lookup-9.1.diff

Thanks again for your patch, Mark :)


Cheers,
spin6lock

2013/11/4 John Luk <john.37@gmail.com>:
> Great! Seems that we're on the right way, I got the output below:
>
> # dtrace -s ufunc.d -c ./a.out a.out
> dtrace: script 'ufunc.d' matched 5 probes
> ^C
>
>   foo                                                               1
>   foo1                                                              1
>   main                                                              1
>
> through the inet_makeaddr was missing. I applied the patch with:
>
> patch < libproc_sym_lookup-9.1.diff
>
> Thanks again for your patch, Mark :)
>
> Cheers,
> spin6lock
>
>
> 2013/11/4 Mark Johnston <markj@freebsd.org>:
>> On Mon, Nov 04, 2013 at 12:11:55PM +0800, John Luk wrote:
>>> 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?
>>
>> Sorry, I missed that you were on 9.1. The patch you pasted had a mistake
>> in it; can you instead try applying the patch here:
>>
>> http://people.freebsd.org/~markj/patches/libproc_sym_lookup-9.1.diff
>>
>> I created it against the 9.1 tree, so it should apply cleanly. I built and
>> installed the patched 9.1 libproc on a machine running head, and got the
>> expected behaviour:
>>
>>     mark@raichu: ~/src/dtrace/ufunc $ sudo dtrace -s ufunc.d -c ./test test
>>     dtrace: script 'ufunc.d' matched 9 probes
>>     dtrace: pid 11555 has exited
>>
>>       __do_global_dtors_aux                                             1
>>       foo                                                               1
>>       foo1                                                              1
>>       inet_makeaddr                                                     1
>>       main                                                              1
>>
>>     mark@raichu: ~/src/dtrace/ufunc $
>>
>> I don't think that this will be the final patch; checking for ET_EXEC to
>> determine whether to add a relocation offset seems a bit dubious; I'm
>> pretty sure it won't work for position-independent executables.
>>
>> Thanks,
>> -Mark
>>
>>>
>>> [...]
>>>

From owner-freebsd-dtrace@FreeBSD.ORG  Mon Nov  4 14:11:08 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 C8CCDBF4
 for <freebsd-dtrace@freebsd.org>; Mon,  4 Nov 2013 14:11:08 +0000 (UTC)
 (envelope-from markjdb@gmail.com)
Received: from mail-ie0-x235.google.com (mail-ie0-x235.google.com
 [IPv6:2607:f8b0:4001:c03::235])
 (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id 95AA127C3
 for <freebsd-dtrace@freebsd.org>; Mon,  4 Nov 2013 14:11:08 +0000 (UTC)
Received: by mail-ie0-f181.google.com with SMTP id ar20so12580943iec.12
 for <freebsd-dtrace@freebsd.org>; Mon, 04 Nov 2013 06:11:08 -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=q54fIYaTP4OeyntxEcgA04YZSrB4m79/SGXCNItKnvE=;
 b=e28M6JoPuUtpHmkDy4mo+cAcGN20Gv92ERZNp4xsO9YqLDdcEr5br85WnmkzofMV2c
 Fe/OCRXP1icmlhyoTvmyyceFVBnhZxytaKkMEOBEJYNQ4uqSD1Y4kMGoht0BK1MMoC9N
 qP6XMjnYVe41tTt5uTAz64k49oSPf8cdRRKNGqo0ztdxsIkWrAoEq0Zp3/q9zYpecQIt
 bX03Xy4u6/4aBL39nJUaNMCMLK6GQAMoh+T9gdBICgdhqiW5S4854pYxM1TWt9HcX6TW
 meX34k+im4EYha/LJllcIv4NLRms5sGKcXs4dCQGOFe0DWRcKtU2/yuTIzBlAiJjdfWR
 Pbvw==
X-Received: by 10.42.46.80 with SMTP id j16mr24775icf.94.1383574267743;
 Mon, 04 Nov 2013 06:11:07 -0800 (PST)
Received: from raichu (24-212-218-13.cable.teksavvy.com. [24.212.218.13])
 by mx.google.com with ESMTPSA id ka1sm2124671igb.7.2013.11.04.06.11.06
 for <multiple recipients>
 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
 Mon, 04 Nov 2013 06:11:07 -0800 (PST)
Sender: Mark Johnston <markjdb@gmail.com>
Date: Mon, 4 Nov 2013 09:11:05 -0500
From: Mark Johnston <markj@freebsd.org>
To: John Luk <john.37@gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
Message-ID: <20131104141105.GE8007@raichu>
References: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
 <20131103235936.GB15661@raichu>
 <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
 <20131104043519.GB8007@raichu>
 <CAHkCX6h312PJvukGo_MNowNpENDLT=hvmXymZRsDFW+tzYNPug@mail.gmail.com>
 <CAHkCX6iT2MKMRwQDQrWLLjMXx9kiiYneT4J_qirxn1EwshmGng@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAHkCX6iT2MKMRwQDQrWLLjMXx9kiiYneT4J_qirxn1EwshmGng@mail.gmail.com>
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Mon, 04 Nov 2013 14:11:08 -0000

On Mon, Nov 04, 2013 at 04:56:43PM +0800, John Luk wrote:
> EDIT:Apologies for miss-sent mail.
> 
> Great! Seems that we're on the right way, I got the output below:
> 
> # dtrace -s ufunc.d -c ./a.out a.out
> dtrace: script 'ufunc.d' matched 5 probes
> ^C
> 
>   foo                                                               1
>   foo1                                                              1
>   main                                                              1
> 
> through the inet_makeaddr was missing. I applied the patch with:

It could be that your compiler is inlining it. Can you run the following
commands and paste the output?

# gdb ./a.out
(gdb) disas main

Thanks
-Mark

> 
> patch < libproc_sym_lookup-9.1.diff
> 
> Thanks again for your patch, Mark :)
> 
> 
> Cheers,
> spin6lock
> 
> 2013/11/4 John Luk <john.37@gmail.com>:
> > Great! Seems that we're on the right way, I got the output below:
> >
> > # dtrace -s ufunc.d -c ./a.out a.out
> > dtrace: script 'ufunc.d' matched 5 probes
> > ^C
> >
> >   foo                                                               1
> >   foo1                                                              1
> >   main                                                              1
> >
> > through the inet_makeaddr was missing. I applied the patch with:
> >
> > patch < libproc_sym_lookup-9.1.diff
> >
> > Thanks again for your patch, Mark :)
> >
> > Cheers,
> > spin6lock
> >
> >
> > 2013/11/4 Mark Johnston <markj@freebsd.org>:
> >> On Mon, Nov 04, 2013 at 12:11:55PM +0800, John Luk wrote:
> >>> 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?
> >>
> >> Sorry, I missed that you were on 9.1. The patch you pasted had a mistake
> >> in it; can you instead try applying the patch here:
> >>
> >> http://people.freebsd.org/~markj/patches/libproc_sym_lookup-9.1.diff
> >>
> >> I created it against the 9.1 tree, so it should apply cleanly. I built and
> >> installed the patched 9.1 libproc on a machine running head, and got the
> >> expected behaviour:
> >>
> >>     mark@raichu: ~/src/dtrace/ufunc $ sudo dtrace -s ufunc.d -c ./test test
> >>     dtrace: script 'ufunc.d' matched 9 probes
> >>     dtrace: pid 11555 has exited
> >>
> >>       __do_global_dtors_aux                                             1
> >>       foo                                                               1
> >>       foo1                                                              1
> >>       inet_makeaddr                                                     1
> >>       main                                                              1
> >>
> >>     mark@raichu: ~/src/dtrace/ufunc $
> >>
> >> I don't think that this will be the final patch; checking for ET_EXEC to
> >> determine whether to add a relocation offset seems a bit dubious; I'm
> >> pretty sure it won't work for position-independent executables.
> >>
> >> Thanks,
> >> -Mark
> >>
> >>>
> >>> [...]
> >>>

From owner-freebsd-dtrace@FreeBSD.ORG  Tue Nov  5 06:47:59 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 4D5BA634;
 Tue,  5 Nov 2013 06:47:59 +0000 (UTC)
 (envelope-from john.37@gmail.com)
Received: from mail-oa0-x22f.google.com (mail-oa0-x22f.google.com
 [IPv6:2607:f8b0:4003:c02::22f])
 (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id 0BCDA2F8D;
 Tue,  5 Nov 2013 06:47:58 +0000 (UTC)
Received: by mail-oa0-f47.google.com with SMTP id k1so151937oag.6
 for <multiple recipients>; Mon, 04 Nov 2013 22:47:58 -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=+bXj5iOEKaiOJollZtbRG2xUVJ5rcEGSMdD3MZ6ba7c=;
 b=zNkZ+uDwLlv38Q/z2DjYDPW00wKgL/1r1zDUkUBAZaAfZCG5D72H1rhnlHn9UjbOmg
 x65Fkfws7i3jqiIUxU8AXqKCDbqDrA9Zja9SmgJnmLlbPW9YJMWnT6l6CUUdppmpEg76
 5iSxJcV3tJfe16KmYG1wIBRjOJQepjKtcVbQCxP9/NCamwbTQZEJb7xZK6SmzN1Z7qkQ
 Grbd2LediMc5RZXE9dNhW+9zR5ilMJstCKkjg73tVejVRgL6ENCORUqR1Mwm340sbHGc
 q63Kc7TWsU4U0YhzijA0af+vCHl8jCEUJtm/MnqN5l49AWrUB7+IXE+8tcZjFEWjFXX0
 vRzA==
MIME-Version: 1.0
X-Received: by 10.60.145.207 with SMTP id sw15mr8634745oeb.38.1383634078375;
 Mon, 04 Nov 2013 22:47:58 -0800 (PST)
Received: by 10.60.35.74 with HTTP; Mon, 4 Nov 2013 22:47:58 -0800 (PST)
In-Reply-To: <20131104141105.GE8007@raichu>
References: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
 <20131103235936.GB15661@raichu>
 <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
 <20131104043519.GB8007@raichu>
 <CAHkCX6h312PJvukGo_MNowNpENDLT=hvmXymZRsDFW+tzYNPug@mail.gmail.com>
 <CAHkCX6iT2MKMRwQDQrWLLjMXx9kiiYneT4J_qirxn1EwshmGng@mail.gmail.com>
 <20131104141105.GE8007@raichu>
Date: Tue, 5 Nov 2013 14:47:58 +0800
Message-ID: <CAHkCX6hyHfzBaHqYg0=wONphkGdDL7x-ErC5s60wK_aiczR3rA@mail.gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
From: John Luk <john.37@gmail.com>
To: Mark Johnston <markj@freebsd.org>
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 05 Nov 2013 06:47:59 -0000

Hi, Mark. The gdb output is included below. I'm wondering why dtrace -l can
trace all my function correctly but the D script failed. Is it because they get
the symbol table in different way?

Cheers,
spin6lock

root@xiangling:/usr/home/spin6lock # cd test
root@xiangling:/usr/home/spin6lock/test # gdb ./a.out
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) disas main
Dump of assembler code for function main:
0x0000000000400610 <main+0>: push   %rbp
0x0000000000400611 <main+1>: mov    %rsp,%rbp
0x0000000000400614 <main+4>: sub    $0x10,%rsp
0x0000000000400618 <main+8>: mov    0x200361(%rip),%rdi        # 0x600980 <s1>
0x000000000040061f <main+15>: mov    0x200362(%rip),%rsi        #
0x600988 <s1+8>
0x0000000000400626 <main+22>: callq  0x4005c0 <foo>
0x000000000040062b <main+27>: mov    $0x7d6,%edi
0x0000000000400630 <main+32>: callq  0x400600 <inet_makeaddr>
0x0000000000400635 <main+37>: movl   $0x186a0,-0x4(%rbp)
0x000000000040063c <main+44>: jmp    0x400642 <main+50>
0x000000000040063e <main+46>: subl   $0x1,-0x4(%rbp)
0x0000000000400642 <main+50>: cmpl   $0x0,-0x4(%rbp)
0x0000000000400646 <main+54>: jg     0x40063e <main+46>
0x0000000000400648 <main+56>: mov    $0x0,%eax
0x000000000040064d <main+61>: leaveq
0x000000000040064e <main+62>: retq
End of assembler dump.

2013/11/4 Mark Johnston <markj@freebsd.org>:
> On Mon, Nov 04, 2013 at 04:56:43PM +0800, John Luk wrote:
>> EDIT:Apologies for miss-sent mail.
>>
>> Great! Seems that we're on the right way, I got the output below:
>>
>> # dtrace -s ufunc.d -c ./a.out a.out
>> dtrace: script 'ufunc.d' matched 5 probes
>> ^C
>>
>>   foo                                                               1
>>   foo1                                                              1
>>   main                                                              1
>>
>> through the inet_makeaddr was missing. I applied the patch with:
>
> It could be that your compiler is inlining it. Can you run the following
> commands and paste the output?
>
> # gdb ./a.out
> (gdb) disas main
>
> Thanks
> -Mark
>
>>
>> patch < libproc_sym_lookup-9.1.diff
>>
>> Thanks again for your patch, Mark :)
>>
>>
>> Cheers,
>> spin6lock
>>
>> 2013/11/4 John Luk <john.37@gmail.com>:
>> > Great! Seems that we're on the right way, I got the output below:
>> >
>> > # dtrace -s ufunc.d -c ./a.out a.out
>> > dtrace: script 'ufunc.d' matched 5 probes
>> > ^C
>> >
>> >   foo                                                               1
>> >   foo1                                                              1
>> >   main                                                              1
>> >
>> > through the inet_makeaddr was missing. I applied the patch with:
>> >
>> > patch < libproc_sym_lookup-9.1.diff
>> >
>> > Thanks again for your patch, Mark :)
>> >
>> > Cheers,
>> > spin6lock
>> >
>> >
>> > 2013/11/4 Mark Johnston <markj@freebsd.org>:
>> >> On Mon, Nov 04, 2013 at 12:11:55PM +0800, John Luk wrote:
>> >>> 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?
>> >>
>> >> Sorry, I missed that you were on 9.1. The patch you pasted had a mistake
>> >> in it; can you instead try applying the patch here:
>> >>
>> >> http://people.freebsd.org/~markj/patches/libproc_sym_lookup-9.1.diff
>> >>
>> >> I created it against the 9.1 tree, so it should apply cleanly. I built and
>> >> installed the patched 9.1 libproc on a machine running head, and got the
>> >> expected behaviour:
>> >>
>> >>     mark@raichu: ~/src/dtrace/ufunc $ sudo dtrace -s ufunc.d -c ./test test
>> >>     dtrace: script 'ufunc.d' matched 9 probes
>> >>     dtrace: pid 11555 has exited
>> >>
>> >>       __do_global_dtors_aux                                             1
>> >>       foo                                                               1
>> >>       foo1                                                              1
>> >>       inet_makeaddr                                                     1
>> >>       main                                                              1
>> >>
>> >>     mark@raichu: ~/src/dtrace/ufunc $
>> >>
>> >> I don't think that this will be the final patch; checking for ET_EXEC to
>> >> determine whether to add a relocation offset seems a bit dubious; I'm
>> >> pretty sure it won't work for position-independent executables.
>> >>
>> >> Thanks,
>> >> -Mark
>> >>
>> >>>
>> >>> [...]
>> >>>

From owner-freebsd-dtrace@FreeBSD.ORG  Tue Nov  5 10:01:52 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
Delivered-To: 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 0CC5363A;
 Tue,  5 Nov 2013 10:01:52 +0000 (UTC) (envelope-from avg@FreeBSD.org)
Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140])
 by mx1.freebsd.org (Postfix) with ESMTP id EEFF52A6F;
 Tue,  5 Nov 2013 10:01:50 +0000 (UTC)
Received: from porto.starpoint.kiev.ua (porto-e.starpoint.kiev.ua
 [212.40.38.100])
 by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id MAA01767;
 Tue, 05 Nov 2013 12:01:49 +0200 (EET) (envelope-from avg@FreeBSD.org)
Received: from localhost ([127.0.0.1])
 by porto.starpoint.kiev.ua with esmtp (Exim 4.34 (FreeBSD))
 id 1VddSG-000ATG-PH; Tue, 05 Nov 2013 12:01:48 +0200
Message-ID: <5278C1D4.1000601@FreeBSD.org>
Date: Tue, 05 Nov 2013 12:00:52 +0200
From: Andriy Gapon <avg@FreeBSD.org>
User-Agent: Mozilla/5.0 (X11; FreeBSD amd64;
 rv:24.0) Gecko/20100101 Thunderbird/24.1.0
MIME-Version: 1.0
To: Mark Johnston <markj@FreeBSD.org>
Subject: Re: sdt "sname" removal
References: <5270246B.6070105@FreeBSD.org> <20131031033636.GC9355@raichu>
 <5271FD6B.1040807@FreeBSD.org>
In-Reply-To: <5271FD6B.1040807@FreeBSD.org>
X-Enigmail-Version: 1.6
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Cc: freebsd-hackers@FreeBSD.org, 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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 05 Nov 2013 10:01:52 -0000

on 31/10/2013 08:49 Andriy Gapon said the following:
> on 31/10/2013 05:36 Mark Johnston said the following:
>> On Tue, Oct 29, 2013 at 11:11:07PM +0200, Andriy Gapon wrote:
>>>
>>> I never understood why FreeBSD SDT as opposed to upstream SDT requires the same
>>> or almost the same probe name to be specified twice.  This seems to be silly and
>>> a little bit error-prone.
>>> In other words, I do not see any reason not to re-use the original upstream
>>> trick where double underscore in a providers name in the C code gets converted
>>> to a single dash in a DTrace provider name. [*]
>>>
>>> So here is my take at that:
>>> http://people.freebsd.org/~avg/sdt-sname-removal.diff
>>>
>>> An inline preview of the change:
>>> -SDT_PROBE_DEFINE1(priv, kernel, priv_check, priv_ok, priv-ok, "int");
>>> -SDT_PROBE_DEFINE1(priv, kernel, priv_check, priv_err, priv-err, "int");
>>> +SDT_PROBE_DEFINE1(priv, kernel, priv_check, priv__ok, "int");
>>> +SDT_PROBE_DEFINE1(priv, kernel, priv_check, priv__err, "int");
>>>
>>> It's possible that I missed some places where old style SDT_PROBE_DEFINE macros
>>> are used or where an old probe name is used with SDT_PROBE_ARGTYPE or SDT_PROBE.
>>
>> A good way to test this is to compare the output of 'dtrace -lv' with and
>> without your change. If nothing changes, I'd be pretty confident that
>> the diff is correct.
> 
> Provided that my kernel has all of the SDT probes :-)
> 
>>>
>>> Please test, review, comment, etc.
>>
>> I don't think this diff will apply cleanly to head - I've made some changes
>> that will cause conflicts, and the diff doesn't touch netinet/in_kdtrace.c
>> or kern/subr_devstat.c.
> 
> Oh, yes, my head is from ~ 2 month ago.  Need to update ASAP and will rebase the
> change then.
> 
>> Could you also update the SDT(9) man page? Also
>> the "strlcpy(name, ..." immediately before the loop you added to sdt.c
>> becomes redundant.
> 
> Good points.  Will fix.

I have rebased my changes and addressed your comments.
The updated patch is in the same place:
http://people.freebsd.org/~avg/sdt-sname-removal.diff

I am also merging the other thread into this one, so here is an update patch for
DTRACE_PROBE* macros:
http://people.freebsd.org/~avg/dtrace-probe-macros.diff

The most notable change is that the argument types are now recorded.

Thank you for reviewing and your suggestions!
-- 
Andriy Gapon

From owner-freebsd-dtrace@FreeBSD.ORG  Wed Nov  6 02:45:56 2013
Return-Path: <owner-freebsd-dtrace@FreeBSD.ORG>
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 B30E954A
 for <freebsd-dtrace@freebsd.org>; Wed,  6 Nov 2013 02:45:56 +0000 (UTC)
 (envelope-from markjdb@gmail.com)
Received: from mail-ie0-x230.google.com (mail-ie0-x230.google.com
 [IPv6:2607:f8b0:4001:c03::230])
 (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
 (No client certificate requested)
 by mx1.freebsd.org (Postfix) with ESMTPS id 7F3942841
 for <freebsd-dtrace@freebsd.org>; Wed,  6 Nov 2013 02:45:56 +0000 (UTC)
Received: by mail-ie0-f176.google.com with SMTP id u16so15904089iet.7
 for <freebsd-dtrace@freebsd.org>; Tue, 05 Nov 2013 18:45:55 -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=jkIJmEaHRr2VJ/7CYNmQqthHy4q365Gwi7/kaFlmvA0=;
 b=XHOSZBkNNWcTmnl0XWsVQEanDqE+zamjv4vwO/7OOpiEq0m0Wi+EDUZN6WnlrvuN+8
 6SaMsC7TbD6Z83xTUQHtnr0V/66ZHAUBTAJcTeqJW/2lJNokPrWgwEbF3Ll9iNVvmYHc
 8jx9IGlbzpg4KZCCcnWmQBWuau5+6KS8i5LXXz6mqImazHnmvRPJPctvXbzoScuNGwOX
 ANDuAfiJtqp/IiWPSZobMOBQYdBXOyMTE10n+0jGc1Y+CkD/A6DcwN329QB5SXE/NHo5
 iZs4UKMQXtKZgJ2HD5AqXn6c7uhKMMXdCofBkwmSIAdqqydJX41RGOB9DGjt07z9QulK
 Afkw==
X-Received: by 10.50.47.101 with SMTP id c5mr629146ign.32.1383705955758;
 Tue, 05 Nov 2013 18:45:55 -0800 (PST)
Received: from raichu (24-212-218-13.cable.teksavvy.com. [24.212.218.13])
 by mx.google.com with ESMTPSA id qi3sm11750428igc.8.2013.11.05.18.45.54
 for <multiple recipients>
 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
 Tue, 05 Nov 2013 18:45:54 -0800 (PST)
Sender: Mark Johnston <markjdb@gmail.com>
Date: Tue, 5 Nov 2013 21:45:49 -0500
From: Mark Johnston <markj@freebsd.org>
To: John Luk <john.37@gmail.com>
Subject: Re: dtrace showed matched probes but nothing in output on FreeBSD
 9.1-RELEASE
Message-ID: <20131106024549.GA2826@raichu>
References: <CAHkCX6j1H4cxeb255gdH_cLop5Lv0xJABbuma+835gNNq-Nshg@mail.gmail.com>
 <20131103235936.GB15661@raichu>
 <CAHkCX6g1jUirMDP4T7W+rP6P8JV5wF-Wsa984op_HP1WftSitA@mail.gmail.com>
 <20131104043519.GB8007@raichu>
 <CAHkCX6h312PJvukGo_MNowNpENDLT=hvmXymZRsDFW+tzYNPug@mail.gmail.com>
 <CAHkCX6iT2MKMRwQDQrWLLjMXx9kiiYneT4J_qirxn1EwshmGng@mail.gmail.com>
 <20131104141105.GE8007@raichu>
 <CAHkCX6hyHfzBaHqYg0=wONphkGdDL7x-ErC5s60wK_aiczR3rA@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAHkCX6hyHfzBaHqYg0=wONphkGdDL7x-ErC5s60wK_aiczR3rA@mail.gmail.com>
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."
 <freebsd-dtrace.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-dtrace>, 
 <mailto:freebsd-dtrace-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-dtrace>
List-Post: <mailto:freebsd-dtrace@freebsd.org>
List-Help: <mailto:freebsd-dtrace-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace>,
 <mailto:freebsd-dtrace-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Wed, 06 Nov 2013 02:45:56 -0000

On Tue, Nov 05, 2013 at 02:47:58PM +0800, John Luk wrote:
> Hi, Mark. The gdb output is included below. I'm wondering why dtrace -l can
> trace all my function correctly but the D script failed. Is it because they get
> the symbol table in different way?

Hm, I can't reproduce the problem using your binary on a machine running
head. I suspect the problem has to do with some other DTrace bugs in the
kernel which have been recently fixed - there were a couple that would
corrupt the state of traced programs in various ways, and it could be
that inet_makeaddr() really isn't getting called as a result. You could
try adding a printf or something to see if that's the case.

In general there have been quite a few DTrace fixes since 9.1, so it's
worth trying out newer revisions if you're interested in trying out
DTrace on FreeBSD.

-Mark