]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/lldb/bindings/interface/SBInstructionList.i
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / lldb / bindings / interface / SBInstructionList.i
1 //===-- SWIG Interface for SBInstructionList --------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include <stdio.h>
10
11 namespace lldb {
12
13 %feature("docstring",
14 "Represents a list of machine instructions.  SBFunction and SBSymbol have
15 GetInstructions() methods which return SBInstructionList instances.
16
17 SBInstructionList supports instruction (SBInstruction instance) iteration.
18 For example (see also SBDebugger for a more complete example),
19
20 def disassemble_instructions (insts):
21     for i in insts:
22         print i
23
24 defines a function which takes an SBInstructionList instance and prints out
25 the machine instructions in assembly format."
26 ) SBInstructionList;
27 class SBInstructionList
28 {
29 public:
30
31     SBInstructionList ();
32
33     SBInstructionList (const SBInstructionList &rhs);
34
35     ~SBInstructionList ();
36
37     bool
38     IsValid () const;
39
40     explicit operator bool() const;
41
42     size_t
43     GetSize ();
44
45     lldb::SBInstruction
46     GetInstructionAtIndex (uint32_t idx);
47
48     size_t GetInstructionsCount(const SBAddress &start, const SBAddress &end,
49                                 bool canSetBreakpoint);
50
51     void
52     Clear ();
53
54     void
55     AppendInstruction (lldb::SBInstruction inst);
56
57     void
58     Print (lldb::SBFile out);
59
60     void
61     Print (lldb::FileSP BORROWED);
62
63     bool
64     GetDescription (lldb::SBStream &description);
65
66     bool
67     DumpEmulationForAllInstructions (const char *triple);
68
69     STRING_EXTENSION(SBInstructionList)
70
71 #ifdef SWIGPYTHON
72     %pythoncode %{
73         def __iter__(self):
74             '''Iterate over all instructions in a lldb.SBInstructionList
75             object.'''
76             return lldb_iter(self, 'GetSize', 'GetInstructionAtIndex')
77
78         def __len__(self):
79             '''Access len of the instruction list.'''
80             return int(self.GetSize())
81
82         def __getitem__(self, key):
83             '''Access instructions by integer index for array access or by lldb.SBAddress to find an instruction that matches a section offset address object.'''
84             if type(key) is int:
85                 # Find an instruction by index
86                 if key < len(self):
87                     return self.GetInstructionAtIndex(key)
88             elif type(key) is SBAddress:
89                 # Find an instruction using a lldb.SBAddress object
90                 lookup_file_addr = key.file_addr
91                 closest_inst = None
92                 for idx in range(self.GetSize()):
93                     inst = self.GetInstructionAtIndex(idx)
94                     inst_file_addr = inst.addr.file_addr
95                     if inst_file_addr == lookup_file_addr:
96                         return inst
97                     elif inst_file_addr > lookup_file_addr:
98                         return closest_inst
99                     else:
100                         closest_inst = inst
101             return None
102     %}
103 #endif
104
105 };
106
107 } // namespace lldb