7

I would really like to see every method, delegate, notification, etc. which is called / sent while I run my app in the iPhone Simulator. I thought the right place for this would be in the debugger, but I can't find the right setting.

My target is to see all that is happening in the background while I, for example, add a row to a UITableView or push the 'back'-button from my UINavigationController.

This would be a big help to figure out what delegate to use when something in the app is happening or when the user is pushing a button, changing a view, etc.

Is it possible to get this information?

3 Answers 3

8

You can log out everything that is happening when your application is running using DTrace, a framework that lets you probe the inner workings of anything running on a modern Mac. We don't yet have DTrace on iOS, but it will work while you're running within the Simulator.

I describe the fundamentals of DTrace in this article for MacResearch, then provide an example of a custom instrument you can build in Instruments using DTrace near the end of this article. That instrument logs out all methods called on all objects (even internal system ones) from the moment your application starts until it hits the end of -applicationDidFinishLaunching:.

To simplify this, you can simply create a custom instrument using the Instrument | Build New Instrument menu item in instruments. Set up one of the probe descriptors to look like the following:

alt text

only ignore the isInApplicationStart and timestamp logging options. A simple probe responding to any Objective-C method in any class will log all of those messages to the Instruments console, which sounds like what you want for your debugging.

1
  • thank you for your answer! i will also try it when i find the time. sorry for the delay!
    – Micko
    Sep 25, 2010 at 12:40
5

Assuming you're sure you want absolutely everything...

  1. Breakpoint objc_msgSend and objc_msgSend_stret. Almost all method calls use those two functions (mumble mumble IMP-cacheing).
  2. Okay, now your app drops into the debugger all the time. So click the auto-continue box.
  3. But now you don't see very much happening, so edit the breakpoints and add the command "bt" to get a backtrace.
  4. Drown in debug spam.

This won't catch other C functions, of course.

If you just want to catch notifications, you can do something like this (much less spammy):

+(void)load
{
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEveryNotification:) name:nil object:nil];
}

+(void)handleEveryNotification:(NSNotification*)notification
{
  CFShow(notification);
}

Of course, notifications are done with normal method calls, so the first method will also show them (albeit in a big pile of spam).

Delegates are not called or sent; they are just normal Obj-C method calls (strictly "message-sends", but that doesn't have the same ring to it).

5
  • thank you for your answer! i will try it when i find the time. sorry for the delay!
    – Micko
    Sep 25, 2010 at 12:37
  • Is it possible to catch other C functions? Mar 7, 2013 at 4:10
  • @BenDowling Sure: Breakpoint every function entry point. Finding these will be a bit more difficult.
    – tc.
    Mar 7, 2013 at 4:14
  • How do I breakpoint every function entry point? My goal is to discover what low-level iOS C functions are getting called, so I don't know their names in advance. Mar 7, 2013 at 7:49
  • @BenDowling Finding them will be a bit more difficult, especially since some private frameworks do not have symbol names.
    – tc.
    Mar 7, 2013 at 19:04
0

If you put a breakpoint into your app, you can watch the call stack change while you step through the code. That's probably as close as you're going to come to what you have in mind.

2
  • this is the right direction, but it still won't give you all things which were happening. is there noting else?
    – Micko
    Sep 24, 2010 at 23:20
  • You can put a breakpoint into the first line of main() and literally step through every line of code, and into every call into the framework. I don't know what more you could possibly want to see.
    – Dan Ray
    Sep 27, 2010 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.