summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python/interface/SBInstructionList.i
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/scripts/Python/interface/SBInstructionList.i')
-rw-r--r--lldb/scripts/Python/interface/SBInstructionList.i28
1 files changed, 28 insertions, 0 deletions
diff --git a/lldb/scripts/Python/interface/SBInstructionList.i b/lldb/scripts/Python/interface/SBInstructionList.i
index 488bbc81676..b2bb3496e34 100644
--- a/lldb/scripts/Python/interface/SBInstructionList.i
+++ b/lldb/scripts/Python/interface/SBInstructionList.i
@@ -58,6 +58,34 @@ public:
bool
DumpEmulationForAllInstructions (const char *triple);
+
+ %pythoncode %{
+ def __len__(self):
+ '''Access len of the instruction list.'''
+ return self.GetSize();
+
+ def __getitem__(self, key):
+ '''Access instructions by integer index.'''
+ if type(key) is int:
+ # Find an instruction by index
+ if key < len(self):
+ return self.GetInstructionAtIndex(key)
+ elif type(key) is SBAddress:
+ # Find an instruction using a lldb.SBAddress object
+ lookup_file_addr = key.file_addr
+ closest_inst = None
+ for idx in range(self.GetSize()):
+ inst = self.GetInstructionAtIndex(idx)
+ inst_file_addr = inst.addr.file_addr
+ if inst_file_addr == lookup_file_addr:
+ return inst
+ elif inst_file_addr > lookup_file_addr:
+ return closest_inst
+ else:
+ closest_inst = inst
+ return None
+ %}
+
};
} // namespace lldb
OpenPOWER on IntegriCloud