{"id":6158,"date":"2014-01-27T05:14:30","date_gmt":"2014-01-26T18:14:30","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=6158"},"modified":"2014-01-27T05:14:30","modified_gmt":"2014-01-26T18:14:30","slug":"c-c-netbeans-gdbserver-debugging-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-c-netbeans-gdbserver-debugging-primer-tutorial\/","title":{"rendered":"C, C++ NetBeans, gdbserver Debugging Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/NetBeans\/gdbserver\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"C, C++ NetBeans, gdbserver Debugging Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/NetBeans\/gdbserver\/NetBeans_gdbserver-163of.jpg\" title=\"C, C++ NetBeans, gdbserver Debugging Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">C, C++ NetBeans, gdbserver Debugging Primer Tutorial<\/p><\/div>\n<p>Today&#8217;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 <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='#xxaicltpt'>Xcode and its Command Line Tools Primer Tutorial<\/a> in the sense that the installation of Xcode Command Line Tools (in earlier Xcode versions &#8230; think maybe less than 4 &#8230; &#8220;out of the box&#8221; it lived with C and C++&#8217;s great gcc compiler &#8230; have talked about this before &#8230; <a target=_blank title='rave' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4844#hfafodm'>raved<\/a> perhaps??!!! &#8230; anyway &#8230; that went away with the later versions &#8230; but you can get it back) <i>&#8220;closes the circle&#8221;<\/i> 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 &#8230; cute, huh?<\/p>\n<p>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 <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='#xxaicltpt'>tutorial<\/a> below and that great link <a target=_blank title='Xcode command line tools link' href='http:\/\/stackoverflow.com\/questions\/9329243\/xcode-4-4-and-later-install-command-line-tools'>here<\/a>.<\/p>\n<p>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 <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='#xxaicltpt'>tutorial<\/a> below).   By the way this broken record is available on iTunes (chortle, chortle).<\/p>\n<p>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 <a target=_blank title='gdbserver remotely on NetBeans' href='http:\/\/netbeans-org.1045718.n5.nabble.com\/Is-it-possible-to-use-gdb-gdbserver-for-remote-debugging-C-C-programs-in-netbeans-td2923778.html'>here<\/a> &#8230; you might need to research further?) &#8230; so thanks to Egor Ushakov for this great plugin.<\/p>\n<p>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 &#8230; well, that&#8217;s true &#8230; set the others if you can &#8230; 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&#8217;ve ever seen.   You can leave the decision for what you watch to that first breakpoint time, as you wish, also.   Anyway, enjoy the <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/NetBeans\/gdbserver\/\" title='Click picture'>tutorial<\/a>.<\/p>\n<hr \/>\n<p id='xxaicltpt'>Previous relevant <a target=_blank title='Xcode and its Command Line Tools Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=5530'>Xcode and its Command Line Tools Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/Xcode_command_line_tools.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Xcode and its Command Line Tools Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/Xcode\/Xcode_command_line_tools.jpg\" title=\"Xcode and its Command Line Tools Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Xcode and its Command Line Tools Primer Tutorial<\/p><\/div>\n<p>Xcode is a great GUI IDE application that comes with Macs &#8220;out of the box&#8221; (quite often).  In the earlier versions &#8230; think maybe less than 4 &#8230; &#8220;out of the box&#8221; it lived with C and C++&#8217;s great gcc compiler &#8230; have talked about this before &#8230; <a target=_blank title='rave' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=4844#hfafodm'>raved<\/a> perhaps??!!! &#8230; anyway &#8230; that went away with the later versions &#8230; 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&#8217;t already.<\/p>\n<p>Remember at the end of the month to say &#8220;hares&#8221; as your last word and &#8220;rabbits&#8221; as the first word of the next month.<\/p>\n<p>Do we need to explain?<\/p>\n<p>Butterflies in Brazil and all &#8230; why buck what the whole world&#8217;s doing? &#8230; chortle, chortle.<\/p>\n<p>Anyway, this action opens a pandora&#8217;s box of possibilities with your Mac, and hope if you are in this position &#8230; you can test if you are by attempting to go <i>gcc<\/i> at the Mac Terminal bash command line &#8230; how&#8217;s the coffee? (if PM, how&#8217;s the daquiri?)<\/p>\n<p>To get started, visit this stupendous <a target=_blank title='Xcode command line tools link' href='http:\/\/stackoverflow.com\/questions\/9329243\/xcode-4-4-and-later-install-command-line-tools'>link<\/a>.   Then get into Xcode and go to Xcode->Preferences&#8230;->Downloads (and hopefully you see the Command Line Tools install button to press &#8230; press with both hands, either hand, while doing a triple pike, but &#8230; just &#8230; do &#8230; it!)<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d5519' onclick='var dv=document.getElementById(\"d5519\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=15\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d5519' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr \/>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d6158' onclick='var dv=document.getElementById(\"d6158\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=debugging\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d6158' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;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 &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/c-c-netbeans-gdbserver-debugging-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,24,37],"tags":[176,307,479,585,728,758,833,997,1319,1475],"class_list":["post-6158","post","type-post","status-publish","format-standard","hentry","category-elearning","category-netbeans","category-tutorials","tag-c","tag-debugging","tag-gdbserver","tag-ide","tag-mac-os-x-10-9-1","tag-mavericks","tag-netbeans","tag-programming","tag-tutorial","tag-xcode5"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/6158"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=6158"}],"version-history":[{"count":0,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/6158\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=6158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=6158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=6158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}