blob: 21f24a28993b572ea6509875da0cd0a2a55518d3 [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"
Enrico Granatad760907c2012-02-17 03:18:30 +000011
Caroline Tice98f930f2010-09-20 05:20:02 +000012#include "lldb/API/SBStream.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000013#include "lldb/API/SBTypeFilter.h"
14#include "lldb/API/SBTypeFormat.h"
15#include "lldb/API/SBTypeSummary.h"
16#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017
Johnny Chenecd4feb2011-10-14 00:42:25 +000018#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000019#include "lldb/Core/DataExtractor.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000020#include "lldb/Core/DataVisualization.h"
Caroline Tice7826c882010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000023#include "lldb/Core/Scalar.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000024#include "lldb/Core/Section.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Core/Stream.h"
26#include "lldb/Core/StreamFile.h"
27#include "lldb/Core/Value.h"
28#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000029#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000030#include "lldb/Symbol/Block.h"
31#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000032#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000034#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000035#include "lldb/Target/ExecutionContext.h"
36#include "lldb/Target/Process.h"
37#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000038#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039#include "lldb/Target/Thread.h"
40
Eli Friedman7a62c8b2010-06-09 07:44:37 +000041#include "lldb/API/SBProcess.h"
42#include "lldb/API/SBTarget.h"
43#include "lldb/API/SBThread.h"
44#include "lldb/API/SBFrame.h"
45#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000046
47using namespace lldb;
48using namespace lldb_private;
49
50SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000051 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000052{
53}
54
Enrico Granatadba1de82012-03-27 02:35:13 +000055SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000056{
Enrico Granatadba1de82012-03-27 02:35:13 +000057 SetSP(value_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
Chris Lattner24943d22010-06-08 16:52:24 +000058}
59
Enrico Granatadba1de82012-03-27 02:35:13 +000060SBValue::SBValue(const SBValue &rhs)
Greg Clayton538eb822010-11-05 23:17:00 +000061{
Enrico Granatadba1de82012-03-27 02:35:13 +000062 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
Greg Clayton538eb822010-11-05 23:17:00 +000063}
64
Greg Claytond68e0892011-09-09 23:04:00 +000065SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000066SBValue::operator = (const SBValue &rhs)
67{
68 if (this != &rhs)
Enrico Granatadba1de82012-03-27 02:35:13 +000069 {
70 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
71 }
Greg Clayton538eb822010-11-05 23:17:00 +000072 return *this;
73}
74
Chris Lattner24943d22010-06-08 16:52:24 +000075SBValue::~SBValue()
76{
77}
78
79bool
Greg Claytond68e0892011-09-09 23:04:00 +000080SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000081{
Greg Clayton49ce6822010-10-31 03:01:06 +000082 // If this function ever changes to anything that does more than just
83 // check if the opaque shared pointer is non NULL, then we need to update
84 // all "if (m_opaque_sp)" code in this file.
85 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000086}
87
Jim Inghame0bd5712011-12-19 20:39:44 +000088void
89SBValue::Clear()
90{
91 m_opaque_sp.reset();
92}
93
Greg Claytonc5f728c2010-10-06 22:10:17 +000094SBError
95SBValue::GetError()
96{
97 SBError sb_error;
98
Greg Clayton0a19a1b2012-02-04 02:27:34 +000099 lldb::ValueObjectSP value_sp(GetSP());
100 if (value_sp)
101 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +0000102 else
103 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000104
105 return sb_error;
106}
107
Johnny Chen968958c2011-07-07 20:46:23 +0000108user_id_t
109SBValue::GetID()
110{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000111 lldb::ValueObjectSP value_sp(GetSP());
112 if (value_sp)
113 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000114 return LLDB_INVALID_UID;
115}
116
Chris Lattner24943d22010-06-08 16:52:24 +0000117const char *
118SBValue::GetName()
119{
Greg Clayton49ce6822010-10-31 03:01:06 +0000120
121 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000122 lldb::ValueObjectSP value_sp(GetSP());
123 if (value_sp)
124 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000125
Greg Claytone005f2c2010-11-06 01:53:30 +0000126 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000127 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000128 {
129 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000130 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000131 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000132 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000133 }
Caroline Tice7826c882010-10-26 03:11:13 +0000134
Greg Clayton49ce6822010-10-31 03:01:06 +0000135 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000136}
137
138const char *
139SBValue::GetTypeName ()
140{
Jim Ingham684d4012012-08-21 01:46:35 +0000141 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000142 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000143 lldb::ValueObjectSP value_sp(GetSP());
144 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000145 {
146 // For a dynamic type we might have to run code to determine the type we are going to report,
147 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
148
149 ProcessSP process_sp(value_sp->GetProcessSP());
150 Process::StopLocker stop_locker;
151 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
152 {
153 if (log)
154 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
155 }
156 else
157 {
158 TargetSP target_sp(value_sp->GetTargetSP());
159 if (target_sp)
160 {
161 Mutex::Locker api_locker (target_sp->GetAPIMutex());
162 name = value_sp->GetQualifiedTypeName().GetCString();
163 }
164 }
165 }
166
Greg Clayton49ce6822010-10-31 03:01:06 +0000167 if (log)
168 {
169 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000170 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000171 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000172 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000173 }
174
175 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000176}
177
178size_t
179SBValue::GetByteSize ()
180{
Jim Ingham684d4012012-08-21 01:46:35 +0000181 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000182 size_t result = 0;
183
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000184 lldb::ValueObjectSP value_sp(GetSP());
185 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000186 {
187 // For a dynamic type we might have to run code to determine the type we are going to report,
188 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
189
190 ProcessSP process_sp(value_sp->GetProcessSP());
191 Process::StopLocker stop_locker;
192 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
193 {
194 if (log)
195 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
196 }
197 else
198 {
199 TargetSP target_sp(value_sp->GetTargetSP());
200 if (target_sp)
201 {
202 Mutex::Locker api_locker (target_sp->GetAPIMutex());
203 result = value_sp->GetByteSize();
204 }
205 }
206 }
Chris Lattner24943d22010-06-08 16:52:24 +0000207
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000209 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000210
Chris Lattner24943d22010-06-08 16:52:24 +0000211 return result;
212}
213
214bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000215SBValue::IsInScope ()
216{
Chris Lattner24943d22010-06-08 16:52:24 +0000217 bool result = false;
218
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000219 lldb::ValueObjectSP value_sp(GetSP());
220 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000221 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000222 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000223 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000224 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000225 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000226 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000227 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000228 }
Chris Lattner24943d22010-06-08 16:52:24 +0000229
Greg Claytone005f2c2010-11-06 01:53:30 +0000230 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000231 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000232 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000233
Chris Lattner24943d22010-06-08 16:52:24 +0000234 return result;
235}
236
237const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000238SBValue::GetValue ()
239{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000240 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
241
Greg Clayton49ce6822010-10-31 03:01:06 +0000242 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000243 lldb::ValueObjectSP value_sp(GetSP());
244 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000245 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000246 ProcessSP process_sp(value_sp->GetProcessSP());
247 Process::StopLocker stop_locker;
248 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000249 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000250 if (log)
251 log->Printf ("SBValue(%p)::GetValue() => error: process is running", value_sp.get());
252 }
253 else
254 {
255 TargetSP target_sp(value_sp->GetTargetSP());
256 if (target_sp)
257 {
258 Mutex::Locker api_locker (target_sp->GetAPIMutex());
259 cstr = value_sp->GetValueAsCString ();
260 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000261 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000262 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000263 if (log)
264 {
265 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000266 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000267 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000268 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000269 }
270
271 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000272}
273
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000274ValueType
275SBValue::GetValueType ()
276{
Greg Clayton49ce6822010-10-31 03:01:06 +0000277 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000278 lldb::ValueObjectSP value_sp(GetSP());
279 if (value_sp)
280 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000282 if (log)
283 {
284 switch (result)
285 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000286 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
287 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
288 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
289 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
290 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
291 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
292 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
293 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
294 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000295 }
296 }
297 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000298}
299
Jim Ingham4ae51962010-09-10 23:12:17 +0000300const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000301SBValue::GetObjectDescription ()
302{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000303 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000304 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000305 lldb::ValueObjectSP value_sp(GetSP());
306 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000307 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000308 ProcessSP process_sp(value_sp->GetProcessSP());
309 Process::StopLocker stop_locker;
310 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000311 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000312 if (log)
313 log->Printf ("SBValue(%p)::GetObjectDescription() => error: process is running", value_sp.get());
314 }
315 else
316 {
317 TargetSP target_sp(value_sp->GetTargetSP());
318 if (target_sp)
319 {
320 Mutex::Locker api_locker (target_sp->GetAPIMutex());
321 cstr = value_sp->GetObjectDescription ();
322 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000323 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000324 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000325 if (log)
326 {
327 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000328 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000329 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000330 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000331 }
332 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000333}
334
Enrico Granata979e20d2011-07-29 19:53:35 +0000335SBType
336SBValue::GetType()
337{
Jim Ingham5b4905d2012-04-13 18:30:20 +0000338 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000339 SBType sb_type;
340 lldb::ValueObjectSP value_sp(GetSP());
341 TypeImplSP type_sp;
342 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000343 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000344 ProcessSP process_sp(value_sp->GetProcessSP());
345 Process::StopLocker stop_locker;
346 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
347 {
348 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000349 log->Printf ("SBValue(%p)::GetType() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000350 }
351 else
352 {
353 TargetSP target_sp(value_sp->GetTargetSP());
354 if (target_sp)
355 {
356 Mutex::Locker api_locker (target_sp->GetAPIMutex());
357 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
358 sb_type.SetSP(type_sp);
359 }
360 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000361 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000362 if (log)
363 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000364 if (type_sp)
365 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000366 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000367 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000368 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000369 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000370}
371
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000372bool
373SBValue::GetValueDidChange ()
374{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000375 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000376 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000377 lldb::ValueObjectSP value_sp(GetSP());
378 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000379 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000380 ProcessSP process_sp(value_sp->GetProcessSP());
381 Process::StopLocker stop_locker;
382 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000383 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000384 if (log)
385 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
386 }
387 else
388 {
389 TargetSP target_sp(value_sp->GetTargetSP());
390 if (target_sp)
391 {
392 Mutex::Locker api_locker (target_sp->GetAPIMutex());
393 result = value_sp->GetValueDidChange ();
394 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000395 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000396 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000397 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000398 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000399
400 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000401}
402
Jason Molendac48ca822012-02-21 05:33:55 +0000403#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000404const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000405SBValue::GetSummary ()
406{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000407 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000408 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000409 lldb::ValueObjectSP value_sp(GetSP());
410 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000411 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000412 ProcessSP process_sp(value_sp->GetProcessSP());
413 Process::StopLocker stop_locker;
414 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000415 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000416 if (log)
417 log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
418 }
419 else
420 {
421 TargetSP target_sp(value_sp->GetTargetSP());
422 if (target_sp)
423 {
424 Mutex::Locker api_locker (target_sp->GetAPIMutex());
425 cstr = value_sp->GetSummaryAsCString();
426 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000427 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000428 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000429 if (log)
430 {
431 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000432 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000433 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000434 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000435 }
436 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000437}
Jason Molendac48ca822012-02-21 05:33:55 +0000438#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000439
440const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000441SBValue::GetLocation ()
442{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000443 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000444 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000445 lldb::ValueObjectSP value_sp(GetSP());
446 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000447 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000448 ProcessSP process_sp(value_sp->GetProcessSP());
449 Process::StopLocker stop_locker;
450 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000451 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000452 if (log)
453 log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
454 }
455 else
456 {
457 TargetSP target_sp(value_sp->GetTargetSP());
458 if (target_sp)
459 {
460 Mutex::Locker api_locker (target_sp->GetAPIMutex());
461 cstr = value_sp->GetLocationAsCString();
462 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000463 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000464 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000465 if (log)
466 {
467 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000468 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000469 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000470 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000471 }
472 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000473}
474
Enrico Granata651cbe22012-05-08 21:25:06 +0000475// Deprecated - use the one that takes an lldb::SBError
Chris Lattner24943d22010-06-08 16:52:24 +0000476bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000477SBValue::SetValueFromCString (const char *value_str)
478{
Enrico Granata651cbe22012-05-08 21:25:06 +0000479 lldb::SBError dummy;
480 return SetValueFromCString(value_str,dummy);
481}
482
483bool
484SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
485{
Chris Lattner24943d22010-06-08 16:52:24 +0000486 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000487 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000488 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000489 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000490 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000491 ProcessSP process_sp(value_sp->GetProcessSP());
492 Process::StopLocker stop_locker;
493 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000494 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000495 if (log)
496 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
497 }
498 else
499 {
500 TargetSP target_sp(value_sp->GetTargetSP());
501 if (target_sp)
502 {
503 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata651cbe22012-05-08 21:25:06 +0000504 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000505 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000506 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000507 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000508 if (log)
509 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
510
Chris Lattner24943d22010-06-08 16:52:24 +0000511 return success;
512}
513
Enrico Granatad760907c2012-02-17 03:18:30 +0000514lldb::SBTypeFormat
515SBValue::GetTypeFormat ()
516{
517 lldb::SBTypeFormat format;
518 lldb::ValueObjectSP value_sp(GetSP());
519 if (value_sp)
520 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000521 ProcessSP process_sp(value_sp->GetProcessSP());
522 Process::StopLocker stop_locker;
523 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000524 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000525 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
526 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000527 log->Printf ("SBValue(%p)::GetTypeFormat() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000528 }
529 else
530 {
531 TargetSP target_sp(value_sp->GetTargetSP());
532 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000533 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000534 Mutex::Locker api_locker (target_sp->GetAPIMutex());
535 if (value_sp->UpdateValueIfNeeded(true))
536 {
537 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
538 if (format_sp)
539 format.SetSP(format_sp);
540 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000541 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000542 }
543 }
544 return format;
545}
546
Jason Molendac48ca822012-02-21 05:33:55 +0000547#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000548lldb::SBTypeSummary
549SBValue::GetTypeSummary ()
550{
551 lldb::SBTypeSummary summary;
552 lldb::ValueObjectSP value_sp(GetSP());
553 if (value_sp)
554 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000555 ProcessSP process_sp(value_sp->GetProcessSP());
556 Process::StopLocker stop_locker;
557 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000558 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000559 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
560 if (log)
561 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
562 }
563 else
564 {
565 TargetSP target_sp(value_sp->GetTargetSP());
566 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000567 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000568 Mutex::Locker api_locker (target_sp->GetAPIMutex());
569 if (value_sp->UpdateValueIfNeeded(true))
570 {
571 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
572 if (summary_sp)
573 summary.SetSP(summary_sp);
574 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000575 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000576 }
577 }
578 return summary;
579}
Jason Molendac48ca822012-02-21 05:33:55 +0000580#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000581
582lldb::SBTypeFilter
583SBValue::GetTypeFilter ()
584{
585 lldb::SBTypeFilter filter;
586 lldb::ValueObjectSP value_sp(GetSP());
587 if (value_sp)
588 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000589 ProcessSP process_sp(value_sp->GetProcessSP());
590 Process::StopLocker stop_locker;
591 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000592 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000593 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
594 if (log)
595 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
596 }
597 else
598 {
599 TargetSP target_sp(value_sp->GetTargetSP());
600 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000601 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000602 Mutex::Locker api_locker (target_sp->GetAPIMutex());
603 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000604 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000605 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
606
607 if (synthetic_sp && !synthetic_sp->IsScripted())
608 {
609 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
610 filter.SetSP(filter_sp);
611 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000612 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000613 }
614 }
615 }
616 return filter;
617}
618
Jason Molendac48ca822012-02-21 05:33:55 +0000619#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000620lldb::SBTypeSynthetic
621SBValue::GetTypeSynthetic ()
622{
623 lldb::SBTypeSynthetic synthetic;
624 lldb::ValueObjectSP value_sp(GetSP());
625 if (value_sp)
626 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000627 ProcessSP process_sp(value_sp->GetProcessSP());
628 Process::StopLocker stop_locker;
629 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000630 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000631 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
632 if (log)
633 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
634 }
635 else
636 {
637 TargetSP target_sp(value_sp->GetTargetSP());
638 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000639 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000640 Mutex::Locker api_locker (target_sp->GetAPIMutex());
641 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000642 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000643 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
644
645 if (children_sp && children_sp->IsScripted())
646 {
647 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
648 synthetic.SetSP(synth_sp);
649 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000650 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000651 }
652 }
653 }
654 return synthetic;
655}
Jason Molendac48ca822012-02-21 05:33:55 +0000656#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000657
Enrico Granata979e20d2011-07-29 19:53:35 +0000658lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000659SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000660{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000661 lldb::SBValue sb_value;
662 lldb::ValueObjectSP value_sp(GetSP());
663 lldb::ValueObjectSP new_value_sp;
664 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000665 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000666 ProcessSP process_sp(value_sp->GetProcessSP());
667 Process::StopLocker stop_locker;
668 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata979e20d2011-07-29 19:53:35 +0000669 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000670 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
671 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000672 log->Printf ("SBValue(%p)::CreateChildAtOffset() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000673 }
674 else
675 {
676 TargetSP target_sp(value_sp->GetTargetSP());
677 if (target_sp)
678 {
679 Mutex::Locker api_locker (target_sp->GetAPIMutex());
680 TypeImplSP type_sp (type.GetSP());
681 if (type.IsValid())
682 {
683 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
684 new_value_sp = sb_value.GetSP();
685 if (new_value_sp)
686 new_value_sp->SetName(ConstString(name));
687 }
688 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000689 }
690 }
691 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
692 if (log)
693 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000694 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000695 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000696 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000697 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000698 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000699 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000700}
701
702lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000703SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000704{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000705 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000706 lldb::ValueObjectSP value_sp(GetSP());
707 TypeImplSP type_sp (type.GetSP());
708 if (value_sp && type_sp)
709 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000710 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000711}
712
713lldb::SBValue
714SBValue::CreateValueFromExpression (const char *name, const char* expression)
715{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000716 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000717 lldb::SBValue sb_value;
718 lldb::ValueObjectSP value_sp(GetSP());
719 lldb::ValueObjectSP new_value_sp;
720 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000721 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000722 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000723 ProcessSP process_sp(exe_ctx.GetProcessSP());
724 Process::StopLocker stop_locker;
725 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000726 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000727 if (log)
728 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
729 }
730 else
731 {
732 Target* target = exe_ctx.GetTargetPtr();
733 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000734 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000735 target->EvaluateExpression (expression,
736 exe_ctx.GetFramePtr(),
737 eExecutionPolicyOnlyWhenNeeded,
738 false, // coerce to id
739 true, // unwind on error
740 true, // keep in memory
741 eNoDynamicValues,
742 new_value_sp);
743 if (new_value_sp)
744 {
745 new_value_sp->SetName(ConstString(name));
746 sb_value.SetSP(new_value_sp);
747 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000748 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000749 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000750 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000751 if (log)
752 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000753 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000754 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000755 value_sp.get(),
756 name,
757 expression,
758 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000759 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000760 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000761 value_sp.get(),
762 name,
763 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000764 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000765 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000766}
767
768lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000769SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000770{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000771 lldb::SBValue sb_value;
772 lldb::ValueObjectSP value_sp(GetSP());
773 lldb::ValueObjectSP new_value_sp;
774 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
775 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000776 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000777 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
778 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
779 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000780 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000781
782 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
783
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000784 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
785 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000786 pointee_type_impl_sp->GetASTContext(),
787 pointee_type_impl_sp->GetOpaqueQualType(),
788 ConstString(name),
789 buffer,
790 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000791 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000792
793 if (ptr_result_valobj_sp)
794 {
795 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
796 Error err;
797 new_value_sp = ptr_result_valobj_sp->Dereference(err);
798 if (new_value_sp)
799 new_value_sp->SetName(ConstString(name));
800 }
801 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000802 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000803 }
804 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
805 if (log)
806 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000807 if (new_value_sp)
808 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000809 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000810 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000811 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000812 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000813}
814
Enrico Granata91544802011-09-06 19:20:51 +0000815lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000816SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000817{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000818 lldb::SBValue sb_value;
819 lldb::ValueObjectSP new_value_sp;
820 lldb::ValueObjectSP value_sp(GetSP());
821 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000822 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000823 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
824
825 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000826 type.m_opaque_sp->GetASTContext() ,
827 type.m_opaque_sp->GetOpaqueQualType(),
828 ConstString(name),
829 *data.m_opaque_sp,
830 LLDB_INVALID_ADDRESS);
831 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
832 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000833 }
834 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
835 if (log)
836 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000837 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000838 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000839 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000840 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000841 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000842 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000843}
844
Chris Lattner24943d22010-06-08 16:52:24 +0000845SBValue
846SBValue::GetChildAtIndex (uint32_t idx)
847{
Greg Clayton8f64c472011-07-15 19:31:49 +0000848 const bool can_create_synthetic = false;
849 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000850 lldb::ValueObjectSP value_sp(GetSP());
851 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000852 {
853 TargetSP target_sp(value_sp->GetTargetSP());
854 if (target_sp)
855 use_dynamic = target_sp->GetPreferDynamicValue();
856 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000857 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000858}
859
860SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000861SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000862{
Chris Lattner24943d22010-06-08 16:52:24 +0000863 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000864 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000865
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000866 lldb::ValueObjectSP value_sp(GetSP());
867 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000868 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000869 ProcessSP process_sp(value_sp->GetProcessSP());
870 Process::StopLocker stop_locker;
871 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000872 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000873 if (log)
874 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
875 }
876 else
877 {
878 TargetSP target_sp(value_sp->GetTargetSP());
879 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000880 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000881 Mutex::Locker api_locker (target_sp->GetAPIMutex());
882 const bool can_create = true;
883 child_sp = value_sp->GetChildAtIndex (idx, can_create);
884 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000885 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000886 if (value_sp->IsPointerType())
887 {
888 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
889 }
890 else if (value_sp->IsArrayType())
891 {
892 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
893 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000894 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000895
896 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000897 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000898 if (use_dynamic != lldb::eNoDynamicValues)
899 {
900 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
901 if (dynamic_sp)
902 child_sp = dynamic_sp;
903 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000904 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000905 }
Jim Inghame41494a2011-04-16 00:01:13 +0000906 }
907 }
908
Chris Lattner24943d22010-06-08 16:52:24 +0000909 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000910 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000911 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000912
Chris Lattner24943d22010-06-08 16:52:24 +0000913 return sb_value;
914}
915
916uint32_t
917SBValue::GetIndexOfChildWithName (const char *name)
918{
Greg Clayton49ce6822010-10-31 03:01:06 +0000919 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000920 lldb::ValueObjectSP value_sp(GetSP());
921 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000922 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000923 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000924 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000925 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000926 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000927
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000928 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000929 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000930 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000931 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000932 if (log)
933 {
934 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000935 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000936 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000937 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000938 }
939 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000940}
941
942SBValue
943SBValue::GetChildMemberWithName (const char *name)
944{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000945 lldb::ValueObjectSP value_sp(GetSP());
946 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000947 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000948 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000949 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000950 if (target_sp)
951 {
952 Mutex::Locker api_locker (target_sp->GetAPIMutex());
953 use_dynamic_value = target_sp->GetPreferDynamicValue();
954 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000955 return GetChildMemberWithName (name, use_dynamic_value);
956 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000957 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000958}
959
960SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000961SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000962{
Chris Lattner24943d22010-06-08 16:52:24 +0000963 lldb::ValueObjectSP child_sp;
964 const ConstString str_name (name);
965
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000966 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000967
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000968 lldb::ValueObjectSP value_sp(GetSP());
969 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000970 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000971 ProcessSP process_sp(value_sp->GetProcessSP());
972 Process::StopLocker stop_locker;
973 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Inghame41494a2011-04-16 00:01:13 +0000974 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000975 if (log)
976 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
977 }
978 else
979 {
980 TargetSP target_sp(value_sp->GetTargetSP());
981 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000982 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000983 Mutex::Locker api_locker (target_sp->GetAPIMutex());
984 child_sp = value_sp->GetChildMemberWithName (str_name, true);
985 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000986 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000987 if (child_sp)
988 {
989 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
990 if (dynamic_sp)
991 child_sp = dynamic_sp;
992 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000993 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000994 }
Jim Inghame41494a2011-04-16 00:01:13 +0000995 }
996 }
997
Chris Lattner24943d22010-06-08 16:52:24 +0000998 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000999
Greg Clayton49ce6822010-10-31 03:01:06 +00001000 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001001 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001002
Chris Lattner24943d22010-06-08 16:52:24 +00001003 return sb_value;
1004}
1005
Enrico Granataf7a9b142011-07-15 02:26:42 +00001006lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +00001007SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1008{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001009 lldb::ValueObjectSP value_sp(GetSP());
1010 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001011 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001012 ProcessSP process_sp(value_sp->GetProcessSP());
1013 Process::StopLocker stop_locker;
1014 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +00001015 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001016 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1017 if (log)
1018 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
1019 }
1020 else
1021 {
1022 TargetSP target_sp(value_sp->GetTargetSP());
1023 if (target_sp)
1024 {
1025 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1026 return SBValue (value_sp->GetDynamicValue(use_dynamic));
1027 }
Jim Ingham1b425752011-12-08 19:44:08 +00001028 }
1029 }
1030
1031 return SBValue();
1032}
1033
1034lldb::SBValue
1035SBValue::GetStaticValue ()
1036{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001037 lldb::ValueObjectSP value_sp(GetSP());
1038 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001039 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001040 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001041 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001042 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001043 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001044 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +00001045 }
1046 }
1047
1048 return SBValue();
1049}
1050
Enrico Granatadba1de82012-03-27 02:35:13 +00001051lldb::SBValue
1052SBValue::GetNonSyntheticValue ()
1053{
1054 SBValue sb_value;
1055 lldb::ValueObjectSP value_sp(GetSP());
1056 if (value_sp)
1057 {
1058 if (value_sp->IsSynthetic())
1059 {
1060 TargetSP target_sp(value_sp->GetTargetSP());
1061 if (target_sp)
1062 {
1063 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1064 // deliberately breaking the rules here to optimize the case where we DO NOT want
1065 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
1066 // the target to suppress the synthetic value, and then return the flag to its original value
Enrico Granata4758a3c2012-05-08 18:47:08 +00001067 if (value_sp->GetNonSyntheticValue())
1068 sb_value.m_opaque_sp = value_sp->GetNonSyntheticValue();
Enrico Granatadba1de82012-03-27 02:35:13 +00001069 }
1070 }
1071 }
1072 return sb_value;
1073}
1074
Jim Ingham1b425752011-12-08 19:44:08 +00001075bool
1076SBValue::IsDynamic()
1077{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001078 lldb::ValueObjectSP value_sp(GetSP());
1079 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001080 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001081 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001082 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001083 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001084 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001085 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +00001086 }
1087 }
1088 return false;
1089}
1090
1091lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001092SBValue::GetValueForExpressionPath(const char* expr_path)
1093{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001094 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001095 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001096 lldb::ValueObjectSP value_sp(GetSP());
1097 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001098 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001099 ProcessSP process_sp(value_sp->GetProcessSP());
1100 Process::StopLocker stop_locker;
1101 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001102 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001103 if (log)
1104 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1105 }
1106 else
1107 {
1108 TargetSP target_sp(value_sp->GetTargetSP());
1109 if (target_sp)
1110 {
1111 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1112 // using default values for all the fancy options, just do it if you can
1113 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1114 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001115 }
1116 }
1117
1118 SBValue sb_value (child_sp);
1119
Enrico Granataf7a9b142011-07-15 02:26:42 +00001120 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001121 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
Enrico Granataf7a9b142011-07-15 02:26:42 +00001122
1123 return sb_value;
1124}
Chris Lattner24943d22010-06-08 16:52:24 +00001125
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001126int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001127SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1128{
Jim Ingham574c3d62011-08-12 23:34:31 +00001129 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001130 lldb::ValueObjectSP value_sp(GetSP());
1131 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001132 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001133 ProcessSP process_sp(value_sp->GetProcessSP());
1134 Process::StopLocker stop_locker;
1135 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001136 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001137 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1138 if (log)
1139 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1140 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001141 }
1142 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001143 {
1144 TargetSP target_sp(value_sp->GetTargetSP());
1145 if (target_sp)
1146 {
1147 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1148 Scalar scalar;
1149 if (value_sp->ResolveValue (scalar))
1150 return scalar.GetRawBits64(fail_value);
1151 else
1152 error.SetErrorString("could not get value");
1153 }
1154 else
1155 error.SetErrorString("could not get target");
1156 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001157 }
1158 error.SetErrorString("invalid SBValue");
1159 return fail_value;
1160}
1161
1162uint64_t
1163SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1164{
Jim Ingham574c3d62011-08-12 23:34:31 +00001165 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001166 lldb::ValueObjectSP value_sp(GetSP());
1167 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001168 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001169 ProcessSP process_sp(value_sp->GetProcessSP());
1170 Process::StopLocker stop_locker;
1171 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001172 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001173 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1174 if (log)
1175 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1176 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001177 }
1178 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001179 {
1180 TargetSP target_sp(value_sp->GetTargetSP());
1181 if (target_sp)
1182 {
1183 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1184 Scalar scalar;
1185 if (value_sp->ResolveValue (scalar))
1186 return scalar.GetRawBits64(fail_value);
1187 else
1188 error.SetErrorString("could not get value");
1189 }
1190 else
1191 error.SetErrorString("could not get target");
1192 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001193 }
1194 error.SetErrorString("invalid SBValue");
1195 return fail_value;
1196}
1197
1198int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001199SBValue::GetValueAsSigned(int64_t fail_value)
1200{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001201 lldb::ValueObjectSP value_sp(GetSP());
1202 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001203 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001204 ProcessSP process_sp(value_sp->GetProcessSP());
1205 Process::StopLocker stop_locker;
1206 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001207 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001208 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1209 if (log)
1210 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1211 }
1212 else
1213 {
1214 TargetSP target_sp(value_sp->GetTargetSP());
1215 if (target_sp)
1216 {
1217 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1218 Scalar scalar;
1219 if (value_sp->ResolveValue (scalar))
1220 return scalar.GetRawBits64(fail_value);
1221 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001222 }
1223 }
1224 return fail_value;
1225}
1226
1227uint64_t
1228SBValue::GetValueAsUnsigned(uint64_t fail_value)
1229{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001230 lldb::ValueObjectSP value_sp(GetSP());
1231 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001232 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001233 ProcessSP process_sp(value_sp->GetProcessSP());
1234 Process::StopLocker stop_locker;
1235 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001236 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001237 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1238 if (log)
1239 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1240 }
1241 else
1242 {
1243 TargetSP target_sp(value_sp->GetTargetSP());
1244 if (target_sp)
1245 {
1246 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1247 Scalar scalar;
1248 if (value_sp->ResolveValue (scalar))
1249 return scalar.GetRawBits64(fail_value);
1250 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001251 }
1252 }
1253 return fail_value;
1254}
1255
Chris Lattner24943d22010-06-08 16:52:24 +00001256uint32_t
1257SBValue::GetNumChildren ()
1258{
1259 uint32_t num_children = 0;
1260
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001261 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001262 lldb::ValueObjectSP value_sp(GetSP());
1263 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001264 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001265 ProcessSP process_sp(value_sp->GetProcessSP());
1266 Process::StopLocker stop_locker;
1267 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001268 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001269 if (log)
1270 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1271 }
1272 else
1273 {
1274 TargetSP target_sp(value_sp->GetTargetSP());
1275 if (target_sp)
1276 {
1277 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001278
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001279 num_children = value_sp->GetNumChildren();
1280 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001281 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001282 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001283
Greg Clayton49ce6822010-10-31 03:01:06 +00001284 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001285 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001286
1287 return num_children;
1288}
1289
Chris Lattner24943d22010-06-08 16:52:24 +00001290
1291SBValue
1292SBValue::Dereference ()
1293{
Greg Clayton49ce6822010-10-31 03:01:06 +00001294 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001295 lldb::ValueObjectSP value_sp(GetSP());
1296 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001297 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001298 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001299 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001300 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001301 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001302
Greg Claytonb9dcc512011-06-29 18:28:50 +00001303 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001304 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001305 }
Chris Lattner24943d22010-06-08 16:52:24 +00001306 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001308 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001309 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001310
1311 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001312}
1313
1314bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001315SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001316{
1317 bool is_ptr_type = false;
1318
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001319 lldb::ValueObjectSP value_sp(GetSP());
1320 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001321 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001322 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001323 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001324 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001325 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001326
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001327 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001328 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001329 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001330
Greg Claytone005f2c2010-11-06 01:53:30 +00001331 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001332 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001333 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001334
Chris Lattner24943d22010-06-08 16:52:24 +00001335
1336 return is_ptr_type;
1337}
1338
Chris Lattner24943d22010-06-08 16:52:24 +00001339void *
1340SBValue::GetOpaqueType()
1341{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001342 lldb::ValueObjectSP value_sp(GetSP());
1343 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001344 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001345 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001346 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001347 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001348 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001349
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001350 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001351 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001352 }
Chris Lattner24943d22010-06-08 16:52:24 +00001353 return NULL;
1354}
1355
Enrico Granata979e20d2011-07-29 19:53:35 +00001356lldb::SBTarget
1357SBValue::GetTarget()
1358{
Greg Clayton334d33a2012-01-30 07:41:31 +00001359 SBTarget sb_target;
1360 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001361 lldb::ValueObjectSP value_sp(GetSP());
1362 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001363 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001364 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001365 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001366 }
1367 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1368 if (log)
1369 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001370 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001371 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001372 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001373 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001374 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001375 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001376}
1377
1378lldb::SBProcess
1379SBValue::GetProcess()
1380{
Greg Clayton334d33a2012-01-30 07:41:31 +00001381 SBProcess sb_process;
1382 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001383 lldb::ValueObjectSP value_sp(GetSP());
1384 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001385 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001386 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001387 if (process_sp)
1388 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001389 }
1390 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1391 if (log)
1392 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001393 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001394 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001395 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001396 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001397 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001398 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001399}
1400
1401lldb::SBThread
1402SBValue::GetThread()
1403{
Greg Clayton90c52142012-01-30 02:53:15 +00001404 SBThread sb_thread;
1405 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001406 lldb::ValueObjectSP value_sp(GetSP());
1407 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001408 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001409 thread_sp = value_sp->GetThreadSP();
1410 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001411 }
1412 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1413 if (log)
1414 {
Greg Clayton90c52142012-01-30 02:53:15 +00001415 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001416 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001417 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001418 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001419 }
Greg Clayton90c52142012-01-30 02:53:15 +00001420 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001421}
1422
1423lldb::SBFrame
1424SBValue::GetFrame()
1425{
Greg Clayton334d33a2012-01-30 07:41:31 +00001426 SBFrame sb_frame;
1427 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001428 lldb::ValueObjectSP value_sp(GetSP());
1429 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001430 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001431 frame_sp = value_sp->GetFrameSP();
1432 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001433 }
1434 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1435 if (log)
1436 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001437 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001438 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001439 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001440 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001441 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001442 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001443}
1444
1445
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001446lldb::ValueObjectSP
1447SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001448{
Greg Clayton63094e02010-06-23 01:19:29 +00001449 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001450}
1451
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001452void
1453SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001454{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001455 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001456 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1457 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001458}
Caroline Tice98f930f2010-09-20 05:20:02 +00001459
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001460
Caroline Tice98f930f2010-09-20 05:20:02 +00001461bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001462SBValue::GetExpressionPath (SBStream &description)
1463{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001464 lldb::ValueObjectSP value_sp(GetSP());
1465 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001466 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001467 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001468 return true;
1469 }
1470 return false;
1471}
1472
1473bool
1474SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1475{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001476 lldb::ValueObjectSP value_sp(GetSP());
1477 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001478 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001479 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001480 return true;
1481 }
1482 return false;
1483}
1484
1485bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001486SBValue::GetDescription (SBStream &description)
1487{
Greg Clayton96154be2011-11-13 06:57:31 +00001488 Stream &strm = description.ref();
1489
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001490 lldb::ValueObjectSP value_sp(GetSP());
1491 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001492 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001493 ProcessSP process_sp(value_sp->GetProcessSP());
1494 Process::StopLocker stop_locker;
1495 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1496 {
1497 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1498 if (log)
1499 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1500 }
1501 else
1502 {
1503 ValueObject::DumpValueObject (strm, value_sp.get());
1504 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001505 }
1506 else
Greg Clayton96154be2011-11-13 06:57:31 +00001507 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001508
1509 return true;
1510}
Greg Claytone179a582011-01-05 18:43:15 +00001511
1512lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001513SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001514{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001515 lldb::ValueObjectSP value_sp(GetSP());
1516 if (value_sp)
1517 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001518 return eFormatDefault;
1519}
1520
1521void
1522SBValue::SetFormat (lldb::Format format)
1523{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001524 lldb::ValueObjectSP value_sp(GetSP());
1525 if (value_sp)
1526 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001527}
1528
Enrico Granata979e20d2011-07-29 19:53:35 +00001529lldb::SBValue
1530SBValue::AddressOf()
1531{
1532 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001533 lldb::ValueObjectSP value_sp(GetSP());
1534 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001535 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001536 TargetSP target_sp (value_sp->GetTargetSP());
1537 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001538 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001539 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001540 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001541 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001542 }
1543 }
1544 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1545 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +00001546 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001547
1548 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001549}
Enrico Granata91544802011-09-06 19:20:51 +00001550
1551lldb::addr_t
1552SBValue::GetLoadAddress()
1553{
1554 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001555 lldb::ValueObjectSP value_sp(GetSP());
1556 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001557 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001558 TargetSP target_sp (value_sp->GetTargetSP());
1559 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001560 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001561 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001562 const bool scalar_is_load_address = true;
1563 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001564 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001565 if (addr_type == eAddressTypeFile)
1566 {
Greg Clayton3508c382012-02-24 01:59:29 +00001567 ModuleSP module_sp (value_sp->GetModule());
1568 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001569 value = LLDB_INVALID_ADDRESS;
1570 else
1571 {
1572 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001573 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001574 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001575 }
1576 }
1577 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1578 value = LLDB_INVALID_ADDRESS;
1579 }
1580 }
1581 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1582 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001583 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001584
1585 return value;
1586}
1587
1588lldb::SBAddress
1589SBValue::GetAddress()
1590{
1591 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001592 lldb::ValueObjectSP value_sp(GetSP());
1593 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001594 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001595 TargetSP target_sp (value_sp->GetTargetSP());
1596 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001597 {
1598 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001599 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001600 const bool scalar_is_load_address = true;
1601 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001602 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001603 if (addr_type == eAddressTypeFile)
1604 {
Greg Clayton3508c382012-02-24 01:59:29 +00001605 ModuleSP module_sp (value_sp->GetModule());
1606 if (module_sp)
1607 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001608 }
1609 else if (addr_type == eAddressTypeLoad)
1610 {
1611 // no need to check the return value on this.. if it can actually do the resolve
1612 // addr will be in the form (section,offset), otherwise it will simply be returned
1613 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001614 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001615 }
1616 }
1617 }
1618 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1619 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001620 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", value_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
Enrico Granata91544802011-09-06 19:20:51 +00001621 return SBAddress(new Address(addr));
1622}
1623
1624lldb::SBData
1625SBValue::GetPointeeData (uint32_t item_idx,
1626 uint32_t item_count)
1627{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001628 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001629 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001630 lldb::ValueObjectSP value_sp(GetSP());
1631 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001632 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001633 ProcessSP process_sp(value_sp->GetProcessSP());
1634 Process::StopLocker stop_locker;
1635 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001636 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001637 if (log)
1638 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1639 }
1640 else
1641 {
1642 TargetSP target_sp (value_sp->GetTargetSP());
1643 if (target_sp)
1644 {
1645 DataExtractorSP data_sp(new DataExtractor());
1646 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1647 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1648 if (data_sp->GetByteSize() > 0)
1649 *sb_data = data_sp;
1650 }
Enrico Granata91544802011-09-06 19:20:51 +00001651 }
1652 }
Enrico Granata91544802011-09-06 19:20:51 +00001653 if (log)
1654 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001655 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001656 item_idx,
1657 item_count,
1658 sb_data.get());
1659
1660 return sb_data;
1661}
1662
1663lldb::SBData
1664SBValue::GetData ()
1665{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001666 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001667 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001668 lldb::ValueObjectSP value_sp(GetSP());
1669 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001670 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001671 ProcessSP process_sp(value_sp->GetProcessSP());
1672 Process::StopLocker stop_locker;
1673 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001674 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001675 if (log)
1676 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1677 }
1678 else
1679 {
1680 TargetSP target_sp (value_sp->GetTargetSP());
1681 if (target_sp)
1682 {
1683 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1684 DataExtractorSP data_sp(new DataExtractor());
1685 value_sp->GetData(*data_sp);
1686 if (data_sp->GetByteSize() > 0)
1687 *sb_data = data_sp;
1688 }
Enrico Granata91544802011-09-06 19:20:51 +00001689 }
1690 }
Enrico Granata91544802011-09-06 19:20:51 +00001691 if (log)
1692 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001693 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001694 sb_data.get());
1695
1696 return sb_data;
1697}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001698
1699lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001700SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001701{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001702 SBWatchpoint sb_watchpoint;
1703
1704 // If the SBValue is not valid, there's no point in even trying to watch it.
1705 lldb::ValueObjectSP value_sp(GetSP());
1706 TargetSP target_sp (GetTarget().GetSP());
1707 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001708 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001709 // Can't watch this if the process is running
1710 ProcessSP process_sp(value_sp->GetProcessSP());
1711 Process::StopLocker stop_locker;
1712 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1713 {
1714 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1715 if (log)
1716 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1717 return sb_watchpoint;
1718 }
1719
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001720 // Read and Write cannot both be false.
1721 if (!read && !write)
1722 return sb_watchpoint;
1723
1724 // If the value is not in scope, don't try and watch and invalid value
1725 if (!IsInScope())
1726 return sb_watchpoint;
1727
1728 addr_t addr = GetLoadAddress();
1729 if (addr == LLDB_INVALID_ADDRESS)
1730 return sb_watchpoint;
1731 size_t byte_size = GetByteSize();
1732 if (byte_size == 0)
1733 return sb_watchpoint;
1734
1735 uint32_t watch_type = 0;
1736 if (read)
1737 watch_type |= LLDB_WATCH_TYPE_READ;
1738 if (write)
1739 watch_type |= LLDB_WATCH_TYPE_WRITE;
1740
Johnny Chen3f883492012-06-04 23:19:54 +00001741 Error rc;
1742 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type, rc);
1743 error.SetError(rc);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001744
1745 if (watchpoint_sp)
1746 {
1747 sb_watchpoint.SetSP (watchpoint_sp);
1748 Declaration decl;
1749 if (value_sp->GetDeclaration (decl))
1750 {
1751 if (decl.GetFile())
1752 {
1753 StreamString ss;
1754 // True to show fullpath for declaration file.
1755 decl.DumpStopContext(&ss, true);
1756 watchpoint_sp->SetDeclInfo(ss.GetString());
1757 }
1758 }
1759 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001760 }
1761 return sb_watchpoint;
1762}
1763
Johnny Chen8a5ce772012-06-04 23:45:50 +00001764// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1765// Backward compatibility fix in the interim.
1766lldb::SBWatchpoint
1767SBValue::Watch (bool resolve_location, bool read, bool write)
1768{
Johnny Chen9c4a3442012-06-05 00:14:15 +00001769 SBError error;
1770 return Watch(resolve_location, read, write, error);
Johnny Chen8a5ce772012-06-04 23:45:50 +00001771}
1772
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001773lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001774SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001775{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001776 SBWatchpoint sb_watchpoint;
1777 if (IsInScope() && GetType().IsPointerType())
Johnny Chen3f883492012-06-04 23:19:54 +00001778 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001779 return sb_watchpoint;
1780}
1781