]> git.saurik.com Git - apple/xnu.git/blobdiff - tools/lldbmacros/process.py
xnu-4570.51.1.tar.gz
[apple/xnu.git] / tools / lldbmacros / process.py
old mode 100644 (file)
new mode 100755 (executable)
index b4c85f9..b86e1a8
@@ -9,6 +9,7 @@ from utils import *
 from core.lazytarget import *
 import time
 import xnudefines
+import memory
 
 def GetProcNameForTask(task):
     """ returns a string name of the process. if proc is not valid "unknown" is returned
@@ -170,22 +171,24 @@ def GetASTSummary(ast):
         B - AST_BSD
         K - AST_KPERF
         M - AST_MACF
-        C - AST_CHUD
-        C - AST_CHUD_URGENT
         G - AST_GUARD
         T - AST_TELEMETRY_USER
         T - AST_TELEMETRY_KERNEL
         T - AST_TELEMETRY_WINDOWED
         S - AST_SFI
+        D - AST_DTRACE
+        I - AST_TELEMETRY_IO
+        E - AST_KEVENT
     """
     out_string = ""
     state = int(ast)
     thread_state_chars = {0x0:'', 0x1:'P', 0x2:'Q', 0x4:'U', 0x8:'H', 0x10:'Y', 0x20:'A',
-                          0x40:'L', 0x80:'B', 0x100:'K', 0x200:'M', 0x400:'C', 0x800:'C',
-                          0x1000:'G', 0x2000:'T', 0x4000:'T', 0x8000:'T', 0x10000:'S'}
+                          0x40:'L', 0x80:'B', 0x100:'K', 0x200:'M',
+                          0x1000:'G', 0x2000:'T', 0x4000:'T', 0x8000:'T', 0x10000:'S',
+                          0x20000: 'D', 0x40000: 'I', 0x80000: 'E'}
     state_str = ''
     mask = 0x1
-    while mask <= 0x10000:
+    while mask <= 0x80000:
         state_str += thread_state_chars[int(state & mask)]
         mask = mask << 1
 
@@ -216,6 +219,8 @@ def GetTaskSummary(task, showcorpse=False):
     task_flags = ''
     if hasattr(task, "suppression_generation") and (int(task.suppression_generation) & 0x1) == 0x1:
         task_flags += 'P'
+    if hasattr(task, "effective_policy") and int(task.effective_policy.tep_sup_active) == 1:
+        task_flags += 'N'
     if hasattr(task, "suspend_count") and int(task.suspend_count) > 0:
         task_flags += 'S'
     if hasattr(task, 'task_imp_base') and unsigned(task.task_imp_base):
@@ -238,6 +243,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):
@@ -257,7 +275,6 @@ def GetThreadSummary(thread):
 
         policy flags:
         B - darwinbg
-        L - lowpri cpu
         T - IO throttle
         P - IO passive
         D - Terminated
@@ -268,7 +285,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))
@@ -289,14 +305,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 '
@@ -305,16 +317,13 @@ def GetThreadSummary(thread):
         
         io_policy_str = ""
         
-        if int(thread.effective_policy.darwinbg) != 0:
+        if int(thread.effective_policy.thep_darwinbg) != 0:
             io_policy_str += "B"
-        if int(thread.effective_policy.lowpri_cpu) != 0:
-            io_policy_str += "L"
-        
-        if int(thread.effective_policy.io_tier) != 0:
+        if int(thread.effective_policy.thep_io_tier) != 0:
             io_policy_str += "T"
-        if int(thread.effective_policy.io_passive) != 0:
+        if int(thread.effective_policy.thep_io_passive) != 0:
             io_policy_str += "P"
-        if int(thread.effective_policy.terminated) != 0:
+        if int(thread.effective_policy.thep_terminated) != 0:
             io_policy_str += "D"
                 
     state = int(thread.state)
@@ -376,6 +385,8 @@ def GetCoalitionFlagString(coal):
         flags.append('reaped')
     if (coal.notified):
         flags.append('notified')
+    if (coal.efficient):
+        flags.append('efficient')
     return "|".join(flags)
 
 def GetCoalitionTasks(queue, coal_type, thread_details=False):
@@ -401,7 +412,7 @@ def GetCoalitionTasks(queue, coal_type, thread_details=False):
     tasks = []
     field_name = 'task_coalition'
     for task in IterateLinkageChain(queue, 'task *', field_name, coal_type * sizeof('queue_chain_t')):
-        task_str = "({0: <d},{1: #x}, {2: <s}, {3: <s})".format(GetProcPIDForTask(task),task,GetProcNameForTask(task),GetTaskRoleString(task.effective_policy.t_role))
+        task_str = "({0: <d},{1: #x}, {2: <s}, {3: <s})".format(GetProcPIDForTask(task),task,GetProcNameForTask(task),GetTaskRoleString(task.effective_policy.tep_role))
         if thread_details:
             for thread in IterateQueue(task.threads, "thread_t", "task_threads"):
                 task_str += "\n\t\t\t|-> thread:" + hex(thread) + ", " + sfi_strs[int(thread.sfi_class)]
@@ -437,6 +448,15 @@ def GetResourceCoalitionSummary(coal, verbose=False):
     out_string += "\t  bytesread {0: <d}\n\t  byteswritten {1: <d}\n\t  gpu_time {2: <d}".format(coal.r.bytesread, coal.r.byteswritten, coal.r.gpu_time)
     out_string += "\n\t  total_tasks {0: <d}\n\t  dead_tasks {1: <d}\n\t  active_tasks {2: <d}".format(coal.r.task_count, coal.r.dead_task_count, coal.r.task_count - coal.r.dead_task_count)
     out_string += "\n\t  last_became_nonempty_time {0: <d}\n\t  time_nonempty {1: <d}".format(coal.r.last_became_nonempty_time, coal.r.time_nonempty)
+    out_string += "\n\t  cpu_ptime {0: <d}".format(coal.r.cpu_ptime)
+    if verbose:
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_DEFAULT] {0: <d}".format(coal.r.cpu_time_eqos[0])
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_MAINTENANCE] {0: <d}".format(coal.r.cpu_time_eqos[1])
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_BACKGROUND] {0: <d}".format(coal.r.cpu_time_eqos[2])
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_UTILITY] {0: <d}".format(coal.r.cpu_time_eqos[3])
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_LEGACY] {0: <d}".format(coal.r.cpu_time_eqos[4])
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_USER_INITIATED] {0: <d}".format(coal.r.cpu_time_eqos[5])
+        out_string += "\n\t  cpu_time_effective[THREAD_QOS_USER_INTERACTIVE] {0: <d}".format(coal.r.cpu_time_eqos[6])
     out_string += "\n\t  Tasks:\n\t\t"
     tasks = GetCoalitionTasks(addressof(coal.r.tasks), 0, thread_details)
     out_string += "\n\t\t".join(tasks)
