SBValue.cpp revision 462d4147f3bb9141bf62d904f58a623db00669df
1//===-- SBValue.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#include "lldb/API/SBValue.h" 11#include "lldb/API/SBStream.h" 12 13#include "lldb/Core/DataExtractor.h" 14#include "lldb/Core/Module.h" 15#include "lldb/Core/Stream.h" 16#include "lldb/Core/StreamFile.h" 17#include "lldb/Core/Value.h" 18#include "lldb/Core/ValueObject.h" 19#include "lldb/Symbol/Block.h" 20#include "lldb/Symbol/ObjectFile.h" 21#include "lldb/Symbol/Variable.h" 22#include "lldb/Target/ExecutionContext.h" 23#include "lldb/Target/Process.h" 24#include "lldb/Target/StackFrame.h" 25#include "lldb/Target/Thread.h" 26 27#include "lldb/API/SBProcess.h" 28#include "lldb/API/SBTarget.h" 29#include "lldb/API/SBThread.h" 30#include "lldb/API/SBFrame.h" 31#include "lldb/API/SBDebugger.h" 32 33using namespace lldb; 34using namespace lldb_private; 35 36SBValue::SBValue () : 37 m_opaque_sp () 38{ 39} 40 41SBValue::SBValue (const lldb::ValueObjectSP &value_sp) : 42 m_opaque_sp (value_sp) 43{ 44} 45 46SBValue::~SBValue() 47{ 48} 49 50bool 51SBValue::IsValid () const 52{ 53 return (m_opaque_sp.get() != NULL); 54} 55 56const char * 57SBValue::GetName() 58{ 59 if (IsValid()) 60 return m_opaque_sp->GetName().AsCString(); 61 else 62 return NULL; 63} 64 65const char * 66SBValue::GetTypeName () 67{ 68 if (IsValid()) 69 return m_opaque_sp->GetTypeName().AsCString(); 70 else 71 return NULL; 72} 73 74size_t 75SBValue::GetByteSize () 76{ 77 size_t result = 0; 78 79 if (IsValid()) 80 result = m_opaque_sp->GetByteSize(); 81 82 return result; 83} 84 85bool 86SBValue::IsInScope (const SBFrame &frame) 87{ 88 bool result = false; 89 90 if (IsValid()) 91 result = m_opaque_sp->IsInScope (frame.get()); 92 93 return result; 94} 95 96const char * 97SBValue::GetValue (const SBFrame &frame) 98{ 99 const char *value_string = NULL; 100 if ( m_opaque_sp) 101 value_string = m_opaque_sp->GetValueAsCString (frame.get()); 102 return value_string; 103} 104 105const char * 106SBValue::GetObjectDescription (const SBFrame &frame) 107{ 108 const char *value_string = NULL; 109 if ( m_opaque_sp) 110 value_string = m_opaque_sp->GetObjectDescription (frame.get()); 111 return value_string; 112} 113 114bool 115SBValue::GetValueDidChange (const SBFrame &frame) 116{ 117 if (IsValid()) 118 return m_opaque_sp->GetValueDidChange (frame.get()); 119 return false; 120} 121 122const char * 123SBValue::GetSummary (const SBFrame &frame) 124{ 125 const char *value_string = NULL; 126 if ( m_opaque_sp) 127 value_string = m_opaque_sp->GetSummaryAsCString(frame.get()); 128 return value_string; 129} 130 131const char * 132SBValue::GetLocation (const SBFrame &frame) 133{ 134 const char *value_string = NULL; 135 if (IsValid()) 136 value_string = m_opaque_sp->GetLocationAsCString(frame.get()); 137 return value_string; 138} 139 140bool 141SBValue::SetValueFromCString (const SBFrame &frame, const char *value_str) 142{ 143 bool success = false; 144 if (IsValid()) 145 success = m_opaque_sp->SetValueFromCString (frame.get(), value_str); 146 return success; 147} 148 149SBValue 150SBValue::GetChildAtIndex (uint32_t idx) 151{ 152 lldb::ValueObjectSP child_sp; 153 154 if (IsValid()) 155 { 156 child_sp = m_opaque_sp->GetChildAtIndex (idx, true); 157 } 158 159 SBValue sb_value (child_sp); 160 return sb_value; 161} 162 163uint32_t 164SBValue::GetIndexOfChildWithName (const char *name) 165{ 166 if (IsValid()) 167 return m_opaque_sp->GetIndexOfChildWithName (ConstString(name)); 168 return UINT32_MAX; 169} 170 171SBValue 172SBValue::GetChildMemberWithName (const char *name) 173{ 174 lldb::ValueObjectSP child_sp; 175 const ConstString str_name (name); 176 177 if (IsValid()) 178 { 179 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true); 180 } 181 182 SBValue sb_value (child_sp); 183 return sb_value; 184} 185 186 187uint32_t 188SBValue::GetNumChildren () 189{ 190 uint32_t num_children = 0; 191 192 if (IsValid()) 193 { 194 num_children = m_opaque_sp->GetNumChildren(); 195 } 196 197 return num_children; 198} 199 200bool 201SBValue::ValueIsStale () 202{ 203 bool result = true; 204 205 if (IsValid()) 206 { 207 result = m_opaque_sp->GetValueIsValid(); 208 } 209 210 return result; 211} 212 213 214SBValue 215SBValue::Dereference () 216{ 217 if (IsValid()) 218 { 219 if (m_opaque_sp->IsPointerType()) 220 { 221 return GetChildAtIndex(0); 222 } 223 } 224 return *this; 225} 226 227bool 228SBValue::TypeIsPtrType () 229{ 230 bool is_ptr_type = false; 231 232 if (IsValid()) 233 { 234 is_ptr_type = m_opaque_sp->IsPointerType(); 235 } 236 237 return is_ptr_type; 238} 239 240void * 241SBValue::GetOpaqueType() 242{ 243 if (m_opaque_sp) 244 return m_opaque_sp->GetClangType(); 245 return NULL; 246} 247 248// Mimic shared pointer... 249lldb_private::ValueObject * 250SBValue::get() const 251{ 252 return m_opaque_sp.get(); 253} 254 255lldb_private::ValueObject * 256SBValue::operator->() const 257{ 258 return m_opaque_sp.get(); 259} 260 261lldb::ValueObjectSP & 262SBValue::operator*() 263{ 264 return m_opaque_sp; 265} 266 267const lldb::ValueObjectSP & 268SBValue::operator*() const 269{ 270 return m_opaque_sp; 271} 272 273bool 274SBValue::GetDescription (SBStream &description) 275{ 276 if (m_opaque_sp) 277 { 278 const char *name = GetName(); 279 const char *type_name = GetTypeName (); 280 size_t byte_size = GetByteSize (); 281 uint32_t num_children = GetNumChildren (); 282 bool is_stale = ValueIsStale (); 283 description.Printf ("name: '%s', type: %s, size: %d", (name != NULL ? name : "<unknown name>"), 284 (type_name != NULL ? type_name : "<unknown type name>"), (int) byte_size); 285 if (num_children > 0) 286 description.Printf (", num_children: %d", num_children); 287 288 if (is_stale) 289 description.Printf (" [value is stale]"); 290 } 291 else 292 description.Printf ("No value"); 293 294 return true; 295} 296