分析 Mac OS X 内核核心转储第 2 部分

Geo*_*nov 3 macos kernel lldb

自从上一篇文章以来我有点感动无限听jabber事件?

现在我得到了正确的核心转储(似乎以前的所有内容都是不正确的)并且我可以进行回溯,但我无法加载此回溯的符号

所以,我所做的是

lldb
target create -d -c ~/Downloads/core-xnu-2050.48.12-10.41.20.195-71371911 /Volumes/KernelDebugKit/mach_kernel
bt

(lldb) bt
* thread #1: tid = 0x0000, 0xffffff8009abcecb, stop reason = signal SIGSTOP
* frame #0: 0xffffff8009abcecb
frame #1: 0xffffff8009a1d636
frame #2: 0xffffff8009d4e45f
frame #3: 0xffffff8009d4cf7d
frame #4: 0xffffff8009d9e585
frame #5: 0xffffff8009d59942
frame #6: 0xffffff8009d58ebd
frame #7: 0xffffff7f8b28c299
frame #8: 0xffffff8009d48dc1
frame #9: 0xffffff8009afc6ee
frame #10: 0xffffff8009b103ee
frame #11: 0xffffff8009b02bc9
frame #12: 0xffffff8009b03394
frame #13: 0xffffff8009de97ba
Run Code Online (Sandbox Code Playgroud)

但没有符号(尽管我从 KernelDebugKit/mach_kernel 加载了一个符号)。此外,例如,当我尝试运行paniclog时,我得到以下输出

(lldb) paniclog

************ LLDB found an exception ************
There has been an uncaught exception. A possible cause could be that remote connection has been disconnected.
However, it is recommended that you report the exception to lldb/kernel debugging team about it.
************ Please run 'xnudebug debug enable' to start collecting logs. ************

Traceback (most recent call last):
  File "/Volumes/KernelDebugKit/mach_kernel.dSYM/Contents/Resources/Python/lldbmacros/xnu.py", line 107, in _internal_command_function
    obj(cmd_args=stream.target_cmd_args)
  File "/Volumes/KernelDebugKit/mach_kernel.dSYM/Contents/Resources/Python/lldbmacros/xnu.py", line 527, in ShowPanicLog
    panic_buf_end = unsigned(kern.globals.debug_buf_ptr)
  File "/Volumes/KernelDebugKit/mach_kernel.dSYM/Contents/Resources/Python/lldbmacros/core/cvalue.py", line 345, in unsigned
    return val._GetValueAsUnsigned()
  File "/Volumes/KernelDebugKit/mach_kernel.dSYM/Contents/Resources/Python/lldbmacros/core/cvalue.py", line 295, in _GetValueAsUnsigned
    raise ValueError("Failed to read unsigned data. "+ str(self._sbval19k84obscure747) +"(type =" + str(self._sbval19k84obscure747_type) + ") Error description: " + serr.GetCString())
ValueError: Failed to read unsigned data. (char *) debug_buf_ptr = <mach_kernel[0xffffff8000801170] can't be resolved, mach_kernel in not currently loaded>
(type =char *) Error description: could not resolve value
(lldb) 
Run Code Online (Sandbox Code Playgroud)

那么,分析此类转储的正确方法是什么?文章还是什么?=)

Jas*_*nda 5

您使用什么版本的 lldb?这看起来应该可以工作 - Xcode 5.x 的 lldb 肯定可以工作,早期版本可能不会(我记不清内核核心文件调试支持何时完成 - 但我认为 Xcode 5 的 lldb 是它的开始)。

当 lldb 开始检查核心文件时,它会在核心文件中搜索内核二进制文件。如果找到,它会从“用户调试”切换到“内核调试”模式(具体来说 - 它选择 DynamicLoader 和 Platform 插件进行内核调试)。

一旦您检查到您正在使用最近的 lldb(例如,最新的 Xcode 5.x 更新为 lldb-310.2.x),您可以尝试直接在核心文件上运行 lldb,而无需指定内核二进制文件作为测试 -

% lldb -c core-xnu-blahblahwhatever--53821b67 
Kernel UUID: 9FEA8EDC-B629-3ED2-A1A3-6521A1885953
Load Address: 0xffffff802c400000
Run Code Online (Sandbox Code Playgroud)

当您看到Kernel UUID:Load Address:行时,这表明 lldb 在核心文件中找到了内核映像。您还可以使用platform status命令来确认选择了哪个平台:

(lldb) pla sta
  Platform: darwin-kernel
 Connected: no
 Debug session type: Mac OS X kernel debugging
 Kext directories: [ 0] "/System/Library/Extensions"
 Kext directories: [ 1] "/Library/Extensions"
 Kext directories: [ 2] "/Applications/Xcode.app/Contents/Symbols"
 Total number of kexts indexed: 818
(lldb) 
Run Code Online (Sandbox Code Playgroud)

当然,如果没有内核二进制文件,您就无法进行真正的内核调试 - 只是一个快速提示,您可以在命令行上指定核心文件和二进制文件,

% lldb -c core-xnu-blahblahwhatever--53821b67 /Volumes/KernelDebugKit/mach_kernel
Run Code Online (Sandbox Code Playgroud)

回溯中的地址看起来像内核核心文件会话,但由于某种原因,您使用的 lldb 在那里找不到内核。