Handmade Network»Forums
Oliver Marsh
193 posts / 1 project
Olster1.github.io
Mac OSX debugging with xcode with a.out file
Edited by Oliver Marsh on
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
Martin Fouilleul
39 posts / 3 projects
PhD student at Ircam, doing research on programming languages for temporal interaction. Former sound engineer and computer music designer.
Mac OSX debugging with xcode with a.out file
Create an empty project in Xcode,

Then right click in the project navigator to the left and choose Add files to "project". Add your sources here.

The go to Product > Scheme > New Scheme, give it a name (eg. debug), then in the dialog window select Run in the left panel. In the "Executable" menu you can choose Other and select your executable. There's also a number of options to pass arguments, set the working directory etc...

Then you simply run the debugger with Cmd-R.
Martin Fouilleul
39 posts / 3 projects
PhD student at Ircam, doing research on programming languages for temporal interaction. Former sound engineer and computer music designer.
Mac OSX debugging with xcode with a.out file
Oh and you may want to compile with -O0 because otherwise some breakpoints may be ignored and some variable may not be viewable in the debugger.

Hope that helps !
Oliver Marsh
193 posts / 1 project
Olster1.github.io
Mac OSX debugging with xcode with a.out file
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.

Mārtiņš Možeiko
2559 posts / 2 projects
Mac OSX debugging with xcode with a.out file
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.
Martin Fouilleul
39 posts / 3 projects
PhD student at Ircam, doing research on programming languages for temporal interaction. Former sound engineer and computer music designer.
Mac OSX debugging with xcode with a.out file
Ironically, I just updated to High Sierra and Xcode 9 and now I'm unable to get the debugger to work (I'm able to pause/resume and inspect variables but it just ignores breakpoints...)

I was previously on Mac OS 10.9, Xcode 6.2, and it worked just fine with the few steps I described...

Any idea ?

Oliver Marsh
193 posts / 1 project
Olster1.github.io
Mac OSX debugging with xcode with a.out file
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.
16 posts
Based in Japan. Building a fully featured music production system with a twist.
Mac OSX debugging with xcode with a.out file
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.
Martin Fouilleul
39 posts / 3 projects
PhD student at Ircam, doing research on programming languages for temporal interaction. Former sound engineer and computer music designer.
Mac OSX debugging with xcode with a.out file
Hello !

I can debug in LLDB without problems, so I guess Xcode is to blame.

Debug symbols were embedded in the executable, so I created an external dSYM file with dsymutil in the same directory as the executable, but to no avail...

Even on a super simple "hello world" project compiled in one go, no luck.

I also tried some suggestions I found searching on google (lots of results for "Xcode 9 breakpoints not working"), like deleting Xcode prefs, project's caches, setting a custom working directory, etc., but no luck either.

LLDB works just fine, and I'm ok using it, but I wish I could use Xcode for debugging. IMO it's one of the rare occasions where a gui actually brings a huge improvement on the workflow...

Maybe I'm missing something super obvious, can you describe me the steps you took to get it working on Xcode 9 ?

Thanks !