Sunday, November 06, 2005

Observe OSX programs behavior using environment variables

it is possible to observe OSX programs behavior that use the objective-c runtime by setting the following variables


The information dumped by the objective-c runtime when these variables are set can be very handy, specially when analyzing programs for which you don't have the source code.

The source code that uses these environment variables to dump the information can be found at

the function objc_setConfiguration() obtains the values of 'LaunchingDebug' and 'OBJC_PRINT_BIND':

static void objc_setConfiguration() {
if ( LaunchingDebug == -1 ) {
// watch image loading and binding
LaunchingDebug = getenv("LaunchingDebug") != NULL;
if ( PrintBinding == -1 ) {
PrintBinding = getenv("OBJC_PRINT_BIND") != NULL;

the function objc_map_image obtains the value of 'OBJC_DUMP_CLASSES' :

static void _objc_map_image(headerType *mh, unsigned long vmaddr_slide)
static int dumpClasses = -1;
if ( dumpClasses == -1 ) {
if ( getenv("OBJC_DUMP_CLASSES") ) dumpClasses = 1;
else dumpClasses = 0;

Next is a list of the functions that use each environment variable:


+ _objc_map_image
+ _objc_bindModuleContainingCategory
+ _objc_bindModuleContainingClass


+ _objc_map_image


+ _objc_map_image

OBJC_PRINT_BIND as the name implies, prints log information about categories and classes that
are binded by the objective-c runtime.
LaunchingDebug logs information about 'modules' loaded.
OBJC_DUMP_CLASSES logs.. mm. yes, classes.

sample output of OBJC_PRINT_BIND when running iMovie

The list of classes and categories logged can be very useful to know what is that the program is doing.
Apart from looking at the classes while the program is loading, you can associate an action in the program to the classes/categories used when that action is performed.

For example,

+ open a Terminal window
+ set the OBJC_PRINT_BIND function variable (e.g.: export OBJC_PRINT_BIND = 1)
+ run iMovie (found at /Applications/
+ Once iMovie is loaded, click on the 'File' menu item, and you'll see the following in the Terminal window

objc: binding class NSPortNameServer
objc: binding class NSMachBootstrapServer
objc: binding class %NSMachPort
objc: binding class NSMachPort
objc: binding class NSDistributedObjectsStatistics
objc: binding class NSDistantObject
objc: binding class NSPortCoder
objc: binding class NSConcretePortCoder
objc: binding class NSDOStreamData
objc: binding class NSPortMessage
objc: binding category NSPortMessage(NSPortMessageMachPortAdditions)
objc: binding class NSServicesMenuHandler

These are the classes/categories that were bind when you clicked on the 'File' menu item, what can
give you a hint about what the program is doing. Remember that what is logged are the classes/categories that were bind when you click the menu item, meaning that the classes/categories that
were bind before will not be shown now, so the list of classes/categories listed is NOT the whole list of
classes/categories used by the code responding to the activation of the 'File' menu item. For the same reason, if you click on the 'File' menu item again, no information will be logged.

sample output of LaunchingDebug when running iMovie

LaunchingDebug shows the modules/images loaded.

sample output of OBJC_DUMP_CLASSES when running iMovie

I don't know exactly what it means, but I guess that is the list of Classes implemented by the loaded module. If this is the case, this information is not that useful. I'll have check this in the future and update this posting.

There are also a bunch of other environment variables that are very interesting. I'll post information
about them in the near future.

No comments: