[ACCEPTED]-Debugging in XCode as root-root

Accepted answer
Score: 29

In Xcode 4.5 Product->Edit Scheme: Look in the Info tab under 1 Debug Process As and choose the root option.

Score: 25

Update: For Xcode 4.5 and later, see this answer instead.


The 21 only way I'm aware of to do what you're 20 asking is to run Xcode as root.

>> sudo /Developer/Applications/Xcode.app/Contents/MacOS/Xcode

Once you're 19 running as root, anything processes launched 18 from Xcode will also run as root. Note, though, that 17 if you create or edit any files, they will 16 be owned by root, which means that you'll 15 have to chown them before you can edit them as 14 your normal user first.

I'd love a way for 13 Xcode to say "Launch process as root", but 12 as far as I know, no such functionality 11 is available.

Note that you can also run 10 the application within the command-line 9 debugger gdb to debug your application. Run 8

>> sudo gdb /path/to/my/application

Then you could keep Xcode open, modify at 7 will, and debug your program within gdb. This 6 is what I generally do.

EDIT: Readers from the 5 future: see the answer from Alexander Stavonin; it 4 talks about how to do this. If you're okay 3 with ssh keys and enabling the root user 2 on your system, his answer is the way to 1 go.

Score: 15

Xcode is able to run the debugging application 22 as root. For this purpose the following 21 steps should be done:

  1. Enable the root user 20 for local machine.

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

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

  2. Enable 17 remote loging.

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

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

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

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

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

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

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

  4. Enable remote debugging 6 via ssh in Xcode.

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

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

  5. Everything should 1 be Ok now ☺

From blog

Score: 3

XCode no longer supports remote debugging 8 rendering most of these answers obsolete.

For 7 debugging a program as root it is now easy. Under 6 the Product menu, use "Edit Scheme…" and 5 in your "Run" schemes "Info" pane, select 4 "Debug process as root". You will have to 3 authenticate once.

As of Xcode 4.5 I got 2 a strange error until I quite Xcode and 1 restarted.

Score: 0

Debug as a root via SSH.

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

Score: 0

If you want to debug a web server running 6 on port 443, you could instead run it on 5 port 8443 on your normal account and then 4 do a: sudo ssh user@localhost -L 443:localhost:8443 3 -N

Then you can still contact your application 2 on the right port, but have the advantage 1 of running the application as a normal user.

More Related questions