1 %extend lldb::SBValueList {
2 
3 #ifdef SWIGPYTHON
4        %nothreadallow;
5 #endif
6        std::string lldb::SBValueList::__str__ (){
7            lldb::SBStream description;
8            const size_t n = $self->GetSize();
9            if (n)
10            {
11                for (size_t i=0; i<n; ++i)
12                    $self->GetValueAtIndex(i).GetDescription(description);
13            }
14            else
15            {
16                description.Printf("<empty> lldb.SBValueList()");
17            }
18            const char *desc = description.GetData();
19            size_t desc_len = description.GetSize();
20            if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r'))
21                --desc_len;
22            return std::string(desc, desc_len);
23        }
24 #ifdef SWIGPYTHON
25        %clearnothreadallow;
26 #endif
27 
28 #ifdef SWIGPYTHON
29     %pythoncode %{
30         def __iter__(self):
31             '''Iterate over all values in a lldb.SBValueList object.'''
32             return lldb_iter(self, 'GetSize', 'GetValueAtIndex')
33 
34         def __len__(self):
35             return int(self.GetSize())
36 
37         def __getitem__(self, key):
38             count = len(self)
39             #------------------------------------------------------------
40             # Access with "int" to get Nth item in the list
41             #------------------------------------------------------------
42             if type(key) is int:
43                 if -count <= key < count:
44                     key %= count
45                     return self.GetValueAtIndex(key)
46             #------------------------------------------------------------
47             # Access with "str" to get values by name
48             #------------------------------------------------------------
49             elif type(key) is str:
50                 matches = []
51                 for idx in range(count):
52                     value = self.GetValueAtIndex(idx)
53                     if value.name == key:
54                         matches.append(value)
55                 return matches
56             #------------------------------------------------------------
57             # Match with regex
58             #------------------------------------------------------------
59             elif isinstance(key, type(re.compile('.'))):
60                 matches = []
61                 for idx in range(count):
62                     value = self.GetValueAtIndex(idx)
63                     re_match = key.search(value.name)
64                     if re_match:
65                         matches.append(value)
66                 return matches
67 
68     %}
69 #endif
70 }
71