views:

982

answers:

3

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.

+8  A: 

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.

BJ Homer
Thanks, but this problem with files owner is really annoying.
Anton
A: 

Debug as a root via SSH.

Edit Active Executable -> Debugging -> Debug executable remotely via SSH.

Cheng
I can't make it working. What I've set on this page: When using "GDB" Use "Pipe" for standard input/output, "Checked" Debug executable remotely via SSH, Connect to: "[email protected]" ,"Unchecked" Start executable after starting debugger.And when I'm running my app it shows dialog with SSH authentication but entering my password as passphrase gives "Authentication failed". I also tried to use my user name but it doesn't work too. And, btw, the app doesn't start at all. What am I doing wrong?
Anton
+3  A: 

Xcode is able to run the debuggin applicationg as root. For this purpose the following steps should be done:

  1. Enable the root user for local machine.

    a. Run “Directory Utility” (/System/Library/CoreServices/ Directory Utility.app)

    b. Choose “Enable Root User” from the Edit menu and enter the root password.

  2. Enable remote loging.

    a. In System Preferences… -> Sharing, check Remote Logging. This option turns on the ssh demon.

  3. Create ssh public/private keys and copy public key in the .ssh/authorized_keys folder for root user.

    a. Open terminal on local machine and type ssh-keygen -t rsa

    b. Accept the default location and type password for the root.

    c. Login as root su - and create ~/.ssh directory. (~ == /var/root)

    d. Copy the public key to the root: cat ~/.ssh/id_rsa.pub | ssh root@localhost "cat - >> ~/.ssh/authorized_keys"

    e. Check whether everything is Ok. Type ssh root@localhost. It shouldn’t ask for the root password.

  4. Enable remote debugging via ssh in Xcode.

    a. Select «Get Info» from drop-down menu on «Executables».

    b. In the "Debugging" settings check «Debug executable remotely via ssh» and put root@localhost as the «Connect to» info.

  5. Everything should be Ok now ☺

From blog

Alexander Stavonin