blob: dc594cbfcbaa41ebbf2bf08441e3c1cdcb05d489 [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
Greg Claytonc5f728c2010-10-06 22:10:17 +000078SBError
79SBValue::GetError()
80{
81 SBError sb_error;
82
83 if (m_opaque_sp.get())
84 sb_error.SetError(m_opaque_sp->GetError());
85
86 return sb_error;
87}
88
Johnny Chen968958c2011-07-07 20:46:23 +000089user_id_t
90SBValue::GetID()
91{
92 if (m_opaque_sp)
93 return m_opaque_sp->GetID();
94 return LLDB_INVALID_UID;
95}
96
Chris Lattner24943d22010-06-08 16:52:24 +000097const char *
98SBValue::GetName()
99{
Greg Clayton49ce6822010-10-31 03:01:06 +0000100
101 const char *name = NULL;
102 if (m_opaque_sp)
103 name = m_opaque_sp->GetName().GetCString();
104
Greg Claytone005f2c2010-11-06 01:53:30 +0000105 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000106 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000107 {
108 if (name)
109 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
110 else
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000111 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000112 }
Caroline Tice7826c882010-10-26 03:11:13 +0000113
Greg Clayton49ce6822010-10-31 03:01:06 +0000114 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000115}
116
117const char *
118SBValue::GetTypeName ()
119{
Greg Clayton49ce6822010-10-31 03:01:06 +0000120 const char *name = NULL;
121 if (m_opaque_sp)
122 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000124 if (log)
125 {
126 if (name)
127 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
128 else
129 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
130 }
131
132 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000133}
134
135size_t
136SBValue::GetByteSize ()
137{
138 size_t result = 0;
139
Greg Clayton49ce6822010-10-31 03:01:06 +0000140 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000141 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000142
Greg Claytone005f2c2010-11-06 01:53:30 +0000143 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000144 if (log)
145 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
146
Chris Lattner24943d22010-06-08 16:52:24 +0000147 return result;
148}
149
150bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000151SBValue::IsInScope ()
152{
Chris Lattner24943d22010-06-08 16:52:24 +0000153 bool result = false;
154
Greg Clayton49ce6822010-10-31 03:01:06 +0000155 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000156 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000157 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000158 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000159 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000160 result = m_opaque_sp->IsInScope ();
161 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000162 }
Chris Lattner24943d22010-06-08 16:52:24 +0000163
Greg Claytone005f2c2010-11-06 01:53:30 +0000164 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000165 if (log)
166 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
167
Chris Lattner24943d22010-06-08 16:52:24 +0000168 return result;
169}
170
171const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000172SBValue::GetValue ()
173{
Greg Clayton49ce6822010-10-31 03:01:06 +0000174 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000175 if (m_opaque_sp)
176 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000177 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000178 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000179 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000180 cstr = m_opaque_sp->GetValueAsCString ();
181 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000182 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000183 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000184 if (log)
185 {
186 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000187 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000188 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000189 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000190 }
191
192 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000193}
194
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000195ValueType
196SBValue::GetValueType ()
197{
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000199 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000200 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000201 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000202 if (log)
203 {
204 switch (result)
205 {
206 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
207 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
208 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
209 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
210 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
211 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
212 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
213 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
214 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
215 }
216 }
217 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000218}
219
Jim Ingham4ae51962010-09-10 23:12:17 +0000220const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000221SBValue::GetObjectDescription ()
222{
Greg Clayton49ce6822010-10-31 03:01:06 +0000223 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000224 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000225 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000226 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000227 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000228 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000229 cstr = m_opaque_sp->GetObjectDescription ();
230 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000231 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000233 if (log)
234 {
235 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000236 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000237 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000238 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000239 }
240 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000241}
242
Enrico Granata979e20d2011-07-29 19:53:35 +0000243SBType
244SBValue::GetType()
245{
246 SBType result;
247 if (m_opaque_sp)
248 {
249 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
250 {
251 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000252 result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000253 }
254 }
255 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
256 if (log)
257 {
258 if (result.IsValid())
259 log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
260 else
261 log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
262 }
263 return result;
264}
265
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000266bool
267SBValue::GetValueDidChange ()
268{
Greg Clayton49ce6822010-10-31 03:01:06 +0000269 bool result = false;
270 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000271 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000272 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000273 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000274 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000275 result = m_opaque_sp->GetValueDidChange ();
276 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000277 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000278 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000279 if (log)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000280 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000281
282 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000283}
284
285const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000286SBValue::GetSummary ()
287{
Greg Clayton49ce6822010-10-31 03:01:06 +0000288 const char *cstr = NULL;
289 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000290 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000291 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000292 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000293 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000294 cstr = m_opaque_sp->GetSummaryAsCString();
295 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000296 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000297 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000298 if (log)
299 {
300 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000301 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000302 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000303 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000304 }
305 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000306}
307
308const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000309SBValue::GetLocation ()
310{
Greg Clayton49ce6822010-10-31 03:01:06 +0000311 const char *cstr = NULL;
312 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000313 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000314 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000315 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000316 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000317 cstr = m_opaque_sp->GetLocationAsCString();
318 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000319 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000320 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000321 if (log)
322 {
323 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000324 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000325 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000326 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000327 }
328 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000329}
330
331bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000332SBValue::SetValueFromCString (const char *value_str)
333{
Chris Lattner24943d22010-06-08 16:52:24 +0000334 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000335 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000336 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000337 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000338 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000339 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000340 success = m_opaque_sp->SetValueFromCString (value_str);
341 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000342 }
Chris Lattner24943d22010-06-08 16:52:24 +0000343 return success;
344}
345
Enrico Granata979e20d2011-07-29 19:53:35 +0000346lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000347SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000348{
349 lldb::SBValue result;
350 if (m_opaque_sp)
351 {
352 if (type.IsValid())
353 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000354 result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
Enrico Granata979e20d2011-07-29 19:53:35 +0000355 result.m_opaque_sp->SetName(ConstString(name));
356 }
357 }
358 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
359 if (log)
360 {
361 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000362 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000363 else
364 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
365 }
366 return result;
367}
368
369lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000370SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000371{
372 return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
373}
374
375lldb::SBValue
376SBValue::CreateValueFromExpression (const char *name, const char* expression)
377{
378 lldb::SBValue result;
379 if (m_opaque_sp)
380 {
381 ValueObjectSP result_valobj_sp;
Greg Claytond68e0892011-09-09 23:04:00 +0000382 m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression,
383 m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame(),
Sean Callanana8428a42011-09-22 00:41:11 +0000384 eExecutionPolicyOnlyWhenNeeded,
Sean Callanan47dc4572011-09-15 02:13:07 +0000385 true, // unwind on error
386 true, // keep in memory
387 eNoDynamicValues,
Greg Claytond68e0892011-09-09 23:04:00 +0000388 result_valobj_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000389 result_valobj_sp->SetName(ConstString(name));
390 result = SBValue(result_valobj_sp);
391 }
392 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
393 if (log)
394 {
395 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000396 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000397 else
398 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
399 }
400 return result;
401}
402
403lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000404SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000405{
406 lldb::SBValue result;
407 if (m_opaque_sp)
408 {
409
410 SBType real_type(type.GetPointerType());
411
412 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
413
Greg Claytond68e0892011-09-09 23:04:00 +0000414 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope(),
415 real_type.m_opaque_sp->GetASTContext(),
416 real_type.m_opaque_sp->GetOpaqueQualType(),
417 ConstString(name),
418 buffer,
419 lldb::endian::InlHostByteOrder(),
420 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000421
Enrico Granatac9310302011-08-04 17:07:02 +0000422 ValueObjectSP result_valobj_sp;
423
424 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
425 if (ptr_result_valobj_sp)
426 {
427 Error err;
428 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
429 if (result_valobj_sp)
430 result_valobj_sp->SetName(ConstString(name));
431 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000432 result = SBValue(result_valobj_sp);
433 }
434 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
435 if (log)
436 {
437 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000438 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000439 else
440 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
441 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000442 return result;
443}
444
Enrico Granata91544802011-09-06 19:20:51 +0000445lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000446SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000447{
448 SBValue result;
449
450 AddressType addr_of_children_priv = eAddressTypeLoad;
451
452 if (m_opaque_sp)
453 {
454 ValueObjectSP valobj_sp;
455 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
456 type.m_opaque_sp->GetASTContext() ,
457 type.m_opaque_sp->GetOpaqueQualType(),
458 ConstString(name),
459 *data.m_opaque_sp,
460 LLDB_INVALID_ADDRESS);
461 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
462 result = SBValue(valobj_sp);
463 }
464 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
465 if (log)
466 {
467 if (result.IsValid())
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000468 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000469 else
470 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
471 }
472 return result;
473}
474
Chris Lattner24943d22010-06-08 16:52:24 +0000475SBValue
476SBValue::GetChildAtIndex (uint32_t idx)
477{
Greg Clayton8f64c472011-07-15 19:31:49 +0000478 const bool can_create_synthetic = false;
479 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000480 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000481 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000482 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000483}
484
485SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000486SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000487{
Chris Lattner24943d22010-06-08 16:52:24 +0000488 lldb::ValueObjectSP child_sp;
489
Greg Clayton49ce6822010-10-31 03:01:06 +0000490 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000491 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000492 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000493 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000494 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000495 const bool can_create = true;
496 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
497 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000498 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000499 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000500 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000501 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
502 }
503 else if (m_opaque_sp->IsArrayType())
504 {
505 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
506 }
507 }
508
509 if (child_sp)
510 {
511 if (use_dynamic != lldb::eNoDynamicValues)
512 {
513 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000514 if (dynamic_sp)
515 child_sp = dynamic_sp;
516 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000517 }
Jim Inghame41494a2011-04-16 00:01:13 +0000518 }
519 }
520
Chris Lattner24943d22010-06-08 16:52:24 +0000521 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000522 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000523 if (log)
524 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
525
Chris Lattner24943d22010-06-08 16:52:24 +0000526 return sb_value;
527}
528
529uint32_t
530SBValue::GetIndexOfChildWithName (const char *name)
531{
Greg Clayton49ce6822010-10-31 03:01:06 +0000532 uint32_t idx = UINT32_MAX;
533 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000534 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000535 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000536 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000537 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000538
Greg Claytonb9dcc512011-06-29 18:28:50 +0000539 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
540 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000541 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000542 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000543 if (log)
544 {
545 if (idx == UINT32_MAX)
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000546 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000547 else
548 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
549 }
550 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000551}
552
553SBValue
554SBValue::GetChildMemberWithName (const char *name)
555{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000556 if (m_opaque_sp)
557 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000558 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000559 return GetChildMemberWithName (name, use_dynamic_value);
560 }
561 else
562 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000563}
564
565SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000566SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000567{
Chris Lattner24943d22010-06-08 16:52:24 +0000568 lldb::ValueObjectSP child_sp;
569 const ConstString str_name (name);
570
Greg Clayton905acaf2011-05-20 22:07:17 +0000571
Greg Clayton49ce6822010-10-31 03:01:06 +0000572 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000573 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000574 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000575 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000576 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000577 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
578 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000579 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000580 if (child_sp)
581 {
582 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
583 if (dynamic_sp)
584 child_sp = dynamic_sp;
585 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000586 }
Jim Inghame41494a2011-04-16 00:01:13 +0000587 }
588 }
589
Chris Lattner24943d22010-06-08 16:52:24 +0000590 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000591
Greg Claytone005f2c2010-11-06 01:53:30 +0000592 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000593 if (log)
594 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
595
Chris Lattner24943d22010-06-08 16:52:24 +0000596 return sb_value;
597}
598
Enrico Granataf7a9b142011-07-15 02:26:42 +0000599lldb::SBValue
600SBValue::GetValueForExpressionPath(const char* expr_path)
601{
602 lldb::ValueObjectSP child_sp;
603 if (m_opaque_sp)
604 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000605 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000606 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000607 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000608 // using default values for all the fancy options, just do it if you can
609 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
610 }
611 }
612
613 SBValue sb_value (child_sp);
614
615 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
616 if (log)
617 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
618
619 return sb_value;
620}
Chris Lattner24943d22010-06-08 16:52:24 +0000621
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000622int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000623SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
624{
Jim Ingham574c3d62011-08-12 23:34:31 +0000625 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000626 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 Scalar scalar;
632 if (m_opaque_sp->ResolveValue (scalar))
633 return scalar.GetRawBits64(fail_value);
634 else
635 error.SetErrorString("could not get value");
636 }
637 else
638 error.SetErrorString("could not get target");
639 }
640 error.SetErrorString("invalid SBValue");
641 return fail_value;
642}
643
644uint64_t
645SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
646{
Jim Ingham574c3d62011-08-12 23:34:31 +0000647 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000648 if (m_opaque_sp)
649 {
650 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
651 {
652 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
653 Scalar scalar;
654 if (m_opaque_sp->ResolveValue (scalar))
655 return scalar.GetRawBits64(fail_value);
656 else
657 error.SetErrorString("could not get value");
658 }
659 else
660 error.SetErrorString("could not get target");
661 }
662 error.SetErrorString("invalid SBValue");
663 return fail_value;
664}
665
666int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000667SBValue::GetValueAsSigned(int64_t fail_value)
668{
669 if (m_opaque_sp)
670 {
671 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
672 {
673 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
674 Scalar scalar;
675 if (m_opaque_sp->ResolveValue (scalar))
676 return scalar.GetRawBits64(fail_value);
677 }
678 }
679 return fail_value;
680}
681
682uint64_t
683SBValue::GetValueAsUnsigned(uint64_t fail_value)
684{
685 if (m_opaque_sp)
686 {
687 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
688 {
689 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
690 Scalar scalar;
691 if (m_opaque_sp->ResolveValue (scalar))
692 return scalar.GetRawBits64(fail_value);
693 }
694 }
695 return fail_value;
696}
697
Chris Lattner24943d22010-06-08 16:52:24 +0000698uint32_t
699SBValue::GetNumChildren ()
700{
701 uint32_t num_children = 0;
702
Greg Clayton49ce6822010-10-31 03:01:06 +0000703 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000704 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000705 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000706 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000707 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000708
Greg Claytonb9dcc512011-06-29 18:28:50 +0000709 num_children = m_opaque_sp->GetNumChildren();
710 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000711 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000712
Greg Claytone005f2c2010-11-06 01:53:30 +0000713 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000714 if (log)
715 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000716
717 return num_children;
718}
719
Chris Lattner24943d22010-06-08 16:52:24 +0000720
721SBValue
722SBValue::Dereference ()
723{
Greg Clayton49ce6822010-10-31 03:01:06 +0000724 SBValue sb_value;
725 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000726 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000727 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000728 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000729 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000730
Greg Claytonb9dcc512011-06-29 18:28:50 +0000731 Error error;
732 sb_value = m_opaque_sp->Dereference (error);
733 }
Chris Lattner24943d22010-06-08 16:52:24 +0000734 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000735 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000736 if (log)
737 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
738
739 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000740}
741
742bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000743SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000744{
745 bool is_ptr_type = false;
746
Greg Clayton49ce6822010-10-31 03:01:06 +0000747 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000748 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000749 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000750 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000751 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000752
Greg Claytonb9dcc512011-06-29 18:28:50 +0000753 is_ptr_type = m_opaque_sp->IsPointerType();
754 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000755 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000756
Greg Claytone005f2c2010-11-06 01:53:30 +0000757 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000758 if (log)
759 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
760
Chris Lattner24943d22010-06-08 16:52:24 +0000761
762 return is_ptr_type;
763}
764
Chris Lattner24943d22010-06-08 16:52:24 +0000765void *
766SBValue::GetOpaqueType()
767{
Greg Clayton63094e02010-06-23 01:19:29 +0000768 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000769 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000770 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000771 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000772 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000773
Greg Claytonb9dcc512011-06-29 18:28:50 +0000774 return m_opaque_sp->GetClangType();
775 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000776 }
Chris Lattner24943d22010-06-08 16:52:24 +0000777 return NULL;
778}
779
Enrico Granata979e20d2011-07-29 19:53:35 +0000780lldb::SBTarget
781SBValue::GetTarget()
782{
783 SBTarget result;
784 if (m_opaque_sp)
785 {
786 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
787 {
788 result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
789 }
790 }
791 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
792 if (log)
793 {
794 if (result.get() == NULL)
795 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
796 else
797 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
798 }
799 return result;
800}
801
802lldb::SBProcess
803SBValue::GetProcess()
804{
805 SBProcess result;
806 if (m_opaque_sp)
807 {
Enrico Granata91544802011-09-06 19:20:51 +0000808 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
809 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000810 {
Enrico Granata91544802011-09-06 19:20:51 +0000811 result = SBProcess(lldb::ProcessSP(target->GetProcessSP()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000812 }
813 }
814 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
815 if (log)
816 {
817 if (result.get() == NULL)
818 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
819 else
820 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
821 }
822 return result;
823}
824
825lldb::SBThread
826SBValue::GetThread()
827{
828 SBThread result;
829 if (m_opaque_sp)
830 {
831 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
832 {
Greg Claytond68e0892011-09-09 23:04:00 +0000833 result = SBThread(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateThread()->GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000834 }
835 }
836 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
837 if (log)
838 {
839 if (result.get() == NULL)
840 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
841 else
842 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get());
843 }
844 return result;
845}
846
847lldb::SBFrame
848SBValue::GetFrame()
849{
850 SBFrame result;
851 if (m_opaque_sp)
852 {
853 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
854 {
Greg Claytond68e0892011-09-09 23:04:00 +0000855 result.SetFrame (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame()->GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000856 }
857 }
858 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
859 if (log)
860 {
861 if (result.get() == NULL)
862 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
863 else
864 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
865 }
866 return result;
867}
868
869
Chris Lattner24943d22010-06-08 16:52:24 +0000870// Mimic shared pointer...
871lldb_private::ValueObject *
872SBValue::get() const
873{
Greg Clayton63094e02010-06-23 01:19:29 +0000874 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000875}
876
877lldb_private::ValueObject *
878SBValue::operator->() const
879{
Greg Clayton63094e02010-06-23 01:19:29 +0000880 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000881}
882
883lldb::ValueObjectSP &
884SBValue::operator*()
885{
Greg Clayton63094e02010-06-23 01:19:29 +0000886 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000887}
888
889const lldb::ValueObjectSP &
890SBValue::operator*() const
891{
Greg Clayton63094e02010-06-23 01:19:29 +0000892 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000893}
Caroline Tice98f930f2010-09-20 05:20:02 +0000894
895bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000896SBValue::GetExpressionPath (SBStream &description)
897{
898 if (m_opaque_sp)
899 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000900 m_opaque_sp->GetExpressionPath (description.ref(), false);
901 return true;
902 }
903 return false;
904}
905
906bool
907SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
908{
909 if (m_opaque_sp)
910 {
911 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000912 return true;
913 }
914 return false;
915}
916
917bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000918SBValue::GetDescription (SBStream &description)
919{
920 if (m_opaque_sp)
921 {
Enrico Granata19030d82011-08-15 18:01:31 +0000922 /*uint32_t ptr_depth = 0;
Greg Claytonbafc86e2011-07-06 16:49:27 +0000923 uint32_t curr_depth = 0;
924 uint32_t max_depth = UINT32_MAX;
925 bool show_types = false;
926 bool show_location = false;
927 bool use_objc = false;
928 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
929 bool scope_already_checked = false;
930 bool flat_output = false;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000931 bool use_synthetic = true;
932 uint32_t no_summary_depth = 0;
Enrico Granata19030d82011-08-15 18:01:31 +0000933 bool ignore_cap = false;*/
Greg Claytonbafc86e2011-07-06 16:49:27 +0000934 ValueObject::DumpValueObject (description.ref(),
Enrico Granata19030d82011-08-15 18:01:31 +0000935 m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000936 }
937 else
938 description.Printf ("No value");
939
940 return true;
941}
Greg Claytone179a582011-01-05 18:43:15 +0000942
943lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +0000944SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +0000945{
946 if (m_opaque_sp)
947 return m_opaque_sp->GetFormat();
948 return eFormatDefault;
949}
950
951void
952SBValue::SetFormat (lldb::Format format)
953{
954 if (m_opaque_sp)
955 m_opaque_sp->SetFormat(format);
956}
957
Enrico Granata979e20d2011-07-29 19:53:35 +0000958lldb::SBValue
959SBValue::AddressOf()
960{
961 SBValue sb_value;
962 if (m_opaque_sp)
963 {
Enrico Granata91544802011-09-06 19:20:51 +0000964 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
965 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000966 {
Enrico Granata91544802011-09-06 19:20:51 +0000967 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +0000968 Error error;
969 sb_value = m_opaque_sp->AddressOf (error);
970 }
971 }
972 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
973 if (log)
974 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
975
976 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +0000977}
Enrico Granata91544802011-09-06 19:20:51 +0000978
979lldb::addr_t
980SBValue::GetLoadAddress()
981{
982 lldb::addr_t value = LLDB_INVALID_ADDRESS;
983 if (m_opaque_sp)
984 {
985 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
986 if (target)
987 {
988 Mutex::Locker api_locker (target->GetAPIMutex());
989 const bool scalar_is_load_address = true;
990 AddressType addr_type;
991 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
992 if (addr_type == eAddressTypeFile)
993 {
994 Module* module = m_opaque_sp->GetModule();
995 if (!module)
996 value = LLDB_INVALID_ADDRESS;
997 else
998 {
999 Address addr;
1000 module->ResolveFileAddress(value, addr);
1001 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
1002 }
1003 }
1004 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1005 value = LLDB_INVALID_ADDRESS;
1006 }
1007 }
1008 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1009 if (log)
1010 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1011
1012 return value;
1013}
1014
1015lldb::SBAddress
1016SBValue::GetAddress()
1017{
1018 Address addr;
1019 if (m_opaque_sp)
1020 {
1021 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1022 if (target)
1023 {
1024 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1025 Mutex::Locker api_locker (target->GetAPIMutex());
1026 const bool scalar_is_load_address = true;
1027 AddressType addr_type;
1028 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1029 if (addr_type == eAddressTypeFile)
1030 {
1031 Module* module = m_opaque_sp->GetModule();
1032 if (module)
1033 module->ResolveFileAddress(value, addr);
1034 }
1035 else if (addr_type == eAddressTypeLoad)
1036 {
1037 // no need to check the return value on this.. if it can actually do the resolve
1038 // addr will be in the form (section,offset), otherwise it will simply be returned
1039 // as (NULL, value)
1040 addr.SetLoadAddress(value, target);
1041 }
1042 }
1043 }
1044 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1045 if (log)
1046 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1047 return SBAddress(new Address(addr));
1048}
1049
1050lldb::SBData
1051SBValue::GetPointeeData (uint32_t item_idx,
1052 uint32_t item_count)
1053{
1054 lldb::SBData sb_data;
1055 if (m_opaque_sp)
1056 {
1057 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1058 if (target)
1059 {
1060 DataExtractorSP data_sp(new DataExtractor());
1061 Mutex::Locker api_locker (target->GetAPIMutex());
1062 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1063 if (data_sp->GetByteSize() > 0)
1064 *sb_data = data_sp;
1065 }
1066 }
1067 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1068 if (log)
1069 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1070 m_opaque_sp.get(),
1071 item_idx,
1072 item_count,
1073 sb_data.get());
1074
1075 return sb_data;
1076}
1077
1078lldb::SBData
1079SBValue::GetData ()
1080{
1081 lldb::SBData sb_data;
1082 if (m_opaque_sp)
1083 {
1084 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1085 if (target)
1086 {
1087 DataExtractorSP data_sp(new DataExtractor());
1088 Mutex::Locker api_locker (target->GetAPIMutex());
1089 m_opaque_sp->GetData(*data_sp);
1090 if (data_sp->GetByteSize() > 0)
1091 *sb_data = data_sp;
1092 }
1093 }
1094 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1095 if (log)
1096 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1097 m_opaque_sp.get(),
1098 sb_data.get());
1099
1100 return sb_data;
1101}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001102
1103lldb::SBWatchpoint
1104SBValue::Watch (bool resolve_location, bool read, bool write)
1105{
1106 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001107 if (!m_opaque_sp)
1108 return sb_watchpoint;
1109
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001110 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1111 if (target)
1112 {
1113 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001114 sb_watchpoint = WatchValue(read, write, false);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001115 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001116 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1117 if (log)
1118 log->Printf ("SBValue(%p)::Watch (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1119 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001120 return sb_watchpoint;
1121}
1122
1123lldb::SBWatchpoint
1124SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1125{
1126 lldb::SBWatchpoint sb_watchpoint;
Johnny Chenecd4feb2011-10-14 00:42:25 +00001127 if (!m_opaque_sp)
1128 return sb_watchpoint;
1129
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001130 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1131 if (target)
1132 {
1133 Mutex::Locker api_locker (target->GetAPIMutex());
Johnny Chenecd4feb2011-10-14 00:42:25 +00001134 sb_watchpoint = WatchValue(read, write, true);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001135 }
Johnny Chenecd4feb2011-10-14 00:42:25 +00001136 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1137 if (log)
1138 log->Printf ("SBValue(%p)::WatchPointee (resolve_location=%i, read=%i, write=%i) => wp(%p)",
1139 m_opaque_sp.get(), resolve_location, read, write, sb_watchpoint.get());
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001140 return sb_watchpoint;
1141}
1142
Johnny Chenecd4feb2011-10-14 00:42:25 +00001143// Helper function for SBValue::Watch() and SBValue::WatchPointee().
1144SBWatchpoint
1145SBValue::WatchValue(bool read, bool write, bool watch_pointee)
1146{
1147 SBWatchpoint sb_wp_empty;
1148
1149 // If the SBValue is not valid, there's no point in even trying to watch it.
1150 if (!IsValid() || !GetFrame().IsValid())
1151 return sb_wp_empty;
1152
1153 // Read and Write cannot both be false.
1154 if (!read && !write)
1155 return sb_wp_empty;
1156
1157 // If we are watching the pointee, check that the SBValue is a pointer type.
1158 if (watch_pointee && !GetType().IsPointerType())
1159 return sb_wp_empty;
1160
1161 addr_t addr;
1162 size_t size;
1163 if (watch_pointee) {
1164 addr = GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
1165 size = GetType().GetPointeeType().GetByteSize();
1166 } else {
1167 addr = GetLoadAddress();
1168 size = GetByteSize();
1169 }
1170
1171 // Sanity check the address and the size before calling Target::CreateWatchpoint().
1172 if (addr == LLDB_INVALID_ADDRESS || size == 0)
1173 return sb_wp_empty;
1174
1175 uint32_t watch_type = (read ? LLDB_WATCH_TYPE_READ : 0) |
1176 (write ? LLDB_WATCH_TYPE_WRITE : 0);
1177 WatchpointSP wp_sp = GetFrame().m_opaque_sp->GetThread().GetProcess().GetTarget().
1178 CreateWatchpoint(addr, size, watch_type);
1179
1180 if (wp_sp) {
1181 // StackFrame::GetInScopeVariableList(true) to get file globals as well.
1182 VariableListSP var_list_sp(GetFrame().m_opaque_sp->GetInScopeVariableList(true));
1183 VariableSP var_sp = var_list_sp->FindVariable(ConstString(GetName()));
1184 if (var_sp && var_sp->GetDeclaration().GetFile()) {
1185 StreamString ss;
1186 // True to show fullpath for declaration file.
1187 var_sp->GetDeclaration().DumpStopContext(&ss, true);
1188 wp_sp->SetDeclInfo(ss.GetString());
1189 }
1190 }
1191 return wp_sp;
1192}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001193