blob: 913a447aba547b6346c2f6cf7407a8cc33e436e8 [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
Enrico Granata49306142012-10-10 22:54:17 +000012#include "lldb/API/SBDeclaration.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000014#include "lldb/API/SBTypeFilter.h"
15#include "lldb/API/SBTypeFormat.h"
16#include "lldb/API/SBTypeSummary.h"
17#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
Johnny Chenecd4feb2011-10-14 00:42:25 +000019#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020#include "lldb/Core/DataExtractor.h"
Enrico Granatad760907c2012-02-17 03:18:30 +000021#include "lldb/Core/DataVisualization.h"
Caroline Tice7826c882010-10-26 03:11:13 +000022#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000024#include "lldb/Core/Scalar.h"
Greg Clayton49ce8962012-08-29 21:13:06 +000025#include "lldb/Core/Section.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Core/Stream.h"
27#include "lldb/Core/StreamFile.h"
28#include "lldb/Core/Value.h"
29#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000030#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000031#include "lldb/Symbol/Block.h"
Enrico Granata49306142012-10-10 22:54:17 +000032#include "lldb/Symbol/Declaration.h"
Chris Lattner24943d22010-06-08 16:52:24 +000033#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000034#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000035#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000036#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000037#include "lldb/Target/ExecutionContext.h"
38#include "lldb/Target/Process.h"
39#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000040#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000041#include "lldb/Target/Thread.h"
42
Eli Friedman7a62c8b2010-06-09 07:44:37 +000043#include "lldb/API/SBProcess.h"
44#include "lldb/API/SBTarget.h"
45#include "lldb/API/SBThread.h"
46#include "lldb/API/SBFrame.h"
47#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000048
49using namespace lldb;
50using namespace lldb_private;
51
52SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000053 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000054{
55}
56
Enrico Granatadba1de82012-03-27 02:35:13 +000057SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000058{
Enrico Granatadba1de82012-03-27 02:35:13 +000059 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 +000060}
61
Enrico Granatadba1de82012-03-27 02:35:13 +000062SBValue::SBValue(const SBValue &rhs)
Greg Clayton538eb822010-11-05 23:17:00 +000063{
Enrico Granatadba1de82012-03-27 02:35:13 +000064 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 +000065}
66
Greg Claytond68e0892011-09-09 23:04:00 +000067SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000068SBValue::operator = (const SBValue &rhs)
69{
70 if (this != &rhs)
Enrico Granatadba1de82012-03-27 02:35:13 +000071 {
72 SetSP(rhs.m_opaque_sp); // whenever setting the SP call SetSP() since it knows how to deal with synthetic values properly
73 }
Greg Clayton538eb822010-11-05 23:17:00 +000074 return *this;
75}
76
Chris Lattner24943d22010-06-08 16:52:24 +000077SBValue::~SBValue()
78{
79}
80
81bool
Greg Claytond68e0892011-09-09 23:04:00 +000082SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000083{
Greg Clayton49ce6822010-10-31 03:01:06 +000084 // If this function ever changes to anything that does more than just
85 // check if the opaque shared pointer is non NULL, then we need to update
86 // all "if (m_opaque_sp)" code in this file.
87 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000088}
89
Jim Inghame0bd5712011-12-19 20:39:44 +000090void
91SBValue::Clear()
92{
93 m_opaque_sp.reset();
94}
95
Greg Claytonc5f728c2010-10-06 22:10:17 +000096SBError
97SBValue::GetError()
98{
99 SBError sb_error;
100
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000101 lldb::ValueObjectSP value_sp(GetSP());
102 if (value_sp)
103 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +0000104 else
105 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +0000106
107 return sb_error;
108}
109
Johnny Chen968958c2011-07-07 20:46:23 +0000110user_id_t
111SBValue::GetID()
112{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000113 lldb::ValueObjectSP value_sp(GetSP());
114 if (value_sp)
115 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000116 return LLDB_INVALID_UID;
117}
118
Chris Lattner24943d22010-06-08 16:52:24 +0000119const char *
120SBValue::GetName()
121{
Greg Clayton49ce6822010-10-31 03:01:06 +0000122
123 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000124 lldb::ValueObjectSP value_sp(GetSP());
125 if (value_sp)
126 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000127
Greg Claytone005f2c2010-11-06 01:53:30 +0000128 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000129 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000130 {
131 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000132 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000133 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000134 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000135 }
Caroline Tice7826c882010-10-26 03:11:13 +0000136
Greg Clayton49ce6822010-10-31 03:01:06 +0000137 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000138}
139
140const char *
141SBValue::GetTypeName ()
142{
Jim Ingham684d4012012-08-21 01:46:35 +0000143 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000144 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000145 lldb::ValueObjectSP value_sp(GetSP());
146 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000147 {
148 // For a dynamic type we might have to run code to determine the type we are going to report,
149 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
150
151 ProcessSP process_sp(value_sp->GetProcessSP());
152 Process::StopLocker stop_locker;
153 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
154 {
155 if (log)
156 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
157 }
158 else
159 {
160 TargetSP target_sp(value_sp->GetTargetSP());
161 if (target_sp)
162 {
163 Mutex::Locker api_locker (target_sp->GetAPIMutex());
164 name = value_sp->GetQualifiedTypeName().GetCString();
165 }
166 }
167 }
168
Greg Clayton49ce6822010-10-31 03:01:06 +0000169 if (log)
170 {
171 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000172 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000173 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000174 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000175 }
176
177 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000178}
179
180size_t
181SBValue::GetByteSize ()
182{
Jim Ingham684d4012012-08-21 01:46:35 +0000183 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner24943d22010-06-08 16:52:24 +0000184 size_t result = 0;
185
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000186 lldb::ValueObjectSP value_sp(GetSP());
187 if (value_sp)
Jim Ingham684d4012012-08-21 01:46:35 +0000188 {
189 // For a dynamic type we might have to run code to determine the type we are going to report,
190 // and we might not have updated the type before we get asked this. So make sure to get the API lock.
191
192 ProcessSP process_sp(value_sp->GetProcessSP());
193 Process::StopLocker stop_locker;
194 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
195 {
196 if (log)
197 log->Printf ("SBValue(%p)::GetTypeName() => error: process is running", value_sp.get());
198 }
199 else
200 {
201 TargetSP target_sp(value_sp->GetTargetSP());
202 if (target_sp)
203 {
204 Mutex::Locker api_locker (target_sp->GetAPIMutex());
205 result = value_sp->GetByteSize();
206 }
207 }
208 }
Chris Lattner24943d22010-06-08 16:52:24 +0000209
Greg Clayton49ce6822010-10-31 03:01:06 +0000210 if (log)
Greg Clayton851e30e2012-09-18 18:04:04 +0000211 log->Printf ("SBValue(%p)::GetByteSize () => %llu", value_sp.get(), (uint64_t)result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000212
Chris Lattner24943d22010-06-08 16:52:24 +0000213 return result;
214}
215
216bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000217SBValue::IsInScope ()
218{
Chris Lattner24943d22010-06-08 16:52:24 +0000219 bool result = false;
220
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000221 lldb::ValueObjectSP value_sp(GetSP());
222 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000223 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000224 TargetSP target_sp(value_sp->GetTargetSP());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000225 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000226 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000227 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000228 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000229 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000230 }
Chris Lattner24943d22010-06-08 16:52:24 +0000231
Greg Claytone005f2c2010-11-06 01:53:30 +0000232 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000233 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000234 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000235
Chris Lattner24943d22010-06-08 16:52:24 +0000236 return result;
237}
238
239const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000240SBValue::GetValue ()
241{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000242 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
243
Greg Clayton49ce6822010-10-31 03:01:06 +0000244 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000245 lldb::ValueObjectSP value_sp(GetSP());
246 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000247 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000248 ProcessSP process_sp(value_sp->GetProcessSP());
249 Process::StopLocker stop_locker;
250 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000251 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000252 if (log)
253 log->Printf ("SBValue(%p)::GetValue() => error: process is running", value_sp.get());
254 }
255 else
256 {
257 TargetSP target_sp(value_sp->GetTargetSP());
258 if (target_sp)
259 {
260 Mutex::Locker api_locker (target_sp->GetAPIMutex());
261 cstr = value_sp->GetValueAsCString ();
262 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000263 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000264 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000265 if (log)
266 {
267 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000268 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000269 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000270 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000271 }
272
273 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000274}
275
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000276ValueType
277SBValue::GetValueType ()
278{
Greg Clayton49ce6822010-10-31 03:01:06 +0000279 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000280 lldb::ValueObjectSP value_sp(GetSP());
281 if (value_sp)
282 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000283 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000284 if (log)
285 {
286 switch (result)
287 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000288 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
289 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
290 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
291 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
292 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
293 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
294 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
295 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
296 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000297 }
298 }
299 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000300}
301
Jim Ingham4ae51962010-09-10 23:12:17 +0000302const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000303SBValue::GetObjectDescription ()
304{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000305 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000306 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000307 lldb::ValueObjectSP value_sp(GetSP());
308 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000309 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000310 ProcessSP process_sp(value_sp->GetProcessSP());
311 Process::StopLocker stop_locker;
312 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000313 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000314 if (log)
315 log->Printf ("SBValue(%p)::GetObjectDescription() => error: process is running", value_sp.get());
316 }
317 else
318 {
319 TargetSP target_sp(value_sp->GetTargetSP());
320 if (target_sp)
321 {
322 Mutex::Locker api_locker (target_sp->GetAPIMutex());
323 cstr = value_sp->GetObjectDescription ();
324 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000325 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000326 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000327 if (log)
328 {
329 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000330 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000331 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000332 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000333 }
334 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000335}
336
Enrico Granata979e20d2011-07-29 19:53:35 +0000337SBType
338SBValue::GetType()
339{
Jim Ingham5b4905d2012-04-13 18:30:20 +0000340 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000341 SBType sb_type;
342 lldb::ValueObjectSP value_sp(GetSP());
343 TypeImplSP type_sp;
344 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000345 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000346 ProcessSP process_sp(value_sp->GetProcessSP());
347 Process::StopLocker stop_locker;
348 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
349 {
350 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000351 log->Printf ("SBValue(%p)::GetType() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000352 }
353 else
354 {
355 TargetSP target_sp(value_sp->GetTargetSP());
356 if (target_sp)
357 {
358 Mutex::Locker api_locker (target_sp->GetAPIMutex());
359 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
360 sb_type.SetSP(type_sp);
361 }
362 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000363 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000364 if (log)
365 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000366 if (type_sp)
367 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000368 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000369 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000370 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000371 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000372}
373
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000374bool
375SBValue::GetValueDidChange ()
376{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000377 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000378 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000379 lldb::ValueObjectSP value_sp(GetSP());
380 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000381 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000382 ProcessSP process_sp(value_sp->GetProcessSP());
383 Process::StopLocker stop_locker;
384 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000385 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000386 if (log)
387 log->Printf ("SBValue(%p)::GetValueDidChange() => error: process is running", value_sp.get());
388 }
389 else
390 {
391 TargetSP target_sp(value_sp->GetTargetSP());
392 if (target_sp)
393 {
394 Mutex::Locker api_locker (target_sp->GetAPIMutex());
395 result = value_sp->GetValueDidChange ();
396 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000397 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000398 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000399 if (log)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000400 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000401
402 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000403}
404
Jason Molendac48ca822012-02-21 05:33:55 +0000405#ifndef LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000406const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000407SBValue::GetSummary ()
408{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000409 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000410 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000411 lldb::ValueObjectSP value_sp(GetSP());
412 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000413 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000414 ProcessSP process_sp(value_sp->GetProcessSP());
415 Process::StopLocker stop_locker;
416 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000417 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000418 if (log)
419 log->Printf ("SBValue(%p)::GetSummary() => error: process is running", value_sp.get());
420 }
421 else
422 {
423 TargetSP target_sp(value_sp->GetTargetSP());
424 if (target_sp)
425 {
426 Mutex::Locker api_locker (target_sp->GetAPIMutex());
427 cstr = value_sp->GetSummaryAsCString();
428 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000429 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000430 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000431 if (log)
432 {
433 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000434 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000435 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000436 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000437 }
438 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000439}
Jason Molendac48ca822012-02-21 05:33:55 +0000440#endif // LLDB_DISABLE_PYTHON
Chris Lattner24943d22010-06-08 16:52:24 +0000441
442const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000443SBValue::GetLocation ()
444{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000445 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000446 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000447 lldb::ValueObjectSP value_sp(GetSP());
448 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000449 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000450 ProcessSP process_sp(value_sp->GetProcessSP());
451 Process::StopLocker stop_locker;
452 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000453 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000454 if (log)
455 log->Printf ("SBValue(%p)::GetLocation() => error: process is running", value_sp.get());
456 }
457 else
458 {
459 TargetSP target_sp(value_sp->GetTargetSP());
460 if (target_sp)
461 {
462 Mutex::Locker api_locker (target_sp->GetAPIMutex());
463 cstr = value_sp->GetLocationAsCString();
464 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000465 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000466 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000467 if (log)
468 {
469 if (cstr)
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000470 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000471 else
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000472 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000473 }
474 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000475}
476
Enrico Granata651cbe22012-05-08 21:25:06 +0000477// Deprecated - use the one that takes an lldb::SBError
Chris Lattner24943d22010-06-08 16:52:24 +0000478bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000479SBValue::SetValueFromCString (const char *value_str)
480{
Enrico Granata651cbe22012-05-08 21:25:06 +0000481 lldb::SBError dummy;
482 return SetValueFromCString(value_str,dummy);
483}
484
485bool
486SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
487{
Chris Lattner24943d22010-06-08 16:52:24 +0000488 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000489 lldb::ValueObjectSP value_sp(GetSP());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000490 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000491 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000492 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000493 ProcessSP process_sp(value_sp->GetProcessSP());
494 Process::StopLocker stop_locker;
495 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Greg Claytonb9dcc512011-06-29 18:28:50 +0000496 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000497 if (log)
498 log->Printf ("SBValue(%p)::SetValueFromCString() => error: process is running", value_sp.get());
499 }
500 else
501 {
502 TargetSP target_sp(value_sp->GetTargetSP());
503 if (target_sp)
504 {
505 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata651cbe22012-05-08 21:25:06 +0000506 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000507 }
Greg Claytonb9dcc512011-06-29 18:28:50 +0000508 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000509 }
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000510 if (log)
511 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
512
Chris Lattner24943d22010-06-08 16:52:24 +0000513 return success;
514}
515
Enrico Granatad760907c2012-02-17 03:18:30 +0000516lldb::SBTypeFormat
517SBValue::GetTypeFormat ()
518{
519 lldb::SBTypeFormat format;
520 lldb::ValueObjectSP value_sp(GetSP());
521 if (value_sp)
522 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000523 ProcessSP process_sp(value_sp->GetProcessSP());
524 Process::StopLocker stop_locker;
525 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000526 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000527 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
528 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000529 log->Printf ("SBValue(%p)::GetTypeFormat() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000530 }
531 else
532 {
533 TargetSP target_sp(value_sp->GetTargetSP());
534 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000535 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000536 Mutex::Locker api_locker (target_sp->GetAPIMutex());
537 if (value_sp->UpdateValueIfNeeded(true))
538 {
539 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
540 if (format_sp)
541 format.SetSP(format_sp);
542 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000543 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000544 }
545 }
546 return format;
547}
548
Jason Molendac48ca822012-02-21 05:33:55 +0000549#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000550lldb::SBTypeSummary
551SBValue::GetTypeSummary ()
552{
553 lldb::SBTypeSummary summary;
554 lldb::ValueObjectSP value_sp(GetSP());
555 if (value_sp)
556 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000557 ProcessSP process_sp(value_sp->GetProcessSP());
558 Process::StopLocker stop_locker;
559 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000560 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000561 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
562 if (log)
563 log->Printf ("SBValue(%p)::GetTypeSummary() => error: process is running", value_sp.get());
564 }
565 else
566 {
567 TargetSP target_sp(value_sp->GetTargetSP());
568 if (target_sp)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000569 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000570 Mutex::Locker api_locker (target_sp->GetAPIMutex());
571 if (value_sp->UpdateValueIfNeeded(true))
572 {
573 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
574 if (summary_sp)
575 summary.SetSP(summary_sp);
576 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000577 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000578 }
579 }
580 return summary;
581}
Jason Molendac48ca822012-02-21 05:33:55 +0000582#endif // LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000583
584lldb::SBTypeFilter
585SBValue::GetTypeFilter ()
586{
587 lldb::SBTypeFilter filter;
588 lldb::ValueObjectSP value_sp(GetSP());
589 if (value_sp)
590 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000591 ProcessSP process_sp(value_sp->GetProcessSP());
592 Process::StopLocker stop_locker;
593 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000594 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000595 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
596 if (log)
597 log->Printf ("SBValue(%p)::GetTypeFilter() => error: process is running", value_sp.get());
598 }
599 else
600 {
601 TargetSP target_sp(value_sp->GetTargetSP());
602 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000603 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000604 Mutex::Locker api_locker (target_sp->GetAPIMutex());
605 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000606 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000607 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
608
609 if (synthetic_sp && !synthetic_sp->IsScripted())
610 {
611 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp);
612 filter.SetSP(filter_sp);
613 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000614 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000615 }
616 }
617 }
618 return filter;
619}
620
Jason Molendac48ca822012-02-21 05:33:55 +0000621#ifndef LLDB_DISABLE_PYTHON
Enrico Granatad760907c2012-02-17 03:18:30 +0000622lldb::SBTypeSynthetic
623SBValue::GetTypeSynthetic ()
624{
625 lldb::SBTypeSynthetic synthetic;
626 lldb::ValueObjectSP value_sp(GetSP());
627 if (value_sp)
628 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000629 ProcessSP process_sp(value_sp->GetProcessSP());
630 Process::StopLocker stop_locker;
631 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granatad760907c2012-02-17 03:18:30 +0000632 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000633 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
634 if (log)
635 log->Printf ("SBValue(%p)::GetTypeSynthetic() => error: process is running", value_sp.get());
636 }
637 else
638 {
639 TargetSP target_sp(value_sp->GetTargetSP());
640 if (target_sp)
Enrico Granatad760907c2012-02-17 03:18:30 +0000641 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000642 Mutex::Locker api_locker (target_sp->GetAPIMutex());
643 if (value_sp->UpdateValueIfNeeded(true))
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000644 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000645 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
646
647 if (children_sp && children_sp->IsScripted())
648 {
649 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp);
650 synthetic.SetSP(synth_sp);
651 }
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000652 }
Enrico Granatad760907c2012-02-17 03:18:30 +0000653 }
654 }
655 }
656 return synthetic;
657}
Jason Molendac48ca822012-02-21 05:33:55 +0000658#endif
Enrico Granatad760907c2012-02-17 03:18:30 +0000659
Enrico Granata979e20d2011-07-29 19:53:35 +0000660lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000661SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000662{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000663 lldb::SBValue sb_value;
664 lldb::ValueObjectSP value_sp(GetSP());
665 lldb::ValueObjectSP new_value_sp;
666 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000667 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000668 ProcessSP process_sp(value_sp->GetProcessSP());
669 Process::StopLocker stop_locker;
670 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Enrico Granata979e20d2011-07-29 19:53:35 +0000671 {
Jim Ingham5b4905d2012-04-13 18:30:20 +0000672 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
673 if (log)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000674 log->Printf ("SBValue(%p)::CreateChildAtOffset() => error: process is running", value_sp.get());
Jim Ingham5b4905d2012-04-13 18:30:20 +0000675 }
676 else
677 {
678 TargetSP target_sp(value_sp->GetTargetSP());
679 if (target_sp)
680 {
681 Mutex::Locker api_locker (target_sp->GetAPIMutex());
682 TypeImplSP type_sp (type.GetSP());
683 if (type.IsValid())
684 {
685 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
686 new_value_sp = sb_value.GetSP();
687 if (new_value_sp)
688 new_value_sp->SetName(ConstString(name));
689 }
690 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000691 }
692 }
693 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
694 if (log)
695 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000696 if (new_value_sp)
Greg Clayton12b7ea32012-06-04 20:13:23 +0000697 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000698 else
Greg Clayton12b7ea32012-06-04 20:13:23 +0000699 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000700 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000701 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000702}
703
704lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000705SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000706{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000707 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000708 lldb::ValueObjectSP value_sp(GetSP());
709 TypeImplSP type_sp (type.GetSP());
710 if (value_sp && type_sp)
711 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000712 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000713}
714
715lldb::SBValue
716SBValue::CreateValueFromExpression (const char *name, const char* expression)
717{
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000718 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000719 lldb::SBValue sb_value;
720 lldb::ValueObjectSP value_sp(GetSP());
721 lldb::ValueObjectSP new_value_sp;
722 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000723 {
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000724 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000725 ProcessSP process_sp(exe_ctx.GetProcessSP());
726 Process::StopLocker stop_locker;
727 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
Johnny Chen9fd2e382011-12-20 01:52:44 +0000728 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000729 if (log)
730 log->Printf ("SBValue(%p)::CreateValueFromExpression() => error: process is running", value_sp.get());
731 }
732 else
733 {
734 Target* target = exe_ctx.GetTargetPtr();
735 if (target)
Greg Claytonb4d7fc02012-02-17 07:49:44 +0000736 {
Enrico Granatad27026e2012-09-05 20:41:26 +0000737 Target::EvaluateExpressionOptions options;
738 options.SetKeepInMemory(true);
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000739 target->EvaluateExpression (expression,
740 exe_ctx.GetFramePtr(),
Enrico Granatad27026e2012-09-05 20:41:26 +0000741 new_value_sp,
742 options);
Greg Clayton9f3c98e2012-04-06 02:17:47 +0000743 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
Enrico Granata49306142012-10-10 22:54:17 +00001699lldb::SBDeclaration
1700SBValue::GetDeclaration ()
1701{
1702 lldb::ValueObjectSP value_sp(GetSP());
1703 SBDeclaration decl_sb;
1704 if (value_sp)
1705 {
1706 Declaration decl;
1707 if (value_sp->GetDeclaration(decl))
1708 decl_sb.SetDeclaration(decl);
1709 }
1710 return decl_sb;
1711}
1712
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001713lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001714SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001715{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001716 SBWatchpoint sb_watchpoint;
1717
1718 // If the SBValue is not valid, there's no point in even trying to watch it.
1719 lldb::ValueObjectSP value_sp(GetSP());
1720 TargetSP target_sp (GetTarget().GetSP());
1721 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001722 {
Greg Clayton9f3c98e2012-04-06 02:17:47 +00001723 // Can't watch this if the process is running
1724 ProcessSP process_sp(value_sp->GetProcessSP());
1725 Process::StopLocker stop_locker;
1726 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock()))
1727 {
1728 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1729 if (log)
1730 log->Printf ("SBValue(%p)::Watch() => error: process is running", value_sp.get());
1731 return sb_watchpoint;
1732 }
1733
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001734 // Read and Write cannot both be false.
1735 if (!read && !write)
1736 return sb_watchpoint;
1737
1738 // If the value is not in scope, don't try and watch and invalid value
1739 if (!IsInScope())
1740 return sb_watchpoint;
1741
1742 addr_t addr = GetLoadAddress();
1743 if (addr == LLDB_INVALID_ADDRESS)
1744 return sb_watchpoint;
1745 size_t byte_size = GetByteSize();
1746 if (byte_size == 0)
1747 return sb_watchpoint;
1748
1749 uint32_t watch_type = 0;
1750 if (read)
1751 watch_type |= LLDB_WATCH_TYPE_READ;
1752 if (write)
1753 watch_type |= LLDB_WATCH_TYPE_WRITE;
1754
Johnny Chen3f883492012-06-04 23:19:54 +00001755 Error rc;
1756 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type, rc);
1757 error.SetError(rc);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001758
1759 if (watchpoint_sp)
1760 {
1761 sb_watchpoint.SetSP (watchpoint_sp);
1762 Declaration decl;
1763 if (value_sp->GetDeclaration (decl))
1764 {
1765 if (decl.GetFile())
1766 {
1767 StreamString ss;
1768 // True to show fullpath for declaration file.
1769 decl.DumpStopContext(&ss, true);
1770 watchpoint_sp->SetDeclInfo(ss.GetString());
1771 }
1772 }
1773 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001774 }
1775 return sb_watchpoint;
1776}
1777
Johnny Chen8a5ce772012-06-04 23:45:50 +00001778// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1779// Backward compatibility fix in the interim.
1780lldb::SBWatchpoint
1781SBValue::Watch (bool resolve_location, bool read, bool write)
1782{
Johnny Chen9c4a3442012-06-05 00:14:15 +00001783 SBError error;
1784 return Watch(resolve_location, read, write, error);
Johnny Chen8a5ce772012-06-04 23:45:50 +00001785}
1786
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001787lldb::SBWatchpoint
Johnny Chen3f883492012-06-04 23:19:54 +00001788SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001789{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001790 SBWatchpoint sb_watchpoint;
1791 if (IsInScope() && GetType().IsPointerType())
Johnny Chen3f883492012-06-04 23:19:54 +00001792 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001793 return sb_watchpoint;
1794}
1795