Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'sourcekitten complete --text...' terminated by signal SIGILL (Illegal instruction) #97

Closed
terhechte opened this issue Nov 11, 2015 · 2 comments

Comments

@terhechte
Copy link
Contributor

Hey, I ran into this bug and I'm not sure what's the best way of solving it. When I try

sourcekitten complete --text "struct a { var u: Int = 0 } ; let x = a() ; x." --offset 45

Then I get the following error:

'sourcekitten complete --text...' terminated by signal SIGILL (Illegal instruction)

I did some investigation and added a unit test, that does exactly the same:

    func testSimpleCodeCompletion2() {
        let file = "\(NSUUID().UUIDString).swift"
        let contents = "struct a { var u: Int = 0 } ; let x = a() ; x."
        let completionItems = CodeCompletionItem.parseResponse(
            Request.CodeCompletionRequest(file: file, contents: contents, offset: Int64(contents.characters.count) - 1,
                arguments: ["-c", file, "-sdk", sdkPath()]).send())
        print(String(completionItems))
        compareJSONStringWithFixturesName("SimpleCodeCompletion",
            jsonString: String(completionItems))
    }

That generates the correct completions.

So I ran sourcekitten in debug mode to see where it fails. What happens is that in SwiftXPC.swift the fromXPC(xpcObject: xpc_object_t) -> XPCDictionary assumes that xpc_object_t is of type xpc_dictionary_t. However, when running on the commandline with the above arguments, it is actually a xpc_data_t:

ct: xpc_object_t) -> XPCDictionary {
    var dict = XPCDictionary()
    var dx =  NSData(bytes: xpc_data_get_bytes_ptr(xpcObject), length: xpc_data_get_length(xpcObject))
    let abc = String(data: dx, encoding: NSUTF8StringEncoding)
   print(abc)
...
 }

This will print:
"\x01error when parsing the compiler arguments\0"

So apparently between the unit test invocation and the command line invocation, something goes wrong that causes a wrong return type from the xpc call.

(I'm using a git-cloned version of the sourcekitten repo master branch, head). Also, on the machine where this happens, I'm on 10.10 running the Xcode 7.1 gold, the xcode-select is properly set to /Applications/Xcode.app)

@terhechte
Copy link
Contributor Author

Addendum, I printed out the parameters to CodeCompletionRequest

Commandline:
F8DB6E0E-6D5F-4930-A7F2-0FA9EE9AD0CF.swift
struct a { var u: Int = 0 } ; let x = a() ; x.
45
["-c", "F8DB6E0E-6D5F-4930-A7F2-0FA9EE9AD0CF.swift", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"]

Unit Test:
F5341891-7247-401B-AEE6-EC4444DAE482.swift
struct a { var u: Int = 0 } ; let x = a() ; x.
45
["-c", "F5341891-7247-401B-AEE6-EC4444DAE482.swift", "-sdk", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk"]

They're really the same. Only that running it via the commandline runs into that weird error.

terhechte added a commit to terhechte/SourceKitten that referenced this issue Nov 11, 2015
There was an error when appending the sdk path
@terhechte
Copy link
Contributor Author

I found the issue and created a PR :)

terhechte added a commit to terhechte/SourceKitten that referenced this issue Nov 11, 2015
S2dentik pushed a commit to S2dentik/SourceKitten that referenced this issue Nov 13, 2015
There was an error when appending the sdk path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant