dtrace showed matched probes but nothing in output on FreeBSD 9.1-RELEASE
John Luk
john.37 at gmail.com
Mon Nov 4 04:11:56 UTC 2013
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 at 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 at home:/home/spin6lock/test # dtrace -V
>> dtrace: Sun D 1.7
>> root at home:/home/spin6lock/test # uname -a
>> FreeBSD 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Mon Oct 28 20:52:03 CST
>> 2013 root at 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;
More information about the freebsd-dtrace
mailing list