Johnny Chen | fdc4a86 | 2011-07-19 22:41:47 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 3a31573 | 2011-07-21 00:48:02 +0000 | [diff] [blame] | 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 | |
Johnny Chen | c7ed223 | 2011-07-21 00:50:54 +0000 | [diff] [blame] | 25 | defines a function which takes an SBInstructionList instance and prints out |
Johnny Chen | 3a31573 | 2011-07-21 00:48:02 +0000 | [diff] [blame] | 26 | the machine instructions in assembly format." |
| 27 | ) SBInstructionList; |
Johnny Chen | fdc4a86 | 2011-07-19 22:41:47 +0000 | [diff] [blame] | 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); |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 61 | |
| 62 | %pythoncode %{ |
| 63 | def __len__(self): |
| 64 | '''Access len of the instruction list.''' |
Filipe Cabecinhas | 1a96ef8 | 2012-05-11 20:39:42 +0000 | [diff] [blame^] | 65 | return int(self.GetSize()) |
Greg Clayton | 6b2bd93 | 2012-02-01 08:09:32 +0000 | [diff] [blame] | 66 | |
| 67 | def __getitem__(self, key): |
| 68 | '''Access instructions by integer index.''' |
| 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 | |
Johnny Chen | fdc4a86 | 2011-07-19 22:41:47 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // namespace lldb |