Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:23:01+00:00 2026-05-25T06:23:01+00:00

I wrote an action that fires when any objc method return (objc:::return). For now,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:23:02+00:00Added an answer on May 25, 2026 at 6:23 am

    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:

    Aside: objc_msgSend()‘s return cannot be traced via dtrace at this time. Not surprising given that the function doesn’t actually return — as far as dtrace is concerned, it is nothing but preamble.

    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:

    NSNumber *n = [NSNumber numberWithInt:1234];
    printf("n has address %p\n", n);
    

    and the following probe:

    objc$target:NSPlaceholderNumber:-initWithInt?:return
    {
        printf("Returning from -[NSPlaceholderNumber initWithInt:]\n");
        printf("\treturn value = 0x%p\n", (void *)arg1);
    }
    

    When run using DTrace, I get the following output:

    n has address 0x4d283
    Returning from -[NSPlaceholderNumber initWithInt:]
        return value = 0x4d283
    

    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() or CFMakeCollectable()) called by -initWithInt: and which ended up placing the expected value in RAX.

    Now consider the following code:

    char *c = "hello";
    NSData *data = [NSData dataWithBytes:c length:strlen(c)];
    NSString *s = [[NSString alloc] initWithData:data
                                        encoding:NSASCIIStringEncoding];
    printf("s has address %p\n", s);
    

    and the following probe:

    objc$target:NSPlaceholderString:-initWithData?encoding?:return
    {
        printf("Returning from -[NSPlaceholderString initWithData:encoding:]\n");
        printf("\treturn value = 0x%p\n", (void *)arg1);
    }
    

    When run using DTrace, I get the following output:

    s has address 0x7fcd92414ea0
    Returning from -[NSPlaceholderString initWithData:encoding:]
        return value = 0x600
    

    As you can see, the addresses (i.e., the return values) don’t match. In fact, 0x600 is the value of kCFStringEncodingASCII which is the Core Foundation counterpart of NSASCIIStringEncoding. 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Pylons controller action that needs to return a file to the
I wrote a macro in VBA that does an action on some of the
I am trying to write a unit test for an action method which calls
I wrote a windows service using VB that read some legacy data from Visual
I wrote myself a little downloading application so that I could easily grab a
I wrote a component that displays a filename, a thumbnail and has a button
I wrote a simple tool to generate a DBUnit XML dataset using queries that
I wrote an application that currently runs against a local instance of MySql. I
I need to solve the following question which i can't get to work by
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.