Use `lldb` to launch macOS applications
Fixes https://github.com/sweetpad-dev/sweetpad/issues/47
Sorry for the previous PR originally I thought the issue was a code-signing one and went down a rabbit hole. This fix is much simpler and directly fixes my issues.
Only, problem I'm seeing with this is that we lose the stderr and stdout. I could open the executable directly instead of app bundle and this would open an external terminal session which would show stdout and stderr but this isn't a nice solution as it takes you out of vscode.
Ok, one solution that works is to use lldb instead of open or executing the application directly. This mirrors Xcode's "Run" (Cmd+R) action which builds, runs and attaches a debugger. While this is a behaviour change it's actually what iOS/macOS developers would expect Run to do anyway.
I would also suggest the same is done for apps running in the iOS simulator. Having to run and then later attach the debugger is problematic for debugging events that happen at launch time. However this PR doesn't make that change.
For some reason, the version with the LLDB debugger doesn't work for me. Maybe I should give it a chance tomorrow.
Also, I’ve found a way to redirect stdout, but I haven't tried how it would work in vscode:
open -W --stdout $(tty) /Users/hyzyla/Library/Developer/Xcode/DerivedData/ControlRoom-gdvrildvemgjaiameavxoegdskby/Build/Products/Debug/Control\ Room.app/
That's interesting, I personally like the launching with debug session option as this not only fixes the issues I was having it's also representative to how Xcode works when running the app. It always starts a debug session, this was already a pain point for me using this library having to manually attach the debugger.
@hyzyla what error did you see when trying to launch the app using lldb?
For some reason, the version with the LLDB debugger doesn't work for me. Maybe I should give it a chance tomorrow.
Also, I’ve found a way to redirect stdout, but I haven't tried how it would work in vscode:
open -W --stdout $(tty) /Users/hyzyla/Library/Developer/Xcode/DerivedData/ControlRoom-gdvrildvemgjaiameavxoegdskby/Build/Products/Debug/Control\ Room.app/
This looks like a great quick fix, maybe we could add new build options (run with debugger) and run (without debugging) that way we can choose.
Technically if you honour the selected scheme sweetpad should attach the debugger if the scheme has that Debug executable option enabled:
Currently, the run command ignores this. I think it should honour this and use lldb as per my PR if this option is enabled in the scheme otherwise use the open command. This should be the same for running apps in the simulator too.
I am going to close this, for now, will have another PR up shortly that doesn't break existing functionality