Hi! I’m having pretty hard time debugging KMM common module on iOS. I can make app compile and run, ...
j
Hi! I’m having pretty hard time debugging KMM common module on iOS. I can make app compile and run, debugger attached, however it: • ignores all line breakpoints • only possible to break on function entry points • when it finaly stops I get into Assembly view • stop on exception in Xcode works (also in assembly view usually) • Kotlin native library APIs usually opens in as Kotlin code when debugging I have debug symbols in kotlin module and in iOS app. Everything looks good, yet it does not work from Android Studio neither. From what I have found out it looks like there is some kind of problem with dSYM debug symbols for llvm generated code from the kotlin library. All .swift files are readable. Most of Kotlin standard library is readable. I have tried to fiddle in Xcode with optimization, linking optimization, debug symbols stripping, etc. Everything is turned off. I have
embedBitcode("marker")
enabled for my binaries. What do I do wrong? This is so frustrating.
Copy code
gradle:7.4.0, OpenJDK@11, Android Studio 2022.1.1, Xcode 14.2, MacOS 13.1 (ARM)
l
You need to install TouchLab’s xcode-kotlin tool to get breakpoints working from XCode.
p
Here’s the xcode-kotlin plugin link - https://github.com/touchlab/xcode-kotlin#installation
l
How is the app setup? Are you using an XCode project with embed framework? Cocoapods?
j
@Landry Norris Thanks for reply. I already have that plugin. It misses all breakpoints even in the [example application](https://github.com/touchlab/KaMPKit). I can only stop on exception and I get into the assembly instead of Kotlin code. On the internet I have found many guides how to debug (and all show that it should work out-of-the box), but most of them are from 2020-2021. So guess there is something wrong with the current versions.
@Landry Norris I have tried both. Same results. My project is using directly framework. The Example application (https://github.com/touchlab/KaMPKit) uses the cocoapods. Result is the same. See attached screenshots.
l
Did you run the steps to set xcode-kotlin up properly? If you re-installed or upgraded XCode, you need to run sync.
j
Yep, all upgraded, reinstalled. It highlights code, so I can see it is active. Strange is that I can see only assembly-only also from Android Studio. (screenshots in my original post)
l
In that case, #touchlab-tools may have a better answer.
j
I guess there is a some kind of incompatibility. Definitely there are some kind of debug symbols available, as there is name of functions in assembly (see screens). However it does not map to kotlin files (even in stack trace).
l
I’d imagine TouchLab’s KampKit and xcode-kotlin tools would work together, but iOS is the biggest cause of pain in my life right now, so I get things not working on iOS.
j
Strange is that this functionality is broken in Android Studio and the Xcode plugin. (even for the example app) running on OpenJDK@11
@Landry Norris That is why I tried to compile and debug that example app. But I was successful only partially, as I was not able to debug the actual kotlin code. Only assembly. Does the debugging feature anywhere works for you? Could you share more details of your setup? Could you debug the example application from touchlabs?
l
I haven’t tried KampKit in a long while. I setup xcode-kotlin for one of my work projects a while back without issues (XCode+cocoapods, multimodule), but I haven’t needed breakpoints in iOS for a bit.
j
@Landry Norris Could you please try to run and put breakpoint anywhere in the KampKit example app? And share the result?
l
Unfortunately, I’m about to leave for the weekend, and won’t have a computer with me, but I can try KampKit on Monday and let you know. I can confirm that breakpoints work in XCode on an app at work, as I just tested this.
I tested on an iPhone 14 simulator. I added the kotlin module files to xcode, set a breakpoint, and ran the app. It stopped at the breakpoint and showed local variables in the variables window.
k
I also don’t have time right now to try this out, but if you’re using KaMP Kit you’re probably on Kotlin 1.7.20, but you’re using Xcode 14.2, for which we’ve heard there have been issues. Kotlin 1.8 supports 14.1, but 1.7.x only supports Xcode 13.x. We’ve directly had issues with cinterop using 14.x with Kotlin 1.7.x, and I have heard from others of potential debugging issues.
j
To be sure I have synced the plugin again, no change in Xcode. And tried to debug sources. No changes. Line breakpoint could not be placed anywhere into the Kotlin code.
I have tried to upgrade to Kotlin 1.8.0, by using Android Studio Canary and EAP Kotlin plugin. Situation is even worse in Android Studio. After upgrade placing breakpoints on function entry points does not stop anymore. After upgrade I can stop the app only by SIGSTOP (pause button).
k
Hello! I see you are trying to debug code near with coroutines' machinery. right? Currently KN debugger doesn't work well with coroutines. that's true 😞 Though, it should work with plain straightforward kotlin code inside a coroutine.
j
The code I try to debug is not in corutine. It is plain good-old direct call. :)
k
Looking at this now…
k
I am fixing the problem right now.
Fixed and may be used in the new release 0.5.2 https://youtrack.jetbrains.com/issue/KT-55988
image.png
k
That link shows not found. Is it a private issue?
k
fixed it
j
Thank you, very much! Will test it in my environment this week hopefully.
986 Views