On Sun, Jul 26, 2009 at 3:35 PM, Matt Ingenthron<mingenth...@acm.org> wrote: > Thanks again for the help Chad, > >> > >> > memcached*::command-get >> > / (signed int) arg3 != -1 / >> > { >> > printf("get %s, FOUND KEY\n", >> stringof(copyin(arg1, arg2))); >> > } >> >> It doesn't look like you're copying in a null >> character, which seems >> likely if arg2 == 5 for "setopt". You're doing the >> copyin() the >> second time around to a buffer that's not been >> zeroed, and stringof() >> is just looking for the first null character it finds >> in that buffer. >> It finds it after the original (if longer) string. > > > I guess I'd assumed that the %s would have been treated as a clause local > variable, but it appears that's not the case. From what you're saying, it > appears it's a global which I can't really reference in the way I'd used it? > That's rather confusing... but I can deal with it.
It's actually the copyin() more than the %s that's at play here. The target memory for copyin() is scratch space. Unused space (if any) in the principal buffer is used for scratch space. It's not global, it's per-cpu, but it's not zeroed after use, so you can't make any assumptions about what's there. > > Looking at some other examples of similar situations, it appears the best > thing to do is create a clause local, then call stringof() on it when doing > the printf, then zeroing it out before the next call. Does that sound like > the right approach? If the memory pointed to by arg1 is a null-terminated string, you could just do this: printf("%s\n", copyinstr(arg1)); If not, then something like this should work: this->foo = (char *)alloca(arg2 + 1); copyinto(arg1, arg2, this->foo); this->foo[arg2 + 1] = '\0'; printf("%s\n", stringof(this->foo)); Chad _______________________________________________ dtrace-discuss mailing list dtrace-discuss@opensolaris.org