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

Illegal instruction: 4 #75

Closed
jeeftor opened this issue Oct 18, 2015 · 9 comments · Fixed by #79
Closed

Illegal instruction: 4 #75

jeeftor opened this issue Oct 18, 2015 · 9 comments · Fixed by #79

Comments

@jeeftor
Copy link

jeeftor commented Oct 18, 2015

I'm getting the error Illegal instruction: 4 on a specific file. Is there a verbose mode so I can get more detail about what is causing the error? The project compiles fine (swift 2 Xcode 7)

@segiddins
Copy link
Collaborator

Can you share the file that's causing the issue? That'll probably be the easiest way to figure out where SK is choking

@jeeftor
Copy link
Author

jeeftor commented Oct 18, 2015

I was trying to render docs on a project - when i don't include this file it works (I was initially using Jazzy - which i guess uses source kitten). When I include this file i get a source kitten error

Parsing GDL90_Heartbeat.swift (20/34)
Illegal instruction: 4

//
//  GDL90_Heartbeat.swift
//  GDL90


import Foundation




/**
GDL90_Heartbeat message is described in section 3.1 of the GDL90 document.  It provides real-time indicitations to the Display of status operation of the GDL90
*/
public class GDL90_Heartbeat : GDL90_Message, CustomStringConvertible {


    public init(initData data : NSData) {
        super.init(initData: data, msgType: GDL90_MESSAGE_TYPE.HEARTBEAT)
    }

    /**
    GPS Position Valid: This bit is set to ONE by the GDL 90 when it has a valid position fix that is being included in its transmitted ADS-B messages. MFD Recommendation: Annunciate to the flight crew when this bit is ZERO, since it indicates that no valid ownship data is being transmitted to other participants.

    - Returns: whether position is valid
     */
    public var gpsPositionValid : Bool {
        get {
            return ((bytes[1] & 0x80) != 0)
        }

        set {
            if (newValue == true) {
                bytes[1] | 0x80
            } else {
                bytes[1] & 0x80
            }
        }
    }

    /**
    Maintenance Required: This bit is set to ONE when the GDL 90 has detected a problem that requires maintenance. MFD Recommendation: Post a message to the flight crew when this bit is ONE, to indicate that maintenance is required.
    */
    public var maintenanceRequired : Bool {
        get {
            return ((bytes[1] & 0x40) != 0)
        }
    }

    /**
    IDENT talkback: This bit is set to ONE when the GDL 90 has set the IDENT indication in its transmitted ADS-B messages. This provides feedback to the display when the IDENT function has been activated from the control source.
    */
    public var identTalkback : Bool {
        get {
            return ((bytes[1] & 0x20) != 0)
        }
    }



    /** SW Mod C Address Type

    This talkback bit is set to ONE to indicate that the GDL 90 is transmitting ADS-B messages using a temporary self-assigned (“anonymous”) address. This provides feedback to the display regarding which type of ownship identity is being transmitted.

    If SW Mod C is not installed, this bit is undefined and is always set to ZERO.
    */
    public var addrType : Bool {
        get {
        return ((bytes[1] & 0x10) != 0)
        }
    }

    /**
    GPS Battery Low: This bit is set to ONE to indicate that the GDL 90 needs maintenance to replace its internal GPS battery. The GDL 90 continues to be capable of normal operation, except that the time for initial GPS acquisition will be much longer than normal
    */
    public var gpsBatteryLowVoltage: Bool {
        get {
        return ((bytes[1] & 0x08) != 0)
        }
    }

    /**
    RATCS: This talkback bit is set to the present state of the Receiving ATC Services indication in the transmitted ADS-B messages. This provides feedback to the display regarding whether the RATCS feature is enabled and operating.

    If SW Mod C is not installed, this bit is undefined and is always set to ZERO.
    */
    public var atcServicesTalkBack : Bool {
        get {
        return ((bytes[1] & 0x04) != 0)
        }
    }


    /**
    UAT Initialized: This bit is set to ONE in all Heartbeat messages.
    */
    public var uatInitialized : Bool {
        get {
        return ((bytes[1] & 0x01) != 0)
        }
    }

    /**
     CSA Requested: When set to ONE, this bit acknowledges to the Display that the GDL 90 Conflict Situational Awareness (CSA) algorithm has been requested. See §3.2.2 for reference.
    */
    public var csaRequested : Bool {
        get {
        return ((bytes[2] & 0x40) != 0)
        }
    }

    /**
    CSA Not Available: When set to ONE, this bit indicates to the Display that the CSA algorithm has been requested but is not available.
    */
    public var csaNotAvailable : Bool {
        get {
        return ((bytes[1] & 0x20) != 0)
        }
    }

    /**
    UTC OK: This bit is set to ONE when the GDL 90 is using a valid UTC timing reference.
    */
    public var utcOK : Bool {
        get {
        return ((bytes[1] & 0x01) != 0)
        }
    }


