Netbeans C/C++ Remote Development With Sudo

C programming on the Raspberry Pi can offer more flexibility and power than script files and can be created using something as simple as a text editor like vi or nano. Using an IDE for more complicated programs can be a time saving tool that offers many resources to simplify your coding; debugging, syntax highlighting and code completion.  There are many resources to show you how to setup NetBeans projects for remote development, links are included at the bottom of the article.

One issue I have with remote development is when I need to debug a program with elevated privileges for GPIO access. I have been unable to find a built-in method in NetBeans for specifying sudo access for the debugger, and I did not want to run the remote host as user root.

The Solution:

The solution I used was to create a simple script file that called GNU gdb with sudo and directed NetBeans to use that file as the debugging default.

nano ~/NetBeansProjects/gdbsudo

Copy and paste the following, and save.

#!/bin/bash
sudo /usr/bin/gdb $*

Change the permissions so only the user has access to the file.

chmod u=rwx,g=,o= ~/NetBeansProjects/gdbsudo

 Lastly, point NetBeans to use the script as the debugger command under the tools menu.

netbean_debug

Test Program:

Here is a simple program to demonstrate the differences when you Run the project (F6)  and when you Debug the project (Ctrl+F5)

 

Reference:

C/C++ Remote Development – NetBeans IDE Tutorial
Setup a Project in Netbeans for Programming on the Raspberry Pi

Shaun Bennett has written 6 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">