blob: 96182e37428b52330976afb9b21db3eaf89da4c6 [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
Johnny Chenecd4feb2011-10-14 00:42:25 +000013#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/Core/DataExtractor.h"
Caroline Tice7826c882010-10-26 03:11:13 +000015#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000017#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Stream.h"
19#include "lldb/Core/StreamFile.h"
20#include "lldb/Core/Value.h"
21#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000022#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Symbol/Block.h"
24#include "lldb/Symbol/ObjectFile.h"
25#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000026#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027#include "lldb/Target/ExecutionContext.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000030#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/Target/Thread.h"
32
Eli Friedman7a62c8b2010-06-09 07:44:37 +000033#include "lldb/API/SBProcess.h"
34#include "lldb/API/SBTarget.h"
35#include "lldb/API/SBThread.h"
36#include "lldb/API/SBFrame.h"
37#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000038
39using namespace lldb;
40using namespace lldb_private;
41
42SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000043 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000044{
45}
46
47SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000048 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000049{
50}
51
Greg Clayton538eb822010-11-05 23:17:00 +000052SBValue::SBValue(const SBValue &rhs) :
53 m_opaque_sp (rhs.m_opaque_sp)
54{
55}
56
Greg Claytond68e0892011-09-09 23:04:00 +000057SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000058SBValue::operator = (const SBValue &rhs)
59{
60 if (this != &rhs)
61 m_opaque_sp = rhs.m_opaque_sp;
62 return *this;
63}
64
Chris Lattner24943d22010-06-08 16:52:24 +000065SBValue::~SBValue()
66{
67}
68
69bool
Greg Claytond68e0892011-09-09 23:04:00 +000070SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000071{
Greg Clayton49ce6822010-10-31 03:01:06 +000072 // If this function ever changes to anything that does more than just
73 // check if the opaque shared pointer is non NULL, then we need to update
74 // all "if (m_opaque_sp)" code in this file.
75 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000076}
77
Jim Inghame0bd5712011-12-19 20:39:44 +000078void
79SBValue::Clear()
80{
81 m_opaque_sp.reset();
82}
83
Greg Claytonc5f728c2010-10-06 22:10:17 +000084SBError
85SBValue::GetError()
86{
87 SBError sb_error;
88
89 if (m_opaque_sp.get())
90 sb_error.SetError(m_opaque_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +000091 else
92 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +000093
94 return sb_error;
95}
96
Johnny Chen968958c2011-07-07 20:46:23 +000097user_id_t
98SBValue::GetID()
99{
100 if (m_opaque_sp)
101 return m_opaque_sp->GetID();
102 return LLDB_INVALID_UID;
103}
104
Chris Lattner24943d22010-06-08 16:52:24 +0000105const char *
106SBValue::GetName()
107{
Greg Clayton49ce6822010-10-31 03:01:06 +0000108
109 const char *name = NULL;
110 if (m_opaque_sp)
111 name = m_opaque_sp->GetName().GetCString();
112
Greg Claytone005f2c2010-11-06 01:53:30 +0000113 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000114 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000115 {
116 if (name)
117 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
118 else
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000119 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000120 }
Caroline Tice7826c882010-10-26 03:11:13 +0000121
Greg Clayton49ce6822010-10-31 03:01:06 +0000122 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000123}
124
125const char *
126SBValue::GetTypeName ()
127{
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 const char *name = NULL;
129 if (m_opaque_sp)
130 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000131 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 if (log)
133 {
134 if (name)
135 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
136 else
137 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
138 }
139
140 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000141}
142
143size_t
144SBValue::GetByteSize ()
145{
146 size_t result = 0;
147
Greg Clayton49ce6822010-10-31 03:01:06 +0000148 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000149 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000150
Greg Claytone005f2c2010-11-06 01:53:30 +0000151 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000152 if (log)
153 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
154
Chris Lattner24943d22010-06-08 16:52:24 +0000155 return result;
156}
157
158bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000159SBValue::IsInScope ()
160{
Chris Lattner24943d22010-06-08 16:52:24 +0000161 bool result = false;
162
Greg Clayton49ce6822010-10-31 03:01:06 +0000163 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000164 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000165 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000166 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000167 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000168 result = m_opaque_sp->IsInScope ();
169 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000170 }
Chris Lattner24943d22010-06-08 16:52:24 +0000171
Greg Claytone005f2c2010-11-06 01:53:30 +0000172 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000173 if (log)
174 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
175
Chris Lattner24943d22010-06-08 16:52:24 +0000176 return result;
177}
178
179const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000180SBValue::GetValue ()
181{
Greg Clayton49ce6822010-10-31 03:01:06 +0000182 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000183 if (m_opaque_sp)
184 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000185 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000186 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000187 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000188 cstr = m_opaque_sp->GetValueAsCString ();
189 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000190 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000191 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000192 if (log)
193 {
194 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000195 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000197 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 }
199
200 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000201}
202
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000203ValueType
204SBValue::GetValueType ()
205{
Greg Clayton49ce6822010-10-31 03:01:06 +0000206 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000207 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000209 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000210 if (log)
211 {
212 switch (result)
213 {
214 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
215 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
216 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
217 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
218 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
219 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
220 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
221 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
222 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
223 }
224 }
225 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000226}
227
Jim Ingham4ae51962010-09-10 23:12:17 +0000228const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000229SBValue::GetObjectDescription ()
230{
Greg Clayton49ce6822010-10-31 03:01:06 +0000231 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000232 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000233 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000234 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000235 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000236 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000237 cstr = m_opaque_sp->GetObjectDescription ();
238 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000239 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000241 if (log)
242 {
243 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000244 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000245 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000246 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000247 }
248 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000249}
250
Enrico Granata979e20d2011-07-29 19:53:35 +0000251SBType
252SBValue::GetType()
253{
254 SBType result;
255 if (m_opaque_sp)
256 {
257 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
258 {
259 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000260 result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000261 }
262 }
263 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
264 if (log)
265 {
266 if (result.IsValid())
267 log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
268 else
269 log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
270 }
271 return result;
272}
273
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000274bool
275SBValue::GetValueDidChange ()
276{
Greg Clayton49ce6822010-10-31 03:01:06 +0000277 bool result = false;
278 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000279 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000281 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000282 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000283 result = m_opaque_sp->GetValueDidChange ();
284 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000285 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000286 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000287 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000288 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000289
290 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000291}
292
293const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000294SBValue::GetSummary ()
295{
Greg Clayton49ce6822010-10-31 03:01:06 +0000296 const char *cstr = NULL;
297 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000298 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000299 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000300 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000301 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000302 cstr = m_opaque_sp->GetSummaryAsCString();
303 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000304 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000305 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000306 if (log)
307 {
308 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000309 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000310 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000311 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000312 }
313 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000314}
315
316const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000317SBValue::GetLocation ()
318{
Greg Clayton49ce6822010-10-31 03:01:06 +0000319 const char *cstr = NULL;
320 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000321 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000322 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000323 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000324 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000325 cstr = m_opaque_sp->GetLocationAsCString();
326 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000327 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000328 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000329 if (log)
330 {
331 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000332 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000333 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000334 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000335 }
336 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000337}
338
339bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000340SBValue::SetValueFromCString (const char *value_str)
341{
Chris Lattner24943d22010-06-08 16:52:24 +0000342 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000343 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000344 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000345 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000346 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000347 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000348 success = m_opaque_sp->SetValueFromCString (value_str);
349 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000350 }
Chris Lattner24943d22010-06-08 16:52:24 +0000351 return success;
352}
353
Enrico Granata979e20d2011-07-29 19:53:35 +0000354lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000355SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000356{
357 lldb::SBValue result;
358 if (m_opaque_sp)
359 {
360 if (type.IsValid())
361 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000362 result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
Enrico Granata979e20d2011-07-29 19:53:35 +0000363 result.m_opaque_sp->SetName(ConstString(name));
364 }
365 }
366 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
367 if (log)
368 {
369 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000370 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000371 else
372 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
373 }
374 return result;
375}
376
377lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000378SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000379{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000380 lldb::SBValue sb_value;
381 if (m_opaque_sp)
382 sb_value = CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
383 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000384}
385
386lldb::SBValue
387SBValue::CreateValueFromExpression (const char *name, const char* expression)
388{
389 lldb::SBValue result;
390 if (m_opaque_sp)
391 {
392 ValueObjectSP result_valobj_sp;
Greg Claytond68e0892011-09-09 23:04:00 +0000393 m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression,
Jim Ingham1586d972011-12-17 01:35:57 +0000394 m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame(),
Sean Callanana8428a42011-09-22 00:41:11 +0000395 eExecutionPolicyOnlyWhenNeeded,
Sean Callanandaa6efe2011-12-21 22:22:58 +0000396 false, // coerce to id
Sean Callanan47dc4572011-09-15 02:13:07 +0000397 true, // unwind on error
398 true, // keep in memory
399 eNoDynamicValues,
Greg Claytond68e0892011-09-09 23:04:00 +0000400 result_valobj_sp);
Johnny Chen9fd2e382011-12-20 01:52:44 +0000401 if (result_valobj_sp)
402 {
403 result_valobj_sp->SetName(ConstString(name));
404 result = SBValue(result_valobj_sp);
405 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000406 }
407 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
408 if (log)
409 {
410 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000411 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000412 else
413 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
414 }
415 return result;
416}
417
418lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000419SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000420{
421 lldb::SBValue result;
Johnny Chen943485c2011-12-15 01:55:36 +0000422 if (m_opaque_sp && type.IsValid() && type.GetPointerType().IsValid())
Enrico Granata979e20d2011-07-29 19:53:35 +0000423 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000424 SBType real_type(type.GetPointerType());
425
426 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
427
Jim Ingham1586d972011-12-17 01:35:57 +0000428 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
Greg Claytond68e0892011-09-09 23:04:00 +0000429 real_type.m_opaque_sp->GetASTContext(),
430 real_type.m_opaque_sp->GetOpaqueQualType(),
431 ConstString(name),
432 buffer,
433 lldb::endian::InlHostByteOrder(),
434 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000435
Enrico Granatac9310302011-08-04 17:07:02 +0000436 ValueObjectSP result_valobj_sp;
437
438 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
439 if (ptr_result_valobj_sp)
440 {
441 Error err;
442 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
443 if (result_valobj_sp)
444 result_valobj_sp->SetName(ConstString(name));
445 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000446 result = SBValue(result_valobj_sp);
447 }
448 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
449 if (log)
450 {
451 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000452 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000453 else
454 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
455 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000456 return result;
457}
458
Enrico Granata91544802011-09-06 19:20:51 +0000459lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000460SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000461{
462 SBValue result;
463
464 AddressType addr_of_children_priv = eAddressTypeLoad;
465
466 if (m_opaque_sp)
467 {
468 ValueObjectSP valobj_sp;
469 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
470 type.m_opaque_sp->GetASTContext() ,
471 type.m_opaque_sp->GetOpaqueQualType(),
472 ConstString(name),
473 *data.m_opaque_sp,
474 LLDB_INVALID_ADDRESS);
475 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
476 result = SBValue(valobj_sp);
477 }
478 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
479 if (log)
480 {
481 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000482 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000483 else
484 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
485 }
486 return result;
487}
488
Chris Lattner24943d22010-06-08 16:52:24 +0000489SBValue
490SBValue::GetChildAtIndex (uint32_t idx)
491{
Greg Clayton8f64c472011-07-15 19:31:49 +0000492 const bool can_create_synthetic = false;
493 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000494 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000495 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000496 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000497}
498
499SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000500SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000501{
Chris Lattner24943d22010-06-08 16:52:24 +0000502 lldb::ValueObjectSP child_sp;
503
Greg Clayton49ce6822010-10-31 03:01:06 +0000504 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000505 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000506 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000507 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000508 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000509 const bool can_create = true;
510 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
511 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000512 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000513 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000514 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000515 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
516 }
517 else if (m_opaque_sp->IsArrayType())
518 {
519 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
520 }
521 }
522
523 if (child_sp)
524 {
525 if (use_dynamic != lldb::eNoDynamicValues)
526 {
527 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000528 if (dynamic_sp)
529 child_sp = dynamic_sp;
530 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000531 }
Jim Inghame41494a2011-04-16 00:01:13 +0000532 }
533 }
534
Chris Lattner24943d22010-06-08 16:52:24 +0000535 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000536 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000537 if (log)
538 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
539
Chris Lattner24943d22010-06-08 16:52:24 +0000540 return sb_value;
541}
542
543uint32_t
544SBValue::GetIndexOfChildWithName (const char *name)
545{
Greg Clayton49ce6822010-10-31 03:01:06 +0000546 uint32_t idx = UINT32_MAX;
547 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000548 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000549 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000550 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000551 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000552
Greg Claytonb9dcc512011-06-29 18:28:50 +0000553 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
554 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000555 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000556 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000557 if (log)
558 {
559 if (idx == UINT32_MAX)
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000560 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000561 else
562 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
563 }
564 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000565}
566
567SBValue
568SBValue::GetChildMemberWithName (const char *name)
569{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000570 if (m_opaque_sp)
571 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000572 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000573 return GetChildMemberWithName (name, use_dynamic_value);
574 }
575 else
576 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000577}
578
579SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000580SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000581{
Chris Lattner24943d22010-06-08 16:52:24 +0000582 lldb::ValueObjectSP child_sp;
583 const ConstString str_name (name);
584
Greg Clayton905acaf2011-05-20 22:07:17 +0000585
Greg Clayton49ce6822010-10-31 03:01:06 +0000586 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000587 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000588 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000589 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000590 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000591 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
592 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000593 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000594 if (child_sp)
595 {
596 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
597 if (dynamic_sp)
598 child_sp = dynamic_sp;
599 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000600 }
Jim Inghame41494a2011-04-16 00:01:13 +0000601 }
602 }
603
Chris Lattner24943d22010-06-08 16:52:24 +0000604 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000605
Greg Claytone005f2c2010-11-06 01:53:30 +0000606 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000607 if (log)
608 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
609
Chris Lattner24943d22010-06-08 16:52:24 +0000610 return sb_value;
611}
612
Enrico Granataf7a9b142011-07-15 02:26:42 +0000613lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000614SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
615{
616 if (m_opaque_sp)
617 {
618 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
619 {
620 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
621 return SBValue (m_opaque_sp->GetDynamicValue(use_dynamic));
622 }
623 }
624
625 return SBValue();
626}
627
628lldb::SBValue
629SBValue::GetStaticValue ()
630{
631 if (m_opaque_sp)
632 {
633 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
634 {
635 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
636 return SBValue(m_opaque_sp->GetStaticValue());
637 }
638 }
639
640 return SBValue();
641}
642
643bool
644SBValue::IsDynamic()
645{
646 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 return m_opaque_sp->IsDynamic();
652 }
653 }
654 return false;
655}
656
657lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000658SBValue::GetValueForExpressionPath(const char* expr_path)
659{
660 lldb::ValueObjectSP child_sp;
661 if (m_opaque_sp)
662 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000663 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000664 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000665 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000666 // using default values for all the fancy options, just do it if you can
667 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
668 }
669 }
670
671 SBValue sb_value (child_sp);
672
673 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
674 if (log)
675 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
676
677 return sb_value;
678}
Chris Lattner24943d22010-06-08 16:52:24 +0000679
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000680int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000681SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
682{
Jim Ingham574c3d62011-08-12 23:34:31 +0000683 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000684 if (m_opaque_sp)
685 {
686 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
687 {
688 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
689 Scalar scalar;
690 if (m_opaque_sp->ResolveValue (scalar))
691 return scalar.GetRawBits64(fail_value);
692 else
693 error.SetErrorString("could not get value");
694 }
695 else
696 error.SetErrorString("could not get target");
697 }
698 error.SetErrorString("invalid SBValue");
699 return fail_value;
700}
701
702uint64_t
703SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
704{
Jim Ingham574c3d62011-08-12 23:34:31 +0000705 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000706 if (m_opaque_sp)
707 {
708 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
709 {
710 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
711 Scalar scalar;
712 if (m_opaque_sp->ResolveValue (scalar))
713 return scalar.GetRawBits64(fail_value);
714 else
715 error.SetErrorString("could not get value");
716 }
717 else
718 error.SetErrorString("could not get target");
719 }
720 error.SetErrorString("invalid SBValue");
721 return fail_value;
722}
723
724int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000725SBValue::GetValueAsSigned(int64_t fail_value)
726{
727 if (m_opaque_sp)
728 {
729 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
730 {
731 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
732 Scalar scalar;
733 if (m_opaque_sp->ResolveValue (scalar))
734 return scalar.GetRawBits64(fail_value);
735 }
736 }
737 return fail_value;
738}
739
740uint64_t
741SBValue::GetValueAsUnsigned(uint64_t fail_value)
742{
743 if (m_opaque_sp)
744 {
745 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
746 {
747 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
748 Scalar scalar;
749 if (m_opaque_sp->ResolveValue (scalar))
750 return scalar.GetRawBits64(fail_value);
751 }
752 }
753 return fail_value;
754}
755
Chris Lattner24943d22010-06-08 16:52:24 +0000756uint32_t
757SBValue::GetNumChildren ()
758{
759 uint32_t num_children = 0;
760
Greg Clayton49ce6822010-10-31 03:01:06 +0000761 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000762 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000763 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000764 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000765 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000766
Greg Claytonb9dcc512011-06-29 18:28:50 +0000767 num_children = m_opaque_sp->GetNumChildren();
768 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000769 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000770
Greg Claytone005f2c2010-11-06 01:53:30 +0000771 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000772 if (log)
773 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000774
775 return num_children;
776}
777
Chris Lattner24943d22010-06-08 16:52:24 +0000778
779SBValue
780SBValue::Dereference ()
781{
Greg Clayton49ce6822010-10-31 03:01:06 +0000782 SBValue sb_value;
783 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000784 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000785 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000786 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000787 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000788
Greg Claytonb9dcc512011-06-29 18:28:50 +0000789 Error error;
790 sb_value = m_opaque_sp->Dereference (error);
791 }
Chris Lattner24943d22010-06-08 16:52:24 +0000792 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000793 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000794 if (log)
795 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
796
797 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000798}
799
800bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000801SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000802{
803 bool is_ptr_type = false;
804
Greg Clayton49ce6822010-10-31 03:01:06 +0000805 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000806 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000807 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000808 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000809 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000810
Greg Claytonb9dcc512011-06-29 18:28:50 +0000811 is_ptr_type = m_opaque_sp->IsPointerType();
812 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000813 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000814
Greg Claytone005f2c2010-11-06 01:53:30 +0000815 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000816 if (log)
817 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
818
Chris Lattner24943d22010-06-08 16:52:24 +0000819
820 return is_ptr_type;
821}
822
Chris Lattner24943d22010-06-08 16:52:24 +0000823void *
824SBValue::GetOpaqueType()
825{
Greg Clayton63094e02010-06-23 01:19:29 +0000826 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000827 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000828 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000829 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000830 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000831
Greg Claytonb9dcc512011-06-29 18:28:50 +0000832 return m_opaque_sp->GetClangType();
833 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000834 }
Chris Lattner24943d22010-06-08 16:52:24 +0000835 return NULL;
836}
837
Enrico Granata979e20d2011-07-29 19:53:35 +0000838lldb::SBTarget
839SBValue::GetTarget()
840{
Greg Clayton334d33a2012-01-30 07:41:31 +0000841 SBTarget sb_target;
842 TargetSP target_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000843 if (m_opaque_sp)
844 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000845 target_sp = m_opaque_sp->GetUpdatePoint().GetTargetSP();
846 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000847 }
848 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
849 if (log)
850 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000851 if (target_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000852 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
853 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000854 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000855 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000856 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +0000857}
858
859lldb::SBProcess
860SBValue::GetProcess()
861{
Greg Clayton334d33a2012-01-30 07:41:31 +0000862 SBProcess sb_process;
863 ProcessSP process_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000864 if (m_opaque_sp)
865 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000866 process_sp = m_opaque_sp->GetUpdatePoint().GetProcessSP();
867 if (process_sp)
868 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000869 }
870 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
871 if (log)
872 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000873 if (process_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000874 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
875 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000876 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000877 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000878 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +0000879}
880
881lldb::SBThread
882SBValue::GetThread()
883{
Greg Clayton90c52142012-01-30 02:53:15 +0000884 SBThread sb_thread;
885 ThreadSP thread_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000886 if (m_opaque_sp)
887 {
Jim Ingham1586d972011-12-17 01:35:57 +0000888 if (m_opaque_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000889 {
Greg Clayton90c52142012-01-30 02:53:15 +0000890 thread_sp = m_opaque_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this();
891 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000892 }
893 }
894 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
895 if (log)
896 {
Greg Clayton90c52142012-01-30 02:53:15 +0000897 if (thread_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000898 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
899 else
Greg Clayton90c52142012-01-30 02:53:15 +0000900 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000901 }
Greg Clayton90c52142012-01-30 02:53:15 +0000902 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +0000903}
904
905lldb::SBFrame
906SBValue::GetFrame()
907{
Greg Clayton334d33a2012-01-30 07:41:31 +0000908 SBFrame sb_frame;
909 StackFrameSP frame_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000910 if (m_opaque_sp)
911 {
Jim Ingham1586d972011-12-17 01:35:57 +0000912 if (m_opaque_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000913 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000914 frame_sp = m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this();
915 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000916 }
917 }
918 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
919 if (log)
920 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000921 if (frame_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000922 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
923 else
Greg Clayton334d33a2012-01-30 07:41:31 +0000924 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000925 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000926 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +0000927}
928
929
Chris Lattner24943d22010-06-08 16:52:24 +0000930// Mimic shared pointer...
931lldb_private::ValueObject *
932SBValue::get() const
933{
Greg Clayton63094e02010-06-23 01:19:29 +0000934 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000935}
936
937lldb_private::ValueObject *
938SBValue::operator->() const
939{
Greg Clayton63094e02010-06-23 01:19:29 +0000940 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000941}
942
943lldb::ValueObjectSP &
944SBValue::operator*()
945{
Greg Clayton63094e02010-06-23 01:19:29 +0000946 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000947}
948
949const lldb::ValueObjectSP &
950SBValue::operator*() const
951{
Greg Clayton63094e02010-06-23 01:19:29 +0000952 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000953}
Caroline Tice98f930f2010-09-20 05:20:02 +0000954
955bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000956SBValue::GetExpressionPath (SBStream &description)
957{
958 if (m_opaque_sp)
959 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000960 m_opaque_sp->GetExpressionPath (description.ref(), false);
961 return true;
962 }
963 return false;
964}
965
966bool
967SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
968{
969 if (m_opaque_sp)
970 {
971 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000972 return true;
973 }
974 return false;
975}
976
977bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000978SBValue::GetDescription (SBStream &description)
979{
Greg Clayton96154be2011-11-13 06:57:31 +0000980 Stream &strm = description.ref();
981
Caroline Tice98f930f2010-09-20 05:20:02 +0000982 if (m_opaque_sp)
983 {
Greg Clayton96154be2011-11-13 06:57:31 +0000984 ValueObject::DumpValueObject (strm, m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000985 }
986 else
Greg Clayton96154be2011-11-13 06:57:31 +0000987 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000988
989 return true;
990}
Greg Claytone179a582011-01-05 18:43:15 +0000991
992lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +0000993SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +0000994{
995 if (m_opaque_sp)
996 return m_opaque_sp->GetFormat();
997 return eFormatDefault;
998}
999
1000void
1001SBValue::SetFormat (lldb::Format format)
1002{
1003 if (m_opaque_sp)
1004 m_opaque_sp->SetFormat(format);
1005}
1006
Enrico Granata979e20d2011-07-29 19:53:35 +00001007lldb::SBValue
1008SBValue::AddressOf()
1009{
1010 SBValue sb_value;
1011 if (m_opaque_sp)
1012 {
Enrico Granata91544802011-09-06 19:20:51 +00001013 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1014 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +00001015 {
Enrico Granata91544802011-09-06 19:20:51 +00001016 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001017 Error error;
1018 sb_value = m_opaque_sp->AddressOf (error);
1019 }
1020 }
1021 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1022 if (log)
1023 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
1024
1025 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001026}
Enrico Granata91544802011-09-06 19:20:51 +00001027
1028lldb::addr_t
1029SBValue::GetLoadAddress()
1030{
1031 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1032 if (m_opaque_sp)
1033 {
1034 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1035 if (target)
1036 {
1037 Mutex::Locker api_locker (target->GetAPIMutex());
1038 const bool scalar_is_load_address = true;
1039 AddressType addr_type;
1040 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1041 if (addr_type == eAddressTypeFile)
1042 {
1043 Module* module = m_opaque_sp->GetModule();
1044 if (!module)
1045 value = LLDB_INVALID_ADDRESS;
1046 else
1047 {
1048 Address addr;
1049 module->ResolveFileAddress(value, addr);
1050 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
1051 }
1052 }
1053 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1054 value = LLDB_INVALID_ADDRESS;
1055 }
1056 }
1057 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1058 if (log)
1059 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1060
1061 return value;
1062}
1063
1064lldb::SBAddress
1065SBValue::GetAddress()
1066{
1067 Address addr;
1068 if (m_opaque_sp)
1069 {
1070 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1071 if (target)
1072 {
1073 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1074 Mutex::Locker api_locker (target->GetAPIMutex());
1075 const bool scalar_is_load_address = true;
1076 AddressType addr_type;
1077 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1078 if (addr_type == eAddressTypeFile)
1079 {
1080 Module* module = m_opaque_sp->GetModule();
1081 if (module)
1082 module->ResolveFileAddress(value, addr);
1083 }
1084 else if (addr_type == eAddressTypeLoad)
1085 {
1086 // no need to check the return value on this.. if it can actually do the resolve
1087 // addr will be in the form (section,offset), otherwise it will simply be returned
1088 // as (NULL, value)
1089 addr.SetLoadAddress(value, target);
1090 }
1091 }
1092 }
1093 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1094 if (log)
1095 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1096 return SBAddress(new Address(addr));
1097}
1098
1099lldb::SBData
1100SBValue::GetPointeeData (uint32_t item_idx,
1101 uint32_t item_count)
1102{
1103 lldb::SBData sb_data;
1104 if (m_opaque_sp)
1105 {
1106 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1107 if (target)
1108 {
1109 DataExtractorSP data_sp(new DataExtractor());
1110 Mutex::Locker api_locker (target->GetAPIMutex());
1111 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1112 if (data_sp->GetByteSize() > 0)
1113 *sb_data = data_sp;
1114 }
1115 }
1116 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1117 if (log)
1118 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1119 m_opaque_sp.get(),
1120 item_idx,
1121 item_count,
1122 sb_data.get());
1123
1124 return sb_data;
1125}
1126
1127lldb::SBData
1128SBValue::GetData ()
1129{
1130 lldb::SBData sb_data;
1131 if (m_opaque_sp)
1132 {
1133 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1134 if (target)
1135 {
1136 DataExtractorSP data_sp(new DataExtractor());
1137 Mutex::Locker api_locker (target->GetAPIMutex());
1138 m_opaque_sp->GetData(*data_sp);
1139 if (data_sp->GetByteSize() > 0)
1140 *sb_data = data_sp;
1141 }
1142 }
1143 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1144 if (log)
1145 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1146 m_opaque_sp.get(),
1147 sb_data.get());
1148
1149 return sb_data;
1150}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001151
1152lldb::SBWatchpoint
1153SBValue::Watch (bool resolve_location, bool read, bool write)
1154{
1155 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001156 if (!m_opaque_sp)
1157 return sb_watchpoint;
1158
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001159 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1160 if (target)
1161 {
1162 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001163 sb_watchpoint = WatchValue(read, write, false);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001164 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001165 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1166 if (log)
1167 log->Printf ("SBValue(%p)::Watch (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1168 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001169 return sb_watchpoint;
1170}
1171
1172lldb::SBWatchpoint
1173SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1174{
1175 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001176 if (!m_opaque_sp)
1177 return sb_watchpoint;
1178
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001179 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1180 if (target)
1181 {
1182 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001183 sb_watchpoint = WatchValue(read, write, true);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001184 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001185 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1186 if (log)
1187 log->Printf ("SBValue(%p)::WatchPointee (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1188 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001189 return sb_watchpoint;
1190}
1191
Johnny Chenecd4feb2011-10-14 00:42:25 +00001192// Helper function for SBValue::Watch() and SBValue::WatchPointee().
1193SBWatchpoint
1194SBValue::WatchValue(bool read, bool write, bool watch_pointee)
1195{
1196 SBWatchpoint sb_wp_empty;
1197
1198 // If the SBValue is not valid, there's no point in even trying to watch it.
Greg Clayton334d33a2012-01-30 07:41:31 +00001199 if (!IsValid())
Johnny Chenecd4feb2011-10-14 00:42:25 +00001200 return sb_wp_empty;
1201
1202 // Read and Write cannot both be false.
1203 if (!read && !write)
1204 return sb_wp_empty;
Greg Clayton334d33a2012-01-30 07:41:31 +00001205
Johnny Chenecd4feb2011-10-14 00:42:25 +00001206 // If we are watching the pointee, check that the SBValue is a pointer type.
1207 if (watch_pointee && !GetType().IsPointerType())
1208 return sb_wp_empty;
1209
Greg Clayton334d33a2012-01-30 07:41:31 +00001210 TargetSP target_sp (GetTarget().GetSP());
1211 if (!target_sp)
1212 return sb_wp_empty;
1213
1214 StackFrameSP frame_sp (GetFrame().GetFrameSP());
1215 if (!frame_sp)
1216 return sb_wp_empty;
1217
Johnny Chenecd4feb2011-10-14 00:42:25 +00001218 addr_t addr;
1219 size_t size;
1220 if (watch_pointee) {
1221 addr = GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
1222 size = GetType().GetPointeeType().GetByteSize();
1223 } else {
1224 addr = GetLoadAddress();
1225 size = GetByteSize();
1226 }
1227
1228 // Sanity check the address and the size before calling Target::CreateWatchpoint().
1229 if (addr == LLDB_INVALID_ADDRESS || size == 0)
1230 return sb_wp_empty;
1231
1232 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
1233 (write ? LLDB_WATCH_TYPE_WRITE : 0);
Greg Clayton334d33a2012-01-30 07:41:31 +00001234 WatchpointSP wp_sp = target_sp->CreateWatchpoint(addr, size, watch_type);
Johnny Chenecd4feb2011-10-14 00:42:25 +00001235
1236 if (wp_sp) {
1237 // StackFrame::GetInScopeVariableList(true) to get file globals as well.
Greg Clayton334d33a2012-01-30 07:41:31 +00001238 VariableListSP var_list_sp(frame_sp->GetInScopeVariableList(true));
Johnny Chenecd4feb2011-10-14 00:42:25 +00001239 VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName()));
1240 if (var_sp && var_sp->GetDeclaration().GetFile()) {
1241 StreamString ss;
1242 // True to show fullpath for declaration file.
1243 var_sp->GetDeclaration().DumpStopContext(&ss, true);
1244 wp_sp->SetDeclInfo(ss.GetString());
1245 }
1246 }
1247 return wp_sp;
1248}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001249