@@ -451,7 +471,7 @@ def GetJetsamCoalitionSummary(coal, verbose=False):
         out_string += "\n\t  NO Leader!"
     else:
         out_string += "\n\t  Leader:\n\t\t"
-        out_string += "({0: <d},{1: #x}, {2: <s}, {3: <s})".format(GetProcPIDForTask(coal.j.leader),coal.j.leader,GetProcNameForTask(coal.j.leader),GetTaskRoleString(coal.j.leader.effective_policy.t_role))
+        out_string += "({0: <d},{1: #x}, {2: <s}, {3: <s})".format(GetProcPIDForTask(coal.j.leader),coal.j.leader,GetProcNameForTask(coal.j.leader),GetTaskRoleString(coal.j.leader.effective_policy.tep_role))
     out_string += "\n\t  Extensions:\n\t\t"
     tasks = GetCoalitionTasks(addressof(coal.j.extensions), 1, thread_details)
     out_string += "\n\t\t".join(tasks)
@@ -461,6 +481,7 @@ def GetJetsamCoalitionSummary(coal, verbose=False):
     out_string += "\n\t  Other Tasks:\n\t\t"
     tasks = GetCoalitionTasks(addressof(coal.j.other), 1, thread_details)
     out_string += "\n\t\t".join(tasks)
+    out_string += "\n\t  Thread Group: {0: <#020x}\n".format(coal.j.thread_group)
     return out_string
 
 @lldb_type_summary(['coalition_t', 'coalition *'])
@@ -508,9 +529,7 @@ def ShowCoalitionInfo(cmd_args=None, cmd_options={}):
     if config['verbosity'] > vHUMAN:
         verbose = True
     if not cmd_args:
-        print "No arguments passed"
-        print ShowCoalitionInfo.__doc__
-        return False
+        raise ArgumentError("No arguments passed")
     coal = kern.GetValueFromAddress(cmd_args[0], 'coalition *')
     if not coal:
         print "unknown arguments:", str(cmd_args)
@@ -532,6 +551,34 @@ def ShowAllCoalitions(cmd_args=None):
 
 # EndMacro: showallcoalitions
 
+# Macro: showallthreadgroups
+
+@lldb_type_summary(['thread_group_t', 'thread_group *'])
+@header("{0: <20s} {1: <5s} {2: <16s} {3: <5s} {4: <8s} {5: <20s}".format("thread_group", "id", "name", "refc", "flags", "recommendation"))
+def GetThreadGroupSummary(tg):
+    if unsigned(tg) == 0:
+        return '{0: <#020x} {1: <5d} {2: <16s} {3: <5d} {4: <8s} {5: <20d}'.format(0, -1, "", -1, "", -1)
+    out_string = ""
+    format_string = '{0: <#020x} {1: <5d} {2: <16s} {3: <5d} {4: <8s} {5: <20d}'
+    tg_flags = ''
+    if (tg.tg_flags & 0x1):
+        tg_flags += 'E'
+    if (tg.tg_flags & 0x2):
+        tg_flags += 'U'
+    out_string += format_string.format(tg, tg.tg_id, tg.tg_name, tg.tg_refcount, tg_flags, tg.tg_recommendation)
+    return out_string
+
+@lldb_command('showallthreadgroups')
+def ShowAllThreadGroups(cmd_args=None):
+    """  Print a summary listing of all thread groups
+    """
+    global kern
+    print GetThreadGroupSummary.header
+    for tg in kern.thread_groups:
+        print GetThreadGroupSummary(tg)
+
+# EndMacro: showallthreadgroups
+
 # Macro: showtaskcoalitions
 
 @lldb_command('showtaskcoalitions', 'F:')
@@ -583,23 +630,21 @@ def GetProcSummary(proc):
     
     io_policy_str = ""
     
-    if int(task.effective_policy.darwinbg) != 0:
+    if int(task.effective_policy.tep_darwinbg) != 0:
         io_policy_str += "B"
-    if int(task.effective_policy.lowpri_cpu) != 0:
+    if int(task.effective_policy.tep_lowpri_cpu) != 0:
         io_policy_str += "L"
     
-    if int(task.effective_policy.io_tier) != 0:
+    if int(task.effective_policy.tep_io_tier) != 0:
         io_policy_str += "T"
-    if int(task.effective_policy.io_passive) != 0:
+    if int(task.effective_policy.tep_io_passive) != 0:
         io_policy_str += "P"
-    if int(task.effective_policy.terminated) != 0:
+    if int(task.effective_policy.tep_terminated) != 0:
         io_policy_str += "D"
     
-    if int(task.effective_policy.t_suspended) != 0:
-        io_policy_str += "S"
-    if int(task.effective_policy.t_latency_qos) != 0:
+    if int(task.effective_policy.tep_latency_qos) != 0:
         io_policy_str += "Q"
-    if int(task.effective_policy.t_sup_active) != 0:
+    if int(task.effective_policy.tep_sup_active) != 0:
         io_policy_str += "A"
     
     
@@ -618,6 +663,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
 
@@ -637,47 +688,6 @@ def GetTTYDevSummary(tty_dev):
     out_string += format_string.format(tty_dev, tty_dev.master, tty_dev.slave, open_fn, free_fn, name_fn, revoke_fn)
     return out_string
 
-@lldb_type_summary(['kqueue *'])
-@header("{: <20s} {: <20s} {: <6s} {: <20s} {: <10s}".format('kqueue', 'process', '#events', 'wqs', 'state'))
-def GetKQueueSummary(kq):
-    """ summarizes kqueue information
-        returns: str - summary of kqueue
-    """
-    out_string = ""
-    format_string = "{o: <#020x} {o.kq_p: <#020x} {o.kq_count: <6d} {o.kq_wqs: <#020x} {st_str: <10s}"
-    state = int(kq.kq_state)
-    state_str = ''
-    mask = 0x1
-    while mask <= 0x80 :
-        if int(state & mask):
-            state_str += ' ' + xnudefines.kq_state_strings[int(state & mask)]
-        mask = mask << 1
-    out_string += format_string.format(o=kq, st_str=state_str)
-    out_string += "\n" + GetKnoteSummary.header
-    for kn in IterateTAILQ_HEAD(kq.kq_head, 'kn_tqe'):
-        out_string += "\n" + GetKnoteSummary(kn)
-    return out_string
-
-@lldb_type_summary(['knote *'])
-@header("{0: <20s} {1: <10s} {2: <10s} {3: <20s} {4: <20s} {5: <30s}".format('knote', 'ident', 'kev_flags', 'kn_kq', 'filtops', ' status'))
-def GetKnoteSummary(kn):
-    """ Summarizes a knote and related information
-        returns: str - summary of knote
-    """
-    out_string = ""
-    format_string = "{o: <#020x} {o.kn_kevent.ident: <#010X} {o.kn_kevent.flags: <#010X} {o.kn_kq: <#020X} {ops_str: <20s} {st_str: <30s}"
-    state = unsigned(kn.kn_status)
-    fops_str = kern.Symbolicate(unsigned(kn.kn_fop))
-    mask = 0x1
-    status_desc = ''
-    while mask <= 0x40:
-        if state & mask:
-            status_desc += ' ' + xnudefines.kn_state_strings[int(state & mask)]
-        mask = mask << 1
-
-    out_string += format_string.format(o=kn, st_str=status_desc, ops_str=fops_str)
-    return out_string
-
 # Macro: showtask
 
 @lldb_command('showtask', 'F:') 
@@ -713,9 +723,7 @@ def ShowPid(cmd_args=None):
          Usage: showpid <pid value>
     """
     if not cmd_args:
-        print "No arguments passed"
-        print ShowPid.__doc__
-        return False
+        raise ArgumentError("No arguments passed")
     pidval = ArgumentStringToInt(cmd_args[0])
     for t in kern.tasks:
         pval = Cast(t.bsd_info, 'proc *')
@@ -734,9 +742,7 @@ def ShowProc(cmd_args=None):
          Usage: showproc <address of proc>
     """
     if not cmd_args:
-        print "No arguments passed"
-        print ShowProc.__doc__
-        return False
+        raise ArgumentError("No arguments passed")
     pval = kern.GetValueFromAddress(cmd_args[0], 'proc *')
     if not pval:
         print "unknown arguments:", str(cmd_args)
@@ -756,9 +762,7 @@ def ShowProcInfo(cmd_args=None):
          Usage: showprocinfo <address of proc>
     """
     if not cmd_args:
-        print "No arguments passed"
-        print ShowProcInfo.__doc__
-        return False
+        raise ArgumentError("No arguments passed")
     pval = kern.GetValueFromAddress(cmd_args[0], 'proc *')
     if not pval:
         print "unknown arguments:", str(cmd_args)
@@ -788,17 +792,6 @@ def ShowProcFiles(cmd_args=None):
     print "{0:-<5s} {0:-<18s} {0:-<10s} {0:-<8s} {0:-<18s} {0:-<64s}".format("")
     count = 0
 
-    # Filetype map
-    filetype_dict = {
-                1: 'VNODE',
-                2: 'SOCKET',
-                3: 'PSXSHM',
-                4: 'PSXSEM',
-                5: 'KQUEUE',
-                6: 'PIPE',
-                7: 'FSEVENTS'
-              }
-
     while count <= proc_lastfile:
         if unsigned(proc_ofiles[count]) != 0:
             out_str = ''
@@ -808,8 +801,8 @@ def ShowProcFiles(cmd_args=None):
             out_str += "{0: <#18x} ".format(unsigned(proc_fd_fglob))
             out_str += "0x{0:0>8x} ".format(unsigned(proc_fd_flags))
             proc_fd_ftype = unsigned(proc_fd_fglob.fg_ops.fo_type)
-            if proc_fd_ftype in filetype_dict:
-                out_str += "{0: <8s} ".format(filetype_dict[proc_fd_ftype])
+            if proc_fd_ftype in xnudefines.filetype_strings:
+                out_str += "{0: <8s} ".format(xnudefines.filetype_strings[proc_fd_ftype])
             else:
                 out_str += "?: {0: <5d} ".format(proc_fd_ftype)
             out_str += "{0: <#18x} ".format(unsigned(proc_fd_fglob.fg_data))
@@ -822,66 +815,6 @@ def ShowProcFiles(cmd_args=None):
 
 #EndMacro: showprocfiles
 
-
-def GetProcKqueues(proc):
-    filetype_KQUEUE = 5
-
-    proc_filedesc = proc.p_fd
-    proc_lastfile = unsigned(proc_filedesc.fd_lastfile)
-    proc_ofiles = proc_filedesc.fd_ofiles
-
-    queues = list()
-
-    if unsigned(proc_ofiles) == 0:
-        return queues
-
-    count = 0
-
-    while count <= proc_lastfile:
-        if unsigned(proc_ofiles[count]) != 0:
-            proc_fd_flags = proc_ofiles[count].f_flags
-            proc_fd_fglob = proc_ofiles[count].f_fglob
-            proc_fd_ftype = unsigned(proc_fd_fglob.fg_ops.fo_type)
-            if proc_fd_ftype == filetype_KQUEUE:
-                q = Cast(proc_fd_fglob.fg_data, 'struct kqueue *')
-                queues.append(q)
-        count += 1
-
-    return queues
-
-def GetAllKqueues():
-    for t in kern.tasks:
-        if unsigned(t.bsd_info) == 0:
-            continue
-        pval = Cast(t.bsd_info, 'proc *')
-        for kq in GetProcKqueues(pval):
-            yield kq
-
-#Macro: showallkqueues
-@lldb_command('showallkqueues' ,'')
-def ShowAllKqueues(cmd_args=[], cmd_options={}):
-    """ Display a summary of all the kqueues in the system """
-    for kq in GetAllKqueues():
-        print GetKQueueSummary.header
-        print GetKQueueSummary(kq)
-        print "\n\n"
-#EndMacro: showallkqueues
-
-#Macro: showkqueue
-@lldb_command('showkqueue' ,'')
-def ShowKQueue(cmd_args=[], cmd_options={}):
-    """ Given a struct kqueue pointer, display the summary of the kqueue
-        Usage: (lldb) showkqueue <struct kqueue *>
-    """
-    if not cmd_args:
-        raise ArgumentError('Invalid arguments')
-
-    kq = kern.GetValueFromAddress(cmd_args[0], 'struct kqueue *')
-    print GetKQueueSummary.header
-    print GetKQueueSummary(kq)
-
-#EndMacro: showkqueue
-
 #Macro: showtty
 
 @lldb_command('showtty')
@@ -1026,6 +959,21 @@ def DumpCallQueue(cmd_args=None):
 
 #EndMacro: dumpcallqueue
 
+@lldb_command('showalltasklogicalwrites')
+def ShowAllTaskIOStats(cmd_args=None):
+    """ Commad to print I/O stats for all tasks
+    """
+    print "{0: <20s} {1: <20s} {2: <20s} {3: <20s} {4: <20s} {5: <20s}".format("task", "Immediate Writes", "Deferred Writes", "Invalidated Writes", "Metadata Writes", "name")
+    for t in kern.tasks:
+        pval = Cast(t.bsd_info, 'proc *')
+        print "{0: <#18x} {1: >20d} {2: >20d} {3: >20d} {4: >20d} {5: <20s}".format(t,
+            t.task_immediate_writes, 
+            t.task_deferred_writes,
+            t.task_invalidated_writes,
+            t.task_metadata_writes,
+            str(pval.p_comm)) 
+
+
 @lldb_command('showalltasks','C')
 def ShowAllTasks(cmd_args=None, cmd_options={}):
     """  Routine to print a summary listing of all the tasks
