Hamish
2009-Aug-07 15:43 UTC
[dtrace-discuss] When is a string constant not a string constant?
AKA, what''s wrong with the following? Isn''t a string literal always a constant? $ cat > cfretain_calayer.d pid$target::CFRetain:entry { isaptr = *(uint32_t*)copyin(arg0, 4); classnameptr = *(uint32_t*)copyin(isaptr+8, 4); classname = copyinstr(classnameptr); p = (classname == "CALayer" ? "CFRetain(CALayer)\n" : ""); printf(p); } $ sudo dtrace -p 31303 -s cfretain_calayer.d dtrace: failed to compile script cfretain_calayer.d: line 8: printf( ) argument #1 is incompatible with prototype: prototype: string constant argument: string Also, please let me know if there''s a better way to be doing this (I''m a dtrace newbie). Thanks, Hamish -- This message posted from opensolaris.org
Adam Leventhal
2009-Aug-07 16:01 UTC
[dtrace-discuss] When is a string constant not a string constant?
Hey Hamish,> AKA, what''s wrong with the following? Isn''t a string literal always > a constant? > > $ cat > cfretain_calayer.d > pid$target::CFRetain:entry > { > isaptr = *(uint32_t*)copyin(arg0, 4); > classnameptr = *(uint32_t*)copyin(isaptr+8, 4); > classname = copyinstr(classnameptr); > > p = (classname == "CALayer" ? "CFRetain(CALayer)\n" : ""); > printf(p); > } > > $ sudo dtrace -p 31303 -s cfretain_calayer.d > dtrace: failed to compile script cfretain_calayer.d: line 8: > printf( ) argument #1 is incompatible with prototype: > prototype: string constant > argument: string > > Also, please let me know if there''s a better way to be doing this > (I''m a dtrace newbie).DTrace requires that you provide a constant string so that it can perform type checking on additional arguments (i.e. to ensure that if you specify the %d format option that you have an int to print). You have two pretty easy ways to fix this: printf("%s\n", classname == "CALayer" ? "CFRetain(CALayer)" : ""); or trace(classname == "CALayer" ? "CFRetain(CALayer)" : ""); Note also, that all of your variables should probably be probe-local (prefixed with this->). Further, if you only want trace when classname == "CALayer", rather than printing out an empty string, you could do something like this: pid$target::CFRetain:entry { this->isaptr = *(uint32_t*)copyin(arg0, 4); this->classnameptr = *(uint32_t*)copyin(isaptr+8, 4); this->classname = copyinstr(classnameptr); } pid$target::CFRetain:entry /this->classname == "CALayer"/ { trace("CFRetain(CALayer)"); } Hope that helps. Adam -- Adam Leventhal, Fishworks http://blogs.sun.com/ahl
Joerg Schilling
2009-Aug-07 16:01 UTC
[dtrace-discuss] When is a string constant not a string constant?
Hamish <hamish at gmail.com> wrote:> AKA, what''s wrong with the following? Isn''t a string literal always a constant? > > $ cat > cfretain_calayer.d > pid$target::CFRetain:entry > { > isaptr = *(uint32_t*)copyin(arg0, 4); > classnameptr = *(uint32_t*)copyin(isaptr+8, 4); > classname = copyinstr(classnameptr); > > p = (classname == "CALayer" ? "CFRetain(CALayer)\n" : ""); > printf(p); > } > > $ sudo dtrace -p 31303 -s cfretain_calayer.d > dtrace: failed to compile script cfretain_calayer.d: line 8: printf( ) argument #1 is incompatible with prototype: > prototype: string constant > argument: stringIt is not simple for a compiler to check this as p is definitely not a string constant but only pointing to one. J?rg -- EMail:joerg at schily.isdn.cs.tu-berlin.de (home) J?rg Schilling D-13353 Berlin js at cs.tu-berlin.de (uni) joerg.schilling at fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/ URL: http://cdrecord.berlios.de/private/ ftp://ftp.berlios.de/pub/schily
Hamish
2009-Aug-07 16:30 UTC
[dtrace-discuss] When is a string constant not a string constant?
Brilliant, thank you! -- This message posted from opensolaris.org
Hamish
2009-Aug-07 16:32 UTC
[dtrace-discuss] When is a string constant not a string constant?
I should probably have mentioned that I only introduced the extra variable "p" as a result of getting exactly the same error with the more direct approach: printf(classname == "CALayer" ? "CFRetain(CALayer)\n" : ""); Anyway, thanks again to Adam for providing a clear solution! -- This message posted from opensolaris.org