1 //===-- SWIG Interface for SBValueList --------------------------*- 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 collection of SBValues. Both :py:class:`SBFrame.GetVariables()` and 13 :py:class:`SBFrame.GetRegisters()` return a SBValueList. 14 15 SBValueList supports :py:class:`SBValue` iteration. For example (from test/lldbutil.py),:: 16 17 def get_registers(frame, kind): 18 '''Returns the registers given the frame and the kind of registers desired. 19 20 Returns None if there's no such kind. 21 ''' 22 registerSet = frame.GetRegisters() # Return type of SBValueList. 23 for value in registerSet: 24 if kind.lower() in value.GetName().lower(): 25 return value 26 27 return None 28 29 def get_GPRs(frame): 30 '''Returns the general purpose registers of the frame as an SBValue. 31 32 The returned SBValue object is iterable. An example: 33 ... 34 from lldbutil import get_GPRs 35 regs = get_GPRs(frame) 36 for reg in regs: 37 print('%s => %s' % (reg.GetName(), reg.GetValue())) 38 ... 39 ''' 40 return get_registers(frame, 'general purpose') 41 42 def get_FPRs(frame): 43 '''Returns the floating point registers of the frame as an SBValue. 44 45 The returned SBValue object is iterable. An example: 46 ... 47 from lldbutil import get_FPRs 48 regs = get_FPRs(frame) 49 for reg in regs: 50 print('%s => %s' % (reg.GetName(), reg.GetValue())) 51 ... 52 ''' 53 return get_registers(frame, 'floating point') 54 55 def get_ESRs(frame): 56 '''Returns the exception state registers of the frame as an SBValue. 57 58 The returned SBValue object is iterable. An example: 59 ... 60 from lldbutil import get_ESRs 61 regs = get_ESRs(frame) 62 for reg in regs: 63 print('%s => %s' % (reg.GetName(), reg.GetValue())) 64 ... 65 ''' 66 return get_registers(frame, 'exception state') 67 " 68 ) SBValueList; 69 class SBValueList 70 { 71 public: 72 73 SBValueList (); 74 75 SBValueList (const lldb::SBValueList &rhs); 76 77 ~SBValueList(); 78 79 bool 80 IsValid() const; 81 82 explicit operator bool() const; 83 84 void 85 Clear(); 86 87 void 88 Append (const lldb::SBValue &val_obj); 89 90 void 91 Append (const lldb::SBValueList& value_list); 92 93 uint32_t 94 GetSize() const; 95 96 lldb::SBValue 97 GetValueAtIndex (uint32_t idx) const; 98 99 lldb::SBValue 100 FindValueObjectByUID (lldb::user_id_t uid); 101 102 lldb::SBValue 103 GetFirstValueByName (const char* name) const; 104 105 lldb::SBError GetError(); 106 107 %extend { 108 #ifdef SWIGPYTHON 109 %nothreadallow; 110 #endif 111 std::string lldb::SBValueList::__str__ (){ 112 lldb::SBStream description; 113 const size_t n = $self->GetSize(); 114 if (n) 115 { 116 for (size_t i=0; i<n; ++i) 117 $self->GetValueAtIndex(i).GetDescription(description); 118 } 119 else 120 { 121 description.Printf("<empty> lldb.SBValueList()"); 122 } 123 const char *desc = description.GetData(); 124 size_t desc_len = description.GetSize(); 125 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 126 --desc_len; 127 return std::string(desc, desc_len); 128 } 129 #ifdef SWIGPYTHON 130 %clearnothreadallow; 131 #endif 132 } 133 134 #ifdef SWIGPYTHON 135 %pythoncode %{ 136 def __iter__(self): 137 '''Iterate over all values in a lldb.SBValueList object.''' 138 return lldb_iter(self, 'GetSize', 'GetValueAtIndex') 139 140 def __len__(self): 141 return int(self.GetSize()) 142 143 def __getitem__(self, key): 144 count = len(self) 145 #------------------------------------------------------------ 146 # Access with "int" to get Nth item in the list 147 #------------------------------------------------------------ 148 if type(key) is int: 149 if key < count: 150 return self.GetValueAtIndex(key) 151 #------------------------------------------------------------ 152 # Access with "str" to get values by name 153 #------------------------------------------------------------ 154 elif type(key) is str: 155 matches = [] 156 for idx in range(count): 157 value = self.GetValueAtIndex(idx) 158 if value.name == key: 159 matches.append(value) 160 return matches 161 #------------------------------------------------------------ 162 # Match with regex 163 #------------------------------------------------------------ 164 elif isinstance(key, type(re.compile('.'))): 165 matches = [] 166 for idx in range(count): 167 value = self.GetValueAtIndex(idx) 168 re_match = key.search(value.name) 169 if re_match: 170 matches.append(value) 171 return matches 172 173 %} 174 #endif 175 176 177 }; 178 179 } // namespace lldb 180