@@ -1051,6 +999,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 <pmap>.
+        Syntax: (lldb) taskforpmap <pmap>
+            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
@@ -1129,6 +1094,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: <s}'.format(trace_addr, symbol_str)
+    return
+
+@lldb_command('showprocrefs')
+def ShowProcRefs(cmd_args = None):
+    """ Display information on threads/BTs that could be holding a reference on the specified proc
+        NOTE: We can't say affirmatively if any of these references are still held since
+              there's no way to pair references with drop-refs in the current infrastructure.
+        Usage: showprocrefs <proc>
+    """
+    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
@@ -1173,10 +1184,8 @@ def ShowAct(cmd_args=None):
     """ Routine to print out the state of a specific thread.
         usage: showact <activation> 
     """
-    if cmd_args == None or len(cmd_args) < 1:
-        print "No arguments passed"
-        print ShowAct.__doc__
-        return False
+    if not cmd_args:
+        raise ArgumentError("No arguments passed")
     threadval = kern.GetValueFromAddress(cmd_args[0], 'thread *')
     print GetThreadSummary.header
     print GetThreadSummary(threadval)
@@ -1186,10 +1195,8 @@ def ShowActStack(cmd_args=None):
     """ Routine to print out the stack of a specific thread.
         usage:  showactstack <activation> 
     """
-    if cmd_args == None or len(cmd_args) < 1:
-        print "No arguments passed"
-        print ShowAct.__doc__.strip()
-        return False
+    if not cmd_args:
+        raise ArgumentError("No arguments passed")
     threadval = kern.GetValueFromAddress(cmd_args[0], 'thread *')
     print GetThreadSummary.header
     print GetThreadSummary(threadval)
@@ -1205,10 +1212,8 @@ def SwitchToAct(cmd_args=None):
     Before resuming execution, issue a "resetctx" command, to
     return to the original execution context.
     """
-    if cmd_args == None or len(cmd_args) < 1:
-        print "No arguments passed"
-        print SwitchToAct.__doc__.strip()
-        return False
+    if cmd_args is None or len(cmd_args) < 1:
+        raise ArgumentError("No arguments passed")
     thval = kern.GetValueFromAddress(cmd_args[0], 'thread *')
     lldbthread = GetLLDBThreadForKernelThread(thval)
     print GetThreadSummary.header
@@ -1236,7 +1241,7 @@ def SwitchToRegs(cmd_args=None):
     fake_thread_id = 0xdead0000 | (saved_state & ~0xffff0000)
     fake_thread_id = fake_thread_id & 0xdeadffff
     lldb_process.CreateOSPluginThread(0xdeadbeef, saved_state)
-    lldbthread = lldb_process.GetThreadByID(fake_thread_id)
+    lldbthread = lldb_process.GetThreadByID(int(fake_thread_id))
     
     if not lldbthread.IsValid():
         print "Failed to create thread"
@@ -1316,7 +1321,7 @@ def GetFullBackTrace(frame_addr, verbosity = vHUMAN, prefix = ""):
     # <rdar://problem/12677290> lldb unable to find symbol for _mh_execute_header
     mh_execute_addr = int(lldb_run_command('p/x (uintptr_t *)&_mh_execute_header').split('=')[-1].strip(), 16)
     while frame_ptr and frame_ptr != previous_frame_ptr and bt_count < 128:
-        if (kern.arch not in ('arm', 'arm64') and frame_ptr < mh_execute_addr) or (kern.arch in ('arm', 'arm64') and frame_ptr > mh_execute_addr):
+        if (not kern.arch.startswith('arm') and frame_ptr < mh_execute_addr) or (kern.arch.startswith('arm') and frame_ptr > mh_execute_addr):
             break
         pc_val = kern.GetValueFromAddress(frame_ptr + kern.ptrsize,'uintptr_t *')
         pc_val = unsigned(dereference(pc_val))
@@ -1447,8 +1452,6 @@ def ShowThreadForTid(cmd_args=None):
                 return
     print "Not a valid thread_id"
 
-# Macro: showallprocessors
-
 def GetProcessorSummary(processor):
     """ Internal function to print summary of processor
         params: processor - value representing struct processor * 
@@ -1497,239 +1500,6 @@ def GetProcessorSummary(processor):
             preemption_disable_str)
     return out_str   
 
