1 //===-- SWIG Interface for SBInstructionList --------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include <stdio.h> 11 12 namespace lldb { 13 14 %feature("docstring", 15 "Represents a list of machine instructions. SBFunction and SBSymbol have 16 GetInstructions() methods which return SBInstructionList instances. 17 18 SBInstructionList supports instruction (SBInstruction instance) iteration. 19 For example (see also SBDebugger for a more complete example), 20 21 def disassemble_instructions (insts): 22 for i in insts: 23 print i 24 25 defines a function which takes an SBInstructionList instance and prints out 26 the machine instructions in assembly format." 27 ) SBInstructionList; 28 class SBInstructionList 29 { 30 public: 31 32 SBInstructionList (); 33 34 SBInstructionList (const SBInstructionList &rhs); 35 36 ~SBInstructionList (); 37 38 bool 39 IsValid () const; 40 41 size_t 42 GetSize (); 43 44 lldb::SBInstruction 45 GetInstructionAtIndex (uint32_t idx); 46 47 void 48 Clear (); 49 50 void 51 AppendInstruction (lldb::SBInstruction inst); 52 53 void 54 Print (FILE *out); 55 56 bool 57 GetDescription (lldb::SBStream &description); 58 59 bool 60 DumpEmulationForAllInstructions (const char *triple); 61 62 %pythoncode %{ 63 def __len__(self): 64 '''Access len of the instruction list.''' 65 return int(self.GetSize()) 66 67 def __getitem__(self, key): 68 '''Access instructions by integer index for array access or by lldb.SBAddress to find an instruction that matches a section offset address object.''' 69 if type(key) is int: 70 # Find an instruction by index 71 if key < len(self): 72 return self.GetInstructionAtIndex(key) 73 elif type(key) is SBAddress: 74 # Find an instruction using a lldb.SBAddress object 75 lookup_file_addr = key.file_addr 76 closest_inst = None 77 for idx in range(self.GetSize()): 78 inst = self.GetInstructionAtIndex(idx) 79 inst_file_addr = inst.addr.file_addr 80 if inst_file_addr == lookup_file_addr: 81 return inst 82 elif inst_file_addr > lookup_file_addr: 83 return closest_inst 84 else: 85 closest_inst = inst 86 return None 87 %} 88 89 }; 90 91 } // namespace lldb 92