在我的程序中,我需要创建套接字并将它们绑定到侦听 HTTP 端口 (80).当我使用 sudo 从命令行启动它时,该程序运行良好,将权限提升到 root.在 XCode 下运行会在调用绑定函数 (asio::ip::tcp::acceptor::bind()) 时出现权限被拒绝"错误.
如何在 XCode 下调试?
全部使用 C++ 和 boost.asio 在 Mac OS X 10.5 和 XCode 3.1.2 上完成.
更新:对于 Xcode 4.5 及更高版本,请参阅 这个答案 代替.
<小时>我所知道的执行您要求的唯一方法是以 root 身份运行 Xcode.
<代码>>>须藤/Developer/Applications/Xcode.app/Contents/MacOS/Xcode
一旦您以 root 身份运行,任何从 Xcode 启动的进程也将以 root 身份运行.但请注意,如果您创建或编辑任何文件,它们将归根用户所有,这意味着您必须先chown
才能以普通用户身份编辑它们.>
我希望 Xcode 能够说以 root 身份启动进程",但据我所知,没有这样的功能可用.
请注意,您还可以在命令行调试器 gdb
中运行应用程序来调试您的应用程序.运行
<代码>>>须藤 gdb/path/to/my/application
然后你可以保持Xcode打开,随意修改,并在gdb中调试你的程序.这就是我通常所做的.
编辑:来自未来的读者:请看 Alexander Stavonin 的回答;它讨论了如何做到这一点.如果您可以使用 ssh 密钥并在您的系统上启用 root 用户,那么他的答案就是您要走的路.
In my program I need to create sockets and bind them to listen HTTP port (80). The program works fine when I launch it from command line with sudo, escalating permissions to root. Running under XCode gives a 'permission denied' error on the call to binding function (asio::ip::tcp::acceptor::bind()).
How can I do debugging under XCode?
All done in C++ and boost.asio on Mac OS X 10.5 with XCode 3.1.2.
Update: For Xcode 4.5 and later, see this answer instead.
The only way I'm aware of to do what you're asking is to run Xcode as root.
>> sudo /Developer/Applications/Xcode.app/Contents/MacOS/Xcode
Once you're running as root, anything processes launched from Xcode will also run as root. Note, though, that if you create or edit any files, they will be owned by root, which means that you'll have to chown
them before you can edit them as your normal user first.
I'd love a way for Xcode to say "Launch process as root", but as far as I know, no such functionality is available.
Note that you can also run the application within the command-line debugger gdb
to debug your application. Run
>> sudo gdb /path/to/my/application
Then you could keep Xcode open, modify at will, and debug your program within gdb. This is what I generally do.
EDIT: Readers from the future: see the answer from Alexander Stavonin; it talks about how to do this. If you're okay with ssh keys and enabling the root user on your system, his answer is the way to go.
这篇关于以 root 身份在 XCode 中调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!