Yossi Lev
2010-May-04 15:23 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
Hi I''m running a simple DTrace script that has the following clause: pid$target::ReportTx:entry /arg1 != 0 && this->numEntries != 0/ { printf("NumEntries: %lld\n", (long long)this->numEntries); this->entry = (ReadAcqEntry*)copyin((uintptr_t)&(this->rAcqArr[this->numEntries-1]), sizeof(ReadAcqEntry)); this->pcInt = (uintptr_t)(this->entry->pc); this->instr = stringof(this->pcInt); /* @AcqTotals[this->instr] = sum(this->entry->acqNum);*/ this->numEntries--; } And I''m getting an invalid address error for the instruction that uses the stringof operation. (If I comment it out, the error goes away.): dtrace: error on enabled probe ID 10 (ID 46110: pid25521:libSkySTMLib-STM-lazy-priv_STATS-m64-TxDbg.so:ReportTx:entry): invalid address (0x100004000) in action #4 at DIF offset 4 Please note that this->entry->pc is of type void*, but I converted it to uintptr_t just in case. The DTrace manual says "Any expression that is a scalar type such as a pointer or integer or a scalar array address may be converted to string.", so I expected it to work. Any idea what am I doing wrong? Thanks, Yossi -- This message posted from opensolaris.org
Chad Mynhier
2010-May-04 15:38 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
On Tue, May 4, 2010 at 11:23 AM, Yossi Lev <yosef.lev at sun.com> wrote:> Hi > > I''m running a simple DTrace script that has the following clause: > > pid$target::ReportTx:entry > /arg1 != 0 && this->numEntries != 0/ > { > ?printf("NumEntries: %lld\n", (long long)this->numEntries); > ?this->entry = (ReadAcqEntry*)copyin((uintptr_t)&(this->rAcqArr[this->numEntries-1]), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sizeof(ReadAcqEntry)); > > ?this->pcInt = (uintptr_t)(this->entry->pc); > ?this->instr = stringof(this->pcInt); > /* ?@AcqTotals[this->instr] = sum(this->entry->acqNum);*/ > > ?this->numEntries--; > } >What is this->rAcqArr in the code above? Did you mean this to be a thread-local variable instead of a clause-local variable? Is it possible that you''re getting garbage because that array hasn''t persisted from where you initialized it? Chad
Yossi Lev
2010-May-04 16:58 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
Thanks Chad, but I don''t think that this is the problem. The this->rAcqArr points to the beginning of an array in the traced process. I initialize it in a previous clause that has exactly the same probe: pid$target::ReportTx:entry /arg1 != 0 / { this->dataP = (ProfData*)copyin(arg2, sizeof(ProfData)); this->numEntries = this->dataP->numRAcqEntries; this->rAcqArr = this->dataP->racqInfoArr; } So the value of this->rAcqArr should be live until all clauses with the same probe are done executing. Moreover, I know that the value that I''m getting is valid, because I had the following printf statement: pid$target::ReportTx:entry /arg1 != 0 && this->numEntries != 0/ { printf("NumEntries: %lld\n", (long long)this->numEntries); this->entry = (ReadAcqEntry*)copyin((uintptr_t)&(this->rAcqArr[this->numEntries-1]), sizeof(ReadAcqEntry)); this->pcInt = (uintptr_t)(this->entry->pc); /* this->instr = stringof(this->pcInt);*/ printf("%p\t%d\t%d\t%d\n", this->entry->pc, this->entry->acqNum, this->entry->upgradeNum + this->entry->contUpgradeNum, this->entry->contUpgradeNum); this->numEntries--; } and the results look fine. The only problem is when I un-comment the stringof statement. I even tried using this->entry->pc as a key to an aggregation, with no problems. I only encountered the problem when I tried to convert it to a string. So, I can printf this->entry->pc (with %p flag), I can use it as a key to an aggregation, but I cannot convert it to a string --- any idea why? As an aside, I noticed that the invalid address specified in the error message is different that the value of this->entry->pc. Thanks again, Yossi -- This message posted from opensolaris.org
Yossi Lev
2010-May-04 17:29 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
I have some more information, that suggests that something is just wrong with the way I''m using stringof. I tried replacing stringof(this->pcInt) with stringof(5) and still got the error. So, I tried the following one-liner from the shell: dtrace -n ''BEGIN{printf("%s\n",stringof(0x5));}'' dtrace: description ''BEGIN'' matched 1 probe dtrace: error on enabled probe ID 1 (ID 1: dtrace:::BEGIN): invalid address (0x0) in action #1 Note that all the script does is convert 0x5 to a string and print it... any ideas? Thanks, Yossi -- This message posted from opensolaris.org
Chad Mynhier
2010-May-04 17:38 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
On Tue, May 4, 2010 at 12:58 PM, Yossi Lev <yosef.lev at sun.com> wrote:> > Moreover, I know that the value that I''m getting is valid, because I had the following printf statement: > > pid$target::ReportTx:entry > /arg1 != 0 && this->numEntries != 0/ > { > ?printf("NumEntries: %lld\n", (long long)this->numEntries); > ?this->entry = (ReadAcqEntry*)copyin((uintptr_t)&(this->rAcqArr[this->numEntries-1]), > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?sizeof(ReadAcqEntry)); > > ?this->pcInt = (uintptr_t)(this->entry->pc); > /* ?this->instr = stringof(this->pcInt);*/ > > ?printf("%p\t%d\t%d\t%d\n", > ? ? ? ? this->entry->pc, > ? ? ? ? this->entry->acqNum, > ? ? ? ? this->entry->upgradeNum + this->entry->contUpgradeNum, > ? ? ? ? this->entry->contUpgradeNum); > ?this->numEntries--; > } > > and the results look fine. ?The only problem is when I un-comment the stringof statement.So this->entry->ps is a userspace pointer? If that''s the case, then you want copyinstr(), not stringof(). Chad
Yossi Lev
2010-May-04 19:13 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
No, this->entry-pc is not a user-space pointer --- it is not a pointer at all, it is an unsigned integer that I would like to convert to a string. Here is what I''m trying to do: - I have a structure of type ReadAcqEntry at userspace with various numeric fields (unsigned long long type). - I would like to convert a few of these fields to a string (e.g. for the purpose of concatenating it with other strings), and use the numerical value of the others. What I was doing so far is copying the whole structure with: this->entry = (ReadAcqEntry*)copyin((uintptr_t)&(this->rAcqArr[this->numEntries-1]) , sizeof(ReadAcqEntry)); so now this->entry points to the local copy of the structure. Now I can access all of the structure''s fields as integers (I tested this part and it works fine), but I am not sure how I can convert some of the fields to strings. What I really need is the equivalent of sprintf or itoa... It seems like stringof requires a pointer, so I am not sure that this is what I need to use here. Thanks, Yossi -- This message posted from opensolaris.org
Michael Schuster, Oracle
2010-May-05 06:22 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
On 04.05.10 21:13, Yossi Lev wrote:> No, this->entry-pc is not a user-space pointer --- it is not a pointer at all, it is an unsigned integer that I would like to convert to a string. > > Here is what I''m trying to do: > > - I have a structure of type ReadAcqEntry at userspace with various > numeric fields (unsigned long long type). > > - I would like to convert a few of these fields to a string (e.g. for > the purpose of concatenating it with other strings), and use the > numerical value of the others. > > What I was doing so far is copying the whole structure with: > > this->entry = (ReadAcqEntry*)copyin((uintptr_t)&(this->rAcqArr[this->numEntries-1]) , sizeof(ReadAcqEntry)); > > so now this->entry points to the local copy of the structure. Now I can > access all of the structure''s fields as integers (I tested this part and > it works fine), but I am not sure how I can convert some of the fields > to strings. What I really need is the equivalent of sprintf or itoa... > > It seems like stringof requires a pointer, so I am not sure that this is > what I need to use here.no, you don''t, regular printf will work: printf("%d", somenumber); stringof(p) returns string pointer to character array(p) (strings and character arrays are not the same in DTrace), but it does not do the integer->string conversion you''re looking for. I can''t think of a way of doing the exact equivalent of "sprintf(s, "%d", number)" and then continue using ''s'' within your D script. what do you need a string for here that the numbers themselves won''t solve? Michael -- Michael Schuster Oracle Recursion, n.: see ''Recursion''
Yossi Lev
2010-May-05 16:11 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
Hi Michael I just found a function that (sort of) does what I need: it is called lltostr and it takes a long long integer, and returns a string that represents it. (Unfortunately I didn''t find an option to do the translation in hexadecimal, but I can live with that...) As for your question, I need to use the numbers as a key to an aggregation, but I need to concatenate a few of those. In particular, I have a sequence of N numbers where N < 9, and I need to count how many times I''m getting each sequence. The value of N may be different in separate invocations of the probe function, so I would like to use an unrolled loop to concatenate the N numbers to single string representing the sequence, and then use the string as the key to my aggregation. Do you see any other option but to use the lltostr function to and concatenate the resulted strings? Thanks, Yossi -- This message posted from opensolaris.org
Michael Schuster
2010-May-05 16:15 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
On 05.05.10 18:11, Yossi Lev wrote:> Hi Michael > > I just found a function that (sort of) does what I need: it is called lltostr and it takes a long long integer, and returns a string that represents it. (Unfortunately I didn''t find an option to do the translation in hexadecimal, but I can live with that...) > > As for your question, I need to use the numbers as a key to an aggregation, but I need to concatenate a few of those. In particular, I have a sequence of N numbers where N< 9, and I need to count how many times I''m getting each sequence. The value of N may be different in separate invocations of the probe function, so I would like to use an unrolled loop to concatenate the N numbers to single string representing the sequence, and then use the string as the key to my aggregation. > > Do you see any other option but to use the lltostr function to and concatenate the resulted strings?does this answer your question: $ pfexec dtrace -n ''syscall:::entry{@c[execname,pid] = count()}'' dtrace: description ''syscall:::entry'' matched 227 probes look closely at the "[...]" part :-) HTH Michael -- michael.schuster at oracle.com http://blogs.sun.com/recursion Recursion, n.: see ''Recursion''
Nicolas Williams
2010-May-05 16:17 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
On Wed, May 05, 2010 at 09:11:27AM -0700, Yossi Lev wrote:> I just found a function that (sort of) does what I need: it is called > lltostr and it takes a long long integer, and returns a string that > represents it. (Unfortunately I didn''t find an option to do the > translation in hexadecimal, but I can live with that...) > > As for your question, I need to use the numbers as a key to an > aggregation, but I need to concatenate a few of those. In > particular, I have a sequence of N numbers where N < 9, and I need to > count how many times I''m getting each sequence. The value of N may > be different in separate invocations of the probe function, so I > would like to use an unrolled loop to concatenate the N numbers to > single string representing the sequence, and then use the string as > the key to my aggregation. > > Do you see any other option but to use the lltostr function to and > concatenate the resulted strings?Yes: aggregations take multiple keys, not just one, so rather than format a string with all the key content that you need: use a comma- separated list of expressions of various types as the key. See: http://docs.sun.com/app/docs/doc/819-5488/gcggh?a=view Nico --
Yossi Lev
2010-May-05 16:40 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
Thanks, I know that I can provide multiple keys, but the number of keys for an aggregation must be constant, and I didn''t want to pad with zeros all missing keys as in the common case my sequence has 2 or 3 keys (and not the maximum number of 8). These are minor issues that have to do with how the data looks when it is printed at the end --- I''m trying to use DTrace to generate a performance profiling report that the users can read, so do not want to add many trailing zeros to everything. I guess I could store the information on different aggregations depending on the number of keys that I get, but an integer-->string translation results in a much simpler/cleaner script, which is why I posted this message asking whether there is a function that does it. Thanks for all the help! Yossi -- This message posted from opensolaris.org
Michael Schuster
2010-May-05 17:50 UTC
[dtrace-discuss] Invalid address error when using stringof to convert a pointer to a string
On 05.05.10 18:40, Yossi Lev wrote:> Thanks, I know that I can provide multiple keys, but the number of keys > for an aggregation must be constant, and I didn''t want to pad with zeros > all missing keys as in the common case my sequence has 2 or 3 keys (and > not the maximum number of 8). These are minor issues that have to do > with how the data looks when it is printed at the end --- I''m trying to > use DTrace to generate a performance profiling report that the users can > read, so do not want to add many trailing zeros to everything.you may want to consider post-processing with your favourite string manipulation tool for the looks of your output. Michael -- michael.schuster at oracle.com http://blogs.sun.com/recursion Recursion, n.: see ''Recursion''