Xcode can’t launch project for debugging - xcode

I’m using Xcode 4.6.3 to build a library for OS X. My project includes a target called LibraryTest, which is a command-line app to test the functionality of the library. Both the library and the test app build fine, but when I try to run the app it quits immediately and the debug console shows:
error: failed to launch '/Users/bdesham/Library/Developer/Xcode/DerivedData/Wavelength_and_Spectrum_Library-byosniusyaoidgdcpzwzuzkitzgv/Build/Products/Debug/LibraryTest'
-- error: Host::LaunchProcess (launch_info) => pid=0,
path='/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver'
err = error: ::posix_spawnp (
pid => 98649,
path = '/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver',
file_actions = 0x10b09e268,
attr = 0x10b09e2a0,
argv = 0x7fe2701377e0,
envp = 0x0 )
err = Bad file descriptor (0x00000009) (0x00000009)
error: failed to launch '/Users/bdesham/Library/Developer/Xcode/DerivedData/Wavelength_and_Spectrum_Library-byosniusyaoidgdcpzwzuzkitzgv/Build/Products/Debug/LibraryTest'
-- error: Host::LaunchProcess (launch_info) => pid=0,
path='/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver'
err = error: ::posix_spawnp (
pid => 98649,
path = '/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/Resources/debugserver',
file_actions = 0x10b09e268,
attr = 0x10b09e2a0,
argv = 0x7fe2701377e0,
envp = 0x0 )
err = Bad file descriptor (0x00000009) (0x00000009)
(Line breaks added for readability.) I have the Xcode 5 DP installed, so I tried removing Xcode 4 and reinstalling it from the Mac App Store, but no dice. Deleting DerivedData didn’t help either. Any ideas?

Restarting my Mac seems to have fixed this.

