How to print logs in Xcode's lldb debugger from extension?
问题:
回答1:
Simple answer:
log messages are not printed, however you can stop at breakpoints, and then print everything using lldb.
- Run your app
- While the app is running, go to Debug -> Attach to process by PID or name
- Write the name or bundle id of your extension and click attach
- Then run your extension with any way you can do this on your device.
- Wait for debugger to stop the extension at breakpoint.
回答2:
You shouldn't need to attach to your app extension by hand like this. Xcode should take care of all this automatically.
Look at the run scheme editor for your extension scheme. The executable will either be set to your app, or to "Ask on Launch". In either case, running the extension target will end up launching the app you have chosen.
Go to that app on your device, create/choose whatever it is in the app that you want to share, click the share icon, choose your extension in the list of active sharing extensions. Then when your sharing extension starts up the debugger will automatically attach to it. This may take a couple of seconds, but you'll see your extension with all its threads show up in the Debug Navigator, and if you set any breakpoints it should stop at them.
If you do it this way, the debugger will also hook up to stdout so you'll see your log messages in the debugger console.
回答3:
If you are debugging on a device you can open the Device Manager using Command, Shift, 2 and view the console messages there. Select your device.
If you are debugging on a simulator, the messages go to the system log. You can open that from the Simulator using Command / or "Open System Log" from the Simulator Debug menu.