blob: 858b8f1144d32e2a8ba50d28e9ac2bf401960514 [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());
91
92 return sb_error;
93}
94
Johnny Chen968958c2011-07-07 20:46:23 +000095user_id_t
96SBValue::GetID()
97{
98 if (m_opaque_sp)
99 return m_opaque_sp->GetID();
100 return LLDB_INVALID_UID;
101}
102
Chris Lattner24943d22010-06-08 16:52:24 +0000103const char *
104SBValue::GetName()
105{
Greg Clayton49ce6822010-10-31 03:01:06 +0000106
107 const char *name = NULL;
108 if (m_opaque_sp)
109 name = m_opaque_sp->GetName().GetCString();
110
Greg Claytone005f2c2010-11-06 01:53:30 +0000111 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000112 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000113 {
114 if (name)
115 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
116 else
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000117 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000118 }
Caroline Tice7826c882010-10-26 03:11:13 +0000119
Greg Clayton49ce6822010-10-31 03:01:06 +0000120 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000121}
122
123const char *
124SBValue::GetTypeName ()
125{
Greg Clayton49ce6822010-10-31 03:01:06 +0000126 const char *name = NULL;
127 if (m_opaque_sp)
128 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000129 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000130 if (log)
131 {
132 if (name)
133 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
134 else
135 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
136 }
137
138 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000139}
140
141size_t
142SBValue::GetByteSize ()
143{
144 size_t result = 0;
145
Greg Clayton49ce6822010-10-31 03:01:06 +0000146 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000147 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000148
Greg Claytone005f2c2010-11-06 01:53:30 +0000149 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000150 if (log)
151 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
152
Chris Lattner24943d22010-06-08 16:52:24 +0000153 return result;
154}
155
156bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000157SBValue::IsInScope ()
158{
Chris Lattner24943d22010-06-08 16:52:24 +0000159 bool result = false;
160
Greg Clayton49ce6822010-10-31 03:01:06 +0000161 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000162 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000163 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000164 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000165 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000166 result = m_opaque_sp->IsInScope ();
167 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000168 }
Chris Lattner24943d22010-06-08 16:52:24 +0000169
Greg Claytone005f2c2010-11-06 01:53:30 +0000170 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000171 if (log)
172 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
173
Chris Lattner24943d22010-06-08 16:52:24 +0000174 return result;
175}
176
177const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000178SBValue::GetValue ()
179{
Greg Clayton49ce6822010-10-31 03:01:06 +0000180 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000181 if (m_opaque_sp)
182 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000183 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000184 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000185 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000186 cstr = m_opaque_sp->GetValueAsCString ();
187 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000188 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000189 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000190 if (log)
191 {
192 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000193 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000194 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000195 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000196 }
197
198 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000199}
200
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000201ValueType
202SBValue::GetValueType ()
203{
Greg Clayton49ce6822010-10-31 03:01:06 +0000204 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000205 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000206 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000207 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 if (log)
209 {
210 switch (result)
211 {
212 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
213 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
214 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
215 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
216 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
217 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
218 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
219 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
220 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
221 }
222 }
223 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000224}
225
Jim Ingham4ae51962010-09-10 23:12:17 +0000226const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000227SBValue::GetObjectDescription ()
228{
Greg Clayton49ce6822010-10-31 03:01:06 +0000229 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000230 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000231 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000232 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000233 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000234 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000235 cstr = m_opaque_sp->GetObjectDescription ();
236 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000237 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000238 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000239 if (log)
240 {
241 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000242 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000243 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000244 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000245 }
246 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000247}
248
Enrico Granata979e20d2011-07-29 19:53:35 +0000249SBType
250SBValue::GetType()
251{
252 SBType result;
253 if (m_opaque_sp)
254 {
255 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
256 {
257 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000258 result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000259 }
260 }
261 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
262 if (log)
263 {
264 if (result.IsValid())
265 log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
266 else
267 log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
268 }
269 return result;
270}
271
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000272bool
273SBValue::GetValueDidChange ()
274{
Greg Clayton49ce6822010-10-31 03:01:06 +0000275 bool result = false;
276 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000277 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000278 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000279 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000281 result = m_opaque_sp->GetValueDidChange ();
282 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000283 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000284 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000285 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000286 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000287
288 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000289}
290
291const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000292SBValue::GetSummary ()
293{
Greg Clayton49ce6822010-10-31 03:01:06 +0000294 const char *cstr = NULL;
295 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000296 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000297 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000298 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000299 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000300 cstr = m_opaque_sp->GetSummaryAsCString();
301 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000302 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000303 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000304 if (log)
305 {
306 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000307 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000308 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000309 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000310 }
311 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000312}
313
314const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000315SBValue::GetLocation ()
316{
Greg Clayton49ce6822010-10-31 03:01:06 +0000317 const char *cstr = NULL;
318 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000319 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000320 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000321 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000322 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000323 cstr = m_opaque_sp->GetLocationAsCString();
324 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000325 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000326 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000327 if (log)
328 {
329 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000330 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000331 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000332 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000333 }
334 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000335}
336
337bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000338SBValue::SetValueFromCString (const char *value_str)
339{
Chris Lattner24943d22010-06-08 16:52:24 +0000340 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000341 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000342 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000343 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000344 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000345 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000346 success = m_opaque_sp->SetValueFromCString (value_str);
347 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000348 }
Chris Lattner24943d22010-06-08 16:52:24 +0000349 return success;
350}
351
Enrico Granata979e20d2011-07-29 19:53:35 +0000352lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000353SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000354{
355 lldb::SBValue result;
356 if (m_opaque_sp)
357 {
358 if (type.IsValid())
359 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000360 result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
Enrico Granata979e20d2011-07-29 19:53:35 +0000361 result.m_opaque_sp->SetName(ConstString(name));
362 }
363 }
364 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
365 if (log)
366 {
367 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000368 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000369 else
370 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
371 }
372 return result;
373}
374
375lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000376SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000377{
378 return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
379}
380
381lldb::SBValue
382SBValue::CreateValueFromExpression (const char *name, const char* expression)
383{
384 lldb::SBValue result;
385 if (m_opaque_sp)
386 {
387 ValueObjectSP result_valobj_sp;
Greg Claytond68e0892011-09-09 23:04:00 +0000388 m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression,
Jim Ingham1586d972011-12-17 01:35:57 +0000389 m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame(),
Sean Callanana8428a42011-09-22 00:41:11 +0000390 eExecutionPolicyOnlyWhenNeeded,
Sean Callanandaa6efe2011-12-21 22:22:58 +0000391 false, // coerce to id
Sean Callanan47dc4572011-09-15 02:13:07 +0000392 true, // unwind on error
393 true, // keep in memory
394 eNoDynamicValues,
Greg Claytond68e0892011-09-09 23:04:00 +0000395 result_valobj_sp);
Johnny Chen9fd2e382011-12-20 01:52:44 +0000396 if (result_valobj_sp)
397 {
398 result_valobj_sp->SetName(ConstString(name));
399 result = SBValue(result_valobj_sp);
400 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000401 }
402 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
403 if (log)
404 {
405 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000406 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000407 else
408 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
409 }
410 return result;
411}
412
413lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000414SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000415{
416 lldb::SBValue result;
Johnny Chen943485c2011-12-15 01:55:36 +0000417 if (m_opaque_sp && type.IsValid() && type.GetPointerType().IsValid())
Enrico Granata979e20d2011-07-29 19:53:35 +0000418 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000419 SBType real_type(type.GetPointerType());
420
421 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
422
Jim Ingham1586d972011-12-17 01:35:57 +0000423 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
Greg Claytond68e0892011-09-09 23:04:00 +0000424 real_type.m_opaque_sp->GetASTContext(),
425 real_type.m_opaque_sp->GetOpaqueQualType(),
426 ConstString(name),
427 buffer,
428 lldb::endian::InlHostByteOrder(),
429 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000430
Enrico Granatac9310302011-08-04 17:07:02 +0000431 ValueObjectSP result_valobj_sp;
432
433 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
434 if (ptr_result_valobj_sp)
435 {
436 Error err;
437 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
438 if (result_valobj_sp)
439 result_valobj_sp->SetName(ConstString(name));
440 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000441 result = SBValue(result_valobj_sp);
442 }
443 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
444 if (log)
445 {
446 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000447 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000448 else
449 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
450 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000451 return result;
452}
453
Enrico Granata91544802011-09-06 19:20:51 +0000454lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000455SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000456{
457 SBValue result;
458
459 AddressType addr_of_children_priv = eAddressTypeLoad;
460
461 if (m_opaque_sp)
462 {
463 ValueObjectSP valobj_sp;
464 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
465 type.m_opaque_sp->GetASTContext() ,
466 type.m_opaque_sp->GetOpaqueQualType(),
467 ConstString(name),
468 *data.m_opaque_sp,
469 LLDB_INVALID_ADDRESS);
470 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
471 result = SBValue(valobj_sp);
472 }
473 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
474 if (log)
475 {
476 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000477 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000478 else
479 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
480 }
481 return result;
482}
483
Chris Lattner24943d22010-06-08 16:52:24 +0000484SBValue
485SBValue::GetChildAtIndex (uint32_t idx)
486{
Greg Clayton8f64c472011-07-15 19:31:49 +0000487 const bool can_create_synthetic = false;
488 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000489 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000490 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000491 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000492}
493
494SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000495SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000496{
Chris Lattner24943d22010-06-08 16:52:24 +0000497 lldb::ValueObjectSP child_sp;
498
Greg Clayton49ce6822010-10-31 03:01:06 +0000499 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000500 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000501 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000502 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000503 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000504 const bool can_create = true;
505 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
506 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000507 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000508 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000509 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000510 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
511 }
512 else if (m_opaque_sp->IsArrayType())
513 {
514 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
515 }
516 }
517
518 if (child_sp)
519 {
520 if (use_dynamic != lldb::eNoDynamicValues)
521 {
522 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000523 if (dynamic_sp)
524 child_sp = dynamic_sp;
525 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000526 }
Jim Inghame41494a2011-04-16 00:01:13 +0000527 }
528 }
529
Chris Lattner24943d22010-06-08 16:52:24 +0000530 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000531 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000532 if (log)
533 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
534
Chris Lattner24943d22010-06-08 16:52:24 +0000535 return sb_value;
536}
537
538uint32_t
539SBValue::GetIndexOfChildWithName (const char *name)
540{
Greg Clayton49ce6822010-10-31 03:01:06 +0000541 uint32_t idx = UINT32_MAX;
542 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000543 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000544 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000545 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000546 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000547
Greg Claytonb9dcc512011-06-29 18:28:50 +0000548 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
549 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000550 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000551 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000552 if (log)
553 {
554 if (idx == UINT32_MAX)
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000555 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000556 else
557 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
558 }
559 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000560}
561
562SBValue
563SBValue::GetChildMemberWithName (const char *name)
564{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000565 if (m_opaque_sp)
566 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000567 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000568 return GetChildMemberWithName (name, use_dynamic_value);
569 }
570 else
571 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000572}
573
574SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000575SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000576{
Chris Lattner24943d22010-06-08 16:52:24 +0000577 lldb::ValueObjectSP child_sp;
578 const ConstString str_name (name);
579
Greg Clayton905acaf2011-05-20 22:07:17 +0000580
Greg Clayton49ce6822010-10-31 03:01:06 +0000581 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000582 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000583 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000584 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000585 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000586 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
587 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000588 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000589 if (child_sp)
590 {
591 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
592 if (dynamic_sp)
593 child_sp = dynamic_sp;
594 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000595 }
Jim Inghame41494a2011-04-16 00:01:13 +0000596 }
597 }
598
Chris Lattner24943d22010-06-08 16:52:24 +0000599 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000600
Greg Claytone005f2c2010-11-06 01:53:30 +0000601 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000602 if (log)
603 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
604
Chris Lattner24943d22010-06-08 16:52:24 +0000605 return sb_value;
606}
607
Enrico Granataf7a9b142011-07-15 02:26:42 +0000608lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000609SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
610{
611 if (m_opaque_sp)
612 {
613 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
614 {
615 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
616 return SBValue (m_opaque_sp->GetDynamicValue(use_dynamic));
617 }
618 }
619
620 return SBValue();
621}
622
623lldb::SBValue
624SBValue::GetStaticValue ()
625{
626 if (m_opaque_sp)
627 {
628 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
629 {
630 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
631 return SBValue(m_opaque_sp->GetStaticValue());
632 }
633 }
634
635 return SBValue();
636}
637
638bool
639SBValue::IsDynamic()
640{
641 if (m_opaque_sp)
642 {
643 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
644 {
645 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
646 return m_opaque_sp->IsDynamic();
647 }
648 }
649 return false;
650}
651
652lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000653SBValue::GetValueForExpressionPath(const char* expr_path)
654{
655 lldb::ValueObjectSP child_sp;
656 if (m_opaque_sp)
657 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000658 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000659 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000660 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000661 // using default values for all the fancy options, just do it if you can
662 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
663 }
664 }
665
666 SBValue sb_value (child_sp);
667
668 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
669 if (log)
670 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
671
672 return sb_value;
673}
Chris Lattner24943d22010-06-08 16:52:24 +0000674
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000675int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000676SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
677{
Jim Ingham574c3d62011-08-12 23:34:31 +0000678 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000679 if (m_opaque_sp)
680 {
681 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
682 {
683 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
684 Scalar scalar;
685 if (m_opaque_sp->ResolveValue (scalar))
686 return scalar.GetRawBits64(fail_value);
687 else
688 error.SetErrorString("could not get value");
689 }
690 else
691 error.SetErrorString("could not get target");
692 }
693 error.SetErrorString("invalid SBValue");
694 return fail_value;
695}
696
697uint64_t
698SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
699{
Jim Ingham574c3d62011-08-12 23:34:31 +0000700 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000701 if (m_opaque_sp)
702 {
703 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
704 {
705 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
706 Scalar scalar;
707 if (m_opaque_sp->ResolveValue (scalar))
708 return scalar.GetRawBits64(fail_value);
709 else
710 error.SetErrorString("could not get value");
711 }
712 else
713 error.SetErrorString("could not get target");
714 }
715 error.SetErrorString("invalid SBValue");
716 return fail_value;
717}
718
719int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000720SBValue::GetValueAsSigned(int64_t fail_value)
721{
722 if (m_opaque_sp)
723 {
724 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
725 {
726 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
727 Scalar scalar;
728 if (m_opaque_sp->ResolveValue (scalar))
729 return scalar.GetRawBits64(fail_value);
730 }
731 }
732 return fail_value;
733}
734
735uint64_t
736SBValue::GetValueAsUnsigned(uint64_t fail_value)
737{
738 if (m_opaque_sp)
739 {
740 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
741 {
742 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
743 Scalar scalar;
744 if (m_opaque_sp->ResolveValue (scalar))
745 return scalar.GetRawBits64(fail_value);
746 }
747 }
748 return fail_value;
749}
750
Chris Lattner24943d22010-06-08 16:52:24 +0000751uint32_t
752SBValue::GetNumChildren ()
753{
754 uint32_t num_children = 0;
755
Greg Clayton49ce6822010-10-31 03:01:06 +0000756 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000757 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000758 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000759 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000760 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000761
Greg Claytonb9dcc512011-06-29 18:28:50 +0000762 num_children = m_opaque_sp->GetNumChildren();
763 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000764 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000765
Greg Claytone005f2c2010-11-06 01:53:30 +0000766 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000767 if (log)
768 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000769
770 return num_children;
771}
772
Chris Lattner24943d22010-06-08 16:52:24 +0000773
774SBValue
775SBValue::Dereference ()
776{
Greg Clayton49ce6822010-10-31 03:01:06 +0000777 SBValue sb_value;
778 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000779 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000780 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000781 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000782 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000783
Greg Claytonb9dcc512011-06-29 18:28:50 +0000784 Error error;
785 sb_value = m_opaque_sp->Dereference (error);
786 }
Chris Lattner24943d22010-06-08 16:52:24 +0000787 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000788 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000789 if (log)
790 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
791
792 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000793}
794
795bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000796SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000797{
798 bool is_ptr_type = false;
799
Greg Clayton49ce6822010-10-31 03:01:06 +0000800 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000801 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000802 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000803 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000804 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000805
Greg Claytonb9dcc512011-06-29 18:28:50 +0000806 is_ptr_type = m_opaque_sp->IsPointerType();
807 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000808 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000809
Greg Claytone005f2c2010-11-06 01:53:30 +0000810 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000811 if (log)
812 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
813
Chris Lattner24943d22010-06-08 16:52:24 +0000814
815 return is_ptr_type;
816}
817
Chris Lattner24943d22010-06-08 16:52:24 +0000818void *
819SBValue::GetOpaqueType()
820{
Greg Clayton63094e02010-06-23 01:19:29 +0000821 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000822 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000823 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000824 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000825 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000826
Greg Claytonb9dcc512011-06-29 18:28:50 +0000827 return m_opaque_sp->GetClangType();
828 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000829 }
Chris Lattner24943d22010-06-08 16:52:24 +0000830 return NULL;
831}
832
Enrico Granata979e20d2011-07-29 19:53:35 +0000833lldb::SBTarget
834SBValue::GetTarget()
835{
836 SBTarget result;
837 if (m_opaque_sp)
838 {
839 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
840 {
841 result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
842 }
843 }
844 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
845 if (log)
846 {
847 if (result.get() == NULL)
848 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
849 else
850 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
851 }
852 return result;
853}
854
855lldb::SBProcess
856SBValue::GetProcess()
857{
858 SBProcess result;
859 if (m_opaque_sp)
860 {
Enrico Granata91544802011-09-06 19:20:51 +0000861 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
862 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000863 {
Enrico Granata91544802011-09-06 19:20:51 +0000864 result = SBProcess(lldb::ProcessSP(target->GetProcessSP()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000865 }
866 }
867 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
868 if (log)
869 {
870 if (result.get() == NULL)
871 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
872 else
873 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
874 }
875 return result;
876}
877
878lldb::SBThread
879SBValue::GetThread()
880{
Greg Clayton90c52142012-01-30 02:53:15 +0000881 SBThread sb_thread;
882 ThreadSP thread_sp;
Enrico Granata979e20d2011-07-29 19:53:35 +0000883 if (m_opaque_sp)
884 {
Jim Ingham1586d972011-12-17 01:35:57 +0000885 if (m_opaque_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000886 {
Greg Clayton90c52142012-01-30 02:53:15 +0000887 thread_sp = m_opaque_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this();
888 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000889 }
890 }
891 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
892 if (log)
893 {
Greg Clayton90c52142012-01-30 02:53:15 +0000894 if (thread_sp.get() == NULL)
Enrico Granata979e20d2011-07-29 19:53:35 +0000895 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
896 else
Greg Clayton90c52142012-01-30 02:53:15 +0000897 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000898 }
Greg Clayton90c52142012-01-30 02:53:15 +0000899 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +0000900}
901
902lldb::SBFrame
903SBValue::GetFrame()
904{
905 SBFrame result;
906 if (m_opaque_sp)
907 {
Jim Ingham1586d972011-12-17 01:35:57 +0000908 if (m_opaque_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000909 {
Greg Clayton13d24fb2012-01-29 20:56:30 +0000910 result.SetFrame (m_opaque_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this());
Enrico Granata979e20d2011-07-29 19:53:35 +0000911 }
912 }
913 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
914 if (log)
915 {
916 if (result.get() == NULL)
917 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
918 else
919 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
920 }
921 return result;
922}
923
924
Chris Lattner24943d22010-06-08 16:52:24 +0000925// Mimic shared pointer...
926lldb_private::ValueObject *
927SBValue::get() const
928{
Greg Clayton63094e02010-06-23 01:19:29 +0000929 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000930}
931
932lldb_private::ValueObject *
933SBValue::operator->() const
934{
Greg Clayton63094e02010-06-23 01:19:29 +0000935 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000936}
937
938lldb::ValueObjectSP &
939SBValue::operator*()
940{
Greg Clayton63094e02010-06-23 01:19:29 +0000941 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000942}
943
944const lldb::ValueObjectSP &
945SBValue::operator*() const
946{
Greg Clayton63094e02010-06-23 01:19:29 +0000947 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000948}
Caroline Tice98f930f2010-09-20 05:20:02 +0000949
950bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000951SBValue::GetExpressionPath (SBStream &description)
952{
953 if (m_opaque_sp)
954 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000955 m_opaque_sp->GetExpressionPath (description.ref(), false);
956 return true;
957 }
958 return false;
959}
960
961bool
962SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
963{
964 if (m_opaque_sp)
965 {
966 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000967 return true;
968 }
969 return false;
970}
971
972bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000973SBValue::GetDescription (SBStream &description)
974{
Greg Clayton96154be2011-11-13 06:57:31 +0000975 Stream &strm = description.ref();
976
Caroline Tice98f930f2010-09-20 05:20:02 +0000977 if (m_opaque_sp)
978 {
Greg Clayton96154be2011-11-13 06:57:31 +0000979 ValueObject::DumpValueObject (strm, m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000980 }
981 else
Greg Clayton96154be2011-11-13 06:57:31 +0000982 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +0000983
984 return true;
985}
Greg Claytone179a582011-01-05 18:43:15 +0000986
987lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +0000988SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +0000989{
990 if (m_opaque_sp)
991 return m_opaque_sp->GetFormat();
992 return eFormatDefault;
993}
994
995void
996SBValue::SetFormat (lldb::Format format)
997{
998 if (m_opaque_sp)
999 m_opaque_sp->SetFormat(format);
1000}
1001
Enrico Granata979e20d2011-07-29 19:53:35 +00001002lldb::SBValue
1003SBValue::AddressOf()
1004{
1005 SBValue sb_value;
1006 if (m_opaque_sp)
1007 {
Enrico Granata91544802011-09-06 19:20:51 +00001008 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1009 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +00001010 {
Enrico Granata91544802011-09-06 19:20:51 +00001011 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001012 Error error;
1013 sb_value = m_opaque_sp->AddressOf (error);
1014 }
1015 }
1016 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1017 if (log)
1018 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
1019
1020 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001021}
Enrico Granata91544802011-09-06 19:20:51 +00001022
1023lldb::addr_t
1024SBValue::GetLoadAddress()
1025{
1026 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1027 if (m_opaque_sp)
1028 {
1029 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1030 if (target)
1031 {
1032 Mutex::Locker api_locker (target->GetAPIMutex());
1033 const bool scalar_is_load_address = true;
1034 AddressType addr_type;
1035 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1036 if (addr_type == eAddressTypeFile)
1037 {
1038 Module* module = m_opaque_sp->GetModule();
1039 if (!module)
1040 value = LLDB_INVALID_ADDRESS;
1041 else
1042 {
1043 Address addr;
1044 module->ResolveFileAddress(value, addr);
1045 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
1046 }
1047 }
1048 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1049 value = LLDB_INVALID_ADDRESS;
1050 }
1051 }
1052 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1053 if (log)
1054 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1055
1056 return value;
1057}
1058
1059lldb::SBAddress
1060SBValue::GetAddress()
1061{
1062 Address addr;
1063 if (m_opaque_sp)
1064 {
1065 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1066 if (target)
1067 {
1068 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1069 Mutex::Locker api_locker (target->GetAPIMutex());
1070 const bool scalar_is_load_address = true;
1071 AddressType addr_type;
1072 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1073 if (addr_type == eAddressTypeFile)
1074 {
1075 Module* module = m_opaque_sp->GetModule();
1076 if (module)
1077 module->ResolveFileAddress(value, addr);
1078 }
1079 else if (addr_type == eAddressTypeLoad)
1080 {
1081 // no need to check the return value on this.. if it can actually do the resolve
1082 // addr will be in the form (section,offset), otherwise it will simply be returned
1083 // as (NULL, value)
1084 addr.SetLoadAddress(value, target);
1085 }
1086 }
1087 }
1088 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1089 if (log)
1090 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1091 return SBAddress(new Address(addr));
1092}
1093
1094lldb::SBData
1095SBValue::GetPointeeData (uint32_t item_idx,
1096 uint32_t item_count)
1097{
1098 lldb::SBData sb_data;
1099 if (m_opaque_sp)
1100 {
1101 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1102 if (target)
1103 {
1104 DataExtractorSP data_sp(new DataExtractor());
1105 Mutex::Locker api_locker (target->GetAPIMutex());
1106 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1107 if (data_sp->GetByteSize() > 0)
1108 *sb_data = data_sp;
1109 }
1110 }
1111 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1112 if (log)
1113 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1114 m_opaque_sp.get(),
1115 item_idx,
1116 item_count,
1117 sb_data.get());
1118
1119 return sb_data;
1120}
1121
1122lldb::SBData
1123SBValue::GetData ()
1124{
1125 lldb::SBData sb_data;
1126 if (m_opaque_sp)
1127 {
1128 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1129 if (target)
1130 {
1131 DataExtractorSP data_sp(new DataExtractor());
1132 Mutex::Locker api_locker (target->GetAPIMutex());
1133 m_opaque_sp->GetData(*data_sp);
1134 if (data_sp->GetByteSize() > 0)
1135 *sb_data = data_sp;
1136 }
1137 }
1138 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1139 if (log)
1140 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1141 m_opaque_sp.get(),
1142 sb_data.get());
1143
1144 return sb_data;
1145}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001146
1147lldb::SBWatchpoint
1148SBValue::Watch (bool resolve_location, bool read, bool write)
1149{
1150 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001151 if (!m_opaque_sp)
1152 return sb_watchpoint;
1153
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001154 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1155 if (target)
1156 {
1157 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001158 sb_watchpoint = WatchValue(read, write, false);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001159 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001160 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1161 if (log)
1162 log->Printf ("SBValue(%p)::Watch (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1163 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001164 return sb_watchpoint;
1165}
1166
1167lldb::SBWatchpoint
1168SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1169{
1170 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001171 if (!m_opaque_sp)
1172 return sb_watchpoint;
1173
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001174 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1175 if (target)
1176 {
1177 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001178 sb_watchpoint = WatchValue(read, write, true);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001179 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001180 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1181 if (log)
1182 log->Printf ("SBValue(%p)::WatchPointee (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1183 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001184 return sb_watchpoint;
1185}
1186
Johnny Chenecd4feb2011-10-14 00:42:25 +00001187// Helper function for SBValue::Watch() and SBValue::WatchPointee().
1188SBWatchpoint
1189SBValue::WatchValue(bool read, bool write, bool watch_pointee)
1190{
1191 SBWatchpoint sb_wp_empty;
1192
1193 // If the SBValue is not valid, there's no point in even trying to watch it.
1194 if (!IsValid() || !GetFrame().IsValid())
1195 return sb_wp_empty;
1196
1197 // Read and Write cannot both be false.
1198 if (!read && !write)
1199 return sb_wp_empty;
1200
1201 // If we are watching the pointee, check that the SBValue is a pointer type.
1202 if (watch_pointee && !GetType().IsPointerType())
1203 return sb_wp_empty;
1204
1205 addr_t addr;
1206 size_t size;
1207 if (watch_pointee) {
1208 addr = GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
1209 size = GetType().GetPointeeType().GetByteSize();
1210 } else {
1211 addr = GetLoadAddress();
1212 size = GetByteSize();
1213 }
1214
1215 // Sanity check the address and the size before calling Target::CreateWatchpoint().
1216 if (addr == LLDB_INVALID_ADDRESS || size == 0)
1217 return sb_wp_empty;
1218
1219 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
1220 (write ? LLDB_WATCH_TYPE_WRITE : 0);
1221 WatchpointSP wp_sp = GetFrame().m_opaque_sp->GetThread().GetProcess().GetTarget().
1222 CreateWatchpoint(addr, size, watch_type);
1223
1224 if (wp_sp) {
1225 // StackFrame::GetInScopeVariableList(true) to get file globals as well.
1226 VariableListSP var_list_sp(GetFrame().m_opaque_sp->GetInScopeVariableList(true));
1227 VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName()));
1228 if (var_sp && var_sp->GetDeclaration().GetFile()) {
1229 StreamString ss;
1230 // True to show fullpath for declaration file.
1231 var_sp->GetDeclaration().DumpStopContext(&ss, true);
1232 wp_sp->SetDeclInfo(ss.GetString());
1233 }
1234 }
1235 return wp_sp;
1236}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001237