Xcode 9.4 always breaks on __posix_spawn

Hi,


I am running into an issue where Xcode is always breaking when a system command is being executed. I don't have any breakpoints configured, yet it always breaks on '__posix_spawn'.


For example, if you run IBM Kitura's 'Hello World' (command line) example, you will immediately run in the issue. When you run the project, execution immediately breaks on gathering statistics (which does a number of command line executions):


[2018-06-13T10:12:36.900+02:00] [WARNING] [ConfigurationManager.swift:261 load(url:deserializerName:)] Unable to load data from URL /Users/me/Developer/Kitura/HelloKitura/config/mappings.json
SwiftMetrics: Error finding .build directory
SwiftMetrics: Error finding directory containing source code in 
[Wed Jun 13 10:12:36 2018] com.ibm.diagnostics.healthcenter.loader INFO: Swift Application Metrics
(lldb)


Which will always break on 'HelloKitura > Thread 1 > 0 __posix_spawn' with 'Thread 1: EXC_SOFTWARE (code=131072, subcode=0x0)':


libsystem_kernel.dylib`__posix_spawn:
    0x7fff54ba493c <+0>:  movl   $0x20000f4, %eax          ; imm = 0x20000F4
    0x7fff54ba4941 <+5>:  movq   %rcx, %r10
    0x7fff54ba4944 <+8>:  syscall
->  0x7fff54ba4946 <+10>: jae    0x7fff54ba4950            ; <+20>
    0x7fff54ba4948 <+12>: movq   %rax, %rdi
    0x7fff54ba494b <+15>: jmp    0x7fff54b9bb25            ; cerror
    0x7fff54ba4950 <+20>: retq  
    0x7fff54ba4951 <+21>: nop   
    0x7fff54ba4952 <+22>: nop   
    0x7fff54ba4953 <+23>: nop  


The underlying 'envplugin.cpp' does a couple of command line executions in order to gather system information (like 'sw_vers -productVersion'), which is causing xcode to break on line 5:


std::string getCommandOutput(std::string command) {
  FILE *fp;
  char str[40];
  std::stringstream output;
  fp = popen(command.c_str(), "r");
  while (fgets(str, sizeof(str), fp))
  {
    output << str;
  }
  pclose(fp);
  return output.str().c_str();
}


The same is also happening in a macOS app I am working on that also performs some command line executions:


let pipe = Pipe()
let process = Process()
process.executableURL = url
process.arguments = arguments
process.standardOutput = pipe
process.terminationHandler = { (process) in
    let data = pipe.fileHandleForReading.readDataToEndOfFile()
    guard let output = String(bytes: data, encoding: .utf8) else {
        seal.reject(MyError.errorExecutingProcess)
        return
    }
   
    let trimmedOutput = output.trimmingCharacters(in: .whitespacesAndNewlines)
    os_log("Executed %@ %@: %@", log: .default, type: .debug, url.filePath, arguments.joined(separator: " "), trimmedOutput)
    seal.fulfill(trimmedOutput)
}

do {
    try process.run()
} catch {
    os_log("Could not execute: %@ %@ (%@)", log: .default, type: .error, url.filePath, arguments.joined(separator: " "), error.reason)
    seal.reject(error)
}


Xcode execution just keeps breaking on every single process call (__posix_spawn), without having any breakpoints defined and breakpoints deactivated (⌘Y). When continueing execution all seems well (the program just does what it expected to do and the command line executions also work as expected apart from the breakpoint).


Does anybody have a clue as to why this happens, and -more importantly-, how to make sure it doesn't? 🙂

Replies

Ah, I think I found out why this is happening... I ran into this thread, and this appears to be related to the Cylance (AI anti virus) product which is also running on my machine. I don't think I can get rid of that, as this is company policy...


Does anybody have a workaround without uninstalling Cylance? Is it perhaps possible to ignore or disable this through lldb?

I'm seeing the same issue, and I would love to find a solution. My IT guy says they can add a workaround to ignore a particular file, but I don't think that's going to help in this case.

Did you raise the issue to Cylance ? Should write to their support.

I'm a bit late to the discussion, but this just started happening to me when running any generic xcode unit tests. In my case, I am running bitdefender, so the problem isn't likely cylance, but rather something apple has done with permissions on a library or something.


I build a brand new cocoa app project with unit tests and ran the test with bitdefender installed and they break in __posix_spawn


After uninstalling bitdefender, it went back to the normal behavior. In my case, it seems like it must be something in an Apple update over the last week or so.

In my case, it seems like it must be something in an Apple update over the last week or so.

That may be the case but you still need to take this up with the Bitdefender folks so that they can investigate and, if necessary, file a bug against Xcode or macOS. If you file a bug against Xcode, it’s likely to be returned as “talk to Bitdefender”.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Did you find a solution? I have Cylance running as well and am running in to the same problem.