Mac OS
In most circumstances, memory debugging works seamlessly on the Mac OS.
From 10.11 El Capitan and onwards, however, the Mac OS introduced some changes that can affect some programs when memory debugging. While these should not affect how your program runs, in some rare cases you may want to fine-tune how the HIA behaves.
Background
In the Mac OS environment, interposition works only for preloaded DLLs, meaning that the Heap Interposition Agent (HIA) can only be preloaded rather than linked with the target as in some other operating systems. (See Behind the Scenes for more information on interposition and the HIA.)
The HIA makes sure that any environment variables related to preloading are correctly propagated if your program calls execve() or system(). The required Mac OS environment variable is DYLD_INSERT_LIBRARIES.
For all Mac OS releases from El Capitan onwards, however, a new feature System Integrity Protection (SIP) implemented a protocol that disallows passing DYLD_INSERT_LIBRARIES to a protected program or a program that resides in a protected directory. Calls to system() are affected because it is defined as invoking /bin/sh, which is in a SIP-protected directory.
Calls to system() on Mac OS
To work around the Mac OS SIP feature, for every system() call, the HIA copies bin/sh to a temporary directory (in /tmp) and arranges for the copy to be used so that DYLD_INSERT_LIBRARIES is not filtered out during the call. Once the child process has completed, the parent deletes the temporary directory.
This is the default behavior. To modify this, enable the environment variable TV_MACOS_SYSTEM.
Setting the Environment Variable TV_MACOS_SYSTEM
The TV_MACOS_SYSTEM environment variable allows customization of memory debugging behavior for Mac OS programs that call system(), and includes the following options:
pass_through=boolean
If true, the call to system () is passed through to the underlying implementation.
The default is false, in which case the HIA controls the call to system() as described in Calls to system() on Mac OS. Setting this option to true may be useful if you have disabled SIP.
Example: "TV_MACOS_SYSTEM=pass_through=true"
shell=<pathname>
Defines the shell for the HIA to use instead of the default bin/sh.
If defined, be sure that the SIP does not control access to this shell so that the HIA has access to it. Note that the named shell is not deleted after the return from system().
This setting may be useful to avoid any potential performance issues caused by copying the shell for each system() call., and then deleting it later.
Be aware, however, that using a previously stashed copy of bin/sh may require some maintenance, since the copy will not be updated when the operating system is updated.
The pathname must not contain commas or whitespace characters.
Example: "TV_MACOS_SYSTEM=shell=/path/to/some/copy/of/bin/sh"
tmpdir=<pathname>
Defines a temporary directory where the HIA will copy the shell (given the default setting of the option pass_through=false).
The HIA does not create the directory, assuming that it exists already. The HIA deletes the copy of the shell after processing is complete, but does not remove the directory.
If not set, the HIA creates a temporary directory in /tmp, which it removes after the call to system () completes.
Example: "TV_MACOS_SYSTEM=tmpdir=/path/to/some/directory"