X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3903760236c30e3b5ace7a4eefac3a269d68957c..008676633c2ad2c325837c2b64915f7ded690a8f:/tools/lldbmacros/process.py diff --git a/tools/lldbmacros/process.py b/tools/lldbmacros/process.py index 71108c100..906d47a7f 100644 --- a/tools/lldbmacros/process.py +++ b/tools/lldbmacros/process.py @@ -238,6 +238,19 @@ def GetTaskSummary(task, showcorpse=False): out_string += " " + GetKCDataSummary(task.corpse_info) return out_string +def GetThreadName(thread): + """ Get the name of a thread, if possible. Returns the empty string + otherwise. + """ + if int(thread.uthread) != 0: + uthread = Cast(thread.uthread, 'uthread *') + if int(uthread.pth_name) != 0 : + th_name_strval = Cast(uthread.pth_name, 'char *') + if len(str(th_name_strval)) > 0 : + return str(th_name_strval) + + return '' + @lldb_type_summary(['thread *', 'thread_t']) @header("{0: <24s} {1: <10s} {2: <20s} {3: <6s} {4: <6s} {5: <15s} {6: <15s} {7: <8s} {8: <12s} {9: <32s} {10: <20s} {11: <20s} {12: <20s}".format('thread', 'thread_id', 'processor', 'base', 'pri', 'sched_mode', 'io_policy', 'state', 'ast', 'waitq', 'wait_event', 'wmesg', 'thread_name')) def GetThreadSummary(thread): @@ -267,7 +280,6 @@ def GetThreadSummary(thread): if int(thread.static_param) : thread_ptr_str+="[WQ]" thread_id = hex(thread.thread_id) - thread_name = '' processor = hex(thread.last_processor) base_priority = str(int(thread.base_pri)) sched_priority = str(int(thread.sched_pri)) @@ -288,14 +300,10 @@ def GetThreadSummary(thread): sched_mode+=" BG" io_policy_str = "" + thread_name = GetThreadName(thread) if int(thread.uthread) != 0: uthread = Cast(thread.uthread, 'uthread *') - #check for thread name - if int(uthread.pth_name) != 0 : - th_name_strval = Cast(uthread.pth_name, 'char *') - if len(str(th_name_strval)) > 0 : - thread_name = str(th_name_strval) - + #check for io_policy flags if int(uthread.uu_flag) & 0x400: io_policy_str+='RAGE ' @@ -612,6 +620,12 @@ def GetProcSummary(proc): wq_idle_threads = -1 wq_req_threads = -1 process_name = str(proc.p_comm) + if process_name == 'xpcproxy': + for thread in IterateQueue(task.threads, 'thread *', 'task_threads'): + thread_name = GetThreadName(thread) + if thread_name: + process_name += ' (' + thread_name + ')' + break out_string += format_string.format(pid, proc_addr, " ".join([proc_rage_str, io_policy_str]), wq_num_threads, wq_idle_threads, wq_req_threads, process_name) return out_string @@ -1060,6 +1074,23 @@ def ShowAllTasks(cmd_args=None, cmd_options={}): print out_str ZombTasks() +@lldb_command('taskforpmap') +def TaskForPmap(cmd_args=None): + """ Find the task whose pmap corresponds to . + Syntax: (lldb) taskforpmap + Multiple -v's can be specified for increased verbosity + """ + if cmd_args == None or len(cmd_args) < 1: + raise ArgumentError("Too few arguments to taskforpmap.") + pmap = kern.GetValueFromAddress(cmd_args[0], 'pmap_t') + print GetTaskSummary.header + " " + GetProcSummary.header + for tasklist in [kern.tasks, kern.terminated_tasks]: + for t in tasklist: + if t.map.pmap == pmap: + pval = Cast(t.bsd_info, 'proc *') + out_str = GetTaskSummary(t) + " " + GetProcSummary(pval) + print out_str + @lldb_command('showterminatedtasks') def ShowTerminatedTasks(cmd_args=None): """ Routine to print a summary listing of all the terminated tasks @@ -1138,6 +1169,52 @@ def ShowTaskStacksCmdHelper(cmd_args=None, cmd_options={}): # EndMacro: showtaskstacks +def CheckTaskProcRefs(task, proc): + for thread in IterateQueue(task.threads, 'thread *', 'task_threads'): + if int(thread.uthread) == 0: + continue + uthread = Cast(thread.uthread, 'uthread *') + refcount = int(uthread.uu_proc_refcount) + uu_ref_index = int(uthread.uu_pindex) + if refcount == 0: + continue + for ref in range(0, uu_ref_index): + if unsigned(uthread.uu_proc_ps[ref]) == unsigned(proc): + print GetTaskSummary.header + " " + GetProcSummary.header + pval = Cast(task.bsd_info, 'proc *') + print GetTaskSummary(task) + " " + GetProcSummary(pval) + print "\t" + GetThreadSummary.header + print "\t" + GetThreadSummary(thread) + "\n" + + for frame in range (0, 10): + trace_addr = unsigned(uthread.uu_proc_pcs[ref][frame]) + symbol_arr = kern.SymbolicateFromAddress(unsigned(trace_addr)) + if symbol_arr: + symbol_str = str(symbol_arr[0].addr) + else: + symbol_str = '' + print '{0: <#x} {1: + """ + if cmd_args == None or len(cmd_args) < 1: + raise ArgumentError("No arguments passed") + + proc = kern.GetValueFromAddress(cmd_args[0], 'proc *') + + for t in kern.tasks: + CheckTaskProcRefs(t, proc) + for t in kern.terminated_tasks: + CheckTaskProcRefs(t, proc) + + return + @lldb_command('showallthreads') def ShowAllThreads(cmd_args = None): """ Display info about all threads in the system