    /**
    The Heartbeat message includes the current time-of-day in whole seconds elapsed since UTC midnight (0000Z). This requires a 17-bit data field.
    */
    public var secondsSinceMidnight : Int {

        /*
        The Heartbeat message includes the current time-of-day in whole seconds elapsed since UTC midnight (0000Z). This requires a 17-bit data field. The most significant bit (bit 16) is in Status Byte 2 bit 7. The remaining 16 bits are conveyed least significant byte first, using the two Time Stamp bytes.
        */


        let v = (UInt32(bytes[2] & 0x8) << 16) | (UInt32(bytes[5]) << 8 ) | UInt32(bytes[4])
        return Int(v);
    }
        /**
Two bytes are used to report the number of UAT messages received by the GDL 90 during the previous second. The count fields are formatted as follows:

a) Uplink receptions: Bits 7..3 of the first Message Count byte contain the count of Uplink Messages received. Bit 7 is the most significant bit.

b) Reserved: Bit 2 of the first Message Count byte is reserved, and is set to ZERO.

c) Basic and Long receptions: The total number of Basic and Long messages together is contained in a 10-bit field. The two most significant bits are in Bit 1..0 of the first Message Count byte, and the eight least significant bits are contained in the second Message Count byte. The counter value will hold at the maximum value if the number of received messages exceeds 1,023.
        */
    public var uatMsgCountUplinkReceived : Int {

        return Int(bytes[6] >> 3)

    }
            /**
Two bytes are used to report the number of UAT messages received by the GDL 90 during the previous second. The count fields are formatted as follows:

a) Uplink receptions: Bits 7..3 of the first Message Count byte contain the count of Uplink Messages received. Bit 7 is the most significant bit.

b) Reserved: Bit 2 of the first Message Count byte is reserved, and is set to ZERO.

c) Basic and Long receptions: The total number of Basic and Long messages together is contained in a 10-bit field. The two most significant bits are in Bit 1..0 of the first Message Count byte, and the eight least significant bits are contained in the second Message Count byte. The counter value will hold at the maximum value if the number of received messages exceeds 1,023.
        */
    public var uatMsgCountBasicLong : Int {

        let v = UInt16(bytes[6] & 0x3) << 8 | UInt16(bytes[7])
        return Int(v);
    }


    public var description : String {
        var ret : String =  ("GDL90_Heartbeat\n")
        ret +=  ("\tTimeStamp: \(self.secondsSinceMidnight)\n")
        ret +=  ("\tMsgCountUplink:  \(self.uatMsgCountUplinkReceived)\n")
        ret +=  ("\tMsgCountBasicLong:  \(self.uatMsgCountBasicLong)\n")

        ret += ("\tgpsPositionValid: [\(gpsPositionValid)]\n");
        ret += ("\tmaintenanceRequired: [\(maintenanceRequired)]\n");
        ret += ("\tidentTalkback: [\(identTalkback)]\n");
        ret += ("\taddrType: [\(addrType)]\n");
        ret += ("\tgpsBatteryLowVoltage: [\(gpsBatteryLowVoltage)]\n");
        ret += ("\tatcServicesTalkBack: [\(atcServicesTalkBack)]\n");
        ret += ("\tuatInitialized: [\(uatInitialized)]\n");
        ret += ("\tcsaRequested: [\(csaRequested)]\n");
        ret += ("\tcsaNotAvailable: [\(csaNotAvailable)]\n");
        ret += ("\tutcOK: [\(utcOK)]\n");

        return ret;
    }

}

@jeeftor
Copy link
Author

jeeftor commented Oct 19, 2015

I'm not 100% sure its actually the contents of this file that is causing the issue. It must be with my project structure because if my file only reads "Import Foundation" and nothing else i still get the error. Any verbose settings I can enable?

@AfricanSwift
Copy link

This is a small rendition is what caused my SourceKitten crash with illegal instruction: 4

extension NSColor {
    public var red: CGFloat {
        /// crash scenario -  This line crashes source kitten.
        let multiplier: CGFloat = 255.0
        return self.redComponent * multiplier
    }
}

@jpsim
Copy link
Owner

jpsim commented Nov 2, 2015

Thanks for sharing that code, @AfricanSwift! Sample code that reproduces an issue is extremely useful, so thanks for taking the time to provide that. #79 should resolve that particular issue of documenting declarations within a function body.

@jeeftor I'm still working on yours!

@jpsim
Copy link
Owner

jpsim commented Nov 2, 2015

Actually, @jeeftor, your issue is the same as @AfricanSwift, documenting declarations nested in a function declaration:

/**
The Heartbeat message includes the current time-of-day in whole seconds elapsed since UTC midnight (0000Z). This requires a 17-bit data field.
*/
public var secondsSinceMidnight : Int {

    /*
    The Heartbeat message includes the current time-of-day in whole seconds elapsed since UTC midnight (0000Z). This requires a 17-bit data field. The most significant bit (bit 16) is in Status Byte 2 bit 7. The remaining 16 bits are conveyed least significant byte first, using the two Time Stamp bytes.
    */


    let v = (UInt32(bytes[2] & 0x8) << 16) | (UInt32(bytes[5]) << 8 ) | UInt32(bytes[4])
    return Int(v);
}

So that's also resolved with #79.

@johncsnyder
Copy link

Hi there, I'm running into the same issue as above:

@jeeftor I'm not 100% sure its actually the contents of this file that is causing the issue. It must be with my project structure because if my file only reads "Import Foundation" and nothing else i still get the error. Any verbose settings I can enable?

this works:
sourcekitten complete --text ' ; import Foundation ; ' --offset 0

running this:
sourcekitten complete --text ' ; import Foundation ; ' --offset 23
gives me an Illegal instruction: 4, i.e. anywhere after the import statement, autocompleting something in the global scope. same with importing other frameworks.

It seems this issue has been closed... but I've tried with SourceKitten on both git HEAD and v0.10.0. Am I doing something stupid ?

Best, John

@norio-nomura
Copy link
Collaborator

@johncsnyder I have reproduced the issue.
The issue caused by that SourceKitService returns string in byte array that can not be decoded as NSUTF8StringEncoding.

@norio-nomura
Copy link
Collaborator

@johncsnyder I can't verify that is same issue as this.
So, I opened another issue for tracking that #184.

SteffenL pushed a commit to SteffenL/SourceKitten that referenced this issue Feb 13, 2019
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

Successfully merging a pull request may close this issue.

6 participants