Mac OS X Low-Level Debugging
Many of the subsystems in Mac OS X include debugging facilities that can help you in your debugging tasks. You can use most of these debugging facilities along with Xcode. Many debugging facilities are enabled or disabled by setting an environment variable; you can modify the executable environment to set these environment variables from Xcode. Xcode also includes several options for enabling specific debugging options, such as
libgmalloc (Guard Malloc), loading debug library variants, and stopping on Core Services debugging functions (described in Pausing on Core Services Debugging Functions). For more on the many debugging facilities available in Mac OS X, see TN2124: Mac OS X Debugging Magic.
Accessing Mac OS X Library Debug Symbols
Many Mac OS X system frameworks include debug versions in addition to the production version. These library variants are identified by their
_debug suffix. Debug variants of the system frameworks usually include debugging symbols, extra assertions, and often extra debugging facilities. You can modify the executable environment to have Xcode use the debug variants for libraries that your program loads.
To use the debug variant of a library, open the Info window for the executable environment that you use to run your program. In the General pane, choose “debug” from the menu “Use [suffix] suffix when loading frameworks.”
Using Guard Malloc
Xcode also integrates Guard Malloc (
libgmalloc ) into the debugger interface. Guard Malloc helps you debug memory problems by causing your program to crash on memory access errors. Because Guard Malloc causes your program to crash, you should use Guard Malloc with the debugger. When a memory access error occurs and your program crashes, you can look at the stack trace, determine exactly where the error occurred, and jump to the location of the problem.
To enable debugging with Guard Malloc from Xcode, choose Debug > Enable Guard Malloc before starting the debugging session. You can also use Guard Malloc with GDB from the command line, by setting the
DYLD_INSERT_LIBRARIES environment variable, as described in the man page for
libgmalloc. To learn how to set environment variables for development, see Configuring Executable Environments.
Guard Malloc has a number of additional options available. You can take advantage of these by setting the appropriate environment variables on the executable. In the inspector window for the executable, open the Arguments pane and add the environment variables to the environment variables table at the bottom of the window. See the man page for
libgmalloc for additional details and information.