Debugging a C ++ program in NetBeans 8.0 that requires sudo

I know that this question has been asked many times on different sites, but I could not find recommendations to fix my problem. I work with GCC 4.8.1 on NetBeans 8.0 and must (visually) debug a program that accesses raw devices, so I need to run it through sudo.

Settings of my project parameters:

  • Run β†’ Run Command = "sudo $ {OUTPUT_PATH}"
  • Run β†’ Console Type = "External Terminal"
  • Run β†’ External terminal type = "Default"

All other settings are standard, including Debug -> Debug Command , which is empty.

So, the program works fine when I run in NetBeans - sudo asks for a password, and then the program continues. However, I cannot debug it in NetBeans - the debugger displays the text below and stops.

Debugger External Terminal

Any ideas? Please do not offer to run NetBeans as root - this is too troublesome for me.

(I am on Xubuntu 3.11 , which runs as guest OS on VMWare Fusion VM on Mac)

UPDATE FROM 2015/09/16:

According to a few tips (from the network), I tried to replace the Debug Command in the popup window Tools β†’ Options β†’ C/C++ my script with the following content:

 #!/bin/bash PROG=$(which gdb) sudo $PROG " $@ " 

This script works fine from the command line. However, when I try to debug my program from NetBeans, I get the following popup:

NetBeans Post

So, the first problem goes away, and the second one appears. I saw a number of recommendations for clearing control points in this case - it did not help me.

Any ideas what to try next?

(gdb version - GNU gdb (Ubuntu / Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04)

+6
source share
6 answers

A little late, but I came across this question while I was looking for a solution to the same problem.

Create a script file with the following:

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

Change the permissions for the script file to an executable file for your user.

In NetBeans, go to Tools -> Options -> C / C ++ -> Debugger Command -> filename

+2
source

The best thing that comes to my mind is to run gdb using sudo and make the system not ask for a password. I believe that there is already an answer to your question (although for Eclipse, but in fact it is the same for Netbeans) here fooobar.com/questions/178508 / ...

Hope this helps.

+1
source

You can try one of them,

  • Launch Netbeans as root. To do this, run Netbeans through the terminal as sudo.
  • Log in as the root user. First of all, you must enable the root account to log in ( https://askubuntu.com/questions/44418/how-to-enable-root-login ). Technically, any operation you do there does not require authentication, since you are already su!

Hope this solves your problem,

Good luck.

0
source

Have you tried just "sudo gdb" as a Debug command (or running Netbeans as root, extreme protection)?

0
source

Here is how I use it:

Run β†’ Run Command = sudo "$ {OUTPUT_PATH}"

You need to move sudo before the quotes.

Other settings should not cause any problems, but here is how I set up:

Run -> Console Type = "Standard Output"

Run β†’ External terminal type = "Default"

0
source
  • Run your program either from NetBeans or from the command line.
  • Then in NetBeans, go to Debug -> Attach Debugger, specify the appropriate project and attach to your process.
0
source

Source: https://habr.com/ru/post/969914/


All Articles