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 9namespace lldb { 10 11%feature("docstring", 12"Represents a collection of SBValues. Both SBFrame's GetVariables() and 13GetRegisters() return a SBValueList. 14 15SBValueList supports SBValue iteration. For example (from test/lldbutil.py), 16 17def 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 29def 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 42def 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 55def 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) SBValueList; 68class SBValueList 69{ 70public: 71 72 SBValueList (); 73 74 SBValueList (const lldb::SBValueList &rhs); 75 76 ~SBValueList(); 77 78 bool 79 IsValid() const; 80 81 explicit operator bool() const; 82 83 void 84 Clear(); 85 86 void 87 Append (const lldb::SBValue &val_obj); 88 89 void 90 Append (const lldb::SBValueList& value_list); 91 92 uint32_t 93 GetSize() const; 94 95 lldb::SBValue 96 GetValueAtIndex (uint32_t idx) const; 97 98 lldb::SBValue 99 FindValueObjectByUID (lldb::user_id_t uid); 100 101 lldb::SBValue 102 GetFirstValueByName (const char* name) const; 103 104 %extend { 105 %nothreadallow; 106 std::string lldb::SBValueList::__str__ (){ 107 lldb::SBStream description; 108 const size_t n = $self->GetSize(); 109 if (n) 110 { 111 for (size_t i=0; i<n; ++i) 112 $self->GetValueAtIndex(i).GetDescription(description); 113 } 114 else 115 { 116 description.Printf("<empty> lldb.SBValueList()"); 117 } 118 const char *desc = description.GetData(); 119 size_t desc_len = description.GetSize(); 120 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 121 --desc_len; 122 return std::string(desc, desc_len); 123 } 124 %clearnothreadallow; 125 } 126 127#ifdef SWIGPYTHON 128 %pythoncode %{ 129 def __iter__(self): 130 '''Iterate over all values in a lldb.SBValueList object.''' 131 return lldb_iter(self, 'GetSize', 'GetValueAtIndex') 132 133 def __len__(self): 134 return int(self.GetSize()) 135 136 def __getitem__(self, key): 137 count = len(self) 138 #------------------------------------------------------------ 139 # Access with "int" to get Nth item in the list 140 #------------------------------------------------------------ 141 if type(key) is int: 142 if key < count: 143 return self.GetValueAtIndex(key) 144 #------------------------------------------------------------ 145 # Access with "str" to get values by name 146 #------------------------------------------------------------ 147 elif type(key) is str: 148 matches = [] 149 for idx in range(count): 150 value = self.GetValueAtIndex(idx) 151 if value.name == key: 152 matches.append(value) 153 return matches 154 #------------------------------------------------------------ 155 # Match with regex 156 #------------------------------------------------------------ 157 elif isinstance(key, type(re.compile('.'))): 158 matches = [] 159 for idx in range(count): 160 value = self.GetValueAtIndex(idx) 161 re_match = key.search(value.name) 162 if re_match: 163 matches.append(value) 164 return matches 165 166 %} 167#endif 168 169 170}; 171 172} // namespace lldb 173