blob: 9b720bdde19c176768ce49ef0e3a139dff523e17 [file] [log] [blame]
Chris Lattner30fdc8d2010-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 Friedman4c5de692010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000011
Enrico Granata10de0902012-10-10 22:54:17 +000012#include "lldb/API/SBDeclaration.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000013#include "lldb/API/SBStream.h"
Enrico Granata864e3e82012-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 Lattner30fdc8d2010-06-08 16:52:24 +000018
Johnny Chen01a67862011-10-14 00:42:25 +000019#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020#include "lldb/Core/DataExtractor.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000021#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/Module.h"
Greg Claytonfe42ac42011-08-03 22:57:10 +000023#include "lldb/Core/Scalar.h"
Greg Clayton1f746072012-08-29 21:13:06 +000024#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-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 Granata6f3533f2011-07-29 19:53:35 +000029#include "lldb/Core/ValueObjectConstResult.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000030#include "lldb/DataFormatters/DataVisualization.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Symbol/Block.h"
Enrico Granata10de0902012-10-10 22:54:17 +000032#include "lldb/Symbol/Declaration.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Symbol/ObjectFile.h"
Greg Clayton81e871e2012-02-04 02:27:34 +000034#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Symbol/Variable.h"
Johnny Chen01a67862011-10-14 00:42:25 +000036#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Target/ExecutionContext.h"
38#include "lldb/Target/Process.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000039#include "lldb/Target/StackFrame.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000040#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041#include "lldb/Target/Thread.h"
42
Jim Ingham35e1bda2012-10-16 21:41:58 +000043#include "lldb/API/SBDebugger.h"
44#include "lldb/API/SBExpressionOptions.h"
45#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000046#include "lldb/API/SBProcess.h"
47#include "lldb/API/SBTarget.h"
48#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049
50using namespace lldb;
51using namespace lldb_private;
52
Enrico Granata19f0e8c2013-04-22 22:57:56 +000053class ValueImpl
54{
55public:
56 ValueImpl ()
Enrico Granatae3e91512012-10-22 18:18:36 +000057 {
Enrico Granata19f0e8c2013-04-22 22:57:56 +000058 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000059
Jim Ingham362e39a2013-05-15 02:16:21 +000060 ValueImpl (lldb::ValueObjectSP in_valobj_sp,
Enrico Granata19f0e8c2013-04-22 22:57:56 +000061 lldb::DynamicValueType use_dynamic,
Jim Ingham362e39a2013-05-15 02:16:21 +000062 bool use_synthetic,
63 const char *name = NULL) :
Enrico Granata989e2132015-06-24 19:53:22 +000064 m_valobj_sp(),
Daniel Maleae0f8f572013-08-26 23:57:52 +000065 m_use_dynamic(use_dynamic),
66 m_use_synthetic(use_synthetic),
67 m_name (name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000068 {
Enrico Granata989e2132015-06-24 19:53:22 +000069 if (in_valobj_sp)
70 {
71 if ( (m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable(lldb::eNoDynamicValues, false)) )
72 {
73 if (!m_name.IsEmpty())
74 m_valobj_sp->SetName(m_name);
75 }
76 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +000077 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000078
Enrico Granata19f0e8c2013-04-22 22:57:56 +000079 ValueImpl (const ValueImpl& rhs) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000080 m_valobj_sp(rhs.m_valobj_sp),
81 m_use_dynamic(rhs.m_use_dynamic),
82 m_use_synthetic(rhs.m_use_synthetic),
83 m_name (rhs.m_name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000084 {
85 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000086
Enrico Granata19f0e8c2013-04-22 22:57:56 +000087 ValueImpl &
88 operator = (const ValueImpl &rhs)
89 {
90 if (this != &rhs)
Enrico Granatae3e91512012-10-22 18:18:36 +000091 {
Jim Ingham362e39a2013-05-15 02:16:21 +000092 m_valobj_sp = rhs.m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +000093 m_use_dynamic = rhs.m_use_dynamic;
94 m_use_synthetic = rhs.m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +000095 m_name = rhs.m_name;
Enrico Granatae3e91512012-10-22 18:18:36 +000096 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +000097 return *this;
98 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000099
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000100 bool
101 IsValid ()
102 {
Jim Ingham793d8d92013-12-06 22:21:04 +0000103 if (m_valobj_sp.get() == NULL)
104 return false;
105 else
106 {
107 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
108 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
109 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
110 // invalid after you call this...
111 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
112 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
113 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
114 // tracking that in all the ValueObject subclasses.
115 TargetSP target_sp = m_valobj_sp->GetTargetSP();
116 if (target_sp && target_sp->IsValid())
117 return true;
118 else
119 return false;
120 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000121 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000122
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000123 lldb::ValueObjectSP
124 GetRootSP ()
125 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000126 return m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000127 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000128
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000129 lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000130 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000131 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000132 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
133 if (!m_valobj_sp)
134 {
135 error.SetErrorString("invalid value object");
136 return m_valobj_sp;
137 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000138
Jim Ingham362e39a2013-05-15 02:16:21 +0000139 lldb::ValueObjectSP value_sp = m_valobj_sp;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000140
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000141 Target *target = value_sp->GetTargetSP().get();
142 if (target)
Jim Ingham362e39a2013-05-15 02:16:21 +0000143 api_locker.Lock(target->GetAPIMutex());
Jim Ingham793d8d92013-12-06 22:21:04 +0000144 else
145 return ValueObjectSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000146
Jim Ingham362e39a2013-05-15 02:16:21 +0000147 ProcessSP process_sp(value_sp->GetProcessSP());
148 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
149 {
150 // We don't allow people to play around with ValueObject if the process is running.
151 // If you want to look at values, pause the process, then look.
152 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000153 log->Printf ("SBValue(%p)::GetSP() => error: process is running",
154 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000155 error.SetErrorString ("process must be stopped.");
156 return ValueObjectSP();
157 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000158
Greg Clayton7d1483f2015-06-22 17:38:30 +0000159 if (m_use_dynamic != eNoDynamicValues)
160 {
161 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic);
162 if (dynamic_sp)
163 value_sp = dynamic_sp;
164 }
165
166 if (m_use_synthetic)
167 {
168 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic);
169 if (synthetic_sp)
170 value_sp = synthetic_sp;
171 }
172
Jim Ingham362e39a2013-05-15 02:16:21 +0000173 if (!value_sp)
174 error.SetErrorString("invalid value object");
175 if (!m_name.IsEmpty())
176 value_sp->SetName(m_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000177
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000178 return value_sp;
179 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000180
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000181 void
182 SetUseDynamic (lldb::DynamicValueType use_dynamic)
183 {
184 m_use_dynamic = use_dynamic;
185 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000186
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000187 void
188 SetUseSynthetic (bool use_synthetic)
189 {
190 m_use_synthetic = use_synthetic;
191 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000192
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000193 lldb::DynamicValueType
194 GetUseDynamic ()
195 {
196 return m_use_dynamic;
197 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000198
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000199 bool
200 GetUseSynthetic ()
201 {
202 return m_use_synthetic;
203 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000204
Jim Ingham362e39a2013-05-15 02:16:21 +0000205 // All the derived values that we would make from the m_valobj_sp will share
206 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
207 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
208 // provide simple accessors for these, which I do here.
209 TargetSP
210 GetTargetSP ()
211 {
212 if (m_valobj_sp)
213 return m_valobj_sp->GetTargetSP();
214 else
215 return TargetSP();
216 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000217
Jim Ingham362e39a2013-05-15 02:16:21 +0000218 ProcessSP
219 GetProcessSP ()
220 {
221 if (m_valobj_sp)
222 return m_valobj_sp->GetProcessSP();
223 else
224 return ProcessSP();
225 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000226
Jim Ingham362e39a2013-05-15 02:16:21 +0000227 ThreadSP
228 GetThreadSP ()
229 {
230 if (m_valobj_sp)
231 return m_valobj_sp->GetThreadSP();
232 else
233 return ThreadSP();
234 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000235
Jason Molendab57e4a12013-11-04 09:33:30 +0000236 StackFrameSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000237 GetFrameSP ()
238 {
239 if (m_valobj_sp)
240 return m_valobj_sp->GetFrameSP();
241 else
Jason Molendab57e4a12013-11-04 09:33:30 +0000242 return StackFrameSP();
Jim Ingham362e39a2013-05-15 02:16:21 +0000243 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000244
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000245private:
Jim Ingham362e39a2013-05-15 02:16:21 +0000246 lldb::ValueObjectSP m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000247 lldb::DynamicValueType m_use_dynamic;
248 bool m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000249 ConstString m_name;
250};
251
252class ValueLocker
253{
254public:
255 ValueLocker ()
256 {
257 }
258
259 ValueObjectSP
260 GetLockedSP(ValueImpl &in_value)
261 {
262 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
263 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000264
Jim Ingham362e39a2013-05-15 02:16:21 +0000265 Error &
266 GetError()
267 {
268 return m_lock_error;
269 }
270
271private:
272 Process::StopLocker m_stop_locker;
273 Mutex::Locker m_api_locker;
274 Error m_lock_error;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000275
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000276};
Enrico Granatae3e91512012-10-22 18:18:36 +0000277
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278SBValue::SBValue () :
Daniel Maleae0f8f572013-08-26 23:57:52 +0000279m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280{
281}
282
Enrico Granatac5bc4122012-03-27 02:35:13 +0000283SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000284{
Enrico Granatae3e91512012-10-22 18:18:36 +0000285 SetSP(value_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286}
287
Enrico Granatac5bc4122012-03-27 02:35:13 +0000288SBValue::SBValue(const SBValue &rhs)
Greg Claytonefabb122010-11-05 23:17:00 +0000289{
Enrico Granatae3e91512012-10-22 18:18:36 +0000290 SetSP(rhs.m_opaque_sp);
Greg Claytonefabb122010-11-05 23:17:00 +0000291}
292
Greg Claytonbf2331c2011-09-09 23:04:00 +0000293SBValue &
Greg Claytonefabb122010-11-05 23:17:00 +0000294SBValue::operator = (const SBValue &rhs)
295{
296 if (this != &rhs)
Enrico Granatac5bc4122012-03-27 02:35:13 +0000297 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000298 SetSP(rhs.m_opaque_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000299 }
Greg Claytonefabb122010-11-05 23:17:00 +0000300 return *this;
301}
302
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303SBValue::~SBValue()
304{
305}
306
307bool
Greg Claytonbf2331c2011-09-09 23:04:00 +0000308SBValue::IsValid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000309{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000310 // If this function ever changes to anything that does more than just
311 // check if the opaque shared pointer is non NULL, then we need to update
312 // all "if (m_opaque_sp)" code in this file.
Jim Ingham793d8d92013-12-06 22:21:04 +0000313 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000314}
315
Jim Ingham5d3bca42011-12-19 20:39:44 +0000316void
317SBValue::Clear()
318{
319 m_opaque_sp.reset();
320}
321
Greg Clayton524e60b2010-10-06 22:10:17 +0000322SBError
323SBValue::GetError()
324{
325 SBError sb_error;
326
Jim Ingham362e39a2013-05-15 02:16:21 +0000327 ValueLocker locker;
328 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000329 if (value_sp)
330 sb_error.SetError(value_sp->GetError());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000331 else
Jim Ingham362e39a2013-05-15 02:16:21 +0000332 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
Greg Clayton524e60b2010-10-06 22:10:17 +0000333
334 return sb_error;
335}
336
Johnny Chenb0b8be72011-07-07 20:46:23 +0000337user_id_t
338SBValue::GetID()
339{
Jim Ingham362e39a2013-05-15 02:16:21 +0000340 ValueLocker locker;
341 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000342 if (value_sp)
343 return value_sp->GetID();
Johnny Chenb0b8be72011-07-07 20:46:23 +0000344 return LLDB_INVALID_UID;
345}
346
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000347const char *
348SBValue::GetName()
349{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000350 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000351 ValueLocker locker;
352 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000353 if (value_sp)
354 name = value_sp->GetName().GetCString();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000355
Greg Clayton5160ce52013-03-27 23:08:40 +0000356 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton93aa84e2010-10-29 04:59:35 +0000357 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000358 {
359 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000360 log->Printf ("SBValue(%p)::GetName () => \"%s\"",
361 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000362 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000363 log->Printf ("SBValue(%p)::GetName () => NULL",
364 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000365 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000366
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000367 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368}
369
370const char *
371SBValue::GetTypeName ()
372{
Greg Clayton5160ce52013-03-27 23:08:40 +0000373 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000374 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000375 ValueLocker locker;
376 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000377 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000378 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000379 name = value_sp->GetQualifiedTypeName().GetCString();
Jim Ingham48cdc582012-08-21 01:46:35 +0000380 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000381
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000382 if (log)
383 {
384 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000385 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
386 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000387 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000388 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
389 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000390 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000391
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000392 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000393}
394
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000395const char *
396SBValue::GetDisplayTypeName ()
397{
398 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
399 const char *name = NULL;
400 ValueLocker locker;
401 lldb::ValueObjectSP value_sp(GetSP(locker));
402 if (value_sp)
403 {
404 name = value_sp->GetDisplayTypeName().GetCString();
405 }
406
407 if (log)
408 {
409 if (name)
410 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
411 static_cast<void*>(value_sp.get()), name);
412 else
413 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
414 static_cast<void*>(value_sp.get()));
415 }
416
417 return name;
418}
419
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420size_t
421SBValue::GetByteSize ()
422{
Greg Clayton5160ce52013-03-27 23:08:40 +0000423 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000425
Jim Ingham362e39a2013-05-15 02:16:21 +0000426 ValueLocker locker;
427 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000428 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000429 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000430 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000431 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000432
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000433 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000434 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
435 static_cast<void*>(value_sp.get()),
436 static_cast<uint64_t>(result));
437
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438 return result;
439}
440
441bool
Jim Ingham6035b672011-03-31 00:19:25 +0000442SBValue::IsInScope ()
443{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000445
Jim Ingham362e39a2013-05-15 02:16:21 +0000446 ValueLocker locker;
447 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000448 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000449 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000450 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000451 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000452
Greg Clayton5160ce52013-03-27 23:08:40 +0000453 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000454 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000455 log->Printf ("SBValue(%p)::IsInScope () => %i",
456 static_cast<void*>(value_sp.get()), result);
457
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000458 return result;
459}
460
461const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000462SBValue::GetValue ()
463{
Greg Clayton5160ce52013-03-27 23:08:40 +0000464 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000465
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000466 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000467 ValueLocker locker;
468 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000469 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000470 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000471 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000472 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000473 if (log)
474 {
475 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000476 log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
477 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000478 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000479 log->Printf ("SBValue(%p)::GetValue() => NULL",
480 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000481 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000482
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000483 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000484}
485
Greg Clayton73b472d2010-10-27 03:32:59 +0000486ValueType
487SBValue::GetValueType ()
488{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000489 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000490 ValueLocker locker;
491 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000492 if (value_sp)
493 result = value_sp->GetValueType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000494
Greg Clayton5160ce52013-03-27 23:08:40 +0000495 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000496 if (log)
497 {
498 switch (result)
499 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000500 case eValueTypeInvalid:
501 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
502 static_cast<void*>(value_sp.get()));
503 break;
504 case eValueTypeVariableGlobal:
505 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
506 static_cast<void*>(value_sp.get()));
507 break;
508 case eValueTypeVariableStatic:
509 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
510 static_cast<void*>(value_sp.get()));
511 break;
512 case eValueTypeVariableArgument:
513 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
514 static_cast<void*>(value_sp.get()));
515 break;
516 case eValueTypeVariableLocal:
517 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
518 static_cast<void*>(value_sp.get()));
519 break;
520 case eValueTypeRegister:
521 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
522 static_cast<void*>(value_sp.get()));
523 break;
524 case eValueTypeRegisterSet:
525 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
526 static_cast<void*>(value_sp.get()));
527 break;
528 case eValueTypeConstResult:
529 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
530 static_cast<void*>(value_sp.get()));
531 break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000532 }
533 }
534 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000535}
536
Jim Ingham53c47f12010-09-10 23:12:17 +0000537const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000538SBValue::GetObjectDescription ()
539{
Greg Clayton5160ce52013-03-27 23:08:40 +0000540 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000541 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000542 ValueLocker locker;
543 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000544 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000545 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000546 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000547 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000548 if (log)
549 {
550 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000551 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
552 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000553 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000554 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
555 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000556 }
557 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000558}
559
Enrico Granataedc44142014-09-06 01:30:04 +0000560const char *
561SBValue::GetTypeValidatorResult ()
562{
563 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
564 const char *cstr = NULL;
565 ValueLocker locker;
566 lldb::ValueObjectSP value_sp(GetSP(locker));
567 if (value_sp)
568 {
569 const auto& validation(value_sp->GetValidationStatus());
570 if (TypeValidatorResult::Failure == validation.first)
571 {
572 if (validation.second.empty())
573 cstr = "unknown error";
574 else
575 cstr = validation.second.c_str();
576 }
577 }
578 if (log)
579 {
580 if (cstr)
581 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
582 static_cast<void*>(value_sp.get()), cstr);
583 else
584 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
585 static_cast<void*>(value_sp.get()));
586 }
587 return cstr;
588}
589
Enrico Granata6f3533f2011-07-29 19:53:35 +0000590SBType
591SBValue::GetType()
592{
Greg Clayton5160ce52013-03-27 23:08:40 +0000593 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000594 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000595 ValueLocker locker;
596 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000597 TypeImplSP type_sp;
598 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000599 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000600 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000601 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000602 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000603 if (log)
604 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000605 if (type_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000606 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
607 static_cast<void*>(value_sp.get()),
608 static_cast<void*>(type_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000609 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000610 log->Printf ("SBValue(%p)::GetType => NULL",
611 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000612 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000613 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000614}
615
Jim Ingham6035b672011-03-31 00:19:25 +0000616bool
617SBValue::GetValueDidChange ()
618{
Greg Clayton5160ce52013-03-27 23:08:40 +0000619 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000620 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000621 ValueLocker locker;
622 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000623 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000624 {
Ilia K761a7a42015-02-06 18:10:30 +0000625 if (value_sp->UpdateValueIfNeeded(false))
626 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000627 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000628 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000629 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
630 static_cast<void*>(value_sp.get()), result);
631
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000632 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000633}
634
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000635#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000637SBValue::GetSummary ()
638{
Greg Clayton5160ce52013-03-27 23:08:40 +0000639 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000640 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000641 ValueLocker locker;
642 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000643 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000644 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000645 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000646 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000647 if (log)
648 {
649 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000650 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
651 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000652 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000653 log->Printf ("SBValue(%p)::GetSummary() => NULL",
654 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000655 }
656 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657}
Enrico Granatac1247f52014-11-06 21:23:20 +0000658
659const char *
Enrico Granata49bfafb2014-11-18 23:36:25 +0000660SBValue::GetSummary (lldb::SBStream& stream,
661 lldb::SBTypeSummaryOptions& options)
Enrico Granatac1247f52014-11-06 21:23:20 +0000662{
663 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granatac1247f52014-11-06 21:23:20 +0000664 ValueLocker locker;
665 lldb::ValueObjectSP value_sp(GetSP(locker));
666 if (value_sp)
667 {
Enrico Granata49bfafb2014-11-18 23:36:25 +0000668 std::string buffer;
669 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
670 stream.Printf("%s",buffer.c_str());
Enrico Granatac1247f52014-11-06 21:23:20 +0000671 }
Enrico Granata49bfafb2014-11-18 23:36:25 +0000672 const char* cstr = stream.GetData();
Enrico Granatac1247f52014-11-06 21:23:20 +0000673 if (log)
674 {
675 if (cstr)
676 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
677 static_cast<void*>(value_sp.get()), cstr);
678 else
679 log->Printf ("SBValue(%p)::GetSummary() => NULL",
680 static_cast<void*>(value_sp.get()));
681 }
682 return cstr;
683}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000684#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685
686const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000687SBValue::GetLocation ()
688{
Greg Clayton5160ce52013-03-27 23:08:40 +0000689 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000690 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000691 ValueLocker locker;
692 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000693 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000694 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000695 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000696 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000697 if (log)
698 {
699 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000700 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
701 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000702 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000703 log->Printf ("SBValue(%p)::GetLocation() => NULL",
704 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000705 }
706 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000707}
708
Enrico Granata07a4ac22012-05-08 21:25:06 +0000709// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000710bool
Jim Ingham6035b672011-03-31 00:19:25 +0000711SBValue::SetValueFromCString (const char *value_str)
712{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000713 lldb::SBError dummy;
714 return SetValueFromCString(value_str,dummy);
715}
716
717bool
718SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
719{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000721 ValueLocker locker;
722 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000723 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000724 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000725 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000726 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000727 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000728 else
729 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000730
Greg Claytonc9858e42012-04-06 02:17:47 +0000731 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000732 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
733 static_cast<void*>(value_sp.get()), value_str, success);
734
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 return success;
736}
737
Enrico Granata864e3e82012-02-17 03:18:30 +0000738lldb::SBTypeFormat
739SBValue::GetTypeFormat ()
740{
741 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000742 ValueLocker locker;
743 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000744 if (value_sp)
745 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000746 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000747 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000748 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
749 if (format_sp)
750 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000751 }
752 }
753 return format;
754}
755
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000756#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000757lldb::SBTypeSummary
758SBValue::GetTypeSummary ()
759{
760 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000761 ValueLocker locker;
762 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000763 if (value_sp)
764 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000765 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000766 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000767 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
768 if (summary_sp)
769 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000770 }
771 }
772 return summary;
773}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000774#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000775
776lldb::SBTypeFilter
777SBValue::GetTypeFilter ()
778{
779 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000780 ValueLocker locker;
781 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000782 if (value_sp)
783 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000784 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000785 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000786 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
787
788 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000789 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000790 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
791 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000792 }
793 }
794 }
795 return filter;
796}
797
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000798#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000799lldb::SBTypeSynthetic
800SBValue::GetTypeSynthetic ()
801{
802 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000803 ValueLocker locker;
804 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000805 if (value_sp)
806 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000807 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000808 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000809 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
810
811 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000812 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000813 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
814 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000815 }
816 }
817 }
818 return synthetic;
819}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000820#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000821
Enrico Granata6f3533f2011-07-29 19:53:35 +0000822lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000823SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000824{
Greg Clayton81e871e2012-02-04 02:27:34 +0000825 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000826 ValueLocker locker;
827 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000828 lldb::ValueObjectSP new_value_sp;
829 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000830 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000831 TypeImplSP type_sp (type.GetSP());
832 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000833 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000834 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000835 }
836 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000837 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000838 if (log)
839 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000840 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000841 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000842 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000843 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000844 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000845 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000846 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000847 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000848 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000849}
850
851lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000852SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000853{
Greg Claytonef496d52012-01-31 04:25:15 +0000854 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000855 ValueLocker locker;
856 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000857 TypeImplSP type_sp (type.GetSP());
858 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000859 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000860 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000861}
862
863lldb::SBValue
864SBValue::CreateValueFromExpression (const char *name, const char* expression)
865{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000866 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000867 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000868 return CreateValueFromExpression (name, expression, options);
869}
870
871lldb::SBValue
872SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
873{
Greg Clayton5160ce52013-03-27 23:08:40 +0000874 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000875 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000876 ValueLocker locker;
877 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000878 lldb::ValueObjectSP new_value_sp;
879 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000880 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000881 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000882 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
883 if (new_value_sp)
884 new_value_sp->SetName(ConstString(name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000885 }
Enrico Granata972be532014-12-17 21:18:43 +0000886 sb_value.SetSP(new_value_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000887 if (log)
888 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000889 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000890 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000891 static_cast<void*>(value_sp.get()), name, expression,
892 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000893 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000894 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000895 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000896 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000897 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000898}
899
900lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000901SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000902{
Greg Clayton81e871e2012-02-04 02:27:34 +0000903 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000904 ValueLocker locker;
905 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000906 lldb::ValueObjectSP new_value_sp;
907 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
908 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000909 {
Enrico Granata972be532014-12-17 21:18:43 +0000910 ClangASTType ast_type(type_impl_sp->GetClangASTType(true));
911 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
912 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000913 }
Enrico Granata972be532014-12-17 21:18:43 +0000914 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000915 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000916 if (log)
917 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000918 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000919 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
920 static_cast<void*>(value_sp.get()),
921 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000922 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000923 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
924 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000925 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000926 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000927}
928
Enrico Granata9128ee22011-09-06 19:20:51 +0000929lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000930SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000931{
Greg Clayton81e871e2012-02-04 02:27:34 +0000932 lldb::SBValue sb_value;
933 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000934 ValueLocker locker;
935 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000936 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000937 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000938 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000939 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true));
Greg Clayton81e871e2012-02-04 02:27:34 +0000940 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
Enrico Granata9128ee22011-09-06 19:20:51 +0000941 }
Enrico Granata972be532014-12-17 21:18:43 +0000942 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000943 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000944 if (log)
945 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000946 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000947 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
948 static_cast<void*>(value_sp.get()),
949 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000950 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000951 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
952 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000953 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000954 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000955}
956
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000957SBValue
958SBValue::GetChildAtIndex (uint32_t idx)
959{
Greg Claytonf66024822011-07-15 19:31:49 +0000960 const bool can_create_synthetic = false;
961 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000962 TargetSP target_sp;
963 if (m_opaque_sp)
964 target_sp = m_opaque_sp->GetTargetSP();
965
966 if (target_sp)
967 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000968
Greg Claytonf66024822011-07-15 19:31:49 +0000969 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000970}
971
972SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000973SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000974{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000975 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000976 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000977
Jim Ingham362e39a2013-05-15 02:16:21 +0000978 ValueLocker locker;
979 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000980 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000982 const bool can_create = true;
983 child_sp = value_sp->GetChildAtIndex (idx, can_create);
984 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000985 {
Bruce Mitchener11d86362015-02-26 23:55:39 +0000986 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
Jim Ingham78a685a2011-04-16 00:01:13 +0000987 }
988 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000989
Enrico Granatae3e91512012-10-22 18:18:36 +0000990 SBValue sb_value;
991 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000992 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000993 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
994 static_cast<void*>(value_sp.get()), idx,
995 static_cast<void*>(value_sp.get()));
996
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000997 return sb_value;
998}
999
1000uint32_t
1001SBValue::GetIndexOfChildWithName (const char *name)
1002{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001003 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +00001004 ValueLocker locker;
1005 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001006 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +00001007 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001008 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +00001009 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001010 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001011 if (log)
1012 {
1013 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001014 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1015 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001016 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001017 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1018 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001019 }
1020 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001021}
1022
1023SBValue
1024SBValue::GetChildMemberWithName (const char *name)
1025{
Jim Ingham362e39a2013-05-15 02:16:21 +00001026 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1027 TargetSP target_sp;
1028 if (m_opaque_sp)
1029 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001030
Jim Ingham362e39a2013-05-15 02:16:21 +00001031 if (target_sp)
1032 use_dynamic_value = target_sp->GetPreferDynamicValue();
1033 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +00001034}
1035
1036SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001037SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001038{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039 lldb::ValueObjectSP child_sp;
1040 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001041
Greg Clayton5160ce52013-03-27 23:08:40 +00001042 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001043
Jim Ingham362e39a2013-05-15 02:16:21 +00001044 ValueLocker locker;
1045 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001046 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001047 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001048 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +00001049 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001050
Enrico Granatae3e91512012-10-22 18:18:36 +00001051 SBValue sb_value;
1052 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001053
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001054 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001055 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1056 static_cast<void*>(value_sp.get()), name,
1057 static_cast<void*>(value_sp.get()));
1058
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001059 return sb_value;
1060}
1061
Enrico Granataf2bbf712011-07-15 02:26:42 +00001062lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001063SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1064{
Enrico Granatae3e91512012-10-22 18:18:36 +00001065 SBValue value_sb;
1066 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001067 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001068 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1069 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001070 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001071 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001072}
1073
1074lldb::SBValue
1075SBValue::GetStaticValue ()
1076{
Enrico Granatae3e91512012-10-22 18:18:36 +00001077 SBValue value_sb;
1078 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001079 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001080 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1081 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001082 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001083 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001084}
1085
Enrico Granatac5bc4122012-03-27 02:35:13 +00001086lldb::SBValue
1087SBValue::GetNonSyntheticValue ()
1088{
Enrico Granatae3e91512012-10-22 18:18:36 +00001089 SBValue value_sb;
1090 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001091 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001092 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1093 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001094 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001095 return value_sb;
1096}
1097
1098lldb::DynamicValueType
1099SBValue::GetPreferDynamicValue ()
1100{
1101 if (!IsValid())
1102 return eNoDynamicValues;
1103 return m_opaque_sp->GetUseDynamic();
1104}
1105
1106void
1107SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1108{
1109 if (IsValid())
1110 return m_opaque_sp->SetUseDynamic (use_dynamic);
1111}
1112
1113bool
1114SBValue::GetPreferSyntheticValue ()
1115{
1116 if (!IsValid())
1117 return false;
1118 return m_opaque_sp->GetUseSynthetic();
1119}
1120
1121void
1122SBValue::SetPreferSyntheticValue (bool use_synthetic)
1123{
1124 if (IsValid())
1125 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001126}
1127
Jim Ingham60dbabb2011-12-08 19:44:08 +00001128bool
1129SBValue::IsDynamic()
1130{
Jim Ingham362e39a2013-05-15 02:16:21 +00001131 ValueLocker locker;
1132 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001133 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001134 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001135 return false;
1136}
1137
Enrico Granatae3e91512012-10-22 18:18:36 +00001138bool
1139SBValue::IsSynthetic ()
1140{
Jim Ingham362e39a2013-05-15 02:16:21 +00001141 ValueLocker locker;
1142 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001143 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001144 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001145 return false;
1146}
1147
Jim Ingham60dbabb2011-12-08 19:44:08 +00001148lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001149SBValue::GetValueForExpressionPath(const char* expr_path)
1150{
Greg Clayton5160ce52013-03-27 23:08:40 +00001151 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001152 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001153 ValueLocker locker;
1154 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001155 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001156 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001157 // using default values for all the fancy options, just do it if you can
1158 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001159 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001160
Enrico Granatae3e91512012-10-22 18:18:36 +00001161 SBValue sb_value;
1162 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001163
Enrico Granataf2bbf712011-07-15 02:26:42 +00001164 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001165 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1166 static_cast<void*>(value_sp.get()), expr_path,
1167 static_cast<void*>(value_sp.get()));
1168
Enrico Granataf2bbf712011-07-15 02:26:42 +00001169 return sb_value;
1170}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001171
Greg Claytonfe42ac42011-08-03 22:57:10 +00001172int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001173SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1174{
Jim Ingham16e0c682011-08-12 23:34:31 +00001175 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001176 ValueLocker locker;
1177 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001178 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001179 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001180 bool success = true;
1181 uint64_t ret_val = fail_value;
1182 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1183 if (!success)
1184 error.SetErrorString("could not resolve value");
1185 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001186 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001187 else
1188 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1189
Enrico Granata6fd87d52011-08-04 01:41:02 +00001190 return fail_value;
1191}
1192
1193uint64_t
1194SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1195{
Jim Ingham16e0c682011-08-12 23:34:31 +00001196 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001197 ValueLocker locker;
1198 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001199 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001200 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001201 bool success = true;
1202 uint64_t ret_val = fail_value;
1203 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1204 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001205 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001206 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001207 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001208 else
1209 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1210
Enrico Granata6fd87d52011-08-04 01:41:02 +00001211 return fail_value;
1212}
1213
1214int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001215SBValue::GetValueAsSigned(int64_t fail_value)
1216{
Jim Ingham362e39a2013-05-15 02:16:21 +00001217 ValueLocker locker;
1218 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001219 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001220 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001221 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001222 }
1223 return fail_value;
1224}
1225
1226uint64_t
1227SBValue::GetValueAsUnsigned(uint64_t fail_value)
1228{
Jim Ingham362e39a2013-05-15 02:16:21 +00001229 ValueLocker locker;
1230 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001231 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001232 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001233 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001234 }
1235 return fail_value;
1236}
1237
Greg Clayton4a792072012-10-23 01:50:10 +00001238bool
1239SBValue::MightHaveChildren ()
1240{
Greg Clayton5160ce52013-03-27 23:08:40 +00001241 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001242 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001243 ValueLocker locker;
1244 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001245 if (value_sp)
1246 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001247
Greg Clayton4a792072012-10-23 01:50:10 +00001248 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001249 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1250 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001251 return has_children;
1252}
1253
Enrico Granata560558e2015-02-11 02:35:39 +00001254bool
1255SBValue::IsRuntimeSupportValue ()
1256{
1257 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1258 bool is_support = false;
1259 ValueLocker locker;
1260 lldb::ValueObjectSP value_sp(GetSP(locker));
1261 if (value_sp)
1262 is_support = value_sp->IsRuntimeSupportValue();
1263
1264 if (log)
1265 log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i",
1266 static_cast<void*>(value_sp.get()), is_support);
1267 return is_support;
1268}
1269
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001270uint32_t
1271SBValue::GetNumChildren ()
1272{
1273 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001274
Greg Clayton5160ce52013-03-27 23:08:40 +00001275 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001276 ValueLocker locker;
1277 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001278 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001279 num_children = value_sp->GetNumChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001280
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001281 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001282 log->Printf ("SBValue(%p)::GetNumChildren () => %u",
1283 static_cast<void*>(value_sp.get()), num_children);
1284
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001285 return num_children;
1286}
1287
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288
1289SBValue
1290SBValue::Dereference ()
1291{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001292 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001293 ValueLocker locker;
1294 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001295 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001296 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001297 Error error;
1298 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001299 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001300 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001301 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001302 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1303 static_cast<void*>(value_sp.get()),
1304 static_cast<void*>(value_sp.get()));
1305
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001306 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001307}
1308
Chaoren Lin4630de82015-07-27 21:51:56 +00001309// Deprecated - please use GetType().IsPointerType() instead.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001311SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001312{
Chaoren Lin4630de82015-07-27 21:51:56 +00001313 return GetType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001314}
1315
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001316void *
1317SBValue::GetOpaqueType()
1318{
Jim Ingham362e39a2013-05-15 02:16:21 +00001319 ValueLocker locker;
1320 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001321 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001322 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001323 return NULL;
1324}
1325
Enrico Granata6f3533f2011-07-29 19:53:35 +00001326lldb::SBTarget
1327SBValue::GetTarget()
1328{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001329 SBTarget sb_target;
1330 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001331 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001332 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001333 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001334 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001335 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001336 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001337 if (log)
1338 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001339 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001340 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1341 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001342 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001343 log->Printf ("SBValue(%p)::GetTarget () => %p",
1344 static_cast<void*>(m_opaque_sp.get()),
1345 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001346 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001347 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001348}
1349
1350lldb::SBProcess
1351SBValue::GetProcess()
1352{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001353 SBProcess sb_process;
1354 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001355 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001356 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001357 process_sp = m_opaque_sp->GetProcessSP();
1358 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001359 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001360 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001361 if (log)
1362 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001363 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001364 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1365 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001366 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001367 log->Printf ("SBValue(%p)::GetProcess () => %p",
1368 static_cast<void*>(m_opaque_sp.get()),
1369 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001370 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001371 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001372}
1373
1374lldb::SBThread
1375SBValue::GetThread()
1376{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001377 SBThread sb_thread;
1378 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001379 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001380 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001381 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001382 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001383 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001385 if (log)
1386 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001387 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001388 log->Printf ("SBValue(%p)::GetThread () => NULL",
1389 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001390 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001391 log->Printf ("SBValue(%p)::GetThread () => %p",
1392 static_cast<void*>(m_opaque_sp.get()),
1393 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001394 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001395 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001396}
1397
1398lldb::SBFrame
1399SBValue::GetFrame()
1400{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001401 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001402 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001403 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001404 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001405 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001406 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001407 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001408 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001409 if (log)
1410 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001411 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001412 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1413 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001414 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001415 log->Printf ("SBValue(%p)::GetFrame () => %p",
1416 static_cast<void*>(m_opaque_sp.get()),
1417 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001418 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001419 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001420}
1421
1422
Greg Clayton81e871e2012-02-04 02:27:34 +00001423lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001424SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001425{
Enrico Granatae3e91512012-10-22 18:18:36 +00001426 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1427 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001428 return locker.GetLockedSP(*m_opaque_sp.get());
1429}
1430
1431lldb::ValueObjectSP
1432SBValue::GetSP () const
1433{
1434 ValueLocker locker;
1435 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001436}
1437
1438void
1439SBValue::SetSP (ValueImplSP impl_sp)
1440{
1441 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001442}
1443
Greg Clayton81e871e2012-02-04 02:27:34 +00001444void
1445SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446{
Enrico Granatae3e91512012-10-22 18:18:36 +00001447 if (sp)
1448 {
1449 lldb::TargetSP target_sp(sp->GetTargetSP());
1450 if (target_sp)
1451 {
1452 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1453 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1454 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1455 }
1456 else
1457 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1458 }
1459 else
1460 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001461}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001462
Enrico Granatae3e91512012-10-22 18:18:36 +00001463void
1464SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1465{
1466 if (sp)
1467 {
1468 lldb::TargetSP target_sp(sp->GetTargetSP());
1469 if (target_sp)
1470 {
1471 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1472 SetSP (sp, use_dynamic, use_synthetic);
1473 }
1474 else
1475 SetSP (sp, use_dynamic, true);
1476 }
1477 else
1478 SetSP (sp, use_dynamic, false);
1479}
1480
1481void
1482SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1483{
1484 if (sp)
1485 {
1486 lldb::TargetSP target_sp(sp->GetTargetSP());
1487 if (target_sp)
1488 {
1489 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1490 SetSP (sp, use_dynamic, use_synthetic);
1491 }
1492 else
1493 SetSP (sp, eNoDynamicValues, use_synthetic);
1494 }
1495 else
1496 SetSP (sp, eNoDynamicValues, use_synthetic);
1497}
1498
1499void
1500SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1501{
1502 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1503}
Greg Clayton81e871e2012-02-04 02:27:34 +00001504
Jim Ingham362e39a2013-05-15 02:16:21 +00001505void
1506SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1507{
1508 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1509}
1510
Caroline Ticedde9cff2010-09-20 05:20:02 +00001511bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001512SBValue::GetExpressionPath (SBStream &description)
1513{
Jim Ingham362e39a2013-05-15 02:16:21 +00001514 ValueLocker locker;
1515 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001516 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001517 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001518 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001519 return true;
1520 }
1521 return false;
1522}
1523
1524bool
1525SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1526{
Jim Ingham362e39a2013-05-15 02:16:21 +00001527 ValueLocker locker;
1528 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001529 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001530 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001531 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001532 return true;
1533 }
1534 return false;
1535}
1536
1537bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001538SBValue::GetDescription (SBStream &description)
1539{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001540 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001541
Jim Ingham362e39a2013-05-15 02:16:21 +00001542 ValueLocker locker;
1543 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001544 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001545 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001546 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001547 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001548
Caroline Ticedde9cff2010-09-20 05:20:02 +00001549 return true;
1550}
Greg Claytondc4e9632011-01-05 18:43:15 +00001551
1552lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001553SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001554{
Jim Ingham362e39a2013-05-15 02:16:21 +00001555 ValueLocker locker;
1556 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001557 if (value_sp)
1558 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001559 return eFormatDefault;
1560}
1561
1562void
1563SBValue::SetFormat (lldb::Format format)
1564{
Jim Ingham362e39a2013-05-15 02:16:21 +00001565 ValueLocker locker;
1566 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001567 if (value_sp)
1568 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001569}
1570
Enrico Granata6f3533f2011-07-29 19:53:35 +00001571lldb::SBValue
1572SBValue::AddressOf()
1573{
1574 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001575 ValueLocker locker;
1576 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001577 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001578 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001579 Error error;
1580 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001581 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001582 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001583 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001584 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1585 static_cast<void*>(value_sp.get()),
1586 static_cast<void*>(value_sp.get()));
1587
Enrico Granata6f3533f2011-07-29 19:53:35 +00001588 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001589}
Enrico Granata9128ee22011-09-06 19:20:51 +00001590
1591lldb::addr_t
1592SBValue::GetLoadAddress()
1593{
1594 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001595 ValueLocker locker;
1596 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001597 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001598 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001599 TargetSP target_sp (value_sp->GetTargetSP());
1600 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001601 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001602 const bool scalar_is_load_address = true;
1603 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001604 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001605 if (addr_type == eAddressTypeFile)
1606 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001607 ModuleSP module_sp (value_sp->GetModule());
1608 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001609 value = LLDB_INVALID_ADDRESS;
1610 else
1611 {
1612 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001613 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001614 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001615 }
1616 }
1617 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1618 value = LLDB_INVALID_ADDRESS;
1619 }
1620 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001621 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001622 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001623 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1624 static_cast<void*>(value_sp.get()), value);
1625
Enrico Granata9128ee22011-09-06 19:20:51 +00001626 return value;
1627}
1628
1629lldb::SBAddress
1630SBValue::GetAddress()
1631{
1632 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001633 ValueLocker locker;
1634 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001635 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001636 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001637 TargetSP target_sp (value_sp->GetTargetSP());
1638 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001639 {
1640 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001641 const bool scalar_is_load_address = true;
1642 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001643 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001644 if (addr_type == eAddressTypeFile)
1645 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001646 ModuleSP module_sp (value_sp->GetModule());
1647 if (module_sp)
1648 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001649 }
1650 else if (addr_type == eAddressTypeLoad)
1651 {
1652 // no need to check the return value on this.. if it can actually do the resolve
1653 // addr will be in the form (section,offset), otherwise it will simply be returned
1654 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001655 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001656 }
1657 }
1658 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001659 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001660 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001661 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1662 static_cast<void*>(value_sp.get()),
1663 (addr.GetSection()
1664 ? addr.GetSection()->GetName().GetCString()
1665 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001666 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001667 return SBAddress(new Address(addr));
1668}
1669
1670lldb::SBData
1671SBValue::GetPointeeData (uint32_t item_idx,
1672 uint32_t item_count)
1673{
Greg Clayton5160ce52013-03-27 23:08:40 +00001674 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001675 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001676 ValueLocker locker;
1677 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001678 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001679 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001680 TargetSP target_sp (value_sp->GetTargetSP());
1681 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001682 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001683 DataExtractorSP data_sp(new DataExtractor());
1684 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1685 if (data_sp->GetByteSize() > 0)
1686 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001687 }
1688 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001689 if (log)
1690 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001691 static_cast<void*>(value_sp.get()), item_idx, item_count,
1692 static_cast<void*>(sb_data.get()));
1693
Enrico Granata9128ee22011-09-06 19:20:51 +00001694 return sb_data;
1695}
1696
1697lldb::SBData
1698SBValue::GetData ()
1699{
Greg Clayton5160ce52013-03-27 23:08:40 +00001700 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001701 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001702 ValueLocker locker;
1703 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001704 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001705 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001706 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001707 Error error;
1708 value_sp->GetData(*data_sp, error);
1709 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001710 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001711 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001712 if (log)
1713 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001714 static_cast<void*>(value_sp.get()),
1715 static_cast<void*>(sb_data.get()));
1716
Enrico Granata9128ee22011-09-06 19:20:51 +00001717 return sb_data;
1718}
Greg Clayton1b282f92011-10-13 18:08:26 +00001719
Sean Callanan389823e2013-04-13 01:21:23 +00001720bool
1721SBValue::SetData (lldb::SBData &data, SBError &error)
1722{
1723 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001724 ValueLocker locker;
1725 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001726 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001727
Sean Callanan389823e2013-04-13 01:21:23 +00001728 if (value_sp)
1729 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001730 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001731
Jim Ingham362e39a2013-05-15 02:16:21 +00001732 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001733 {
1734 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001735 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1736 static_cast<void*>(value_sp.get()));
1737
Jim Ingham362e39a2013-05-15 02:16:21 +00001738 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001739 ret = false;
1740 }
1741 else
1742 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001743 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001744
Jim Ingham362e39a2013-05-15 02:16:21 +00001745 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001746
Jim Ingham362e39a2013-05-15 02:16:21 +00001747 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001748 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001749 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001750 ret = false;
1751 }
Sean Callanan389823e2013-04-13 01:21:23 +00001752 }
1753 }
1754 else
1755 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001756 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001757 ret = false;
1758 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001759
Sean Callanan389823e2013-04-13 01:21:23 +00001760 if (log)
1761 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001762 static_cast<void*>(value_sp.get()),
1763 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001764 return ret;
1765}
1766
Enrico Granata10de0902012-10-10 22:54:17 +00001767lldb::SBDeclaration
1768SBValue::GetDeclaration ()
1769{
Jim Ingham362e39a2013-05-15 02:16:21 +00001770 ValueLocker locker;
1771 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001772 SBDeclaration decl_sb;
1773 if (value_sp)
1774 {
1775 Declaration decl;
1776 if (value_sp->GetDeclaration(decl))
1777 decl_sb.SetDeclaration(decl);
1778 }
1779 return decl_sb;
1780}
1781
Greg Clayton1b282f92011-10-13 18:08:26 +00001782lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001783SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001784{
Greg Clayton81e871e2012-02-04 02:27:34 +00001785 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001786
Greg Clayton81e871e2012-02-04 02:27:34 +00001787 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001788 ValueLocker locker;
1789 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001790 TargetSP target_sp (GetTarget().GetSP());
1791 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001792 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001793 // Read and Write cannot both be false.
1794 if (!read && !write)
1795 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001796
Greg Clayton81e871e2012-02-04 02:27:34 +00001797 // If the value is not in scope, don't try and watch and invalid value
1798 if (!IsInScope())
1799 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001800
Greg Clayton81e871e2012-02-04 02:27:34 +00001801 addr_t addr = GetLoadAddress();
1802 if (addr == LLDB_INVALID_ADDRESS)
1803 return sb_watchpoint;
1804 size_t byte_size = GetByteSize();
1805 if (byte_size == 0)
1806 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001807
Greg Clayton81e871e2012-02-04 02:27:34 +00001808 uint32_t watch_type = 0;
1809 if (read)
1810 watch_type |= LLDB_WATCH_TYPE_READ;
1811 if (write)
1812 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001813
Johnny Chenb90827e2012-06-04 23:19:54 +00001814 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001815 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001816 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001817 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001818
Daniel Maleae0f8f572013-08-26 23:57:52 +00001819 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001820 {
1821 sb_watchpoint.SetSP (watchpoint_sp);
1822 Declaration decl;
1823 if (value_sp->GetDeclaration (decl))
1824 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001825 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001826 {
1827 StreamString ss;
1828 // True to show fullpath for declaration file.
1829 decl.DumpStopContext(&ss, true);
1830 watchpoint_sp->SetDeclInfo(ss.GetString());
1831 }
1832 }
1833 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001834 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001835 else if (target_sp)
1836 {
1837 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1838 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001839 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1840 static_cast<void*>(value_sp.get()),
1841 locker.GetError().AsCString());
1842
Jim Ingham362e39a2013-05-15 02:16:21 +00001843 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1844 }
1845 else
1846 {
1847 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1848 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001849 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1850 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001851 error.SetErrorString("could not set watchpoint, a target is required");
1852 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001853
Greg Clayton1b282f92011-10-13 18:08:26 +00001854 return sb_watchpoint;
1855}
1856
Johnny Chend3761a72012-06-04 23:45:50 +00001857// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1858// Backward compatibility fix in the interim.
1859lldb::SBWatchpoint
1860SBValue::Watch (bool resolve_location, bool read, bool write)
1861{
Johnny Chen974759f2012-06-05 00:14:15 +00001862 SBError error;
1863 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001864}
1865
Greg Clayton1b282f92011-10-13 18:08:26 +00001866lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001867SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001868{
Greg Clayton81e871e2012-02-04 02:27:34 +00001869 SBWatchpoint sb_watchpoint;
1870 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001871 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001872 return sb_watchpoint;
1873}
Enrico Granata0c10a852014-12-08 23:13:56 +00001874
1875lldb::SBValue
1876SBValue::Persist ()
1877{
1878 ValueLocker locker;
1879 lldb::ValueObjectSP value_sp(GetSP(locker));
1880 SBValue persisted_sb;
1881 if (value_sp)
1882 {
1883 persisted_sb.SetSP(value_sp->Persist());
1884 }
1885 return persisted_sb;
1886}