Discussion:
save and recall more than one value of the same thread
goinsane
2010-10-26 13:32:26 UTC
Permalink
Hi,

I'd like to know if D enables to save and recall values of the same thread in a way like self->... does.

Let's say a thread fires syscall::open:entry two times and gets 2 filedescriptors. How could I save those in syscall::open:return for later reuse?
The use of just 1 variable (e.g.self->fd) only would overwrite the value at the 2nd call. Maybe an associative array would tend to a solution, like self->fd[port] = ... ?
And how could I evaluate them in a predicate of another probe?


thank you,

goinsane
--
This message posted from opensolaris.org
Michael Schuster
2010-10-26 13:38:23 UTC
Permalink
Post by goinsane
Hi,
I'd like to know if D enables to save and recall values of the same thread in a way like self->... does.
Let's say a thread fires syscall::open:entry two times and gets 2 filedescriptors. How could I save those in syscall::open:return for later reuse?
The use of just 1 variable (e.g.self->fd) only would overwrite the value at the 2nd call. Maybe an associative array would tend to a solution, like self->fd[port] = ... ?
And how could I evaluate them in a predicate of another probe?
how about storing what interests you about this fd in self->stuff[self->fd]
(where I assume self->fd is the "current" fd being opened)? would that work
for your app?

Michael
--
michael.schuster-QHcLZuEGTsvQT0dZR+***@public.gmane.org http://blogs.sun.com/recursion
Recursion, n.: see 'Recursion'
goinsane
2010-10-28 07:44:07 UTC
Permalink
yes, it does. thank you!
--
This message posted from opensolaris.org
James Carlson
2010-10-26 13:43:36 UTC
Permalink
Post by goinsane
Hi,
I'd like to know if D enables to save and recall values of the same thread in a way like self->... does.
Let's say a thread fires syscall::open:entry two times and gets 2 filedescriptors. How could I save those in syscall::open:return for later reuse?
The use of just 1 variable (e.g.self->fd) only would overwrite the value at the 2nd call. Maybe an associative array would tend to a solution, like self->fd[port] = ... ?
Yep; that's how you'd do it.

Note that this might not work quite the way you want for multi-threaded
programs that use the same fd in more than one thread. To handle that
case (which is a superset of the case you're looking at), I think you'd
need a global array indexed on pid and fd, because fds are allocated to
a process, not a thread, and D doesn't seem to have a per-process
storage mechanism.
Post by goinsane
And how could I evaluate them in a predicate of another probe?
self->fd[port] -- where "port" needs to be the fd. Depending on the
definition of the probe and the way you write your code, "port" might be
argv0, or it might be self->port, or perhaps something else.
--
James Carlson 42.703N 71.076W <carlsonj-dlRbGz2WjHhmlEb+***@public.gmane.org>
goinsane
2010-10-28 07:47:04 UTC
Permalink
Thank you again for assistance, James. Actually, there was another thread accessing the fd too, so the global array did work for me.
--
This message posted from opensolaris.org
Loading...