]> git.saurik.com Git - apple/xnu.git/blobdiff - tools/lldbmacros/core/operating_system.py
xnu-6153.61.1.tar.gz
[apple/xnu.git] / tools / lldbmacros / core / operating_system.py
index 2e7e21847cbb36c249bf269d3241aff402888c2b..c1fc18cc341788330055e5fad27eadd6751f0307 100755 (executable)
@@ -649,6 +649,32 @@ def IterateQueue(queue_head, element_ptr_type, element_field_name):
         yield elt
         cur_elt = elt.GetChildMemberWithName(element_field_name).GetChildMemberWithName('next')
 
+def IterateCircleQueue(queue_head, element_ptr_type, element_field_name):
+    """ iterate over a circle queue in kernel of type circle_queue_head_t. refer to osfmk/kern/circle_queue.h
+        params:
+            queue_head         - lldb.SBValue : Value object for queue_head.
+            element_type       - lldb.SBType : a pointer type of the element 'next' points to. Typically its structs like thread, task etc..
+            element_field_name - str : name of the field in target struct.
+        returns:
+            A generator does not return. It is used for iterating.
+            SBValue  : an object thats of type (element_type) queue_head->next. Always a pointer object
+    """
+    head = queue_head.head
+    queue_head_addr = 0x0
+    if head.TypeIsPointerType():
+        queue_head_addr = head.GetValueAsUnsigned()
+    else:
+        queue_head_addr = head.GetAddress().GetLoadAddress(osplugin_target_obj)
+    cur_elt = head
+    while True:
+        if not cur_elt.IsValid() or cur_elt.GetValueAsUnsigned() == 0:
+            break
+        elt = cur_elt.Cast(element_ptr_type)
+        yield elt
+        cur_elt = elt.GetChildMemberWithName(element_field_name).GetChildMemberWithName('next')
+        if cur_elt.GetValueAsUnsigned() == queue_head_addr:
+            break
+
 def GetUniqueSessionID(process_obj):
     """ Create a unique session identifier.
         params: