blob: 37a524495e7085f7d40309e2e6c21b5415ec0dc8 [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
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000109 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000110 }
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())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000360 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000361 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(),
Sean Callanana8428a42011-09-22 00:41:11 +0000382 eExecutionPolicyOnlyWhenNeeded,
Sean Callanan47dc4572011-09-15 02:13:07 +0000383 true, // unwind on error
384 true, // keep in memory
385 eNoDynamicValues,
Greg Claytond68e0892011-09-09 23:04:00 +0000386 result_valobj_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000387 result_valobj_sp->SetName(ConstString(name));
388 result = SBValue(result_valobj_sp);
389 }
390 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
391 if (log)
392 {
393 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000394 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000395 else
396 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
397 }
398 return result;
399}
400
401lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000402SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000403{
404 lldb::SBValue result;
405 if (m_opaque_sp)
406 {
407
408 SBType real_type(type.GetPointerType());
409
410 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
411
Greg Claytond68e0892011-09-09 23:04:00 +0000412 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope(),
413 real_type.m_opaque_sp->GetASTContext(),
414 real_type.m_opaque_sp->GetOpaqueQualType(),
415 ConstString(name),
416 buffer,
417 lldb::endian::InlHostByteOrder(),
418 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000419
Enrico Granatac9310302011-08-04 17:07:02 +0000420 ValueObjectSP result_valobj_sp;
421
422 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
423 if (ptr_result_valobj_sp)
424 {
425 Error err;
426 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
427 if (result_valobj_sp)
428 result_valobj_sp->SetName(ConstString(name));
429 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000430 result = SBValue(result_valobj_sp);
431 }
432 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
433 if (log)
434 {
435 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000436 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000437 else
438 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
439 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000440 return result;
441}
442
Enrico Granata91544802011-09-06 19:20:51 +0000443lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000444SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000445{
446 SBValue result;
447
448 AddressType addr_of_children_priv = eAddressTypeLoad;
449
450 if (m_opaque_sp)
451 {
452 ValueObjectSP valobj_sp;
453 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
454 type.m_opaque_sp->GetASTContext() ,
455 type.m_opaque_sp->GetOpaqueQualType(),
456 ConstString(name),
457 *data.m_opaque_sp,
458 LLDB_INVALID_ADDRESS);
459 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
460 result = SBValue(valobj_sp);
461 }
462 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
463 if (log)
464 {
465 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000466 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000467 else
468 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
469 }
470 return result;
471}
472
Chris Lattner24943d22010-06-08 16:52:24 +0000473SBValue
474SBValue::GetChildAtIndex (uint32_t idx)
475{
Greg Clayton8f64c472011-07-15 19:31:49 +0000476 const bool can_create_synthetic = false;
477 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000478 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000479 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000480 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000481}
482
483SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000484SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000485{
Chris Lattner24943d22010-06-08 16:52:24 +0000486 lldb::ValueObjectSP child_sp;
487
Greg Clayton49ce6822010-10-31 03:01:06 +0000488 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000489 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000490 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000491 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000492 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000493 const bool can_create = true;
494 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
495 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000496 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000497 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000498 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000499 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
500 }
501 else if (m_opaque_sp->IsArrayType())
502 {
503 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
504 }
505 }
506
507 if (child_sp)
508 {
509 if (use_dynamic != lldb::eNoDynamicValues)
510 {
511 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000512 if (dynamic_sp)
513 child_sp = dynamic_sp;
514 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000515 }
Jim Inghame41494a2011-04-16 00:01:13 +0000516 }
517 }
518
Chris Lattner24943d22010-06-08 16:52:24 +0000519 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000520 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000521 if (log)
522 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
523
Chris Lattner24943d22010-06-08 16:52:24 +0000524 return sb_value;
525}
526
527uint32_t
528SBValue::GetIndexOfChildWithName (const char *name)
529{
Greg Clayton49ce6822010-10-31 03:01:06 +0000530 uint32_t idx = UINT32_MAX;
531 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000532 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000533 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000534 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000535 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000536
Greg Claytonb9dcc512011-06-29 18:28:50 +0000537 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
538 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000539 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000540 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000541 if (log)
542 {
543 if (idx == UINT32_MAX)
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000544 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000545 else
546 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
547 }
548 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000549}
550
551SBValue
552SBValue::GetChildMemberWithName (const char *name)
553{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000554 if (m_opaque_sp)
555 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000556 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000557 return GetChildMemberWithName (name, use_dynamic_value);
558 }
559 else
560 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000561}
562
563SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000564SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000565{
Chris Lattner24943d22010-06-08 16:52:24 +0000566 lldb::ValueObjectSP child_sp;
567 const ConstString str_name (name);
568
Greg Clayton905acaf2011-05-20 22:07:17 +0000569
Greg Clayton49ce6822010-10-31 03:01:06 +0000570 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000571 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000572 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000573 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000574 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000575 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
576 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000577 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000578 if (child_sp)
579 {
580 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
581 if (dynamic_sp)
582 child_sp = dynamic_sp;
583 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000584 }
Jim Inghame41494a2011-04-16 00:01:13 +0000585 }
586 }
587
Chris Lattner24943d22010-06-08 16:52:24 +0000588 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000589
Greg Claytone005f2c2010-11-06 01:53:30 +0000590 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000591 if (log)
592 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
593
Chris Lattner24943d22010-06-08 16:52:24 +0000594 return sb_value;
595}
596
Enrico Granataf7a9b142011-07-15 02:26:42 +0000597lldb::SBValue
598SBValue::GetValueForExpressionPath(const char* expr_path)
599{
600 lldb::ValueObjectSP child_sp;
601 if (m_opaque_sp)
602 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000603 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000604 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000605 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000606 // using default values for all the fancy options, just do it if you can
607 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
608 }
609 }
610
611 SBValue sb_value (child_sp);
612
613 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
614 if (log)
615 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
616
617 return sb_value;
618}
Chris Lattner24943d22010-06-08 16:52:24 +0000619
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000620int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000621SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
622{
Jim Ingham574c3d62011-08-12 23:34:31 +0000623 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000624 if (m_opaque_sp)
625 {
626 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
627 {
628 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
629 Scalar scalar;
630 if (m_opaque_sp->ResolveValue (scalar))
631 return scalar.GetRawBits64(fail_value);
632 else
633 error.SetErrorString("could not get value");
634 }
635 else
636 error.SetErrorString("could not get target");
637 }
638 error.SetErrorString("invalid SBValue");
639 return fail_value;
640}
641
642uint64_t
643SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
644{
Jim Ingham574c3d62011-08-12 23:34:31 +0000645 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000646 if (m_opaque_sp)
647 {
648 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
649 {
650 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
651 Scalar scalar;
652 if (m_opaque_sp->ResolveValue (scalar))
653 return scalar.GetRawBits64(fail_value);
654 else
655 error.SetErrorString("could not get value");
656 }
657 else
658 error.SetErrorString("could not get target");
659 }
660 error.SetErrorString("invalid SBValue");
661 return fail_value;
662}
663
664int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000665SBValue::GetValueAsSigned(int64_t fail_value)
666{
667 if (m_opaque_sp)
668 {
669 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
670 {
671 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
672 Scalar scalar;
673 if (m_opaque_sp->ResolveValue (scalar))
674 return scalar.GetRawBits64(fail_value);
675 }
676 }
677 return fail_value;
678}
679
680uint64_t
681SBValue::GetValueAsUnsigned(uint64_t fail_value)
682{
683 if (m_opaque_sp)
684 {
685 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
686 {
687 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
688 Scalar scalar;
689 if (m_opaque_sp->ResolveValue (scalar))
690 return scalar.GetRawBits64(fail_value);
691 }
692 }
693 return fail_value;
694}
695
Chris Lattner24943d22010-06-08 16:52:24 +0000696uint32_t
697SBValue::GetNumChildren ()
698{
699 uint32_t num_children = 0;
700
Greg Clayton49ce6822010-10-31 03:01:06 +0000701 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000702 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000703 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000704 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000705 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000706
Greg Claytonb9dcc512011-06-29 18:28:50 +0000707 num_children = m_opaque_sp->GetNumChildren();
708 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000709 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000710
Greg Claytone005f2c2010-11-06 01:53:30 +0000711 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000712 if (log)
713 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000714
715 return num_children;
716}
717
Chris Lattner24943d22010-06-08 16:52:24 +0000718
719SBValue
720SBValue::Dereference ()
721{
Greg Clayton49ce6822010-10-31 03:01:06 +0000722 SBValue sb_value;
723 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000724 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000725 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000726 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000727 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000728
Greg Claytonb9dcc512011-06-29 18:28:50 +0000729 Error error;
730 sb_value = m_opaque_sp->Dereference (error);
731 }
Chris Lattner24943d22010-06-08 16:52:24 +0000732 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000733 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000734 if (log)
735 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
736
737 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000738}
739
740bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000741SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000742{
743 bool is_ptr_type = false;
744
Greg Clayton49ce6822010-10-31 03:01:06 +0000745 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000746 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000747 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000748 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000749 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000750
Greg Claytonb9dcc512011-06-29 18:28:50 +0000751 is_ptr_type = m_opaque_sp->IsPointerType();
752 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000753 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000754
Greg Claytone005f2c2010-11-06 01:53:30 +0000755 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000756 if (log)
757 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
758
Chris Lattner24943d22010-06-08 16:52:24 +0000759
760 return is_ptr_type;
761}
762
Chris Lattner24943d22010-06-08 16:52:24 +0000763void *
764SBValue::GetOpaqueType()
765{
Greg Clayton63094e02010-06-23 01:19:29 +0000766 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000767 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000768 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000769 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000770 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000771
Greg Claytonb9dcc512011-06-29 18:28:50 +0000772 return m_opaque_sp->GetClangType();
773 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000774 }
Chris Lattner24943d22010-06-08 16:52:24 +0000775 return NULL;
776}
777
Enrico Granata979e20d2011-07-29 19:53:35 +0000778lldb::SBTarget
779SBValue::GetTarget()
780{
781 SBTarget result;
782 if (m_opaque_sp)
783 {
784 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
785 {
786 result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
787 }
788 }
789 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
790 if (log)
791 {
792 if (result.get() == NULL)
793 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
794 else
795 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
796 }
797 return result;
798}
799
800lldb::SBProcess
801SBValue::GetProcess()
802{
803 SBProcess result;
804 if (m_opaque_sp)
805 {
Enrico Granata91544802011-09-06 19:20:51 +0000806 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
807 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000808 {
Enrico Granata91544802011-09-06 19:20:51 +0000809 result = SBProcess(lldb::ProcessSP(target->GetProcessSP()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000810 }
811 }
812 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
813 if (log)
814 {
815 if (result.get() == NULL)
816 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
817 else
818 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
819 }
820 return result;
821}
822
823lldb::SBThread
824SBValue::GetThread()
825{
826 SBThread result;
827 if (m_opaque_sp)
828 {
829 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
830 {
Greg Claytond68e0892011-09-09 23:04:00 +0000831 result = SBThread(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateThread()->GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000832 }
833 }
834 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
835 if (log)
836 {
837 if (result.get() == NULL)
838 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
839 else
840 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get());
841 }
842 return result;
843}
844
845lldb::SBFrame
846SBValue::GetFrame()
847{
848 SBFrame result;
849 if (m_opaque_sp)
850 {
851 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
852 {
Greg Claytond68e0892011-09-09 23:04:00 +0000853 result.SetFrame (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame()->GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000854 }
855 }
856 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
857 if (log)
858 {
859 if (result.get() == NULL)
860 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
861 else
862 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
863 }
864 return result;
865}
866
867
Chris Lattner24943d22010-06-08 16:52:24 +0000868// Mimic shared pointer...
869lldb_private::ValueObject *
870SBValue::get() const
871{
Greg Clayton63094e02010-06-23 01:19:29 +0000872 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000873}
874
875lldb_private::ValueObject *
876SBValue::operator->() const
877{
Greg Clayton63094e02010-06-23 01:19:29 +0000878 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000879}
880
881lldb::ValueObjectSP &
882SBValue::operator*()
883{
Greg Clayton63094e02010-06-23 01:19:29 +0000884 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000885}
886
887const lldb::ValueObjectSP &
888SBValue::operator*() const
889{
Greg Clayton63094e02010-06-23 01:19:29 +0000890 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000891}
Caroline Tice98f930f2010-09-20 05:20:02 +0000892
893bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000894SBValue::GetExpressionPath (SBStream &description)
895{
896 if (m_opaque_sp)
897 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000898 m_opaque_sp->GetExpressionPath (description.ref(), false);
899 return true;
900 }
901 return false;
902}
903
904bool
905SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
906{
907 if (m_opaque_sp)
908 {
909 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000910 return true;
911 }
912 return false;
913}
914
915bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000916SBValue::GetDescription (SBStream &description)
917{
918 if (m_opaque_sp)
919 {
Enrico Granata19030d82011-08-15 18:01:31 +0000920 /*uint32_t ptr_depth = 0;
Greg Claytonbafc86e2011-07-06 16:49:27 +0000921 uint32_t curr_depth = 0;
922 uint32_t max_depth = UINT32_MAX;
923 bool show_types = false;
924 bool show_location = false;
925 bool use_objc = false;
926 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
927 bool scope_already_checked = false;
928 bool flat_output = false;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000929 bool use_synthetic = true;
930 uint32_t no_summary_depth = 0;
Enrico Granata19030d82011-08-15 18:01:31 +0000931 bool ignore_cap = false;*/
Greg Claytonbafc86e2011-07-06 16:49:27 +0000932 ValueObject::DumpValueObject (description.ref(),
Enrico Granata19030d82011-08-15 18:01:31 +0000933 m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000934 }
935 else
936 description.Printf ("No value");
937
938 return true;
939}
Greg Claytone179a582011-01-05 18:43:15 +0000940
941lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +0000942SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +0000943{
944 if (m_opaque_sp)
945 return m_opaque_sp->GetFormat();
946 return eFormatDefault;
947}
948
949void
950SBValue::SetFormat (lldb::Format format)
951{
952 if (m_opaque_sp)
953 m_opaque_sp->SetFormat(format);
954}
955
Enrico Granata979e20d2011-07-29 19:53:35 +0000956lldb::SBValue
957SBValue::AddressOf()
958{
959 SBValue sb_value;
960 if (m_opaque_sp)
961 {
Enrico Granata91544802011-09-06 19:20:51 +0000962 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
963 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000964 {
Enrico Granata91544802011-09-06 19:20:51 +0000965 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +0000966 Error error;
967 sb_value = m_opaque_sp->AddressOf (error);
968 }
969 }
970 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
971 if (log)
972 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
973
974 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +0000975}
Enrico Granata91544802011-09-06 19:20:51 +0000976
977lldb::addr_t
978SBValue::GetLoadAddress()
979{
980 lldb::addr_t value = LLDB_INVALID_ADDRESS;
981 if (m_opaque_sp)
982 {
983 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
984 if (target)
985 {
986 Mutex::Locker api_locker (target->GetAPIMutex());
987 const bool scalar_is_load_address = true;
988 AddressType addr_type;
989 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
990 if (addr_type == eAddressTypeFile)
991 {
992 Module* module = m_opaque_sp->GetModule();
993 if (!module)
994 value = LLDB_INVALID_ADDRESS;
995 else
996 {
997 Address addr;
998 module->ResolveFileAddress(value, addr);
999 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
1000 }
1001 }
1002 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1003 value = LLDB_INVALID_ADDRESS;
1004 }
1005 }
1006 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1007 if (log)
1008 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1009
1010 return value;
1011}
1012
1013lldb::SBAddress
1014SBValue::GetAddress()
1015{
1016 Address addr;
1017 if (m_opaque_sp)
1018 {
1019 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1020 if (target)
1021 {
1022 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1023 Mutex::Locker api_locker (target->GetAPIMutex());
1024 const bool scalar_is_load_address = true;
1025 AddressType addr_type;
1026 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1027 if (addr_type == eAddressTypeFile)
1028 {
1029 Module* module = m_opaque_sp->GetModule();
1030 if (module)
1031 module->ResolveFileAddress(value, addr);
1032 }
1033 else if (addr_type == eAddressTypeLoad)
1034 {
1035 // no need to check the return value on this.. if it can actually do the resolve
1036 // addr will be in the form (section,offset), otherwise it will simply be returned
1037 // as (NULL, value)
1038 addr.SetLoadAddress(value, target);
1039 }
1040 }
1041 }
1042 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1043 if (log)
1044 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1045 return SBAddress(new Address(addr));
1046}
1047
1048lldb::SBData
1049SBValue::GetPointeeData (uint32_t item_idx,
1050 uint32_t item_count)
1051{
1052 lldb::SBData sb_data;
1053 if (m_opaque_sp)
1054 {
1055 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1056 if (target)
1057 {
1058 DataExtractorSP data_sp(new DataExtractor());
1059 Mutex::Locker api_locker (target->GetAPIMutex());
1060 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1061 if (data_sp->GetByteSize() > 0)
1062 *sb_data = data_sp;
1063 }
1064 }
1065 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1066 if (log)
1067 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1068 m_opaque_sp.get(),
1069 item_idx,
1070 item_count,
1071 sb_data.get());
1072
1073 return sb_data;
1074}
1075
1076lldb::SBData
1077SBValue::GetData ()
1078{
1079 lldb::SBData sb_data;
1080 if (m_opaque_sp)
1081 {
1082 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1083 if (target)
1084 {
1085 DataExtractorSP data_sp(new DataExtractor());
1086 Mutex::Locker api_locker (target->GetAPIMutex());
1087 m_opaque_sp->GetData(*data_sp);
1088 if (data_sp->GetByteSize() > 0)
1089 *sb_data = data_sp;
1090 }
1091 }
1092 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1093 if (log)
1094 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1095 m_opaque_sp.get(),
1096 sb_data.get());
1097
1098 return sb_data;
1099}