1 STRING_EXTENSION_OUTSIDE(SBInstructionList)
2 
3 %extend lldb::SBInstructionList {
4 #ifdef SWIGPYTHON
5     %pythoncode %{
6         def __iter__(self):
7             '''Iterate over all instructions in a lldb.SBInstructionList
8             object.'''
9             return lldb_iter(self, 'GetSize', 'GetInstructionAtIndex')
10 
11         def __len__(self):
12             '''Access len of the instruction list.'''
13             return int(self.GetSize())
14 
15         def __getitem__(self, key):
16             '''Access instructions by integer index for array access or by lldb.SBAddress to find an instruction that matches a section offset address object.'''
17             if type(key) is int:
18                 # Find an instruction by index
19                 count = len(self)
20                 if -count <= key < count:
21                     key %= count
22                     return self.GetInstructionAtIndex(key)
23             elif type(key) is SBAddress:
24                 # Find an instruction using a lldb.SBAddress object
25                 lookup_file_addr = key.file_addr
26                 closest_inst = None
27                 for idx in range(self.GetSize()):
28                     inst = self.GetInstructionAtIndex(idx)
29                     inst_file_addr = inst.addr.file_addr
30                     if inst_file_addr == lookup_file_addr:
31                         return inst
32                     elif inst_file_addr > lookup_file_addr:
33                         return closest_inst
34                     else:
35                         closest_inst = inst
36             return None
37     %}
38 #endif
39 }
40