Nat! bio photo

Nat!

Senior Mull

Twitter Github Twitch

Hope and Disillusionment

Got a reply off the darwin developers list how to interface with the malloc library events system. This sounded great as it would make writing the tracer a cinch. Basically it's a hook into the malloc system, where you can "sniff" off all malloc related events.

So I just needed to create a dylib with an -init routine that sets the malloc_logger global variable and then start outputting the events to a file. As easy said as done and as I typed the magic incantations:

export DYLD_INSERT_LIBRARIES=/usr/local/libMulleMallocTracer.dylib
export DYLD_FORCE_FLAT_NAMESPACE=1

and then

ls

to generated a trace, I knew, good things were bound to happen.

They were not.

As I searched the /tmp directory in vain for the log file to be generated, I began to understand that the no-show of my debug message on stderr was not just coincidence. I wrote a little test program and linked the library directly. Still nothing happened. Reading through the ld documentation, it became apparent that the -init function is only called, when the shared library is referenced for the first time.

ARGH!

Back to square one. Next up, perusal of the Darwin dyld. I am searchin' for clues.

Playing now: Ghost of the Sun from the album "Viva Emptiness" by Katatonia