blob: 46f5e07ebdc92cea25a6ee0a4f5cb468333416eb [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 {
Enrico Granatad27026e2012-09-05 20:41:26 +0000735 Target::EvaluateExpressionOptions options;
736 options.SetKeepInMemory(true);
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000737 target->EvaluateExpression (expression,
738 exe_ctx.GetFramePtr(),
Enrico Granatad27026e2012-09-05 20:41:26 +0000739 new_value_sp,
740 options);
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000741 if (new_value_sp)
742 {
743 new_value_sp->SetName(ConstString(name));
744 sb_value.SetSP(new_value_sp);
745 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000746 }
Johnny Chen9fd2e382011-12-20 01:52:44 +0000747 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000748 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000749 if (log)
750 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000751 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000752 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000753 value_sp.get(),
754 name,
755 expression,
756 new_value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000757 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000758 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000759 value_sp.get(),
760 name,
761 expression);
Enrico Granata979e20d2011-07-29 19:53:35 +0000762 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000763 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000764}
765
766lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000767SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000768{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000769 lldb::SBValue sb_value;
770 lldb::ValueObjectSP value_sp(GetSP());
771 lldb::ValueObjectSP new_value_sp;
772 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
773 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000774 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000775 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
776 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
777 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000778 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000779
780 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
781
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000782 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
783 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000784 pointee_type_impl_sp->GetASTContext(),
785 pointee_type_impl_sp->GetOpaqueQualType(),
786 ConstString(name),
787 buffer,
788 lldb::endian::InlHostByteOrder(),
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000789 exe_ctx.GetAddressByteSize()));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000790
791 if (ptr_result_valobj_sp)
792 {
793 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
794 Error err;
795 new_value_sp = ptr_result_valobj_sp->Dereference(err);
796 if (new_value_sp)
797 new_value_sp->SetName(ConstString(name));
798 }
799 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000800 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000801 }
802 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
803 if (log)
804 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000805 if (new_value_sp)
806 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000807 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000808 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000809 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000810 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000811}
812
Enrico Granata91544802011-09-06 19:20:51 +0000813lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000814SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000815{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000816 lldb::SBValue sb_value;
817 lldb::ValueObjectSP new_value_sp;
818 lldb::ValueObjectSP value_sp(GetSP());
819 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000820 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000821 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
822
823 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000824 type.m_opaque_sp->GetASTContext() ,
825 type.m_opaque_sp->GetOpaqueQualType(),
826 ConstString(name),
827 *data.m_opaque_sp,
828 LLDB_INVALID_ADDRESS);
829 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
830 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000831 }
832 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
833 if (log)
834 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000835 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000836 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000837 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000838 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000839 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000840 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000841}
842
Chris Lattner24943d22010-06-08 16:52:24 +0000843SBValue
844SBValue::GetChildAtIndex (uint32_t idx)
845{
Greg Clayton8f64c472011-07-15 19:31:49 +0000846 const bool can_create_synthetic = false;
847 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000848 lldb::ValueObjectSP value_sp(GetSP());
849 if (value_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000850 {
851 TargetSP target_sp(value_sp->GetTargetSP());
852 if (target_sp)
853 use_dynamic = target_sp->GetPreferDynamicValue();
854 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000855 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000856}
857
858SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000859SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000860{
Chris Lattner24943d22010-06-08 16:52:24 +0000861 lldb::ValueObjectSP child_sp;
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000862 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000863
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000864 lldb::ValueObjectSP value_sp(GetSP());
865 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000866 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000867 ProcessSP process_sp(value_sp->GetProcessSP());
868 Process::StopLocker stop_locker;
869 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000870 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000871 if (log)
872 log->Printf ("SBValue(%p)::GetChildAtIndex() => error: process is running", value_sp.get());
873 }
874 else
875 {
876 TargetSP target_sp(value_sp->GetTargetSP());
877 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000878 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000879 Mutex::Locker api_locker (target_sp->GetAPIMutex());
880 const bool can_create = true;
881 child_sp = value_sp->GetChildAtIndex (idx, can_create);
882 if (can_create_synthetic && !child_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000883 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000884 if (value_sp->IsPointerType())
885 {
886 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
887 }
888 else if (value_sp->IsArrayType())
889 {
890 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
891 }
Greg Clayton8f64c472011-07-15 19:31:49 +0000892 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000893
894 if (child_sp)
Greg Clayton8f64c472011-07-15 19:31:49 +0000895 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000896 if (use_dynamic != lldb::eNoDynamicValues)
897 {
898 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
899 if (dynamic_sp)
900 child_sp = dynamic_sp;
901 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000902 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000903 }
Jim Inghame41494a2011-04-16 00:01:13 +0000904 }
905 }
906
Chris Lattner24943d22010-06-08 16:52:24 +0000907 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000908 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000909 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000910
Chris Lattner24943d22010-06-08 16:52:24 +0000911 return sb_value;
912}
913
914uint32_t
915SBValue::GetIndexOfChildWithName (const char *name)
916{
Greg Clayton49ce6822010-10-31 03:01:06 +0000917 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000918 lldb::ValueObjectSP value_sp(GetSP());
919 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000920 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000921 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000922 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000923 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000924 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000925
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000926 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000927 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000928 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000929 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000930 if (log)
931 {
932 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000933 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000934 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000935 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000936 }
937 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000938}
939
940SBValue
941SBValue::GetChildMemberWithName (const char *name)
942{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000943 lldb::ValueObjectSP value_sp(GetSP());
944 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000945 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000946 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000947 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000948 if (target_sp)
949 {
950 Mutex::Locker api_locker (target_sp->GetAPIMutex());
951 use_dynamic_value = target_sp->GetPreferDynamicValue();
952 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000953 return GetChildMemberWithName (name, use_dynamic_value);
954 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000955 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000956}
957
958SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000959SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000960{
Chris Lattner24943d22010-06-08 16:52:24 +0000961 lldb::ValueObjectSP child_sp;
962 const ConstString str_name (name);
963
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000964 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton905acaf2011-05-20 22:07:17 +0000965
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000966 lldb::ValueObjectSP value_sp(GetSP());
967 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000968 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000969 ProcessSP process_sp(value_sp->GetProcessSP());
970 Process::StopLocker stop_locker;
971 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Inghame41494a2011-04-16 00:01:13 +0000972 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000973 if (log)
974 log->Printf ("SBValue(%p)::GetChildMemberWithName() => error: process is running", value_sp.get());
975 }
976 else
977 {
978 TargetSP target_sp(value_sp->GetTargetSP());
979 if (target_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000980 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000981 Mutex::Locker api_locker (target_sp->GetAPIMutex());
982 child_sp = value_sp->GetChildMemberWithName (str_name, true);
983 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000984 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000985 if (child_sp)
986 {
987 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
988 if (dynamic_sp)
989 child_sp = dynamic_sp;
990 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000991 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000992 }
Jim Inghame41494a2011-04-16 00:01:13 +0000993 }
994 }
995
Chris Lattner24943d22010-06-08 16:52:24 +0000996 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000997
Greg Clayton49ce6822010-10-31 03:01:06 +0000998 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000999 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001000
Chris Lattner24943d22010-06-08 16:52:24 +00001001 return sb_value;
1002}
1003
Enrico Granataf7a9b142011-07-15 02:26:42 +00001004lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +00001005SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1006{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001007 lldb::ValueObjectSP value_sp(GetSP());
1008 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001009 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001010 ProcessSP process_sp(value_sp->GetProcessSP());
1011 Process::StopLocker stop_locker;
1012 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Jim Ingham1b425752011-12-08 19:44:08 +00001013 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001014 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1015 if (log)
1016 log->Printf ("SBValue(%p)::GetDynamicValue() => error: process is running", value_sp.get());
1017 }
1018 else
1019 {
1020 TargetSP target_sp(value_sp->GetTargetSP());
1021 if (target_sp)
1022 {
1023 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1024 return SBValue (value_sp->GetDynamicValue(use_dynamic));
1025 }
Jim Ingham1b425752011-12-08 19:44:08 +00001026 }
1027 }
1028
1029 return SBValue();
1030}
1031
1032lldb::SBValue
1033SBValue::GetStaticValue ()
1034{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001035 lldb::ValueObjectSP value_sp(GetSP());
1036 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001037 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001038 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001039 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001040 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001041 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001042 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +00001043 }
1044 }
1045
1046 return SBValue();
1047}
1048
Enrico Granatadba1de82012-03-27 02:35:13 +00001049lldb::SBValue
1050SBValue::GetNonSyntheticValue ()
1051{
1052 SBValue sb_value;
1053 lldb::ValueObjectSP value_sp(GetSP());
1054 if (value_sp)
1055 {
1056 if (value_sp->IsSynthetic())
1057 {
1058 TargetSP target_sp(value_sp->GetTargetSP());
1059 if (target_sp)
1060 {
1061 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1062 // deliberately breaking the rules here to optimize the case where we DO NOT want
1063 // the synthetic value to be returned to the user - if we did not do this, we would have to tell
1064 // the target to suppress the synthetic value, and then return the flag to its original value
Enrico Granata4758a3c2012-05-08 18:47:08 +00001065 if (value_sp->GetNonSyntheticValue())
1066 sb_value.m_opaque_sp = value_sp->GetNonSyntheticValue();
Enrico Granatadba1de82012-03-27 02:35:13 +00001067 }
1068 }
1069 }
1070 return sb_value;
1071}
1072
Jim Ingham1b425752011-12-08 19:44:08 +00001073bool
1074SBValue::IsDynamic()
1075{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001076 lldb::ValueObjectSP value_sp(GetSP());
1077 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001078 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001079 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001080 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +00001081 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001082 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001083 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +00001084 }
1085 }
1086 return false;
1087}
1088
1089lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +00001090SBValue::GetValueForExpressionPath(const char* expr_path)
1091{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001092 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf7a9b142011-07-15 02:26:42 +00001093 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001094 lldb::ValueObjectSP value_sp(GetSP());
1095 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +00001096 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001097 ProcessSP process_sp(value_sp->GetProcessSP());
1098 Process::StopLocker stop_locker;
1099 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granataf7a9b142011-07-15 02:26:42 +00001100 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001101 if (log)
1102 log->Printf ("SBValue(%p)::GetValueForExpressionPath() => error: process is running", value_sp.get());
1103 }
1104 else
1105 {
1106 TargetSP target_sp(value_sp->GetTargetSP());
1107 if (target_sp)
1108 {
1109 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1110 // using default values for all the fancy options, just do it if you can
1111 child_sp = value_sp->GetValueForExpressionPath(expr_path);
1112 }
Enrico Granataf7a9b142011-07-15 02:26:42 +00001113 }
1114 }
1115
1116 SBValue sb_value (child_sp);
1117
Enrico Granataf7a9b142011-07-15 02:26:42 +00001118 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001119 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 +00001120
1121 return sb_value;
1122}
Chris Lattner24943d22010-06-08 16:52:24 +00001123
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001124int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +00001125SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1126{
Jim Ingham574c3d62011-08-12 23:34:31 +00001127 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001128 lldb::ValueObjectSP value_sp(GetSP());
1129 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001130 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001131 ProcessSP process_sp(value_sp->GetProcessSP());
1132 Process::StopLocker stop_locker;
1133 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001134 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001135 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1136 if (log)
1137 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1138 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001139 }
1140 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001141 {
1142 TargetSP target_sp(value_sp->GetTargetSP());
1143 if (target_sp)
1144 {
1145 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1146 Scalar scalar;
1147 if (value_sp->ResolveValue (scalar))
1148 return scalar.GetRawBits64(fail_value);
1149 else
1150 error.SetErrorString("could not get value");
1151 }
1152 else
1153 error.SetErrorString("could not get target");
1154 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001155 }
1156 error.SetErrorString("invalid SBValue");
1157 return fail_value;
1158}
1159
1160uint64_t
1161SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1162{
Jim Ingham574c3d62011-08-12 23:34:31 +00001163 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001164 lldb::ValueObjectSP value_sp(GetSP());
1165 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +00001166 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001167 ProcessSP process_sp(value_sp->GetProcessSP());
1168 Process::StopLocker stop_locker;
1169 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatac92eb402011-08-04 01:41:02 +00001170 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001171 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1172 if (log)
1173 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1174 error.SetErrorString("process is running");
Enrico Granatac92eb402011-08-04 01:41:02 +00001175 }
1176 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001177 {
1178 TargetSP target_sp(value_sp->GetTargetSP());
1179 if (target_sp)
1180 {
1181 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1182 Scalar scalar;
1183 if (value_sp->ResolveValue (scalar))
1184 return scalar.GetRawBits64(fail_value);
1185 else
1186 error.SetErrorString("could not get value");
1187 }
1188 else
1189 error.SetErrorString("could not get target");
1190 }
Enrico Granatac92eb402011-08-04 01:41:02 +00001191 }
1192 error.SetErrorString("invalid SBValue");
1193 return fail_value;
1194}
1195
1196int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001197SBValue::GetValueAsSigned(int64_t fail_value)
1198{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001199 lldb::ValueObjectSP value_sp(GetSP());
1200 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001201 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001202 ProcessSP process_sp(value_sp->GetProcessSP());
1203 Process::StopLocker stop_locker;
1204 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001205 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001206 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1207 if (log)
1208 log->Printf ("SBValue(%p)::GetValueAsSigned() => error: process is running", value_sp.get());
1209 }
1210 else
1211 {
1212 TargetSP target_sp(value_sp->GetTargetSP());
1213 if (target_sp)
1214 {
1215 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1216 Scalar scalar;
1217 if (value_sp->ResolveValue (scalar))
1218 return scalar.GetRawBits64(fail_value);
1219 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001220 }
1221 }
1222 return fail_value;
1223}
1224
1225uint64_t
1226SBValue::GetValueAsUnsigned(uint64_t fail_value)
1227{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001228 lldb::ValueObjectSP value_sp(GetSP());
1229 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001230 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001231 ProcessSP process_sp(value_sp->GetProcessSP());
1232 Process::StopLocker stop_locker;
1233 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001234 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001235 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1236 if (log)
1237 log->Printf ("SBValue(%p)::GetValueAsUnsigned() => error: process is running", value_sp.get());
1238 }
1239 else
1240 {
1241 TargetSP target_sp(value_sp->GetTargetSP());
1242 if (target_sp)
1243 {
1244 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1245 Scalar scalar;
1246 if (value_sp->ResolveValue (scalar))
1247 return scalar.GetRawBits64(fail_value);
1248 }
Greg Clayton0fb0bcc2011-08-03 22:57:10 +00001249 }
1250 }
1251 return fail_value;
1252}
1253
Chris Lattner24943d22010-06-08 16:52:24 +00001254uint32_t
1255SBValue::GetNumChildren ()
1256{
1257 uint32_t num_children = 0;
1258
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001259 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001260 lldb::ValueObjectSP value_sp(GetSP());
1261 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001262 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001263 ProcessSP process_sp(value_sp->GetProcessSP());
1264 Process::StopLocker stop_locker;
1265 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +00001266 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001267 if (log)
1268 log->Printf ("SBValue(%p)::GetNumChildren() => error: process is running", value_sp.get());
1269 }
1270 else
1271 {
1272 TargetSP target_sp(value_sp->GetTargetSP());
1273 if (target_sp)
1274 {
1275 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001276
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001277 num_children = value_sp->GetNumChildren();
1278 }
Greg Claytonb9dcc512011-06-29 18:28:50 +00001279 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001280 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001281
Greg Clayton49ce6822010-10-31 03:01:06 +00001282 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001283 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +00001284
1285 return num_children;
1286}
1287
Chris Lattner24943d22010-06-08 16:52:24 +00001288
1289SBValue
1290SBValue::Dereference ()
1291{
Greg Clayton49ce6822010-10-31 03:01:06 +00001292 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001293 lldb::ValueObjectSP value_sp(GetSP());
1294 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001295 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001296 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001297 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001298 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001299 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001300
Greg Claytonb9dcc512011-06-29 18:28:50 +00001301 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001302 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +00001303 }
Chris Lattner24943d22010-06-08 16:52:24 +00001304 }
Greg Claytone005f2c2010-11-06 01:53:30 +00001305 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001306 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001307 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +00001308
1309 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +00001310}
1311
1312bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001313SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +00001314{
1315 bool is_ptr_type = false;
1316
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001317 lldb::ValueObjectSP value_sp(GetSP());
1318 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001319 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001320 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001321 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001322 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001323 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001324
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001325 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001326 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001327 }
Greg Clayton49ce6822010-10-31 03:01:06 +00001328
Greg Claytone005f2c2010-11-06 01:53:30 +00001329 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +00001330 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001331 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +00001332
Chris Lattner24943d22010-06-08 16:52:24 +00001333
1334 return is_ptr_type;
1335}
1336
Chris Lattner24943d22010-06-08 16:52:24 +00001337void *
1338SBValue::GetOpaqueType()
1339{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001340 lldb::ValueObjectSP value_sp(GetSP());
1341 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +00001342 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001343 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001344 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +00001345 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001346 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +00001347
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001348 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +00001349 }
Greg Claytonfab305b2011-05-20 23:51:26 +00001350 }
Chris Lattner24943d22010-06-08 16:52:24 +00001351 return NULL;
1352}
1353
Enrico Granata979e20d2011-07-29 19:53:35 +00001354lldb::SBTarget
1355SBValue::GetTarget()
1356{
Greg Clayton334d33a2012-01-30 07:41:31 +00001357 SBTarget sb_target;
1358 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001359 lldb::ValueObjectSP value_sp(GetSP());
1360 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001361 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001362 target_sp = value_sp->GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001363 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001364 }
1365 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1366 if (log)
1367 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001368 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001369 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001370 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001371 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001372 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001373 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +00001374}
1375
1376lldb::SBProcess
1377SBValue::GetProcess()
1378{
Greg Clayton334d33a2012-01-30 07:41:31 +00001379 SBProcess sb_process;
1380 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001381 lldb::ValueObjectSP value_sp(GetSP());
1382 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001383 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001384 process_sp = value_sp->GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +00001385 if (process_sp)
1386 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001387 }
1388 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1389 if (log)
1390 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001391 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001392 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001393 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001394 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001395 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001396 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +00001397}
1398
1399lldb::SBThread
1400SBValue::GetThread()
1401{
Greg Clayton90c52142012-01-30 02:53:15 +00001402 SBThread sb_thread;
1403 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001404 lldb::ValueObjectSP value_sp(GetSP());
1405 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001406 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001407 thread_sp = value_sp->GetThreadSP();
1408 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001409 }
1410 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1411 if (log)
1412 {
Greg Clayton90c52142012-01-30 02:53:15 +00001413 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001414 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001415 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001416 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001417 }
Greg Clayton90c52142012-01-30 02:53:15 +00001418 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +00001419}
1420
1421lldb::SBFrame
1422SBValue::GetFrame()
1423{
Greg Clayton334d33a2012-01-30 07:41:31 +00001424 SBFrame sb_frame;
1425 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001426 lldb::ValueObjectSP value_sp(GetSP());
1427 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001428 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001429 frame_sp = value_sp->GetFrameSP();
1430 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +00001431 }
1432 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1433 if (log)
1434 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001435 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001436 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001437 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001438 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001439 }
Greg Clayton334d33a2012-01-30 07:41:31 +00001440 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +00001441}
1442
1443
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001444lldb::ValueObjectSP
1445SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001446{
Greg Clayton63094e02010-06-23 01:19:29 +00001447 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001448}
1449
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001450void
1451SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001452{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001453 m_opaque_sp = sp;
Enrico Granatadba1de82012-03-27 02:35:13 +00001454 if (IsValid() && m_opaque_sp->HasSyntheticValue())
1455 m_opaque_sp = m_opaque_sp->GetSyntheticValue();
Chris Lattner24943d22010-06-08 16:52:24 +00001456}
Caroline Tice98f930f2010-09-20 05:20:02 +00001457
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001458
Caroline Tice98f930f2010-09-20 05:20:02 +00001459bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001460SBValue::GetExpressionPath (SBStream &description)
1461{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001462 lldb::ValueObjectSP value_sp(GetSP());
1463 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001464 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001465 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001466 return true;
1467 }
1468 return false;
1469}
1470
1471bool
1472SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1473{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001474 lldb::ValueObjectSP value_sp(GetSP());
1475 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001476 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001477 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001478 return true;
1479 }
1480 return false;
1481}
1482
1483bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001484SBValue::GetDescription (SBStream &description)
1485{
Greg Clayton96154be2011-11-13 06:57:31 +00001486 Stream &strm = description.ref();
1487
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001488 lldb::ValueObjectSP value_sp(GetSP());
1489 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001490 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001491 ProcessSP process_sp(value_sp->GetProcessSP());
1492 Process::StopLocker stop_locker;
1493 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1494 {
1495 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1496 if (log)
1497 log->Printf ("SBValue(%p)::GetDescription() => error: process is running", value_sp.get());
1498 }
1499 else
1500 {
1501 ValueObject::DumpValueObject (strm, value_sp.get());
1502 }
Caroline Tice98f930f2010-09-20 05:20:02 +00001503 }
1504 else
Greg Clayton96154be2011-11-13 06:57:31 +00001505 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001506
1507 return true;
1508}
Greg Claytone179a582011-01-05 18:43:15 +00001509
1510lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001511SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001512{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001513 lldb::ValueObjectSP value_sp(GetSP());
1514 if (value_sp)
1515 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001516 return eFormatDefault;
1517}
1518
1519void
1520SBValue::SetFormat (lldb::Format format)
1521{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001522 lldb::ValueObjectSP value_sp(GetSP());
1523 if (value_sp)
1524 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001525}
1526
Enrico Granata979e20d2011-07-29 19:53:35 +00001527lldb::SBValue
1528SBValue::AddressOf()
1529{
1530 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001531 lldb::ValueObjectSP value_sp(GetSP());
1532 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001533 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001534 TargetSP target_sp (value_sp->GetTargetSP());
1535 if (target_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001536 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001537 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001538 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001539 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001540 }
1541 }
1542 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1543 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +00001544 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001545
1546 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001547}
Enrico Granata91544802011-09-06 19:20:51 +00001548
1549lldb::addr_t
1550SBValue::GetLoadAddress()
1551{
1552 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001553 lldb::ValueObjectSP value_sp(GetSP());
1554 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001555 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001556 TargetSP target_sp (value_sp->GetTargetSP());
1557 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001558 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001559 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001560 const bool scalar_is_load_address = true;
1561 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001562 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001563 if (addr_type == eAddressTypeFile)
1564 {
Greg Clayton3508c382012-02-24 01:59:29 +00001565 ModuleSP module_sp (value_sp->GetModule());
1566 if (!module_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001567 value = LLDB_INVALID_ADDRESS;
1568 else
1569 {
1570 Address addr;
Greg Clayton3508c382012-02-24 01:59:29 +00001571 module_sp->ResolveFileAddress(value, addr);
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001572 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001573 }
1574 }
1575 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1576 value = LLDB_INVALID_ADDRESS;
1577 }
1578 }
1579 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1580 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001581 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001582
1583 return value;
1584}
1585
1586lldb::SBAddress
1587SBValue::GetAddress()
1588{
1589 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001590 lldb::ValueObjectSP value_sp(GetSP());
1591 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001592 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001593 TargetSP target_sp (value_sp->GetTargetSP());
1594 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001595 {
1596 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001597 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001598 const bool scalar_is_load_address = true;
1599 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001600 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001601 if (addr_type == eAddressTypeFile)
1602 {
Greg Clayton3508c382012-02-24 01:59:29 +00001603 ModuleSP module_sp (value_sp->GetModule());
1604 if (module_sp)
1605 module_sp->ResolveFileAddress(value, addr);
Enrico Granata91544802011-09-06 19:20:51 +00001606 }
1607 else if (addr_type == eAddressTypeLoad)
1608 {
1609 // no need to check the return value on this.. if it can actually do the resolve
1610 // addr will be in the form (section,offset), otherwise it will simply be returned
1611 // as (NULL, value)
Greg Claytonb4d7fc02012-02-17 07:49:44 +00001612 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +00001613 }
1614 }
1615 }
1616 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1617 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001618 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 +00001619 return SBAddress(new Address(addr));
1620}
1621
1622lldb::SBData
1623SBValue::GetPointeeData (uint32_t item_idx,
1624 uint32_t item_count)
1625{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001626 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001627 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001628 lldb::ValueObjectSP value_sp(GetSP());
1629 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001630 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001631 ProcessSP process_sp(value_sp->GetProcessSP());
1632 Process::StopLocker stop_locker;
1633 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001634 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001635 if (log)
1636 log->Printf ("SBValue(%p)::GetPointeeData() => error: process is running", value_sp.get());
1637 }
1638 else
1639 {
1640 TargetSP target_sp (value_sp->GetTargetSP());
1641 if (target_sp)
1642 {
1643 DataExtractorSP data_sp(new DataExtractor());
1644 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1645 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1646 if (data_sp->GetByteSize() > 0)
1647 *sb_data = data_sp;
1648 }
Enrico Granata91544802011-09-06 19:20:51 +00001649 }
1650 }
Enrico Granata91544802011-09-06 19:20:51 +00001651 if (log)
1652 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001653 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001654 item_idx,
1655 item_count,
1656 sb_data.get());
1657
1658 return sb_data;
1659}
1660
1661lldb::SBData
1662SBValue::GetData ()
1663{
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001664 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata91544802011-09-06 19:20:51 +00001665 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001666 lldb::ValueObjectSP value_sp(GetSP());
1667 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001668 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001669 ProcessSP process_sp(value_sp->GetProcessSP());
1670 Process::StopLocker stop_locker;
1671 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata91544802011-09-06 19:20:51 +00001672 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001673 if (log)
1674 log->Printf ("SBValue(%p)::GetData() => error: process is running", value_sp.get());
1675 }
1676 else
1677 {
1678 TargetSP target_sp (value_sp->GetTargetSP());
1679 if (target_sp)
1680 {
1681 Mutex::Locker api_locker (target_sp->GetAPIMutex());
1682 DataExtractorSP data_sp(new DataExtractor());
1683 value_sp->GetData(*data_sp);
1684 if (data_sp->GetByteSize() > 0)
1685 *sb_data = data_sp;
1686 }
Enrico Granata91544802011-09-06 19:20:51 +00001687 }
1688 }
Enrico Granata91544802011-09-06 19:20:51 +00001689 if (log)
1690 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001691 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001692 sb_data.get());
1693
1694 return sb_data;
1695}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001696
1697lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001698SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001699{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001700 SBWatchpoint sb_watchpoint;
1701
1702 // If the SBValue is not valid, there's no point in even trying to watch it.
1703 lldb::ValueObjectSP value_sp(GetSP());
1704 TargetSP target_sp (GetTarget().GetSP());
1705 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001706 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001707 // Can't watch this if the process is running
1708 ProcessSP process_sp(value_sp->GetProcessSP());
1709 Process::StopLocker stop_locker;
1710 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1711 {
1712 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1713 if (log)
1714 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1715 return sb_watchpoint;
1716 }
1717
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001718 // Read and Write cannot both be false.
1719 if (!read && !write)
1720 return sb_watchpoint;
1721
1722 // If the value is not in scope, don't try and watch and invalid value
1723 if (!IsInScope())
1724 return sb_watchpoint;
1725
1726 addr_t addr = GetLoadAddress();
1727 if (addr == LLDB_INVALID_ADDRESS)
1728 return sb_watchpoint;
1729 size_t byte_size = GetByteSize();
1730 if (byte_size == 0)
1731 return sb_watchpoint;
1732
1733 uint32_t watch_type = 0;
1734 if (read)
1735 watch_type |= LLDB_WATCH_TYPE_READ;
1736 if (write)
1737 watch_type |= LLDB_WATCH_TYPE_WRITE;
1738
Johnny Chen3f883492012-06-04 23:19:54 +00001739 Error rc;
1740 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type, rc);
1741 error.SetError(rc);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001742
1743 if (watchpoint_sp)
1744 {
1745 sb_watchpoint.SetSP (watchpoint_sp);
1746 Declaration decl;
1747 if (value_sp->GetDeclaration (decl))
1748 {
1749 if (decl.GetFile())
1750 {
1751 StreamString ss;
1752 // True to show fullpath for declaration file.
1753 decl.DumpStopContext(&ss, true);
1754 watchpoint_sp->SetDeclInfo(ss.GetString());
1755 }
1756 }
1757 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001758 }
1759 return sb_watchpoint;
1760}
1761
Johnny Chen8a5ce772012-06-04 23:45:50 +00001762// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1763// Backward compatibility fix in the interim.
1764lldb::SBWatchpoint
1765SBValue::Watch (bool resolve_location, bool read, bool write)
1766{
Johnny Chen9c4a3442012-06-05 00:14:15 +00001767 SBError error;
1768 return Watch(resolve_location, read, write, error);
Johnny Chen8a5ce772012-06-04 23:45:50 +00001769}
1770
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001771lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001772SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001773{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001774 SBWatchpoint sb_watchpoint;
1775 if (IsInScope() && GetType().IsPointerType())
Johnny Chen3f883492012-06-04 23:19:54 +00001776 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001777 return sb_watchpoint;
1778}
1779