blob: d0e2e67879362b69ad618ef36287b0a37b63cf71 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012
13#include "lldb/Core/DataExtractor.h"
Caroline Tice7826c882010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000016#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamFile.h"
19#include "lldb/Core/Value.h"
20#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000021#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Symbol/Block.h"
23#include "lldb/Symbol/ObjectFile.h"
24#include "lldb/Symbol/Variable.h"
25#include "lldb/Target/ExecutionContext.h"
26#include "lldb/Target/Process.h"
27#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000028#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Target/Thread.h"
30
Eli Friedman7a62c8b2010-06-09 07:44:37 +000031#include "lldb/API/SBProcess.h"
32#include "lldb/API/SBTarget.h"
33#include "lldb/API/SBThread.h"
34#include "lldb/API/SBFrame.h"
35#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036
37using namespace lldb;
38using namespace lldb_private;
39
40SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000041 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000042{
43}
44
45SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000046 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000047{
48}
49
Greg Clayton538eb822010-11-05 23:17:00 +000050SBValue::SBValue(const SBValue &rhs) :
51 m_opaque_sp (rhs.m_opaque_sp)
52{
53}
54
Greg Claytond68e0892011-09-09 23:04:00 +000055SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000056SBValue::operator = (const SBValue &rhs)
57{
58 if (this != &rhs)
59 m_opaque_sp = rhs.m_opaque_sp;
60 return *this;
61}
62
Chris Lattner24943d22010-06-08 16:52:24 +000063SBValue::~SBValue()
64{
65}
66
67bool
Greg Claytond68e0892011-09-09 23:04:00 +000068SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000069{
Greg Clayton49ce6822010-10-31 03:01:06 +000070 // If this function ever changes to anything that does more than just
71 // check if the opaque shared pointer is non NULL, then we need to update
72 // all "if (m_opaque_sp)" code in this file.
73 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000074}
75
Greg Claytonc5f728c2010-10-06 22:10:17 +000076SBError
77SBValue::GetError()
78{
79 SBError sb_error;
80
81 if (m_opaque_sp.get())
82 sb_error.SetError(m_opaque_sp->GetError());
83
84 return sb_error;
85}
86
Johnny Chen968958c2011-07-07 20:46:23 +000087user_id_t
88SBValue::GetID()
89{
90 if (m_opaque_sp)
91 return m_opaque_sp->GetID();
92 return LLDB_INVALID_UID;
93}
94
Chris Lattner24943d22010-06-08 16:52:24 +000095const char *
96SBValue::GetName()
97{
Greg Clayton49ce6822010-10-31 03:01:06 +000098
99 const char *name = NULL;
100 if (m_opaque_sp)
101 name = m_opaque_sp->GetName().GetCString();
102
Greg Claytone005f2c2010-11-06 01:53:30 +0000103 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000104 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000105 {
106 if (name)
107 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
108 else
109 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get(), name);
110 }
Caroline Tice7826c882010-10-26 03:11:13 +0000111
Greg Clayton49ce6822010-10-31 03:01:06 +0000112 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000113}
114
115const char *
116SBValue::GetTypeName ()
117{
Greg Clayton49ce6822010-10-31 03:01:06 +0000118 const char *name = NULL;
119 if (m_opaque_sp)
120 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000121 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000122 if (log)
123 {
124 if (name)
125 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
126 else
127 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
128 }
129
130 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000131}
132
133size_t
134SBValue::GetByteSize ()
135{
136 size_t result = 0;
137
Greg Clayton49ce6822010-10-31 03:01:06 +0000138 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000139 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000140
Greg Claytone005f2c2010-11-06 01:53:30 +0000141 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000142 if (log)
143 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
144
Chris Lattner24943d22010-06-08 16:52:24 +0000145 return result;
146}
147
148bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000149SBValue::IsInScope ()
150{
Chris Lattner24943d22010-06-08 16:52:24 +0000151 bool result = false;
152
Greg Clayton49ce6822010-10-31 03:01:06 +0000153 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000154 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000155 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000156 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000157 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000158 result = m_opaque_sp->IsInScope ();
159 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000160 }
Chris Lattner24943d22010-06-08 16:52:24 +0000161
Greg Claytone005f2c2010-11-06 01:53:30 +0000162 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000163 if (log)
164 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
165
Chris Lattner24943d22010-06-08 16:52:24 +0000166 return result;
167}
168
169const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000170SBValue::GetValue ()
171{
Greg Clayton49ce6822010-10-31 03:01:06 +0000172 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000173 if (m_opaque_sp)
174 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000175 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000176 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000177 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000178 cstr = m_opaque_sp->GetValueAsCString ();
179 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000180 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000181 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000182 if (log)
183 {
184 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000185 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000186 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000187 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000188 }
189
190 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000191}
192
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000193ValueType
194SBValue::GetValueType ()
195{
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000197 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000199 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000200 if (log)
201 {
202 switch (result)
203 {
204 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
205 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
206 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
207 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
208 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
209 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
210 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
211 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
212 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
213 }
214 }
215 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000216}
217
Jim Ingham4ae51962010-09-10 23:12:17 +0000218const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000219SBValue::GetObjectDescription ()
220{
Greg Clayton49ce6822010-10-31 03:01:06 +0000221 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000222 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000223 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000224 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000225 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000226 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000227 cstr = m_opaque_sp->GetObjectDescription ();
228 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000229 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000230 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000231 if (log)
232 {
233 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000234 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000235 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000236 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000237 }
238 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000239}
240
Enrico Granata979e20d2011-07-29 19:53:35 +0000241SBType
242SBValue::GetType()
243{
244 SBType result;
245 if (m_opaque_sp)
246 {
247 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
248 {
249 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000250 result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000251 }
252 }
253 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
254 if (log)
255 {
256 if (result.IsValid())
257 log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
258 else
259 log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
260 }
261 return result;
262}
263
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000264bool
265SBValue::GetValueDidChange ()
266{
Greg Clayton49ce6822010-10-31 03:01:06 +0000267 bool result = false;
268 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000269 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000270 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000271 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000272 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000273 result = m_opaque_sp->GetValueDidChange ();
274 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000275 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000276 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000277 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000278 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000279
280 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000281}
282
283const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000284SBValue::GetSummary ()
285{
Greg Clayton49ce6822010-10-31 03:01:06 +0000286 const char *cstr = NULL;
287 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000288 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000289 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000290 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000291 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000292 cstr = m_opaque_sp->GetSummaryAsCString();
293 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000294 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000295 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000296 if (log)
297 {
298 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000299 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000300 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000301 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000302 }
303 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000304}
305
306const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000307SBValue::GetLocation ()
308{
Greg Clayton49ce6822010-10-31 03:01:06 +0000309 const char *cstr = NULL;
310 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000311 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000312 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000313 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000314 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000315 cstr = m_opaque_sp->GetLocationAsCString();
316 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000317 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000318 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000319 if (log)
320 {
321 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000322 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000323 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000324 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000325 }
326 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000327}
328
329bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000330SBValue::SetValueFromCString (const char *value_str)
331{
Chris Lattner24943d22010-06-08 16:52:24 +0000332 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000333 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000334 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000335 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000336 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000337 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000338 success = m_opaque_sp->SetValueFromCString (value_str);
339 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000340 }
Chris Lattner24943d22010-06-08 16:52:24 +0000341 return success;
342}
343
Enrico Granata979e20d2011-07-29 19:53:35 +0000344lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000345SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000346{
347 lldb::SBValue result;
348 if (m_opaque_sp)
349 {
350 if (type.IsValid())
351 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000352 result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
Enrico Granata979e20d2011-07-29 19:53:35 +0000353 result.m_opaque_sp->SetName(ConstString(name));
354 }
355 }
356 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
357 if (log)
358 {
359 if (result.IsValid())
360 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
361 else
362 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
363 }
364 return result;
365}
366
367lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000368SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000369{
370 return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
371}
372
373lldb::SBValue
374SBValue::CreateValueFromExpression (const char *name, const char* expression)
375{
376 lldb::SBValue result;
377 if (m_opaque_sp)
378 {
379 ValueObjectSP result_valobj_sp;
Greg Claytond68e0892011-09-09 23:04:00 +0000380 m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression,
381 m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame(),
382 true, true, eNoDynamicValues,
383 result_valobj_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000384 result_valobj_sp->SetName(ConstString(name));
385 result = SBValue(result_valobj_sp);
386 }
387 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
388 if (log)
389 {
390 if (result.IsValid())
391 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
392 else
393 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
394 }
395 return result;
396}
397
398lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000399SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000400{
401 lldb::SBValue result;
402 if (m_opaque_sp)
403 {
404
405 SBType real_type(type.GetPointerType());
406
407 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
408
Greg Claytond68e0892011-09-09 23:04:00 +0000409 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope(),
410 real_type.m_opaque_sp->GetASTContext(),
411 real_type.m_opaque_sp->GetOpaqueQualType(),
412 ConstString(name),
413 buffer,
414 lldb::endian::InlHostByteOrder(),
415 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000416
Enrico Granatac9310302011-08-04 17:07:02 +0000417 ValueObjectSP result_valobj_sp;
418
419 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
420 if (ptr_result_valobj_sp)
421 {
422 Error err;
423 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
424 if (result_valobj_sp)
425 result_valobj_sp->SetName(ConstString(name));
426 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000427 result = SBValue(result_valobj_sp);
428 }
429 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
430 if (log)
431 {
432 if (result.IsValid())
433 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000434 else
435 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
436 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000437 return result;
438}
439
Enrico Granata91544802011-09-06 19:20:51 +0000440lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000441SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000442{
443 SBValue result;
444
445 AddressType addr_of_children_priv = eAddressTypeLoad;
446
447 if (m_opaque_sp)
448 {
449 ValueObjectSP valobj_sp;
450 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
451 type.m_opaque_sp->GetASTContext() ,
452 type.m_opaque_sp->GetOpaqueQualType(),
453 ConstString(name),
454 *data.m_opaque_sp,
455 LLDB_INVALID_ADDRESS);
456 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
457 result = SBValue(valobj_sp);
458 }
459 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
460 if (log)
461 {
462 if (result.IsValid())
463 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
464 else
465 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
466 }
467 return result;
468}
469
Chris Lattner24943d22010-06-08 16:52:24 +0000470SBValue
471SBValue::GetChildAtIndex (uint32_t idx)
472{
Greg Clayton8f64c472011-07-15 19:31:49 +0000473 const bool can_create_synthetic = false;
474 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000475 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000476 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000477 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000478}
479
480SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000481SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000482{
Chris Lattner24943d22010-06-08 16:52:24 +0000483 lldb::ValueObjectSP child_sp;
484
Greg Clayton49ce6822010-10-31 03:01:06 +0000485 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000486 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000487 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000488 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000489 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000490 const bool can_create = true;
491 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
492 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000493 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000494 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000495 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000496 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
497 }
498 else if (m_opaque_sp->IsArrayType())
499 {
500 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
501 }
502 }
503
504 if (child_sp)
505 {
506 if (use_dynamic != lldb::eNoDynamicValues)
507 {
508 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000509 if (dynamic_sp)
510 child_sp = dynamic_sp;
511 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000512 }
Jim Inghame41494a2011-04-16 00:01:13 +0000513 }
514 }
515
Chris Lattner24943d22010-06-08 16:52:24 +0000516 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000517 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000518 if (log)
519 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
520
Chris Lattner24943d22010-06-08 16:52:24 +0000521 return sb_value;
522}
523
524uint32_t
525SBValue::GetIndexOfChildWithName (const char *name)
526{
Greg Clayton49ce6822010-10-31 03:01:06 +0000527 uint32_t idx = UINT32_MAX;
528 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000529 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000530 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000531 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000532 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000533
Greg Claytonb9dcc512011-06-29 18:28:50 +0000534 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
535 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000536 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000537 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000538 if (log)
539 {
540 if (idx == UINT32_MAX)
541 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
542 else
543 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
544 }
545 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000546}
547
548SBValue
549SBValue::GetChildMemberWithName (const char *name)
550{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000551 if (m_opaque_sp)
552 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000553 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000554 return GetChildMemberWithName (name, use_dynamic_value);
555 }
556 else
557 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000558}
559
560SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000561SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000562{
Chris Lattner24943d22010-06-08 16:52:24 +0000563 lldb::ValueObjectSP child_sp;
564 const ConstString str_name (name);
565
Greg Clayton905acaf2011-05-20 22:07:17 +0000566
Greg Clayton49ce6822010-10-31 03:01:06 +0000567 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000568 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000569 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000570 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000571 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000572 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
573 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000574 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000575 if (child_sp)
576 {
577 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
578 if (dynamic_sp)
579 child_sp = dynamic_sp;
580 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000581 }
Jim Inghame41494a2011-04-16 00:01:13 +0000582 }
583 }
584
Chris Lattner24943d22010-06-08 16:52:24 +0000585 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000586
Greg Claytone005f2c2010-11-06 01:53:30 +0000587 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000588 if (log)
589 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
590
Chris Lattner24943d22010-06-08 16:52:24 +0000591 return sb_value;
592}
593
Enrico Granataf7a9b142011-07-15 02:26:42 +0000594lldb::SBValue
595SBValue::GetValueForExpressionPath(const char* expr_path)
596{
597 lldb::ValueObjectSP child_sp;
598 if (m_opaque_sp)
599 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000600 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000601 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000602 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000603 // using default values for all the fancy options, just do it if you can
604 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
605 }
606 }
607
608 SBValue sb_value (child_sp);
609
610 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
611 if (log)
612 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
613
614 return sb_value;
615}
Chris Lattner24943d22010-06-08 16:52:24 +0000616
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000617int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000618SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
619{
Jim Ingham574c3d62011-08-12 23:34:31 +0000620 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000621 if (m_opaque_sp)
622 {
623 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
624 {
625 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
626 Scalar scalar;
627 if (m_opaque_sp->ResolveValue (scalar))
628 return scalar.GetRawBits64(fail_value);
629 else
630 error.SetErrorString("could not get value");
631 }
632 else
633 error.SetErrorString("could not get target");
634 }
635 error.SetErrorString("invalid SBValue");
636 return fail_value;
637}
638
639uint64_t
640SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
641{
Jim Ingham574c3d62011-08-12 23:34:31 +0000642 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000643 if (m_opaque_sp)
644 {
645 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
646 {
647 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
648 Scalar scalar;
649 if (m_opaque_sp->ResolveValue (scalar))
650 return scalar.GetRawBits64(fail_value);
651 else
652 error.SetErrorString("could not get value");
653 }
654 else
655 error.SetErrorString("could not get target");
656 }
657 error.SetErrorString("invalid SBValue");
658 return fail_value;
659}
660
661int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000662SBValue::GetValueAsSigned(int64_t fail_value)
663{
664 if (m_opaque_sp)
665 {
666 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
667 {
668 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
669 Scalar scalar;
670 if (m_opaque_sp->ResolveValue (scalar))
671 return scalar.GetRawBits64(fail_value);
672 }
673 }
674 return fail_value;
675}
676
677uint64_t
678SBValue::GetValueAsUnsigned(uint64_t fail_value)
679{
680 if (m_opaque_sp)
681 {
682 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
683 {
684 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
685 Scalar scalar;
686 if (m_opaque_sp->ResolveValue (scalar))
687 return scalar.GetRawBits64(fail_value);
688 }
689 }
690 return fail_value;
691}
692
Chris Lattner24943d22010-06-08 16:52:24 +0000693uint32_t
694SBValue::GetNumChildren ()
695{
696 uint32_t num_children = 0;
697
Greg Clayton49ce6822010-10-31 03:01:06 +0000698 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000699 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000700 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000701 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000702 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000703
Greg Claytonb9dcc512011-06-29 18:28:50 +0000704 num_children = m_opaque_sp->GetNumChildren();
705 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000706 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000707
Greg Claytone005f2c2010-11-06 01:53:30 +0000708 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000709 if (log)
710 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000711
712 return num_children;
713}
714
Chris Lattner24943d22010-06-08 16:52:24 +0000715
716SBValue
717SBValue::Dereference ()
718{
Greg Clayton49ce6822010-10-31 03:01:06 +0000719 SBValue sb_value;
720 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000721 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000722 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000723 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000724 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000725
Greg Claytonb9dcc512011-06-29 18:28:50 +0000726 Error error;
727 sb_value = m_opaque_sp->Dereference (error);
728 }
Chris Lattner24943d22010-06-08 16:52:24 +0000729 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000730 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000731 if (log)
732 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
733
734 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000735}
736
737bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000738SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000739{
740 bool is_ptr_type = false;
741
Greg Clayton49ce6822010-10-31 03:01:06 +0000742 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000743 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000744 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000745 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000746 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000747
Greg Claytonb9dcc512011-06-29 18:28:50 +0000748 is_ptr_type = m_opaque_sp->IsPointerType();
749 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000750 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000751
Greg Claytone005f2c2010-11-06 01:53:30 +0000752 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000753 if (log)
754 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
755
Chris Lattner24943d22010-06-08 16:52:24 +0000756
757 return is_ptr_type;
758}
759
Chris Lattner24943d22010-06-08 16:52:24 +0000760void *
761SBValue::GetOpaqueType()
762{
Greg Clayton63094e02010-06-23 01:19:29 +0000763 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000764 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000765 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000766 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000767 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000768
Greg Claytonb9dcc512011-06-29 18:28:50 +0000769 return m_opaque_sp->GetClangType();
770 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000771 }
Chris Lattner24943d22010-06-08 16:52:24 +0000772 return NULL;
773}
774
Enrico Granata979e20d2011-07-29 19:53:35 +0000775lldb::SBTarget
776SBValue::GetTarget()
777{
778 SBTarget result;
779 if (m_opaque_sp)
780 {
781 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
782 {
783 result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
784 }
785 }
786 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
787 if (log)
788 {
789 if (result.get() == NULL)
790 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
791 else
792 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
793 }
794 return result;
795}
796
797lldb::SBProcess
798SBValue::GetProcess()
799{
800 SBProcess result;
801 if (m_opaque_sp)
802 {
Enrico Granata91544802011-09-06 19:20:51 +0000803 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
804 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000805 {
Enrico Granata91544802011-09-06 19:20:51 +0000806 result = SBProcess(lldb::ProcessSP(target->GetProcessSP()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000807 }
808 }
809 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
810 if (log)
811 {
812 if (result.get() == NULL)
813 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
814 else
815 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
816 }
817 return result;
818}
819
820lldb::SBThread
821SBValue::GetThread()
822{
823 SBThread result;
824 if (m_opaque_sp)
825 {
826 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
827 {
Greg Claytond68e0892011-09-09 23:04:00 +0000828 result = SBThread(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateThread()->GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000829 }
830 }
831 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
832 if (log)
833 {
834 if (result.get() == NULL)
835 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
836 else
837 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get());
838 }
839 return result;
840}
841
842lldb::SBFrame
843SBValue::GetFrame()
844{
845 SBFrame result;
846 if (m_opaque_sp)
847 {
848 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
849 {
Greg Claytond68e0892011-09-09 23:04:00 +0000850 result.SetFrame (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame()->GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000851 }
852 }
853 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
854 if (log)
855 {
856 if (result.get() == NULL)
857 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
858 else
859 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
860 }
861 return result;
862}
863
864
Chris Lattner24943d22010-06-08 16:52:24 +0000865// Mimic shared pointer...
866lldb_private::ValueObject *
867SBValue::get() const
868{
Greg Clayton63094e02010-06-23 01:19:29 +0000869 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000870}
871
872lldb_private::ValueObject *
873SBValue::operator->() const
874{
Greg Clayton63094e02010-06-23 01:19:29 +0000875 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000876}
877
878lldb::ValueObjectSP &
879SBValue::operator*()
880{
Greg Clayton63094e02010-06-23 01:19:29 +0000881 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000882}
883
884const lldb::ValueObjectSP &
885SBValue::operator*() const
886{
Greg Clayton63094e02010-06-23 01:19:29 +0000887 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000888}
Caroline Tice98f930f2010-09-20 05:20:02 +0000889
890bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000891SBValue::GetExpressionPath (SBStream &description)
892{
893 if (m_opaque_sp)
894 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000895 m_opaque_sp->GetExpressionPath (description.ref(), false);
896 return true;
897 }
898 return false;
899}
900
901bool
902SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
903{
904 if (m_opaque_sp)
905 {
906 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000907 return true;
908 }
909 return false;
910}
911
912bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000913SBValue::GetDescription (SBStream &description)
914{
915 if (m_opaque_sp)
916 {
Enrico Granata19030d82011-08-15 18:01:31 +0000917 /*uint32_t ptr_depth = 0;
Greg Claytonbafc86e2011-07-06 16:49:27 +0000918 uint32_t curr_depth = 0;
919 uint32_t max_depth = UINT32_MAX;
920 bool show_types = false;
921 bool show_location = false;
922 bool use_objc = false;
923 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
924 bool scope_already_checked = false;
925 bool flat_output = false;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000926 bool use_synthetic = true;
927 uint32_t no_summary_depth = 0;
Enrico Granata19030d82011-08-15 18:01:31 +0000928 bool ignore_cap = false;*/
Greg Claytonbafc86e2011-07-06 16:49:27 +0000929 ValueObject::DumpValueObject (description.ref(),
Enrico Granata19030d82011-08-15 18:01:31 +0000930 m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000931 }
932 else
933 description.Printf ("No value");
934
935 return true;
936}
Greg Claytone179a582011-01-05 18:43:15 +0000937
938lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +0000939SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +0000940{
941 if (m_opaque_sp)
942 return m_opaque_sp->GetFormat();
943 return eFormatDefault;
944}
945
946void
947SBValue::SetFormat (lldb::Format format)
948{
949 if (m_opaque_sp)
950 m_opaque_sp->SetFormat(format);
951}
952
Enrico Granata979e20d2011-07-29 19:53:35 +0000953lldb::SBValue
954SBValue::AddressOf()
955{
956 SBValue sb_value;
957 if (m_opaque_sp)
958 {
Enrico Granata91544802011-09-06 19:20:51 +0000959 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
960 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000961 {
Enrico Granata91544802011-09-06 19:20:51 +0000962 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +0000963 Error error;
964 sb_value = m_opaque_sp->AddressOf (error);
965 }
966 }
967 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
968 if (log)
969 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
970
971 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +0000972}
Enrico Granata91544802011-09-06 19:20:51 +0000973
974lldb::addr_t
975SBValue::GetLoadAddress()
976{
977 lldb::addr_t value = LLDB_INVALID_ADDRESS;
978 if (m_opaque_sp)
979 {
980 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
981 if (target)
982 {
983 Mutex::Locker api_locker (target->GetAPIMutex());
984 const bool scalar_is_load_address = true;
985 AddressType addr_type;
986 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
987 if (addr_type == eAddressTypeFile)
988 {
989 Module* module = m_opaque_sp->GetModule();
990 if (!module)
991 value = LLDB_INVALID_ADDRESS;
992 else
993 {
994 Address addr;
995 module->ResolveFileAddress(value, addr);
996 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
997 }
998 }
999 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1000 value = LLDB_INVALID_ADDRESS;
1001 }
1002 }
1003 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1004 if (log)
1005 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1006
1007 return value;
1008}
1009
1010lldb::SBAddress
1011SBValue::GetAddress()
1012{
1013 Address addr;
1014 if (m_opaque_sp)
1015 {
1016 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1017 if (target)
1018 {
1019 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1020 Mutex::Locker api_locker (target->GetAPIMutex());
1021 const bool scalar_is_load_address = true;
1022 AddressType addr_type;
1023 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1024 if (addr_type == eAddressTypeFile)
1025 {
1026 Module* module = m_opaque_sp->GetModule();
1027 if (module)
1028 module->ResolveFileAddress(value, addr);
1029 }
1030 else if (addr_type == eAddressTypeLoad)
1031 {
1032 // no need to check the return value on this.. if it can actually do the resolve
1033 // addr will be in the form (section,offset), otherwise it will simply be returned
1034 // as (NULL, value)
1035 addr.SetLoadAddress(value, target);
1036 }
1037 }
1038 }
1039 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1040 if (log)
1041 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1042 return SBAddress(new Address(addr));
1043}
1044
1045lldb::SBData
1046SBValue::GetPointeeData (uint32_t item_idx,
1047 uint32_t item_count)
1048{
1049 lldb::SBData sb_data;
1050 if (m_opaque_sp)
1051 {
1052 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1053 if (target)
1054 {
1055 DataExtractorSP data_sp(new DataExtractor());
1056 Mutex::Locker api_locker (target->GetAPIMutex());
1057 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1058 if (data_sp->GetByteSize() > 0)
1059 *sb_data = data_sp;
1060 }
1061 }
1062 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1063 if (log)
1064 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1065 m_opaque_sp.get(),
1066 item_idx,
1067 item_count,
1068 sb_data.get());
1069
1070 return sb_data;
1071}
1072
1073lldb::SBData
1074SBValue::GetData ()
1075{
1076 lldb::SBData sb_data;
1077 if (m_opaque_sp)
1078 {
1079 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1080 if (target)
1081 {
1082 DataExtractorSP data_sp(new DataExtractor());
1083 Mutex::Locker api_locker (target->GetAPIMutex());
1084 m_opaque_sp->GetData(*data_sp);
1085 if (data_sp->GetByteSize() > 0)
1086 *sb_data = data_sp;
1087 }
1088 }
1089 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1090 if (log)
1091 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1092 m_opaque_sp.get(),
1093 sb_data.get());
1094
1095 return sb_data;
1096}