Today’s tutorial is about debugging C (and C++ can be done too) using the gdbserver plugin in the NetBeans IDE, and its progression brought into play issues regarding the upgrade of Xcode 4 to Xcode 5 (and Mac OS 10.7.5 to Mac OS X Mavericks 10.9.1) made here (to facilitate IOS 7 development in Xcode), and the whole scenario has come about as a consequence of Xcode and its Command Line Tools Primer Tutorial in the sense that the installation of Xcode Command Line Tools (in earlier Xcode versions … think maybe less than 4 … “out of the box” it lived with C and C++’s great gcc compiler … have talked about this before … raved perhaps??!!! … anyway … that went away with the later versions … but you can get it back) “closes the circle” on the separation of C and C++, at least as far as NetBeans is concerned, so that we can use the installed Xcode Command Line Tool gcc compiler for C work and use the GNU compiler for C++ in NetBeans … cute, huh?
The bottom line is, when you upgrade from Xcode 4 to Xcode 5 the command line functionality will disappear, but you can resurrect it, and we bring your attention back to the tutorial below and that great link here.
So all this just gets us back to square one with NetBeans, and the first slides of the tutorial may seem a bit irrelevant to gdbserver, but they are showing the restoration of the relationship Xcode and NetBeans can have if the Xcode command line functionality is intact (but read more about this in the tutorial below). By the way this broken record is available on iTunes (chortle, chortle).
Okay, back with debugging for C (and C++ also) in NetBeans using gdbserver. We, in this tutorial, only show (a very simple example of) local debugging, but what about remote debugging (read more here … you might need to research further?) … so thanks to Egor Ushakov for this great plugin.
Debugging in gdbserver or gdb (or most debuggers) uses terminology like breakpoint (place where you stop), watch (find the values in variables and structures), step into (progress forward one line of code), step over (step over some code), continue (let debugger run the code to the next breakpoint) and restart (start the debugging session again). So the sensible first thing before you start a debugging session is to imagine the best place to position that first breakpoint (but bear in mind the program may have other ideas, and that you should be ready for the program to actually lob on a number of different possible places, (especially) if your debug place of interest is well into the execution sequence of your program). Why only worry about the first breakpoint … well, that’s true … set the others if you can … but sometimes you can only do this on getting to that first break, and either/both possibilities of use are okay with gdbserver or gdb or any other debugger I’ve ever seen. You can leave the decision for what you watch to that first breakpoint time, as you wish, also. Anyway, enjoy the tutorial.
Previous relevant Xcode and its Command Line Tools Primer Tutorial is shown below.
Xcode is a great GUI IDE application that comes with Macs “out of the box” (quite often). In the earlier versions … think maybe less than 4 … “out of the box” it lived with C and C++’s great gcc compiler … have talked about this before … raved perhaps??!!! … anyway … that went away with the later versions … but you can get it back. Why bother? If you like to look around and do those great command line offerings like Tcl/Tk or just plain simple C (like we do in this tutorial), as well as leaving your Xcode GUI C++ and Objective-C iOS mobile development intact, then think you should install Xcode Command Line Tools, like, yesterday, if you haven’t already.
Remember at the end of the month to say “hares” as your last word and “rabbits” as the first word of the next month.
Do we need to explain?
Butterflies in Brazil and all … why buck what the whole world’s doing? … chortle, chortle.
Anyway, this action opens a pandora’s box of possibilities with your Mac, and hope if you are in this position … you can test if you are by attempting to go gcc at the Mac Terminal bash command line … how’s the coffee? (if PM, how’s the daquiri?)
To get started, visit this stupendous link. Then get into Xcode and go to Xcode->Preferences…->Downloads (and hopefully you see the Command Line Tools install button to press … press with both hands, either hand, while doing a triple pike, but … just … do … it!)
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
24 Responses to C, C++ NetBeans, gdbserver Debugging Primer Tutorial