Just for kicks, I'n trying to create a .dylib that intercepts malloc() calls. I wanted to print out allocations sizes and caller addresses for later munging. The output format is like this:
0x7fff93b8ffa7: 20 bytes
0x7fff69eaec18: 16 bytes
0x000100a2d45b: 8 bytes
0x000100a2d45b: 8 bytes
0x000100a2d45b: 8 bytes
Which is a result of running any program like this:
DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=debugmalloc.dylib mybinary 2>debug.log
mybinary
can be replaced by any other program. debugmalloc.dylib
is the malloc() interceptor.
Now I can start creating histograms and calculating waste! There's just one thing missing though: I'd like to see the names (symbols) of the actual (public) callers instead of just the addresses. So I start looking around and find some interesting pieces of the puzzle.
- Using nm: Offset in nm symbol value?
- Using lldb to symbolicate with
image lookup -address
: http://lldb.llvm.org/symbolication.html (usingotool -l $BINARY
to find theaddr
of the __TEXT.__text fragment and trying if offsetting with that works). I was hoping this would be even better because lldb has debugging information and thus I would be able to symbolicate internal symbols as well.
But to date I haven't been able to work back to the file address of the symbol. lldb's image lookup -address
stays silent. My next step is probably to look at the otool -l
output some more to see if I can square it with some of the addresses I'm seeing, but that will be tedious manual work. If someone has a better idea of how to do this, I'm all ears.