+@lldb_command('showtaskuserstacks', "P:F:")
+def ShowTaskUserStacksCmdHelper(cmd_args=None, cmd_options={}):
+ """ Print out the user stack for each thread in a task, followed by the user libraries.
+ Syntax: (lldb) showtaskuserstacks <task_t>
+ or: (lldb) showtaskuserstacks -P <pid>
+ or: (lldb) showtaskuserstacks -F <task_name>
+ The format is compatible with CrashTracer. You can also use the speedtracer plugin as follows
+ (lldb) showtaskuserstacks <task_t> -p speedtracer
+
+ Note: the address ranges are approximations. Also the list may not be completely accurate. This command expects memory read failures
+ and hence will skip a library if unable to read information. Please use your good judgement and not take the output as accurate
+ """
+ task_list = []
+ if "-F" in cmd_options:
+ task_list = FindTasksByName(cmd_options["-F"])
+ elif "-P" in cmd_options:
+ pidval = ArgumentStringToInt(cmd_options["-P"])
+ for t in kern.tasks:
+ pval = Cast(t.bsd_info, 'proc *')
+ if pval and pval.p_pid == pidval:
+ task_list.append(t)
+ break
+ elif cmd_args:
+ t = kern.GetValueFromAddress(cmd_args[0], 'task *')
+ task_list.append(t)
+ else:
+ raise ArgumentError("Insufficient arguments")
+
+ for task in task_list:
+ ShowTaskUserStacks(task)