1 //===-- SBValueList.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 11 #include "lldb/API/SBValueList.h" 12 #include "lldb/API/SBValue.h" 13 #include "lldb/API/SBStream.h" 14 #include "lldb/Core/Log.h" 15 #include "lldb/Core/ValueObjectList.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 SBValueList::SBValueList () : 21 m_opaque_ap () 22 { 23 } 24 25 SBValueList::SBValueList (const SBValueList &rhs) : 26 m_opaque_ap () 27 { 28 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 29 30 if (rhs.IsValid()) 31 m_opaque_ap.reset (new ValueObjectList (*rhs)); 32 33 if (log) 34 { 35 log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p", 36 (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), 37 m_opaque_ap.get()); 38 } 39 } 40 41 SBValueList::SBValueList (const ValueObjectList *lldb_object_ptr) : 42 m_opaque_ap () 43 { 44 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 45 46 if (lldb_object_ptr) 47 m_opaque_ap.reset (new ValueObjectList (*lldb_object_ptr)); 48 49 if (log) 50 { 51 log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p", 52 lldb_object_ptr, 53 m_opaque_ap.get()); 54 } 55 } 56 57 SBValueList::~SBValueList () 58 { 59 } 60 61 bool 62 SBValueList::IsValid () const 63 { 64 return (m_opaque_ap.get() != NULL); 65 } 66 67 void 68 SBValueList::Clear() 69 { 70 m_opaque_ap.reset(); 71 } 72 73 const SBValueList & 74 SBValueList::operator = (const SBValueList &rhs) 75 { 76 if (this != &rhs) 77 { 78 if (rhs.IsValid()) 79 m_opaque_ap.reset (new ValueObjectList (*rhs)); 80 else 81 m_opaque_ap.reset (); 82 } 83 return *this; 84 } 85 86 ValueObjectList * 87 SBValueList::operator->() 88 { 89 return m_opaque_ap.get(); 90 } 91 92 ValueObjectList & 93 SBValueList::operator*() 94 { 95 return *m_opaque_ap; 96 } 97 98 const ValueObjectList * 99 SBValueList::operator->() const 100 { 101 return m_opaque_ap.get(); 102 } 103 104 const ValueObjectList & 105 SBValueList::operator*() const 106 { 107 return *m_opaque_ap; 108 } 109 110 void 111 SBValueList::Append (const SBValue &val_obj) 112 { 113 if (val_obj.get()) 114 { 115 CreateIfNeeded (); 116 m_opaque_ap->Append (*val_obj); 117 } 118 } 119 120 void 121 SBValueList::Append (lldb::ValueObjectSP& val_obj_sp) 122 { 123 if (val_obj_sp) 124 { 125 CreateIfNeeded (); 126 m_opaque_ap->Append (val_obj_sp); 127 } 128 } 129 130 void 131 SBValueList::Append (const lldb::SBValueList& value_list) 132 { 133 if (value_list.IsValid()) 134 { 135 CreateIfNeeded (); 136 m_opaque_ap->Append (*value_list); 137 } 138 } 139 140 141 SBValue 142 SBValueList::GetValueAtIndex (uint32_t idx) const 143 { 144 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 145 146 //if (log) 147 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx); 148 149 SBValue sb_value; 150 if (m_opaque_ap.get()) 151 *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx); 152 153 if (log) 154 { 155 SBStream sstr; 156 sb_value.GetDescription (sstr); 157 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')", 158 m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData()); 159 } 160 161 return sb_value; 162 } 163 164 uint32_t 165 SBValueList::GetSize () const 166 { 167 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 168 169 //if (log) 170 // log->Printf ("SBValueList::GetSize ()"); 171 172 uint32_t size = 0; 173 if (m_opaque_ap.get()) 174 size = m_opaque_ap->GetSize(); 175 176 if (log) 177 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size); 178 179 return size; 180 } 181 182 void 183 SBValueList::CreateIfNeeded () 184 { 185 if (m_opaque_ap.get() == NULL) 186 m_opaque_ap.reset (new ValueObjectList()); 187 } 188 189 190 SBValue 191 SBValueList::FindValueObjectByUID (lldb::user_id_t uid) 192 { 193 SBValue sb_value; 194 if (m_opaque_ap.get()) 195 *sb_value = m_opaque_ap->FindValueObjectByUID (uid); 196 return sb_value; 197 } 198 199 ValueObjectList * 200 SBValueList::get () 201 { 202 return m_opaque_ap.get(); 203 } 204 205 ValueObjectList & 206 SBValueList::ref () 207 { 208 CreateIfNeeded(); 209 return *m_opaque_ap.get(); 210 } 211 212 213