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 %extend { 106 %nothreadallow; 107 std::string lldb::SBValueList::__str__ (){ 108 lldb::SBStream description; 109 const size_t n = $self->GetSize(); 110 if (n) 111 { 112 for (size_t i=0; i<n; ++i) 113 $self->GetValueAtIndex(i).GetDescription(description); 114 } 115 else 116 { 117 description.Printf("<empty> lldb.SBValueList()"); 118 } 119 const char *desc = description.GetData(); 120 size_t desc_len = description.GetSize(); 121 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 122 --desc_len; 123 return std::string(desc, desc_len); 124 } 125 %clearnothreadallow; 126 } 127 128 #ifdef SWIGPYTHON 129 %pythoncode %{ 130 def __iter__(self): 131 '''Iterate over all values in a lldb.SBValueList object.''' 132 return lldb_iter(self, 'GetSize', 'GetValueAtIndex') 133 134 def __len__(self): 135 return int(self.GetSize()) 136 137 def __getitem__(self, key): 138 count = len(self) 139 #------------------------------------------------------------ 140 # Access with "int" to get Nth item in the list 141 #------------------------------------------------------------ 142 if type(key) is int: 143 if key < count: 144 return self.GetValueAtIndex(key) 145 #------------------------------------------------------------ 146 # Access with "str" to get values by name 147 #------------------------------------------------------------ 148 elif type(key) is str: 149 matches = [] 150 for idx in range(count): 151 value = self.GetValueAtIndex(idx) 152 if value.name == key: 153 matches.append(value) 154 return matches 155 #------------------------------------------------------------ 156 # Match with regex 157 #------------------------------------------------------------ 158 elif isinstance(key, type(re.compile('.'))): 159 matches = [] 160 for idx in range(count): 161 value = self.GetValueAtIndex(idx) 162 re_match = key.search(value.name) 163 if re_match: 164 matches.append(value) 165 return matches 166 167 %} 168 #endif 169 170 171 }; 172 173 } // namespace lldb 174