3 Replies
      Latest reply on Jun 14, 2018 9:34 AM by Claude31
      .jeroen. Level 1 Level 1 (0 points)



        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


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


            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;
          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 {
            let trimmedOutput = output.trimmingCharacters(in: .whitespacesAndNewlines)
            os_log("Executed %@ %@: %@", log: .default, type: .debug, url.filePath, arguments.joined(separator: " "), trimmedOutput)
        do {
            try process.run()
        } catch {
            os_log("Could not execute: %@ %@ (%@)", log: .default, type: .error, url.filePath, arguments.joined(separator: " "), error.reason)


        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?