-def GetGroupSetSummary(runq, task_map):
-    """ Internal function to print summary of group run queue
-        params: runq - value representing struct run_queue * 
-        return: str - representing the details of given run_queue
-    """
-    out_str = "    runq: count {: <10d} highq: {: <10d} urgency {: <10d}\n".format(runq.count, runq.highq, runq.urgency)
-    
-    runq_queue_i = 0
-    runq_queue_count = sizeof(runq.queues)/sizeof(runq.queues[0])
-    
-    for runq_queue_i in range(runq_queue_count) :
-        runq_queue_head = addressof(runq.queues[runq_queue_i])
-        runq_queue_p = runq_queue_head.next
-        
-        if unsigned(runq_queue_p) != unsigned(runq_queue_head):
-            runq_queue_this_count = 0
-            
-            for entry in IterateQueue(runq_queue_head, "sched_entry_t", "links"):
-                runq_queue_this_count += 1
-            
-            out_str += "      Queue [{: <#012x}] Priority {: <3d} count {:d}\n".format(runq_queue_head, runq_queue_i, runq_queue_this_count)
-            for entry in IterateQueue(runq_queue_head, "sched_entry_t", "links"):
-                group_addr = unsigned(entry) - (sizeof(dereference(entry)) * unsigned(entry.sched_pri))
-                group = kern.GetValueFromAddress(unsigned(group_addr), 'sched_group_t')
-                task = task_map.get(unsigned(group), 0x0)
-                if task == 0x0 :
-                    print "Cannot find task for group: {: <#012x}".format(group)
-                out_str += "\tEntry [{: <#012x}] Priority {: <3d} Group {: <#012x} Task {: <#012x}\n".format(unsigned(entry), entry.sched_pri, unsigned(group), unsigned(task))
-                
-    return out_str
-
-@lldb_command('showrunq')
-def ShowRunq(cmd_args=None):
-    """  Routine to print information of a runq
-         Usage: showrunq <runq>
-    """
-    out_str = ''
-    runq = kern.GetValueFromAddress(cmd_args[0], 'struct run_queue *')
-    out_str += GetRunQSummary(runq)
-    print out_str
-
-def GetRunQSummary(runq):
-    """ Internal function to print summary of run_queue
-        params: runq - value representing struct run_queue * 
-        return: str - representing the details of given run_queue
-    """
-    out_str = "    runq: count {: <10d} highq: {: <10d} urgency {: <10d}\n".format(runq.count, runq.highq, runq.urgency)
-    
-    runq_queue_i = 0
-    runq_queue_count = sizeof(runq.queues)/sizeof(runq.queues[0])
-    
-    for runq_queue_i in range(runq_queue_count) :
-        runq_queue_head = addressof(runq.queues[runq_queue_i])
-        runq_queue_p = runq_queue_head.next
-        
-        if unsigned(runq_queue_p) != unsigned(runq_queue_head):
-            runq_queue_this_count = 0
-            
-            for thread in IterateQueue(runq_queue_head, "thread_t", "links"):
-                runq_queue_this_count += 1
-            
-            out_str += "      Queue [{: <#012x}] Priority {: <3d} count {:d}\n".format(runq_queue_head, runq_queue_i, runq_queue_this_count)
-            out_str += "\t" + GetThreadSummary.header + "\n"
-            for thread in IterateQueue(runq_queue_head, "thread_t", "links"):
-                out_str += "\t" + GetThreadSummary(thread) + "\n"
-                if config['verbosity'] > vHUMAN :
-                    out_str += "\t" + GetThreadBackTrace(thread, prefix="\t\t") + "\n"
-    return out_str
-
-
-def GetGrrrSummary(grrr_runq):
-    """ Internal function to print summary of grrr_run_queue
-        params: grrr_runq - value representing struct grrr_run_queue * 
-        return: str - representing the details of given grrr_run_queue
-    """
-    out_str = "    GRRR Info: Count {: <10d} Weight {: <10d} Current Group {: <#012x}\n".format(grrr_runq.count,
-        grrr_runq.weight, grrr_runq.current_group)
-    grrr_group_i = 0
-    grrr_group_count = sizeof(grrr_runq.groups)/sizeof(grrr_runq.groups[0])
-    for grrr_group_i in range(grrr_group_count) :
-        grrr_group = addressof(grrr_runq.groups[grrr_group_i])
-        if grrr_group.count > 0:
-            out_str += "      Group {: <3d} [{: <#012x}] ".format(grrr_group.index, grrr_group)
-            out_str += "Count {:d} Weight {:d}\n".format(grrr_group.count, grrr_group.weight)
-            grrr_group_client_head = addressof(grrr_group.clients)
-            out_str += GetThreadSummary.header
-            for thread in IterateQueue(grrr_group_client_head, "thread_t", "links"):
-                out_str += "\t" + GetThreadSummary(thread) + "\n"
-                if config['verbosity'] > vHUMAN :
-                    out_str += "\t" + GetThreadBackTrace(thread, prefix="\t\t") + "\n"
-    return out_str
-
-def ShowNextThread(processor):
-    out_str = ""
-    if (processor.next_thread != 0) :
-        out_str += "      " + "Next thread:\n"
-        out_str += "\t" + GetThreadSummary.header + "\n"
-        out_str += "\t" + GetThreadSummary(processor.next_thread) + "\n"
-    return out_str
-
-def ShowActiveThread(processor):
-    out_str = ""
-    if (processor.active_thread != 0) :
-        out_str += "\t" + GetThreadSummary.header + "\n"
-        out_str += "\t" + GetThreadSummary(processor.active_thread) + "\n"
-    return out_str
-
-@lldb_command('showallprocessors') 
-def ShowAllProcessors(cmd_args=None):
-    """  Routine to print information of all psets and processors
-         Usage: showallprocessors
-    """
-    pset = addressof(kern.globals.pset0)
-    show_grrr = 0
-    show_priority_runq = 0
-    show_priority_pset_runq = 0
-    show_group_pset_runq = 0
-    sched_string = str(kern.globals.sched_current_dispatch.sched_name)
-    
-    if sched_string == "traditional":
-        show_priority_runq = 1
-    elif sched_string == "traditional_with_pset_runqueue":
-        show_priority_pset_runq = 1
-    elif sched_string == "grrr":
-        show_grrr = 1
-    elif sched_string == "multiq":
-        show_priority_runq = 1
-        show_group_pset_runq = 1
-    elif sched_string == "dualq":
-        show_priority_pset_runq = 1        
-        show_priority_runq = 1
-    else :
-        print "Unknown sched_string {:s}".format(sched_string)
-
-    out_str = ''
-    
-    out_str += "Scheduler: {:s} ({:s})\n".format(sched_string,
-            kern.Symbolicate(unsigned(kern.globals.sched_current_dispatch)))
-    
-    out_str += "Runnable threads: {:d} Timeshare threads: {:d} Background threads: {:d}\n".format(
-            kern.globals.sched_run_count, kern.globals.sched_share_count, kern.globals.sched_background_count)    
-    
-    if show_group_pset_runq:
-        # Create a group->task mapping
-        task_map = {}
-        for task in kern.tasks:
-            task_map[unsigned(task.sched_group)] = task
-        for task in kern.terminated_tasks:
-            task_map[unsigned(task.sched_group)] = task
-    
-    while unsigned(pset) != 0:
-        out_str += "Processor Set  {: <#012x} Count {:d} (cpu_id {:<#x}-{:<#x})\n".format(pset, 
-            pset.cpu_set_count, pset.cpu_set_low, pset.cpu_set_hi)
-        
-        if show_priority_pset_runq:
-            runq = pset.pset_runq
-            out_str += GetRunQSummary(runq)
-            
-        if show_group_pset_runq:
-            out_str += "Main Runq:\n"    
-            runq = pset.pset_runq
-            out_str += GetGroupSetSummary(runq, task_map)
-            out_str += "All Groups:\n"    
-            # TODO: Possibly output task header for each group
-            for group in IterateQueue(kern.globals.sched_groups, "sched_group_t", "sched_groups"):
-                if (group.runq.count != 0) :
-                    task = task_map.get(unsigned(group), "Unknown task!")
-                    out_str += "Group {: <#012x} Task {: <#012x}\n".format(unsigned(group), unsigned(task))
-                    out_str += GetRunQSummary(group.runq)
-
-        out_str += "  Active Processors:\n"
-        for processor in IterateQueue(pset.active_queue, "processor_t", "processor_queue"):
-            out_str += "    "
-            out_str += GetProcessorSummary(processor)
-            out_str += ShowActiveThread(processor)
-            out_str += ShowNextThread(processor)
-
-            if show_priority_runq:
-                runq = processor.runq
-                out_str += GetRunQSummary(runq)
-            if show_grrr:
-                grrr_runq = processor.grrr_runq
-                out_str += GetGrrrSummary(grrr_runq)
-
-        out_str += "  Idle Processors:\n"
-        for processor in IterateQueue(pset.idle_queue, "processor_t", "processor_queue"):
-            out_str += "    " + GetProcessorSummary(processor)
-            out_str += ShowActiveThread(processor)
-            out_str += ShowNextThread(processor)
-
-            if show_priority_runq:            
-                out_str += GetRunQSummary(processor.runq)
-
-        out_str += "  Idle Secondary Processors:\n"
-        for processor in IterateQueue(pset.idle_secondary_queue, "processor_t", "processor_queue"):
-            out_str += "    " + GetProcessorSummary(processor)
-            out_str += ShowActiveThread(processor)
-            out_str += ShowNextThread(processor)
-
-            if show_priority_runq:            
-                out_str += GetRunQSummary(processor.runq)
-        
-        pset = pset.pset_list
-
-    out_str += "\nRealtime Queue ({:<#012x}) Count {:d}\n".format(addressof(kern.globals.rt_runq.queue), kern.globals.rt_runq.count)
-    if kern.globals.rt_runq.count != 0:
-        out_str += "\t" + GetThreadSummary.header + "\n"
-        for rt_runq_thread in IterateQueue(kern.globals.rt_runq.queue, "thread_t", "links"):
-            out_str += "\t" + GetThreadSummary(rt_runq_thread) + "\n"
-
-    out_str += "\nTerminate Queue: ({:<#012x})\n".format(addressof(kern.globals.thread_terminate_queue))
-    first = False
-    for thread in IterateQueue(kern.globals.thread_terminate_queue, "thread_t", "links"):
-        if first:
-            out_str += "\t" + GetThreadSummary.header + "\n"
-            first = True
-        out_str += "\t" + GetThreadSummary(thread) + "\n"
-
-    out_str += "\nCrashed Threads Queue: ({:<#012x})\n".format(addressof(kern.globals.crashed_threads_queue))
-    first = False
-    for thread in IterateQueue(kern.globals.crashed_threads_queue, "thread_t", "links"):
-        if first:
-            out_str += "\t" + GetThreadSummary.header + "\n"
-            first = True
-        out_str += "\t" + GetThreadSummary(thread) + "\n"
-
-    out_str += "\n"
-    
-    out_str += "\n"
-
-    print out_str
-# EndMacro: showallprocessors
-
 def GetLedgerEntrySummary(ledger_template, ledger, i):
     """ Internal function to get internals of a ledger entry (*not* a ledger itself)
         params: ledger_template - value representing struct ledger_template_t for the task or thread
@@ -1747,11 +1517,14 @@ def GetLedgerEntrySummary(ledger_template, ledger, i):
     out_str += "{: >32s} {:<2d}:".format(ledger_template.lt_entries[i].et_key, i)
     out_str += "{: >15d} ".format(unsigned(ledger.le_credit) - unsigned(ledger.le_debit))
     if (ledger.le_flags & lf_tracking_max):
-        out_str += "{:9d} {:5d} ".format(ledger._le.le_peaks[0].le_max, now - unsigned(ledger._le.le_peaks[0].le_time))
-        out_str += "{:9d} {:4d} ".format(ledger._le.le_peaks[1].le_max, now - unsigned(ledger._le.le_peaks[1].le_time))
+        out_str += "{:9d} {:5d} ".format(ledger._le.le_maxtracking.le_peaks[0].le_max, now - unsigned(ledger._le.le_maxtracking.le_peaks[0].le_time))
     else:
-        out_str += "        -     -         -    - "
-    
+        out_str += "        -     -"
+
+    if (ledger.le_flags & lf_tracking_max):
+        out_str += "{:12d} ".format(ledger._le.le_maxtracking.le_lifetime_max)
+    else:
+        out_str += "             -"
     out_str += "{:12d} {:12d} ".format(unsigned(ledger.le_credit), unsigned(ledger.le_debit))
     if (unsigned(ledger.le_limit) != ledger_limit_infinity):
         out_str += "{:12d} ".format(unsigned(ledger.le_limit))
@@ -1796,9 +1569,9 @@ def GetThreadLedgerSummary(thread_val):
             i = i + 1
     return out_str
 
-@header("{0: <15s} {1: >16s} {2: <2s} {3: >15s} {4: >9s} {5: >6s} {6: >8s} {7: <10s} {8: <9s} \
-    {9: <12s} {10: <7s} {11: <15s} {12: <8s} {13: <9s} {14: <6s} {15: >6s}".format(
-    "task [thread]", "entry", "#", "balance", "peakA", "(age)", "peakB", "(age)", "credit",
+@header("{0: <15s} {1: >16s} {2: <2s} {3: >15s} {4: >9s} {5: >6s} {6: >12s} {7: >11s} \
+    {8: >7s} {9: >13s}   {10: <15s} {11: <8s} {12: <9s} {13: <6s} {14: >6s}".format(
+    "task [thread]", "entry", "#", "balance", "peakA", "(age)", "lifemax", "credit",
      "debit", "limit", "refill period", "lim pct", "warn pct", "over?", "flags"))
 def GetTaskLedgers(task_val):
     """ Internal function to get summary of ledger entries from the task and its threads
