在内核空间中显示远程线程的回溯

时间:2017-12-27 13:17:23

标签: multithreading debugging kernel lldb xnu

在内核空间调试时,我有时希望根据一组线程中的回溯帧来搜索线程,就像特定任务中的所有线程一样。

例如,获取kernel_task id

(lldb) showalltasks
task                 vm_map              ...command             
0xffffff800d828550   0xffffff800a1038d8  ...kernel_task         

转储属于kernel_task的所有线程

(lldb) showtaskthreads 0xffffff800d828550
task                 vm_map               ipc_space            #acts flags    pid       process             io_policy  wq_state  command
0xffffff800d828550   0xffffff800a1038d8   0xffffff800d5d17c0     140            0   0xffffff8007abb460                -1 -1 -1    kernel_task         
thread                   thread_id  processor            base   pri    sched_mode      io_policy       state    ast          waitq                            wait_event           wmesg                thread_name         
    0xffffff8007acf098       0x65       0xffffff8007a8a7b8   92     92     fixed bound                     WU       L            0xffffff804119e550               0xffffff8007a87a30 <vm_page_free_wanted>                                          
    0xffffff800d83f4c0       0x66       0xffffff8007a8a7b8   0      0      fixed bound                     RI       L                                                                                                           
    0xffffff800d83f958       0x67       0xffffff8041ad6000   95     95     fixed                           WU       L            0xffffff804119c240               0xffffff8007303840 <sched_timeshare_maintenance_continue>                      sched_maintenance_thread
    0xffffff800d83fdf0       0x68       0xffffff8041ad6000   80     80     fixed                           WU       L            0xffffff804119e850               0xffffff8007acf9f0                                            
    0xffffff800d83f028       0x69       0xffffff8007a8a7b8   93     93     fixed                           WU                    0xffffff804119e5e0               0xffffff8007acfa08                                            

现在我可以看到线程ID以及有关线程的许多其他信息,但是我如何观察线程的回溯?

1 个答案:

答案 0 :(得分:1)

无论出于何种原因,xnu内核调试宏都使用&#34; thread&#34;和&#34;激活&#34; (在谈论线程时,缩写为&#34; act&#34;)术语。有了这些信息,您很快就会找到:

showactstack <activation>

其中<activation>是线程地址(指针值,而不是ID),例如showactstack 0xffffff8007acf098

还请注意以下有用的命令:

showtaskstacks <task address>
showtaskstacks -F <taskname>

这些显示所有与任务/进程相对应的堆栈。

showallstacks

这将打印系统中所有线程的内核堆栈。请注意:这个可能需要一段时间才能完成。 (IIRC它比Firewire更快,而不是以太网kdp,但仍然需要几分钟。)

相关问题