Debugging in XCode as root

后端 未结 6 2046
一生所求
一生所求 2020-12-03 04:59

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

6条回答
  •  眼角桃花
    2020-12-03 05:21

    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.

提交回复
热议问题