@@ -1921,11 +1694,8 @@ def ShowAllTaskPolicy(cmd_args=None):
                 ["bg_iotier",           "bg-iotier"],
                 ["terminated",          "terminated"],
                 ["th_pidbind_bg",       "bg-pidbind"],
-                ["th_workq_bg",         "bg-workq"],
                 ["t_apptype",           "apptype"],
                 ["t_boosted",           "boosted"],
-                ["t_int_gpu_deny",      "gpudeny-int"],
-                ["t_ext_gpu_deny",      "gpudeny-ext"],
                 ["t_role",              "role"],
                 ["t_tal_enabled",       "tal-enabled"],
                 ["t_base_latency_qos",  "latency-base"],
@@ -1984,25 +1754,9 @@ def ShowAllTaskPolicy(cmd_args=None):
             else:
                 effective+=""
                 
-
-        pended_strings = [
-                ["t_updating_policy",     "updating"],
-                ["update_sockets",        "update_sockets"],
-                ["t_update_timers",       "update_timers"],
-                ["t_update_watchers",     "update_watchers"]
-                ]
-            
-        pended=""
-        for value in pended_strings:
-            if t.pended_policy.__getattr__(value[0]) :
-                pended+=value[1] + ": " + str(t.pended_policy.__getattr__(value[0])) + " "
-            else:
-                pended+=""
-                
         print "requested: " + requested
         print "suppression: " + suppression
         print "effective: " + effective
