touchlab / xcode-kotlin

Kotlin Native Xcode Plugin
https://touchlab.co/xcodekotlin
Apache License 2.0
1.15k stars 47 forks source link

Xcode breakpoints indicating that the code is not compiled #91

Closed sean-howard closed 1 year ago

sean-howard commented 1 year ago

Hey folks, My team has been using this plugin reliably for a year or so but recently we've found when we set breakpoints in our shared Kotlin code and press run the breakpoints turn to the dotted blue outline state indicating that the code is never executed/compiled - it definitely is getting executed!

We've tried uninstalling and reinstalling the plugin through the CLI as well as reinstalling with Homebrew but with no luck. We've also reimported the folder references to the shared code in our Xcode project too.

Interestingly the KaMPKit sample project breakpoints perfectly fine. Any ideas on how to resolve?

Details

xcode-kotlin info

Installed plugin version:   1.2.1
Bundled plugin version:     1.2.1

Language spec installed: Yes
LLDB init installed: Yes
LLDB Xcode init sources main LLDB init: No

Installed Xcode versions:
✔   Xcode 14.2 (14C11a) C91F3560-00E7-4749-8E3F-4D83B1496051    /Applications/Xcode.app

In addition we've also made sure our preprocessor macros for debug is set to: DEBUG=1.

Expected result

Breakpoints get triggered when code is executed.

Current state

Xcode is indicating that the code is never executed.

Screenshots

Screenshot 2022-12-21 at 10 54 40 Screenshot 2022-12-21 at 10 25 55 image Screenshot 2022-12-21 at 11 08 29
kpgalligan commented 1 year ago

We had discussed this internally but holidays, etc. Anyway, the "plugin" uses lldb, and relies on Xcode to set breakpoints based on file line numbers. All of that is handled by lldb and whatever the Kotlin compiler writes out for lldb. That's a long way to say, if some breakpoints work and others don't, reinstalling the plugin won't do much. When you update Xcode, you need to refresh the uuid, but if some breakpoints are working, that shouldn't be an issue.

It looks like you're using Xcode 14.2 and judging by the date, I assume you're on Kotlin 1.7.x. 1.7.x only supports Xcode 13.x. We've run into issues with cinterop and Xcode 14.x on Kotlin 1.7.20. I don't know if that's contributing, but installing 13.4.1 and clean building everything (including the kotlin build dir) would be something to try. The Kotlin compiler uses the Xcode build tools, so it's important to stay with supported versions.

Outside of that, it looks like all of your code is built locally, but that's another potential cause of this. lldb writes absolute paths of source files in debug binaries, so if your binary is built on CI, or built locally but you're pointing to source in a different folder for some reason, breakpoints won't work. That's not a Kotlin-specific issue. Swift, etc, same.

Outside of those, there's not much we can do without a repro. As you've stated, this works for KaMP Kit and other projects we use it for.

sean-howard commented 1 year ago

Ah okay thanks for detailed response @kpgalligan! Looks like this issue has coincided with an upgrade to Xcode 14.2 then. Sadly we're unable to revert to an older version of Xcode right now due to some Swift 5.7 language features we're leveraging.

Is it safe to assume that upgrading to Kotlin 1.8 would play friendly with Xcode 14.x?

kpgalligan commented 1 year ago

Well, "officially" 14.1, but I'm guessing it'll be generally OK with 14.2.

Source: https://kotlinlang.org/docs/whatsnew18.html#kotlin-native

sean-howard commented 1 year ago

Closing until I'm able to test using Kotlin 1.8, thanks for the information!

feiliu123 commented 1 year ago

I have encountered the same problem, Xcode 14.2,mac M1,koltion 1.8.21, there is further progress on this problem, has it been solved? If possible, could you share your experience? Thanks a million