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;
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace
To unsubscribe, send any mail to "[email protected]"

Reply via email to