OBJECTIVE C - Catch all Objective-C messages and get list of objects in Cocoa runtime

I need to catch and log all messages sended by objects in Cocoa app. And also I need list of object instances in runtime. It's is posible?

This question and answers originated from www.stackoverflow.com
Question by (10/6/2010 1:25:09 PM)

Answer

Use dtrace, it's already built-in to the system. See this great introductory article at MacTech.

Dtrace is a system-wide standard mechanism so that you can log activities. Various system APIs notify the kernel, i.e. every system call, every objc_msgSend, etc generates a traceable point, and you can pass dtrace script to the kernel to log these activities. It's very powerful.

As an exercise, please put the following into a file called objc.d:

objc$target:::entry
{
    printf("[%s %s]\n", probemod,probefunc);
}

Then run from the command line

$ sudo dtrace -q -s objc.d -p 3333

where 3333 should be the pid of some Cocoa app. You'll get a log of every message sent to any object! Woo-hoo!

Answer by

Find More Answers
Related Topics  objective-c  cocoa
Related Questions