blob: 32603be5cc1e0792d6cdd4deae85a1c98915635f [file] [log] [blame]
Johnny Chenfdc4a862011-07-19 22:41:47 +00001//===-- 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
12namespace lldb {
13
Johnny Chen3a315732011-07-21 00:48:02 +000014%feature("docstring",
15"Represents a list of machine instructions. SBFunction and SBSymbol have
16GetInstructions() methods which return SBInstructionList instances.
17
18SBInstructionList supports instruction (SBInstruction instance) iteration.
19For example (see also SBDebugger for a more complete example),
20
21def disassemble_instructions (insts):
22 for i in insts:
23 print i
24
Johnny Chenc7ed2232011-07-21 00:50:54 +000025defines a function which takes an SBInstructionList instance and prints out
Johnny Chen3a315732011-07-21 00:48:02 +000026the machine instructions in assembly format."
27) SBInstructionList;
Johnny Chenfdc4a862011-07-19 22:41:47 +000028class SBInstructionList
29{
30public:
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 Clayton6b2bd932012-02-01 08:09:32 +000061
62 %pythoncode %{
63 def __len__(self):
64 '''Access len of the instruction list.'''
Filipe Cabecinhas1a96ef82012-05-11 20:39:42 +000065 return int(self.GetSize())
Greg Clayton6b2bd932012-02-01 08:09:32 +000066
67 def __getitem__(self, key):
Greg Clayton5ef31a92012-06-29 22:00:42 +000068 '''Access instructions by integer index for array access or by lldb.SBAddress to find an instruction that matches a section offset address object.'''
Greg Clayton6b2bd932012-02-01 08:09:32 +000069 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 Chenfdc4a862011-07-19 22:41:47 +000089};
90
91} // namespace lldb