Check "Build Settings" -> "Provisioning Profile". It should be "none" or some provisioning for Max OSX (if you're building for the app-store) . In my case it erroneously had "iOS Ad Hoc Provisioning Profile". This resolved this problem for me.
Note: I found this out by checking the syslog ("cat -f /var/log/system.log" in terminal, then start app). It wrote a crash report which had "...embedded provisioning profile not valid:..." among other lines. Checking the app container itself indeed showed an "embedded.provisionprofile" file, which triggered me to check the build settings for it.

I solved it by updating iOS. I was using JailBreak iOS version.

Related

Why Xcode can not attach to some programs?

i had to reinstall my MacBook Pro. I have installed the newest macOS & Xcode version so
macOS Monterey 12.0.1 (21A559)
and
Version 13.1 (13A1030d)
I'm programming Audio plugins so to test my plugins I'm normally running a DAW (Digital Audio Workstation) in my case I'm working the most of the time with Ableton or Bitwig.
So if I start the debuging process, I get the follow error:
Could not attach to pid XXXXXX
attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
If I have an eye to the console.app the the following lines:
[LaunchAttach] (3277) about to task_for_pid(2930)
error: [LaunchAttach] MachTask::TaskPortForProcessID
task_for_pid(2930) failed: ::task_for_pid ( target_tport = 0x0203, pid
= 2930, &task ) => err = 0x00000005 ((os/kern) failure)
macOSTaskPolicy: (com.apple.debugserver) may not get the task control
port of (BitwigStudio) (pid: 2930): (BitwigStudio) is hardened,
(BitwigStudio) doesn't have get-task-allow, (com.apple.debugserver) is
a declared debugger(com.apple.debugserver) is not a declared read-only
debugger
1 +0.000000 sec [0ccd/0103]: error: ::task_for_pid ( target_tport =
0x0203, pid = 2930, &task ) => err = 0x00000005 ((os/kern) failure)
err = ::task_for_pid ( target_tport = 0x0203, pid = 2930, &task ) =>
err = 0x00000005 ((os/kern) failure) (0x00000005)
I have done some research and found this:
Stackoverflow link about What does get-task-allow do
get-task-allow, when signed into an application, allows other
processes (like the debugger) to attach to your app. Distribution
profiles require that this value be turned off, while development
profiles require this value to be turned on (otherwise Xcode would
never be able to launch and attach to your app).
So there is nothing I can do to debug my programs with that software. Is that correct? :(
You can debug but you have to set the "Code Signing Inject Base Entitlements" to "Yes" for debugging
And then you have to add a provisioning profile. Go to developer.apple.com then select "Certificates, IDs & Profiles" to create a provisioning profile for the bundle ID you are testing.
This solved it for me on terminal
sudo DevToolsSecurity -enable
When you don't have access to the original source code or don't want to rebuild it, such as when developing plug-ins for another app (a DAW in your case), you can easily change the entitlements of the application as follows to enable debugging:
Read the current entitlements as follows (replace daw.app with the actual app name):
codesign --display --xml --entitlements daw.entitlements daw.app
Note: Run this in the Terminal app. It will create a file named daw.entitlements in the current folder. Run the command only once or delete any previously created daw.entitlements; otherwise the command keeps appending to the same file.
Open daw.entitlements in any text editor and insert the following text just before </dict></plist> at the end of the file:
<key>com.apple.security.get-task-allow</key><true/>
Note: If there’s already an entry with the same name, change its value from false to true instead of adding a new one.
Apply the new entitlements as follows (replace daw.app with the actual app name):
codesign -s - --deep --force --options=runtime --entitlements daw.entitlements daw.app
This should do it. In the unlikely chance that you already have a file named daw.entitlements in the same folder, use a different file name in all steps.
I tried all of these and had no luck until I figured out that I also had to disable SIP (system integrity protection) to attach to the audio server plugin I am working on.
Hopefully this helps someone to not lose a whole day on it as I did.

Visual Studio Xamarin free provisionning from XCode 7.3.1

I requested free provisionning on XCode with a certain bundle id. I used the same bundle id in Info.plist (Visual Studio Xamarin). I am able to build my IOS projet, but when I try to run it in XCode simulator, I get:
2017-03-28 22:02:16.564 simctl[3496:33726] There was an error parsing the Info.plist for the bundle at URL Info.plist -- file:///Users/XXXXX/Desktop/Phoneword.IOS.app/
NSCocoaErrorDomain - 3840
{type = immutable dict, count = 1,
entries =>
0 : {contents = "NSDebugDescription"} = {contents = "Cannot parse a NULL or zero-length data"}
}
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):
Failed to install the requested application
The bundle identifier of the application could not be determined.
Ensure that the application's Info.plist contains a value for CFBundleIdentifier.PL
My Info.plist is empty inside the app. Can someone help me ?

Xcode Instruments gives this error "Could not start script, target application is not frontmost."

I am using Xcode version 5.0 and trying to use instruments,when i am running the script which contains "var target = UIATarget.localTarget();"
the following error appears :" Could not start script, target application is not frontmost."
It's known issue:
The message “Could Not Start Script : Target app is not frontmost” may be displayed when attempting to capture a UI Automation script in Instruments against the iOS 7 Simulator.
If this occurs, close the trace document and create a new one. 15387075
Source: Xcode 5.0.2 Release notes

Xcode lldb error in lauch program

i get smilar error when i try launch my application (c++ command line) from xcode , (the application work fine from terminal .
XCode: Could not launch "APP_X_Y" - 'A' packet returned an error: -1
i tried every mentioned solution in above question but none of them helped me.
i finally found problem is launching using LLDB so GDB works fine. but i want to debug my program using LLDB and launch with default config in xcode.
the error is in following lldb function:
Error
PlatformRemoteGDBServer::LaunchProcess (ProcessLaunchInfo &launch_info)
{
Error error;
lldb::pid_t pid = LLDB_INVALID_PROCESS_ID;
m_gdb_client.SetSTDIN ("/dev/null");
m_gdb_client.SetSTDOUT ("/dev/null");
m_gdb_client.SetSTDERR ("/dev/null");
m_gdb_client.SetDisableASLR (launch_info.GetFlags().Test (eLaunchFlagDisableASLR));
const char *working_dir = launch_info.GetWorkingDirectory();
if (working_dir && working_dir[0])
{
m_gdb_client.SetWorkingDir (working_dir);
}
// Send the environment and the program + arguments after we connect
const char **argv = launch_info.GetArguments().GetConstArgumentVector();
const char **envp = launch_info.GetEnvironmentEntries().GetConstArgumentVector();
if (envp)
{
const char *env_entry;
for (int i=0; (env_entry = envp[i]); ++i)
{
if (m_gdb_client.SendEnvironmentPacket(env_entry) != 0)
break;
}
}
const uint32_t old_packet_timeout = m_gdb_client.SetPacketTimeout (5);
int arg_packet_err = m_gdb_client.SendArgumentsPacket (argv);
m_gdb_client.SetPacketTimeout (old_packet_timeout);
if (arg_packet_err == 0)
{
std::string error_str;
if (m_gdb_client.GetLaunchSuccess (error_str))
{
pid = m_gdb_client.GetCurrentProcessID ();
if (pid != LLDB_INVALID_PROCESS_ID)
launch_info.SetProcessID (pid);
}
else
{
error.SetErrorString (error_str.c_str());
}
}
else
{
**error.SetErrorStringWithFormat("**'A' packet returned an error: %i",** arg_packet_err);**
}
return error;
}
as you can see 'a' packet error is in lldb now question is how can fix this problem ? is there any solution to reinstall / reconfigure LLDB in xcode? can anyone find where is problem from lldb function.
i'm using latest Mac OS + Xcode 4.6.3 latest
please share your ideas .
This error happens when debugserver cannot launch the app you are trying to debug. debugserver launches, attaches, stops, inspects and controls the process - it is a small program with all of these responsibilities. It communicates to lldb (possibly inside Xcode) via the "gdb remote protocol", with some minor extensions.
If you've built your own lldb, chances are that debugserver is not properly code signed so it cannot launch apps.
If you've changed your /etc/hosts file, check that you have a line like 127.0.0.1 localhost in there. Some people have modified their /etc/hosts (I have no idea why) and removed this line, and this has caused problems for lldb trying to communicate with debugserver.
Otherwise, check the output in Console.app to see if there are any useful messages logged.
I was in the same situation. It happened after updating to Xcode 5 in my case.
After all it works fine now.
I followed the command line executions as per the comment from Jason Molenda.
When running "xcrun lldb ..." I got an error:
xcrun error failed to exec real xcrun. (no such file or directory)
After Googling, I figured this out:
xcode-select -print-path
/Developer
As my Xcode was not in there, I did:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
I don't know why, but it didn't work immediately in my case. After quitting Xcode, Terminal, etc., Xcode ran and debug worked as expected.

Xcode 4.2/IOS 5 Segmentation fault on exit of newly created project for Device

Since upgrading to XCode 4.2, I noticed a problem and I am at a lost on what to do. Here are the steps to reproduce:
1) Create a new xcode project, an iphone empty project with no options enabled.
2) Go to main.m and just make main into "return 0;"
3) Set minimum OS to 3.3 (I haven't updated my ipod touch 2nd gen yet)
4) Build and Run
It seems to build and run okay, but if you look in the device console in the xcode organizer you see the following errors:
<Warning>: 1 [0698/1403]: error: ::read ( 4, 0x3807f0, 1024 ) => -1 err = Bad file descriptor (0x00000009)
<Warning>: Application 'Test' exited abnormally with signal 11: Segmentation fault
I am thinking that perhaps I am missing a file? But I'm not sure what file I am missing. Everything else in the new project is set to the default. If I make it print out something then exit with 0, I can see the output, but then I do not see the exit code because it has crashed as above.
If I Build and Run for simulator I see no errors in the console output of the simulator.

Resources