Thank you for your response Adam!

The example you provided worked with BEGIN, but failed to work on any other probes. For example:

$ sudo dtrace -l | grep sys_read
32272        fbt            kernel                          sys_read entry

This is the read syscall on FreeBSD, but any example would likely function the same way.

$ sudo dtrace -s foo.d '"fbt:kernel:sys_read:entry"'
dtrace: failed to compile script foo.d: line 1: probe description :::"fbt:kernel:sys_read:entry" does not match any probes
$ sudo dtrace -s foo.d "'fbt:kernel:sys_read:entry'"
dtrace: failed to compile script foo.d: line 1: probe description :::'fbt:kernel:sys_read:entry' does not match any probes

It seems to be adding the ::: string. I am not certain how to resolve this issue.

On 11/12/2017 09:40 PM, Adam Leventhal wrote:
Hey Farhan,

You can't use variables (e.g. self->func) as a probespec (the string that specifies the set of probes to enable), but you can use command-line arguments. The mistake you're making in the second example is using $$1 (which quotes the first command-line argument); you want to use $1. For example:

---8<---
# cat foo.d
$1
{
trace("hi");
}
# dtrace -s foo.d BEGIN
dtrace: script 'foo.d' matched 1 probe
CPU     ID                    FUNCTION:NAME
   0      1                           :BEGIN   hi
^C
---8<---

Hopefully that helps.


A couple of notes:

Here's an example that demonstrates where you'd use $$1:
dtrace -n 'BEGIN{ trace($$1) }' foo

If you use just "$1" you'll see an error like this:
dtrace: invalid probe specifier BEGIN{ trace($1) }: in action list: failed to resolve foo: Unknown variable name


You'll never put the $ before D variables; $variable is exclusively for macros--replaced before the D language parser executes.

Adam


On Sun, Nov 12, 2017 at 12:19 AM, Farhan Khan <kha...@gmail.com <mailto:kha...@gmail.com>> wrote:

    Hi all,

    I am trying to write a generic Dtrace script that will read the
    probe function from the console, but can't figure out the syntax. I
    am doing this:

    # ./myscript.d "variable"

I must use the quotes, otherwise it complains that "variable" was
not found. I want to do:

dtrace:::BEGIN { self->func=$1; }

And then:

fbt::$self->func:entry { ... }

However, $self->func does not seem to work. If I use $$1, it tells
me that the function fbt::"variable":entry does not exist, because
the quotes are present. When I remove the quotes from the command
line, it gives me that initial error.

How do I read in a probefunc name from the console?

Thanks,

Farhan



-------------------------------------------
dtrace-discuss
Archives: https://www.listbox.com/member/archive/184261/=now
RSS Feed: https://www.listbox.com/member/archive/rss/184261/25769126-e243886f
Modify Your Subscription: 
https://www.listbox.com/member/?member_id=25769126&id_secret=25769126-8d47a7b2
Powered by Listbox: http://www.listbox.com

Reply via email to