-        print "pended: " + pended
 
 
 @lldb_type_summary(['wait_queue', 'wait_queue_t'])
@@ -2052,4 +1806,270 @@ def ShowSuspendedTasks(cmd_args=[], options={}):
             print GetTaskSummary(t) + ' ' + GetProcSummary(Cast(t.bsd_info, 'proc *'))
     return True
 
+# Macro: showallpte
+@lldb_command('showallpte')
+def ShowAllPte(cmd_args=None):
+    """ Prints out the physical address of the pte for all tasks
+    """
+    head_taskp = addressof(kern.globals.tasks)
+    taskp = Cast(head_taskp.next, 'task *')
+    while taskp != head_taskp:
+        procp = Cast(taskp.bsd_info, 'proc *')
+        out_str = "task = {:#x} pte = {:#x}\t".format(taskp, taskp.map.pmap.ttep)
+        if procp != 0:
+            out_str += "{:s}\n".format(procp.p_comm)
+        else:
+            out_str += "\n"
+        print out_str
+        taskp = Cast(taskp.tasks.next, 'struct task *')
+
+# EndMacro: showallpte
+
+# Macro: showallrefcounts
+@lldb_command('showallrefcounts')
+@header("{0: <20s} {1: ^10s}".format("task", "ref_count"))
+def ShowAllRefCounts(cmd_args=None):
+    """ Prints the ref_count of all tasks
+    """
+    out_str = ''
+    head_taskp = addressof(kern.globals.tasks)
+    taskp = Cast(head_taskp.next, 'task *')
+    print ShowAllRefCounts.header
+    while taskp != head_taskp:
+        out_str += "{: <#20x}".format(taskp)
+        out_str += "{: ^10d}\n".format(taskp.ref_count)
+        taskp = Cast(taskp.tasks.next, 'task *')
+    print out_str
+# EndMacro: showallrefcounts
+
+# Macro: showallrunnablethreads
+@lldb_command('showallrunnablethreads')
+def ShowAllRunnableThreads(cmd_args=None):
+    """ Prints the sched usage information for all threads of each task
+    """
+    out_str = ''
+    for taskp in kern.tasks:
+        for actp in IterateQueue(taskp.threads, 'thread *', 'task_threads'):
+            if int(actp.state & 0x4):
+                ShowActStack([unsigned(actp)])
+
+# EndMacro: showallrunnablethreads
+
+# Macro: showallschedusage
+@lldb_command('showallschedusage')
+@header("{0:<20s} {1:^10s} {2:^10s} {3:^15s}".format("Thread", "Priority", "State", "sched_usage"))
+def ShowAllSchedUsage(cmd_args=None):
+    """ Prints the sched usage information for all threads of each task
+    """
+    out_str = ''
+    for taskp in kern.tasks:
+        ShowTask([unsigned(taskp)])
+        print ShowAllSchedUsage.header
+        for actp in IterateQueue(taskp.threads, 'thread *', 'task_threads'):
+            out_str = "{: <#20x}".format(actp)
+            out_str += "{: ^10s}".format(str(int(actp.sched_pri)))
+            state = int(actp.state)
+            thread_state_chars = {0:'', 1:'W', 2:'S', 4:'R', 8:'U', 16:'H', 32:'A', 64:'P', 128:'I'}
+            state_str = ''
+            state_str += thread_state_chars[int(state & 0x1)]
+            state_str += thread_state_chars[int(state & 0x2)]
+            state_str += thread_state_chars[int(state & 0x4)]
+            state_str += thread_state_chars[int(state & 0x8)]
+            state_str += thread_state_chars[int(state & 0x10)]
+            state_str += thread_state_chars[int(state & 0x20)]
+            state_str += thread_state_chars[int(state & 0x40)]
+            state_str += thread_state_chars[int(state & 0x80)]
+            out_str += "{: ^10s}".format(state_str)
+            out_str += "{: >15d}".format(actp.sched_usage)
+            print out_str + "\n"
+        print "\n\n"
+
+# EndMacro: showallschedusage
+
+#Macro: showprocfilessummary
+@lldb_command('showprocfilessummary')
+@header("{0: <20s} {1: <20s} {2: >10s}".format("Process", "Name", "Number of Open Files"))
+def ShowProcFilesSummary(cmd_args=None):
+    """ Display the summary of open file descriptors for all processes in task list
+        Usage: showprocfilessummary
+    """
+    print ShowProcFilesSummary.header
+    for proc in kern.procs:
+        proc_filedesc = proc.p_fd
+        proc_ofiles = proc_filedesc.fd_ofiles
+        proc_lastfile = unsigned(proc_filedesc.fd_lastfile)
+        count = 0
+        proc_file_count = 0
+        if proc_filedesc.fd_nfiles != 0:
+            while count <= proc_lastfile:
+                if unsigned(proc_ofiles[count]) != 0:
+                    proc_file_count += 1
+                count += 1
+        print "{0: <#020x} {1: <20s} {2: >10d}".format(proc, proc.p_comm, proc_file_count)
+
+#EndMacro: showprocfilessummary
+
+@lldb_command('workinguserstacks')
+def WorkingUserStacks(cmd_args=None):
+    """ Print out the user stack for each thread in a task, followed by the user libraries.
+        Syntax: (lldb) workinguserstacks <task_t>
+    """
+    if not cmd_args:
+        print "Insufficient arguments" + ShowTaskUserStacks.__doc__
+        return False
+    task = kern.GetValueFromAddress(cmd_args[0], 'task *')
+    print GetTaskSummary.header + " " + GetProcSummary.header
+    pval = Cast(task.bsd_info, 'proc *')
+    print GetTaskSummary(task) + " " + GetProcSummary(pval) + "\n \n"
+    for thval in IterateQueue(task.threads, 'thread *', 'task_threads'):
+        print "For thread 0x{0:x}".format(thval)
+        try:
+            ShowThreadUserStack([hex(thval)])
+        except Exception as exc_err:
+            print "Failed to show user stack for thread 0x{0:x}".format(thval)
+            if config['debug']:
+                raise exc_err
+            else:
+                print "Enable debugging ('(lldb) xnudebug debug') to see detailed trace."
+    WorkingUserLibraries([hex(task)])
+    return
+
+@static_var("exec_load_path", 0)
+@lldb_command("workingkuserlibraries")
+def WorkingUserLibraries(cmd_args=None):
+    """ Show binary images known by dyld in target task
+        For a given user task, inspect the dyld shared library state and print information about all Mach-O images.
+        Syntax: (lldb)workinguserlibraries <task_t>
+    """
+    if not cmd_args:
+        print "Insufficient arguments"
+        print ShowTaskUserLibraries.__doc__
+        return False
+
+    print "{0: <18s} {1: <12s} {2: <36s} {3: <50s}".format('address','type','uuid','path')
+    out_format = "0x{0:0>16x} {1: <12s} {2: <36s} {3: <50s}"
+    task = kern.GetValueFromAddress(cmd_args[0], 'task_t')
+    is_task_64 = int(task.t_flags) & 0x1
+    dyld_all_image_infos_address = unsigned(task.all_image_info_addr)
+    cur_data_offset = 0
+    if dyld_all_image_infos_address == 0:
+        print "No dyld shared library information available for task"
+        return False
+    vers_info_data = GetUserDataAsString(task, dyld_all_image_infos_address, 112)
+    version = _ExtractDataFromString(vers_info_data, cur_data_offset, "uint32_t")
+    cur_data_offset += 4
+    if version > 12:
+        print "Unknown dyld all_image_infos version number %d" % version
+    image_info_count = _ExtractDataFromString(vers_info_data, cur_data_offset, "uint32_t")
+    WorkingUserLibraries.exec_load_path = 0
+    if is_task_64:
+        image_info_size = 24
+        image_info_array_address = _ExtractDataFromString(vers_info_data, 8, "uint64_t")
+        dyld_load_address = _ExtractDataFromString(vers_info_data, 8*4, "uint64_t")
+        dyld_all_image_infos_address_from_struct = _ExtractDataFromString(vers_info_data, 8*13, "uint64_t")
+    else:
+        image_info_size = 12
+        image_info_array_address = _ExtractDataFromString(vers_info_data, 4*2, "uint32_t")
+        dyld_load_address = _ExtractDataFromString(vers_info_data, 4*5, "uint32_t")
+        dyld_all_image_infos_address_from_struct = _ExtractDataFromString(vers_info_data, 4*14, "uint32_t")
+    # Account for ASLR slide before dyld can fix the structure
+    dyld_load_address = dyld_load_address + (dyld_all_image_infos_address - dyld_all_image_infos_address_from_struct)
+
+    i = 0
+    while i < image_info_count:
+        image_info_address = image_info_array_address + i * image_info_size
+        img_data = GetUserDataAsString(task, image_info_address, image_info_size)
+        if is_task_64:
+            image_info_addr = _ExtractDataFromString(img_data, 0, "uint64_t")
+            image_info_path = _ExtractDataFromString(img_data, 8, "uint64_t")
+        else:
+            image_info_addr = _ExtractDataFromString(img_data, 0, "uint32_t")
+            image_info_path = _ExtractDataFromString(img_data, 4, "uint32_t")
+        PrintImageInfo(task, image_info_addr, image_info_path)
+        i += 1
+
+    # load_path might get set when the main executable is processed.
+    if WorkingUserLibraries.exec_load_path != 0:
+        PrintImageInfo(task, dyld_load_address, WorkingUserLibraries.exec_load_path)
+    return
+
+# Macro: showstackaftertask
+@lldb_command('showstackaftertask','F:')
+def Showstackaftertask(cmd_args=None,cmd_options={}):
+    """ Routine to print the thread stacks for all tasks succeeding a given task
+        Usage: showstackaftertask <0xaddress of task>
+           or: showstackaftertask  -F <taskname>
+    """
+    if "-F" in cmd_options:
+        # Find the task pointer corresponding to its task name
+        find_task_str = cmd_options["-F"]
+        task_list = FindTasksByName(find_task_str)
+
+        # Iterate through the list of tasks and print all task stacks thereafter
+        for tval in task_list:
+            ListTaskStacks(tval)
+        return
+
+    if not cmd_args:
+        raise ArgumentError("Insufficient arguments")
+    tval = kern.GetValueFromAddress(cmd_args[0], 'task *')
+    if not tval:
+        raise ArgumentError("unknown arguments: {:s}".format(str(cmd_args)))
+    else:
+        ListTaskStacks(tval)
+
+    ZombStacks()
+    return
+# EndMacro: showstackaftertask
+
+def ListTaskStacks(task):
+    """ Search for a given task and print the list of all task stacks thereafter.
+    """
+    # Initialize local variable task_flag to mark when a given task is found.
+    task_flag=0
+
+    for t in kern.tasks:
+        if (task_flag == 1):
+            ShowTaskStacks(t)
+            print "\n"
+        if (t == task):
+            task_flag = 1
+
+# Macro: showstackafterthread
+@lldb_command('showstackafterthread')
+def Showstackafterthread(cmd_args = None):
+    """ Routine to print the stacks of all threads succeeding a given thread.
+        Usage: Showstackafterthread <0xaddress of thread>
+    """
+    # local variable thread_flag is used to mark when a given thread is found.
+    thread_flag=0
+    if cmd_args:
+       threadval = kern.GetValueFromAddress(cmd_args[0], 'thread *')
+    else:
+        raise ArgumentError("No arguments passed")
+    # Iterate through list of all tasks to look up a given thread
+    for t in kern.tasks:
+        if(thread_flag==1):
+            pval = Cast(t.bsd_info, 'proc *')
+            print GetTaskSummary.header + " "+ GetProcSummary.header
+            print GetTaskSummary(t) +     " "+ GetProcSummary(pval)
+            print "\n"
+         # Look up for a given thread from the the list of threads of a given task
+        for thval in IterateQueue(t.threads, 'thread *', 'task_threads'):
+            if (thread_flag==1):
+               print "\n"
+               print "  " + GetThreadSummary.header
+               print "  " + GetThreadSummary(thval)
+               print GetThreadBackTrace(thval, prefix="\t")+"\n"
+               print "\n"
+
+            if(thval==threadval):
+               pval = Cast(t.bsd_info, 'proc *')
+               process_name = "{:s}".format(pval.p_comm)
+               print "\n\n"
+               print " *** Continuing to dump the thread stacks from the process *** :" + " " + process_name
+               print "\n\n"
+               thread_flag = 1
+        print '\n'
+    return