Finding the Binary Image Address Range in macOS


#1

Hi everyone, I’m in the process of writing a tool to symbolicate stack traces on macOS. As there’s lots of useful information in our existing log files I thought it best to use SystemStats::getStackBacktrace() to simply print the stack of the culprit thread into our log files. This also keeps consistency between OSes.

This gives a log similar to the below:

0   Waveform 8 (64-bit)                 0x000000010450488a Waveform 8 (64-bit) + 7096458
1   libsystem_platform.dylib            0x00007fff9a6a6bba _sigtramp + 26
2   libsystem_c.dylib                   0x00007fffa32c5240 __sF + 304
3   libsystem_c.dylib                   0x00007fff9a52d420 abort + 129
4   libc++abi.dylib                     0x00007fff9908a85a __cxa_bad_cast + 0
5   libc++abi.dylib                     0x00007fff990afb72 _ZL25default_terminate_handlerv + 46
6   libc++abi.dylib                     0x00007fff990acd69 _ZSt11__terminatePFvvE + 8
7   libc++abi.dylib                     0x00007fff990acdf0 _ZSt9terminatev + 64
8   JuceDemoPluginCrash                 0x0000000108c9fdcc main_macho + 32044
9   JuceDemoPluginCrash                 0x0000000108c9c305 main_macho + 16997
10  Waveform 8 (64-bit)                 0x0000000104461224 Waveform 8 (64-bit) + 6427172
11  Waveform 8 (64-bit)                 0x00000001049452cc Waveform 8 (64-bit) + 11555532
12  Waveform 8 (64-bit)                 0x0000000104941b08 Waveform 8 (64-bit) + 11541256
13  Waveform 8 (64-bit)                 0x0000000104931696 Waveform 8 (64-bit) + 11474582
14  Waveform 8 (64-bit)                 0x0000000104951a91 Waveform 8 (64-bit) + 11606673
15  Waveform 8 (64-bit)                 0x0000000104951003 Waveform 8 (64-bit) + 11603971

It appears I can calculate the base address of the main binary to pass to atos but for plugins I don’t seem to have enough information to get the address range. In the macOS crash logs these are listed at the bottom under the “Binary Images” section. Does anyone know how to get these at run time and possibly add them to our log files?


#2

I think dladdr() will provide you the correct address ( via the Dl_info.dli_fbase pointer )


#3

Awesome. That, did the trick. Thanks!