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(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 29 30 if (rhs.IsValid()) 31 m_opaque_ap.reset (new lldb_private::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 lldb_private::ValueObjectList *lldb_object_ptr) : 42 m_opaque_ap () 43 { 44 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 45 46 if (lldb_object_ptr) 47 m_opaque_ap.reset (new lldb_private::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 const SBValueList & 68 SBValueList::operator = (const SBValueList &rhs) 69 { 70 if (this != &rhs) 71 { 72 if (rhs.IsValid()) 73 m_opaque_ap.reset (new lldb_private::ValueObjectList (*rhs)); 74 else 75 m_opaque_ap.reset (); 76 } 77 return *this; 78 } 79 80 lldb_private::ValueObjectList * 81 SBValueList::operator->() 82 { 83 return m_opaque_ap.get(); 84 } 85 86 lldb_private::ValueObjectList & 87 SBValueList::operator*() 88 { 89 return *m_opaque_ap; 90 } 91 92 const lldb_private::ValueObjectList * 93 SBValueList::operator->() const 94 { 95 return m_opaque_ap.get(); 96 } 97 98 const lldb_private::ValueObjectList & 99 SBValueList::operator*() const 100 { 101 return *m_opaque_ap; 102 } 103 104 void 105 SBValueList::Append (const SBValue &val_obj) 106 { 107 if (val_obj.get()) 108 { 109 CreateIfNeeded (); 110 m_opaque_ap->Append (*val_obj); 111 } 112 } 113 114 void 115 SBValueList::Append (lldb::ValueObjectSP& val_obj_sp) 116 { 117 if (val_obj_sp) 118 { 119 CreateIfNeeded (); 120 m_opaque_ap->Append (val_obj_sp); 121 } 122 } 123 124 125 SBValue 126 SBValueList::GetValueAtIndex (uint32_t idx) const 127 { 128 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 129 130 //if (log) 131 // log->Printf ("SBValueList::GetValueAtIndex (uint32_t idx) idx = %d", idx); 132 133 SBValue sb_value; 134 if (m_opaque_ap.get()) 135 *sb_value = m_opaque_ap->GetValueObjectAtIndex (idx); 136 137 if (log) 138 { 139 SBStream sstr; 140 sb_value.GetDescription (sstr); 141 log->Printf ("SBValueList::GetValueAtIndex (this.ap=%p, idx=%d) => SBValue (this.sp = %p, '%s')", 142 m_opaque_ap.get(), idx, sb_value.get(), sstr.GetData()); 143 } 144 145 return sb_value; 146 } 147 148 uint32_t 149 SBValueList::GetSize () const 150 { 151 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 152 153 //if (log) 154 // log->Printf ("SBValueList::GetSize ()"); 155 156 uint32_t size = 0; 157 if (m_opaque_ap.get()) 158 size = m_opaque_ap->GetSize(); 159 160 if (log) 161 log->Printf ("SBValueList::GetSize (this.ap=%p) => %d", m_opaque_ap.get(), size); 162 163 return size; 164 } 165 166 void 167 SBValueList::CreateIfNeeded () 168 { 169 if (m_opaque_ap.get() == NULL) 170 m_opaque_ap.reset (new ValueObjectList()); 171 } 172 173 174 SBValue 175 SBValueList::FindValueObjectByUID (lldb::user_id_t uid) 176 { 177 SBValue sb_value; 178 if (m_opaque_ap.get()) 179 *sb_value = m_opaque_ap->FindValueObjectByUID (uid); 180 return sb_value; 181 } 182 183 lldb_private::ValueObjectList * 184 SBValueList::get () 185 { 186 return m_opaque_ap.get(); 187 } 188 189