在NetBeans 8.0中调试需要运行sudo的C ++程序 [英] Debugging a C++ program in NetBeans 8.0 which needs the sudo to run

查看:236
本文介绍了在NetBeans 8.0中调试需要运行sudo的C ++程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题在各个网站上被问到很多次,但是我找不到任何建议如何解决我的问题。我正在使用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.

我的项目属性设置是:



  • 运行 - >运行命令=sudo $ {OUTPUT_PATH}

  • 运行 - >控制台类型=外部终端

  • 运行 - >外部终端类型=默认

所有其他设置都是默认设置,包括 Debug - >调试命令,这是空的。

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 ,它在Mac上的VMWare Fusion VM中作为客户机OS 运行)

(I'm on Xubuntu 3.11, which runs as a guest OS in the VMWare Fusion VM on Mac)

更新从2015/09/16:

根据多个意见(从网络),我试图替换 Debug Command c c code code code code code code code 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