1
0
Fork 0
jai-resources/macos_development/how_to_debug_in_xcode.md

2.4 KiB

Debugging on OSX

TODO: Figure out how to set breakpoints in Xcode TODO: Figure out why Xcode detaches from the process after you take a Metal snapshot, leavin the window there forever

Basics

  1. Open XCode
  2. Create a new Project using the External Build Tool configuration
  3. Set the Build Tool for the target to either:
  • /usr/bin/true - this is essentially a no-op if you want to be building elsewhere
  • ../bin/build.sh (or similar) - the path to your build script. IMPORTANT: it seems Xcode doesn't resolve absolute paths, just paths relative to the project location.
  1. With the project open go to Product > Scheme > Edit Scheme > Run > Info > Executable and select the executable you want to run.
  2. Cmd+R to Run.

Debugging this way, you can have Xcode run an executable in a .app or just from any directory. There do seem to be differences in the ways some graphics systems are initialized - I get different window scaling in each case.

Breakpoints

I can't get these to be set via the Xcode Debugger at the moment. I'm not sure why. As an alternative, you can set them via the lldb command line interface in Xcode, and then navigate the stack with the UI just fine.

To set on a particular file/line

b --file <file_name> --line <line_number>

To set at the entry to a particular function

b <function_name> Note: this doesn't work if function_name is "main" - it adds a baker's dozen of breakpoints at different places

To remove all breakpoints

breakpoint delete

Graphics

OpenGL

I didn't have any luck with any of Xcode's graphics debugging utilities while developing for OpenGL.

Metal

If you want to use XCode's Metal Graphics Debugging utilities, follow these steps:

  1. Product > Scheme > Edit Scheme > Diagnostics
  2. Turn on/off any options in the Metal section at the bottom.

Note: Some of these will crash your app if you fail their checks.

Errors

The specified architecture 'arm64--' is not compatible with 'x86_64-apple-macosx10.13.0' in '/Users/ps/work/minos/p_scratch/package/scratch.app/Contents/MacOS/scratch' This will happen if you are trying to debug an x86/x86_64 executable on an arm machine.

  1. Go to Product > Destination > Destination Architectures > Show Both
  2. Select Intel (Rosetta)

Sources: