Xcode debugger: cmd line application - start with sudo? - xcode

I need to debug a command line application with Xcode...
and I need to have the debugger launch my app with 'sudo'.
How do I tell Xcode to do that?
thx->adv

Running XCode as root is a bad idea.
There is an option for this in XCode (6.2):
Product -> Scheme -> Edit Scheme
Select the "Run" configuration
Change the radio button for "Debug Process As" to "root"

Have you tried starting Xcode with sudo?
The processes it spawns (gdb,...) should also run with superuser privileges:
sudo /Applications/Xcode.app/Contents/MacOS/Xcode

You could launch XCode itself with sudo, then it will be running with the privileges of your nominated user, and also your application would run with the same privileges.
This may not be the best way; there may be a way to tell XCode to launch your application in a particular way. But the above method will work in any case.

Related

Netbeans Apache 12.2 on macOS Big Sur only runs properly as super user

When running as a normal user, if you click on Netbeans->Preferences the window will open, shake, flash, freeze, and not let you do anything. The same thing happens with the Tools->Plugins. Running as super user it works perfectly. I have cleaned up all NetBeans related files. You can see it in action here.
It's useless as it is.
Ive found a partial workaround for this.
You need to setup the OS not to open new documents as new tab.
Go to the Apple Menu, select System Preferences > General. In the Prefer tabs when opening documents option, select "never".
Then restart Netbeans and try to open Netbeans preferences.
If you don't want a system-wide change, you can set the following setting. It should affect only applications running on JDK, run this in terminal:
defaults write net.java.openjdk.cmd "AppleWindowTabbingMode" never
It turns out that is a problem related to the AppleWindowTabbingMode
settings. I was using "always", since I want that apps like Finder and
other use new tabs rather than new windows.
This settings worked fine with NetBeans since Catalina. So I reset the
behavior to "never" only for NetBeans, with the follow command
defaults write net.java.openjdk.cmd "AppleWindowTabbingMode" never
With this setting NetBeans works finally fine!
Sources: apparently, it's a bug, please see here and corresponding JDK bug.
Also, it's not a problem with NetBeans only. It affects AndroidStudio also see here for example:
If you choose to run it as root, here's what I use:
#!/bin/bash
APP=/Applications/NetBeans/Apache\ NetBeans\ 12.2.app/Contents/MacOS/netbeans
COMPLAINT="Netbeans must run as %U because of bugs in the UI implementation :{"
PROMPT=$(echo -e "${COMPLAINT}\nPlease enter your login password for privilege escalation:")
sudo -p "${PROMPT}" -b -s "${APP}"
This lets me limp by with a recent JDK (15.0.2) which placates the corresponding NetBeans (12.2, as you can see from the code). The -b option tells sudo to run the app in the background, which in this case means simply that the Terminal in which you ran this script will not be polluted with JDK whinging about "illegal reflective access".

"sudo su" equivalent in windows

I've seen multiple questions on this topic and some answers about runas but none of them was sufficient...
I need a Windows command to upgrade privileges of a terminal after it has already been opened with permissions of an average user. ie. To upgrade permissions for the whole terminal session and not just to run one command as administrator! Something just like sudo su in Linux.
If anyone knows any trick to do this that would be much appreciated.
Edit:
Why I need this? I use the terminal in Visual Studio Code; it wouldn't let me run commands that require administrative permissions. It sucks to have to open an external terminal to do this... And currently, the only way I'm aware of to run a terminal in VS code in elevated permissions would be by editing the Code.exe's compatibility settings to run as administrator. But that adds more trouble because now it shows the user account control prompt every time I run an instance of VS Code.
Also creating a special shortcut to run VS Code in administrative mode wouldn't help because I run it from the context menu (Open With Code) so I don't have to manually navigate to the project folder.
There is no such an equivalent in Windows.
What you might do is to open your desired process from cmd with:
runas /user:administrator processname.
or open any application with right-click and run as..

Why do I need root privileges to run GDB?

When I start GDB from the command line I have no problems. But when I start debugging a programs from NetBeans (C++), I get this message:
"Type the name and password of a user in the "Developer Tools" group to allow Developer Tools Access to make changes."
My user is already in the "Developer Tools" group, but this fact seems to be ignored.
With the root password it lets me debug, but I would not debug with the root account!
I checked the GDB executable and path, and they all grant executable permissions to everyone.
Any idea?
Thank you!
Platform:
MacOS X 10.6.6
NetBeans 6.9.1
GCC 4.2
GDB 6.3.50-20050815
I believe you will find the answer over here: Stop "developer tools access needs to take control of another process for debugging to continue" alert
Basically, you can reinstall Xcode or fix the authorization database.
No, you shouldn't need root privileges to run GDB. Does your software need to run as root? If your software runs as root GDB will also need to be run as root.
What happens if you run GDB on the command line?

Terminal Command or Apple Script to run XCode?

Is is possible to make XCode run by executing an AppleScript or some sort of terminal command?
Can you pass XCode startup arguments, like a project to open, or to build a project on startup?
Edit:
Please excuse my laziness, but Apple Script samples are appreciated.
It's fairly simple to run Xcode from the Terminal: open -a Xcode to simply open it, or open yourproject.xcodeproj to open your project in Xcode. As for getting it to build on startup, you'd probably have to turn to AppleScript for that:
tell application "Xcode"
build
launch
end tell

How to get the output of an OS X application on the console, or to a file?

I am writing a Cocoa application with Mono embedded. I want to run and see my debug output in Terminal. On the Cocoa side I am using NSLog(), and on the Mono side I am using Debug.Write(). I can see my debug output in Xcode's console, but not in Terminal. This is what I tried:
$: open /path/build/Debug/MyProgram.app
$: open /path/build/Debug/MyProgram.app > output
$: open /path/build/Debug/MyProgram.app 2> output
in a terminal but I do not my output on the console or in 'ouput'.
What's the correct command?
PS. My ultimate goal is to write a vim plugin to manage, build, run, debug the xcode project. You can save me this hassle if you can get this vi input manager to work with xcode.
Chris gave a good overview of how the Console works, but to specifically answer your question: If you want to see the results directly in your Terminal, you need to run the built product as a child of the Terminal, which means using something like
/path/debug/build/MyProgram.app/Contents/MacOS/MyProgram
to launch the app.
Terminal on Mac OS X is just another application. Opening a terminal window for text I/O is not an inherent capability of every application as it is on Windows.
Furthermore, open /path/to/MyApp.app does not execute MyApp.app as a subprocess of your shell, it sends a message to the operating system's launch infrastructure asking it to execute the application in a normal fashion, the same as if it were double-clicked in the Finder or clicked in the Dock. That's why you're not able to just redirect its output to see what your app is sending to stdout or stderr.
You can use Console.app to see the output of applications launched in the normal manner, because the launch infrastructure specifically sends their stdout and stderr there. You can also use the asl routines to query the log, or perform more sophisticated logging if you so desire.
Open Console.app in /Applications/Utilities. All NSLog output will be printed in the System log.
Or, if you run it from within Xcode, all of the output will be printed in the Debug console.
I'm not on my Mac right now and don't recall the command sequence or the menu the Debug Console is in, possibly the Build menu?
Overview
The idea is to simply run the app from command line using ios-deploy.
Instructions
Install ios-deploy
Run the app from xcode (make sure it runs successfully)
go to xcode menu > preferences > locations and click on arrow in derived data:
in the derived data directory, search for your .app file under Build/intermediates/Products
in the terminal type the following
ios-deploy --debug --bundle
then drag the .app file from step 4 unto the terminal.. you should have something like this
ios-deploy --debug --bundle path/to/your/applicationName.app
and that's it! The app should successfully run and all the logs will go to your terminal.

Resources