如何通过扩展使日志打印出现在 Xcode 的 lldb 调试器中?
最佳答案
简单的回答:
- 不会打印日志消息,但是您可以在断点处停止,然后使用 lldb 打印所有内容。
- 运行您的应用
- 在应用运行时,转到调试 -> 按 PID 或名称附加到进程
- 写下您的扩展名(因为 bundle-id 不起作用!?),然后单击“附加”。
- 然后以您可以在设备上执行此操作的任何方式运行您的扩展程序。
- 等待 Xcode 的调试器在断点处停止扩展,但有些可能需要调用
waitForDebugger
(这是一个自定义函数,请参见下面的逻辑)。
等待调试器示例
public static func isDebuggerAttached() -> Bool {
// Buffer for "sysctl(...)" call's result.
var info = kinfo_proc()
// Counts buffer's size in bytes (like C/C++'s `sizeof`).
var size = MemoryLayout.stride(ofValue: info)
// Tells we want info about own process.
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
// Call the API (and assert success).
let junk = sysctl(&mib, UInt32(mib.count), &info, &size, nil, 0)
assert(junk == 0, "sysctl failed")
// Finally, checks if debugger's flag is present yet.
return (info.kp_proc.p_flag & P_TRACED) != 0
}
@discardableResult
public static func waitForDebugger(_ timeout: Int = 30000) -> Bool {
var now: UInt64 = DispatchTime.now().uptimeNanoseconds
let begin = now
repeat {
if isDebuggerAttached() {
// Wait a little bit longer,
// because early breakpoints may still not work.
Thread.sleep(forTimeInterval: 3.0)
return true
}
Thread.sleep(forTimeInterval: 0.1)
now = DispatchTime.now().uptimeNanoseconds
} while Double(now - begin) / 1000000.0 < Double(timeout);
return false;
}
关于ios - 如何调试 iOS 扩展 (.appex)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33524051/