I wrote an action that fires when any objc method return (objc:::return).
For now, I need to get the return value. Is it possible?
I wrote an action that fires when any objc method return (objc:::return). For now,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In summary: no, you can’t get the return value of an Objective-C method in a DTrace probe.
Bill Bumgarner has a post on tracing messages to nil in which he says the following:
The blog post is rather old (January 2008) and it uses the pid provider, not the objc provider. That said, it is still valid as of Mac OS X v10.7.1 and it also applies to the objc provider.
Amusingly, it might seem that it sometimes works but it depends on when DTrace reads the RAX register. Since
objc_msgSend()doesn’t return, DTrace ends up using values in RAX that have been stored by code that is not necessarily the return of the method being traced.Consider the following code:
and the following probe:
When run using DTrace, I get the following output:
so it seems that the probe was able to capture the return value of
-initWithInt:. That’s only luck though, probably caused by a function (e.g.CFNumberCreate()orCFMakeCollectable()) called by-initWithInt:and which ended up placing the expected value in RAX.Now consider the following code:
and the following probe:
When run using DTrace, I get the following output:
As you can see, the addresses (i.e., the return values) don’t match. In fact, 0x600 is the value of
kCFStringEncodingASCIIwhich is the Core Foundation counterpart ofNSASCIIStringEncoding. At some point either the method or a function called by the method moved 0x600 to RAX and that’s the value that DTrace wrongly considered to be the return value.