Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 4 external build project and debugging

Tags:

c++

xcode4

I've got a makefile based project set up that builds my code on multiple platforms. On my Mac I want to use Xcode for debugging though. I've set up an Xcode as an External Build Project I can run the application from within Xcode. The output is shown in Xcode and if the app crashes it drops in to the debugger, but when running the debugger cannot locate the source files, so I just see assembly output. How can I tell Xcode where to locate the source?

I also cannot set breakpoints, but I think that this is all the same problem.

like image 745
jdswain Avatar asked Sep 27 '11 12:09

jdswain


People also ask

How do you debug an Xcode project?

When you run an application in Xcode, the debugger is automatically started and attached to the process of the application. Click the Run button in the top left or press Command + R. From the moment the application is up and running, we can start inspecting the process and, if necessary, debug it.

Does Xcode have a debugger?

The Xcode debugger provides several methods to step through your code and inspect variables. You can precisely control execution of your code from a breakpoint, stepping into and out of called functions as necessary to determine where your bug occurs.

What is debugging executable in Xcode?

The “Debug executable” checkbox specifies whether or not you want to run with the debugger enabled. Once running, you can use Debug > Attach to Process on a process that has been launched with debugging disabled if needed. It seems like all this does is start your app with the debugger attached.

How do breakpoints work in Xcode?

Navigate to a line in your code where you want execution to pause, then click the gutter or line number in the source editor to set a breakpoint. Xcode displays a breakpoint icon to indicate the location. Drag a breakpoint up or down to move it to another location; drag it away from the gutter to remove it.


2 Answers

I was able to fix the issue of not stopping at breakpoints by setting a custom working directory for the executable. Before this change I was able to build successfully using the external scons system from Xcode 4. My code would run when called from XCode but breakpoints would be ignored.

Then in XCode, Go to Product -> Edit Scheme... CHeck 'use custom working directory' and I set this to the same directory as the executable.

Breakpoints then started working.

like image 99
NoahR Avatar answered Oct 13 '22 00:10

NoahR


  1. Ensure -g is included in the compiler options in the makefile.
  2. Set a custom working directory in the scheme, set the executable if this hasn't already been set.
  3. Ensure that the project isn't pulling in dylibs that haven't been compiled with -g. You might need a build step to run make install if the project builds dylibs as well as the main target.
  4. Make sure that "strip" isn't being called. There are environment vars that xcode set that allow you to keep a working makefile when used outside xcode.

Just had this problem and this worked (Xcode 4.6) (got source debugging and working breakpoints)

like image 42
januszb Avatar answered Oct 13 '22 01:10

januszb