Chap 16 講解了如何顯示出來(lái)蘋(píng)果的調(diào)試窗口 UIDebuggingInformationOverlay
敛助,內(nèi)容最后当船,作者提到他自己的lldb_commands
里提供了python腳本核偿,可以直接完成在模擬器或者真機(jī)上顯示出這個(gè)Overlay壹士,嘗試了一下筑公,簡(jiǎn)單記錄了步驟颓鲜。
lldb_commands在這里。
模擬器是 iOS 11.2
如何查看模擬器里Apple原生App的 process
名稱:
1, 用lldb隨便連接一個(gè)已經(jīng)知道process name的App:
flora:~ flora $ lldb -n Maps
(lldb) process attach --name "Maps"
成功連上后棚放,控制臺(tái)輸出信息的最底部枚粘,出現(xiàn):
Executable module set to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/Maps.app/Maps".
Architecture set to: x86_64h-apple-ios.
復(fù)制地址:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications
并在控制臺(tái)用open
命令打開(kāi), 進(jìn)入到Finder
, Applications
目錄中顯示了模擬器自帶的app.
2, 查找自己要找的App, 如果不確定找的對(duì)不對(duì),可以右鍵打開(kāi)包查看是不是自己需要的飘蚯。
3, 我要找的是Calendar
, 直接lldb -n Calendar
會(huì)報(bào)錯(cuò):
(lldb) process attach --name "Calendar"
error: attach failed: could not find a process named Calendar
可見(jiàn)它的名字不是Calendar
4, 通過(guò)上面的方法, 在Applications
目錄里找到了MobileCal.app
, 試一下:
# lldb -n MobileCal
(lldb) process attach --name "MobileCal"
Process 52308 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x000000011689c34a libsystem_kernel.dylib` mach_msg_trap + 10
libsystem_kernel.dylib`mach_msg_trap:
-> 0x11689c34a <+10>: ret
0x11689c34b <+11>: nop
libsystem_kernel.dylib'mach_msg_overwrite_trap: 0x11689c34c <+0>: mov r10, rcx
0x11689c34f <+3>: mov eax, 0x1000020
0x11689c354 <+8>: syscall
0x11689c356 <+10>: ret
0x11689c357 <+11>: nop
libsystem_kernel.dylib'semaphore_signal_trap: 0x11689c358 <+0>: mov r10, rcx
Target 0: (MobileCal) stopped.
Executable module set to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal".
Architecture set to: x86_64h-apple-ios.
attach成功
5, 顯示overlaywindow
(lldb) overlaydbg
Displaying UIDebuggingInformationOverlay... resume execution
(lldb) continue
Process 52308 resuming
在iphone x 模擬器上截屏如下:
6, 這是一次就成功的情況, 我第一次執(zhí)行lldb -n MobileCal
時(shí),遇到了一個(gè)問(wèn)題福也,提示attach失斁种琛:
flora:~ flora $ lldb -n MobileCal
(lldb) process attach --name "MobileCal"
error: attach failed: more than one process named MobileCal:
PID PARENT USER TRIPLE ARGUMENTS
====== ====== ========== ======================== ============================
52308 587 flora x86_64-apple-macosx /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal
20201 20091 flora x86_64-apple-macosx /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal
只能使用pid進(jìn)行attach。
(lldb) process attach --pid 52308
Process 52308 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x000000011689c34a libsystem_kernel.dylib` mach_msg_trap + 10
libsystem_kernel.dylib`mach_msg_trap:
-> 0x11689c34a <+10>: ret
0x11689c34b <+11>: nop
libsystem_kernel.dylib'mach_msg_overwrite_trap: 0x11689c34c <+0>: mov r10, rcx
0x11689c34f <+3>: mov eax, 0x1000020
0x11689c354 <+8>: syscall
0x11689c356 <+10>: ret
0x11689c357 <+11>: nop
libsystem_kernel.dylib'semaphore_signal_trap: 0x11689c358 <+0>: mov r10, rcx
Target 0: (MobileCal) stopped.
Executable module set to "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Applications/MobileCal.app/MobileCal".
Architecture set to: x86_64h-apple-ios.
attach 成功暴凑。
(lldb) overlaydbg
Displaying UIDebuggingInformationOverlay... resume execution
(lldb) continue
Process 52308 resuming
很奇怪的現(xiàn)象是峦甩,此時(shí)使用另外一個(gè)控制臺(tái),直接執(zhí)行 lldb -n MobileCal
就能成功attach上.
如果剛才指定pid時(shí)现喳,指定另外一個(gè)呢凯傲?
(lldb) process attach --pid 20201
There is a running process, detach from it and attach?: [Y/n] y
Process 52308 detached
Process 20201 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
frame #0: 0x000000010b72834a libsystem_kernel.dylib` mach_msg_trap + 10
libsystem_kernel.dylib`mach_msg_trap:
-> 0x10b72834a <+10>: ret
0x10b72834b <+11>: nop
libsystem_kernel.dylib'mach_msg_overwrite_trap: 0x10b72834c <+0>: mov r10, rcx
0x10b72834f <+3>: mov eax, 0x1000020
0x10b728354 <+8>: syscall
0x10b728356 <+10>: ret
0x10b728357 <+11>: nop
libsystem_kernel.dylib'semaphore_signal_trap: 0x10b728358 <+0>: mov r10, rcx
Target 0: (MobileCal) stopped.
看樣子也是成功的, 但是想要查看overlay是,卻不能夠:
(lldb) overlaydbg
Failure, womp
看來(lái)這個(gè)進(jìn)程不能顯示overlay嗦篱,那么第一個(gè)嘗試的pid就是當(dāng)前正在前臺(tái)的Calendar的進(jìn)程了.
當(dāng)然冰单,此時(shí)在另外的控制臺(tái)直接lldb -n MobileCal
也是能夠成功attach到Calendar的。
7, 如果是有源碼的App, 直接在Schemes
中查看Executable
就是它進(jìn)程的名稱, 不需要額外的查看灸促。
8, 模擬器里安裝AppStore上的應(yīng)用有點(diǎn)困難, 就不考慮了诫欠。
9, 真機(jī)環(huán)境 iPhone 6p, iOS 11.2
運(yùn)行我自己的程序,然后點(diǎn)『暫驮≡裕』進(jìn)入lldb調(diào)試環(huán)境, 輸入: overlaydbg:
(lldb) overlaydbg
Displaying UIDebuggingInformationOverlay... resume execution
(lldb) continue
Process 5240 resuming
真機(jī)成功顯示debuggingOverlay
荒叼。
第一次執(zhí)行報(bào)了兩個(gè)python的錯(cuò)誤(手慢沒(méi)幾下來(lái)), 再次執(zhí)行就成功了,也沒(méi)有再出現(xiàn)錯(cuò)誤, 可惜。