1 //===-- SWIG Interface for SBSymbolContextList ------------------*- 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 namespace lldb {
10 
11 %feature("docstring",
12 "Represents a list of symbol context object. See also SBSymbolContext.
13 
14 For example (from test/python_api/target/TestTargetAPI.py), ::
15 
16     def find_functions(self, exe_name):
17         '''Exercise SBTaget.FindFunctions() API.'''
18         exe = os.path.join(os.getcwd(), exe_name)
19 
20         # Create a target by the debugger.
21         target = self.dbg.CreateTarget(exe)
22         self.assertTrue(target, VALID_TARGET)
23 
24         list = lldb.SBSymbolContextList()
25         num = target.FindFunctions('c', lldb.eFunctionNameTypeAuto, False, list)
26         self.assertTrue(num == 1 and list.GetSize() == 1)
27 
28         for sc in list:
29             self.assertTrue(sc.GetModule().GetFileSpec().GetFilename() == exe_name)
30             self.assertTrue(sc.GetSymbol().GetName() == 'c')") SBSymbolContextList;
31 class SBSymbolContextList
32 {
33 public:
34     SBSymbolContextList ();
35 
36     SBSymbolContextList (const lldb::SBSymbolContextList& rhs);
37 
38     ~SBSymbolContextList ();
39 
40     bool
41     IsValid () const;
42 
43     explicit operator bool() const;
44 
45     uint32_t
46     GetSize() const;
47 
48     SBSymbolContext
49     GetContextAtIndex (uint32_t idx);
50 
51     void
52     Append (lldb::SBSymbolContext &sc);
53 
54     void
55     Append (lldb::SBSymbolContextList &sc_list);
56 
57     bool
58     GetDescription (lldb::SBStream &description);
59 
60     void
61     Clear();
62 
63     STRING_EXTENSION(SBSymbolContextList)
64 
65 #ifdef SWIGPYTHON
66     %pythoncode %{
67         def __iter__(self):
68             '''Iterate over all symbol contexts in a lldb.SBSymbolContextList
69             object.'''
70             return lldb_iter(self, 'GetSize', 'GetContextAtIndex')
71 
72         def __len__(self):
73             return int(self.GetSize())
74 
75         def __getitem__(self, key):
76             count = len(self)
77             if type(key) is int:
78                 if key < count:
79                     return self.GetContextAtIndex(key)
80                 else:
81                     raise IndexError
82             raise TypeError
83 
84         def get_module_array(self):
85             a = []
86             for i in range(len(self)):
87                 obj = self.GetContextAtIndex(i).module
88                 if obj:
89                     a.append(obj)
90             return a
91 
92         def get_compile_unit_array(self):
93             a = []
94             for i in range(len(self)):
95                 obj = self.GetContextAtIndex(i).compile_unit
96                 if obj:
97                     a.append(obj)
98             return a
99         def get_function_array(self):
100             a = []
101             for i in range(len(self)):
102                 obj = self.GetContextAtIndex(i).function
103                 if obj:
104                     a.append(obj)
105             return a
106         def get_block_array(self):
107             a = []
108             for i in range(len(self)):
109                 obj = self.GetContextAtIndex(i).block
110                 if obj:
111                     a.append(obj)
112             return a
113         def get_symbol_array(self):
114             a = []
115             for i in range(len(self)):
116                 obj = self.GetContextAtIndex(i).symbol
117                 if obj:
118                     a.append(obj)
119             return a
120         def get_line_entry_array(self):
121             a = []
122             for i in range(len(self)):
123                 obj = self.GetContextAtIndex(i).line_entry
124                 if obj:
125                     a.append(obj)
126             return a
127 
128         modules = property(get_module_array, None, doc='''Returns a list() of lldb.SBModule objects, one for each module in each SBSymbolContext object in this list.''')
129         compile_units = property(get_compile_unit_array, None, doc='''Returns a list() of lldb.SBCompileUnit objects, one for each compile unit in each SBSymbolContext object in this list.''')
130         functions = property(get_function_array, None, doc='''Returns a list() of lldb.SBFunction objects, one for each function in each SBSymbolContext object in this list.''')
131         blocks = property(get_block_array, None, doc='''Returns a list() of lldb.SBBlock objects, one for each block in each SBSymbolContext object in this list.''')
132         line_entries = property(get_line_entry_array, None, doc='''Returns a list() of lldb.SBLineEntry objects, one for each line entry in each SBSymbolContext object in this list.''')
133         symbols = property(get_symbol_array, None, doc='''Returns a list() of lldb.SBSymbol objects, one for each symbol in each SBSymbolContext object in this list.''')
134     %}
135 #endif
136 
137 };
138 
139 } // namespace lldb
140