(target: lldb.SBTarget, total: int)
| 126 | |
| 127 | |
| 128 | def get_all_bthreads(target: lldb.SBTarget, total: int): |
| 129 | bthreads = [] |
| 130 | groups = find_global_value( |
| 131 | target, "butil::ResourcePool<bthread::TaskMeta>::_ngroup.val").GetValueAsUnsigned() |
| 132 | long_type = target.GetBasicType(lldb.eBasicTypeLong) |
| 133 | uint32_t_type = target.FindFirstType("uint32_t") |
| 134 | block_groups = find_global_value( |
| 135 | target, "butil::ResourcePool<bthread::TaskMeta>::_block_groups") |
| 136 | for group in range(groups): |
| 137 | block_group = get_child( |
| 138 | block_groups.GetChildAtIndex(group), "val").Dereference() |
| 139 | nblock = get_child(block_group, "nblock").Cast( |
| 140 | long_type).GetValueAsUnsigned() |
| 141 | blocks = get_child(block_group, "blocks") |
| 142 | for block in range(nblock): |
| 143 | # block_type: butil::ResourcePool<bthread::TaskMeta>::Block |
| 144 | block_type = blocks.GetChildAtIndex( |
| 145 | block).GetType().GetTemplateArgumentType(0) |
| 146 | block = blocks.GetChildAtIndex( |
| 147 | block).Cast(block_type).Dereference() |
| 148 | nitem = get_child(block, "nitem").GetValueAsUnsigned() |
| 149 | task_meta_array_type = target.FindFirstType( |
| 150 | "bthread::TaskMeta").GetArrayType(nitem) |
| 151 | tasks = get_child(block, "items").Cast(task_meta_array_type) |
| 152 | for i in range(nitem): |
| 153 | task_meta = tasks.GetChildAtIndex(i) |
| 154 | version_tid = get_child( |
| 155 | task_meta, "tid").GetValueAsUnsigned() >> 32 |
| 156 | version_butex = get_child(task_meta, "version_butex").Cast( |
| 157 | uint32_t_type.GetPointerType()).Dereference().GetValueAsUnsigned() |
| 158 | # stack_type: bthread::ContextualStack |
| 159 | stack_type = get_child( |
| 160 | task_meta, "attr.stack_type").GetValueAsUnsigned() |
| 161 | if version_tid == version_butex and stack_type != 0: |
| 162 | if len(bthreads) >= total: |
| 163 | return bthreads |
| 164 | bthreads.append(task_meta) |
| 165 | return bthreads |
| 166 | |
| 167 | # lldb bthread commands |
| 168 | def bthread_begin(debugger, command, result, internal_dict): |
no test coverage detected