Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

James-B

macrumors newbie
Original poster
Oct 6, 2009
17
0
Dear All, I've just started (trying to) teach myself C++. My only prior experience of programming is writing VBA code where, after I've written it, I can step through it line by line and see what's happening. Can I get X-Code to do the equivalent with C++ code?
 
Yes. XCode is integrated with the GDB debugging tool. If you double-click to the left of the line you want to start debugging from, then choose "compile and debug" instead of "compile and run", you'll be presented with the debugger when your code reaches that line. From there you can single step through code, display variable contents, etc.

-Lee
 
Thanks for the reply. I can't find "compile and debug" though, or "compile and run" for that matter. I run projects via terminal. All I've done is what was suggested on this thread. Is there something else I need to do, or am I just missing the obvious?
 
If you're compiling and running from the terminal(which is A-OK), you're not using XCode. To get debugging symbols in your compiled binary, just add a "-g" switch in your g++ command line when compiling. Now your binary is "ready to debug". You can then run:
gdb ./mybinary
gdb> b main
gdb> run

Then to single step:
gdb> s

To go to the next line (stepping over functions):
gdb> n

There is a tutorial for using the debugger here:
http://www.cs.cmu.edu/~gilpin/tutorial/

-Lee
 
I see. Thanks a lot. This seems to be working. Is there any particular advantage to using X-code to debug, or is it just as good doing it as you've suggested?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.