]> git.saurik.com Git - apple/xnu.git/blob - tools/lldbmacros/atm.py
xnu-3789.21.4.tar.gz
[apple/xnu.git] / tools / lldbmacros / atm.py
1 from xnu import *
2 from utils import *
3
4
5 @lldb_type_summary(['atm_value', 'atm_value_t'])
6 @header("{0: <20s} {1: <16s} {2: <20s} {3: <16s}".format("atm_value", "aid", "voucher_value", "sync"))
7 def GetATMValueSummary(atm_value):
8 """ Summarizes the atm_value
9 params: atm_value = value object of type atm_value_t
10 returns: string with the summary of the type.
11 """
12 format_str = "{0: <#020x} {1: <16d} {2: <#020x} {3: <16d}"
13 out_string = format_str.format(atm_value, unsigned(atm_value.aid), atm_value, atm_value.sync)
14 return out_string
15
16
17 @lldb_type_summary(['atm_task_descriptor', 'atm_task_descriptor_t'])
18 @header("{0: <20s} {1: <20s} {2: <16s} {3: <16s} {4: <10s}".format("task_descriptor", "trace_buffer", "buffer_size", "refcount", "flags"))
19 def GetATMTaskDescriptorSummary(descriptor):
20 """ Summarizes atm_task_descriptor object
21 params: descriptor - value object of type atm_task_descriptor_t
22 returns: string - containing the description.
23 """
24 format_str = "{0: <#020x} {1: <#020x} {2: <#016x} {3: <16d} {4: <10s}"
25 flags_str = ""
26 if unsigned(descriptor.flags) & 0x1:
27 flags_str = "DEAD"
28 out_string = format_str.format(descriptor, descriptor.trace_buffer, descriptor.trace_buffer_size, descriptor.reference_count, flags_str)
29
30 #if DEVELOPMENT
31 if hasattr(descriptor, 'task'):
32 out_string += " " + GetTaskSummary(descriptor.task) + " " + GetProcNameForTask(descriptor.task)
33 #endif
34
35 return out_string
36
37 # Macro: showatmvaluelisteners
38 @lldb_command('showatmvaluelisteners')
39 def ShowATMValueListeners(cmd_args=None, cmd_options={}):
40 """ show a list of listeners for an atm_value object.
41 Usage: (lldb)showatmvaluelisteners <atm_value_t>
42 """
43 if not cmd_args:
44 raise ArgumentError("Please provide arguments")
45
46 atm_val = kern.GetValueFromAddress(cmd_args[0], 'atm_value_t')
47 print GetATMValueSummary.header
48 print GetATMValueSummary(atm_val)
49 header_str = "{0: <20s} ".format("#guard") + GetATMTaskDescriptorSummary.header
50 #if DEVELOPMENT
51 header_str += " " + GetTaskSummary.header + " procname"
52 #endif
53 print header_str
54 for listener in IterateQueue(atm_val.listeners, 'atm_link_object_t', 'listeners_element'):
55 listener_summary = "{0: <#020x}".format(listener.guard)
56 listener_summary += " " + GetATMTaskDescriptorSummary(listener.descriptor)
57 print listener_summary
58 return
59 # EndMacro: showatmvaluelisteners
60
61
62 #if DEVELOPMENT
63
64 # Macro: showallatmallocatedvalueslist
65 @lldb_command('showallatmallocatedvalueslist')
66 def ShowAllATMAllocatedValuesList(cmd_args=None, cmd_options={}):
67 """ A DEVELOPMENT macro that walks the list of all allocated atm_value objects
68 and prints them.
69 usage: (lldb) showallatmallocatedvalueslist
70 """
71 if not hasattr(kern.globals, 'atm_values_list'):
72 print "It seems you are running a build of kernel that does not have the list of all atm_values_list."
73 return False
74 print GetATMValueSummary.header
75 for v in IterateQueue(kern.globals.atm_values_list, 'atm_value_t', 'value_elt'):
76 print GetATMValueSummary(v)
77 return True
78 # EndMacro: showallatmallocatedvalueslist
79
80 # Macro: showallatmdescriptors
81 @lldb_command('showallatmdescriptors')
82 def ShowAllATMDescriptors(cmd_args=None, cmd_options={}):
83 """ A DEVELOPMENT macro that walks the list of all atm_descriptors_list
84 and prints the summary for each.
85 usage: (lldb) showallatmdescriptors
86 """
87 if not hasattr(kern.globals, 'atm_descriptors_list'):
88 print "It seems you are running a build of kernel that does not have the list of all atm_descriptors_list."
89 return False
90
91 print GetATMTaskDescriptorSummary.header
92 for d in IterateQueue(kern.globals.atm_descriptors_list, 'atm_task_descriptor_t', 'descriptor_elt'):
93 print GetATMTaskDescriptorSummary(d)
94 return True
95 # EndMacro
96 #endif