dtracing static symbols
Daniel O'Connor
doconnor at gsoft.com.au
Tue Mar 11 05:34:58 UTC 2014
On 11 Mar 2014, at 15:34, Prashanth Kumar <pra_udupi at yahoo.co.in> wrote:
> If the binary being traced has static symbols in its symbol table, DTrace should
> be able to trace the function. Can you describe the example where you found this
> difference in FreeBSD and OSX?
Unfortunately the static symbols don't show up in the symbol table (as shown by nm).
Is there a compile or link flag which will change that?
Here is an example..
[ur 15:43] ~ >cat static.c
#include <stdio.h>
static void
foo(void) {
printf("Foo\n");
}
void
bar(void) {
printf("Boo\n");
}
int
main(int argc, char **argv) {
foo();
bar();
return 0;
}
[ur 15:43] ~ >cc static.c -o static
[ur 15:43] ~ >sudo dtrace -Ppid\$target -l -c ./static|less
On OSX you see..
...
956613 pid46749 static foo return
956614 pid46749 static foo entry
956615 pid46749 static foo 0
956616 pid46749 static foo 1
956617 pid46749 static foo 4
956618 pid46749 static foo 8
956619 pid46749 static foo f
956620 pid46749 static foo 11
956621 pid46749 static foo 16
956622 pid46749 static foo 19
956623 pid46749 static foo 1d
956624 pid46749 static foo 1e
..
(I'm not sure what the various numbers mean)
However on FreeBSD you don't see any thing for the binary itself, only the libraries.
This is true even if you build with..
[mdtest 5:22] ~ >cc static.o -o static
[mdtest 5:22] ~ >ctfconvert -g -L labelenv static.o
[mdtest 5:22] ~ >cc -g static.c -o static.o -c
Curiously you also can't run it with -c, I had to put a usleep() at the start and then use -p. Trying to use -c fails with..
[mdtest 5:25] ~ >sudo dtrace -Ppid\$target -l -c ./static
Foo
Bar
dtrace: failed to control pid 52006: process exited with status 0
FWIW nm on the binary shows both symbols (foo and bar)
[mdtest 5:33] ~ >nm static|egrep '(foo|bar)'
0000000000400700 T bar
00000000004006f0 t foo
Finally, while -c doesn't work on FreeBSD but actually runs the binary, -c on OSX works (but the binary isn't executed - or at least you don't see its output)
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/freebsd-dtrace/attachments/20140311/89c2586c/attachment.sig>
More information about the freebsd-dtrace
mailing list