問題描述
在我的程序中,我需要創建套接字并將它們綁定到偵聽 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 中調試的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!