Mac OSX debugging with xcode with a.out file

Hi there,

I am doing a mac platform layer for a game using the SDL library, and compiling from the command line in a linux style fashion. My build.sh script is as follows:

1
gcc platform_layer.cpp -w -lSDL2 -std=gnu++11 -framework OpenGL -g 


The code compiles and produces an a.out executable that runs.

I was wanting to debug the code in XCode, similar to the way Casey uses visual studio for debugging. I'm not sure how to do this though. I pass -g to the compiler which produces .dsym files (which i think is similar to .pdb files on windows?), however I'm not sure how to tell Xcode that I'm not an app package.

Any help would be greatly appreciated.

Thanks,
Oliver

Edited by Oliver Marsh on
Thanks for that, i've got it working. I thought there must have been an easier way. I read TOP! will be made for mac, so if I've got any more questions I'll know who to ask! Thanks again.

gcc and clang has a nice "-Og" optimization option. It enables optimizations that are "safe" for debugging. Basically it will do some optimizations that doesn't affect debugging experience (breakpoints, local vars, ...) negatively. Obviously it the code will run faster than -O0.
Ah! Not sure, I'm on El Captain and xcode version 7.3.1 . Your definitely creating debug symbols? Hope they don't drop support for building this way.
I had the exact same issue after upgrading to High Sierra and Xcode 9.

Turned out in my case it was because I was using HMH style hot loading with a dylib. HMH makes a copy of the compiled dylib but not the associated .dSYM, so copying the dSYM along with the dylib applying the new name fixed the issue for me.

If that's not the case I would definitely recommend using lldb command line to see if you're still getting problems (I was), so at least you can eliminate Xcode as being a cause.