在NetBeans 8.0中调试需要sudo运行的C ++程序 [英] Debugging a C++ program in NetBeans 8.0 which needs the sudo to run
问题描述
我知道这个问题在各种网站上被问过很多次,但我找不到任何建议如何解决我的问题。我在NetBeans 8.0中使用GCC 4.8.1,需要(可视地)调试一个访问裸设备的程序,所以我需要通过sudo运行它。
I know that this question was asked many times on various sites, but I couldn't find any recommendations how to fix my problem. I'm working with GCC 4.8.1 in NetBeans 8.0 and need to (visually) debug a program, which accesses raw devices, so I need to run it via sudo.
我的项目属性设置是:
- 运行 - > Run Command =sudo $ {OUTPUT_PATH} / li>
- 运行 - >外部终端类型=默认
所有其他设置都是默认设置,包括 Debug - > Debug Command
All the other settings are default ones, including Debug -> Debug Command
, which is empty.
因此,当我在NetBeans中运行时,该程序运行正常 - sudo请求密码,然后程序继续。但是,我不能在NetBeans中调试 - 调试器会输出以下文本并停止。
So, the program works fine when I run it in NetBeans - sudo asks for a password and then the program continues. However, I can't debug it in the NetBeans - the debugger outputs the text below and stops.
任何想法?请不要以root身份运行NetBeans - 这对我来说太麻烦了。
Any ideas? Please don't suggest running the NetBeans as root - it's too troublesome for me.
(我在 Xubuntu 3.11
作为 guest OS
在Mac上的VMWare Fusion VM中运行)
(I'm on Xubuntu 3.11
, which runs as a guest OS
in the VMWare Fusion VM on Mac)
UPDATE FROM 2015/09/16:
根据多个建议(从网络),我试图替换调试命令$在
工具
- > 选项
- > C / C ++
弹出式窗口,其脚本包含以下内容:
According to multiple advices (from the net) I tried to replace the Debug Command
in the Tools
-> Options
-> C/C++
pop-up window by my script with the following content:
#!/bin/bash
PROG=$(which gdb)
sudo $PROG "$@"
从命令行罚款。但是,当我尝试从NetBeans调试我的程序时,我得到以下弹出窗口:
This script works fine from command line. However, when I try to debug my program from NetBeans I get the following pop-up window:
所以,第一个问题消失了,第二个问题弹出。在这种情况下,我看到了一些建议来清除断点 - 它没有帮助我。
So, the first problem goes away and the second one pops up. I saw a number of recommendations to clear breakpoints in this case - it didn't help me.
任何想法接下来要尝试什么?
Any ideas what to try next?
(gdb版本是GNU gdb(Ubuntu / Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04)
(The gdb version is GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04)
推荐答案
有点晚了,但我遇到了这个问题,而我正在寻找一个解决方案完全相同的问题。
A bit late, but I ran across this question while I was looking for a solution to the exact same problem.
使用以下命令创建脚本文件:
Create a script file with the following:
#!/bin/bash
sudo /usr/bin/gdb $*
将脚本文件的权限更改为用户的可执行文件。
Change the permissions of the script file to executable for your user.
在NetBeans中,转到工具 - >选项 - > C / C ++ - >调试器命令 - > script_file_name
In NetBeans, go to Tools -> Options -> C/C++ -> Debugger Command -> script_file_name
这篇关于在NetBeans 8.0中调试需要sudo运行的C ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!