blob: a8584c5d38c9e83e257c9274337886b3e6c573d6 [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
635const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000636SBValue::GetSummary ()
637{
Greg Clayton5160ce52013-03-27 23:08:40 +0000638 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000639 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000640 ValueLocker locker;
641 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000642 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000643 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000644 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000645 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000646 if (log)
647 {
648 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000649 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
650 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000651 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000652 log->Printf ("SBValue(%p)::GetSummary() => NULL",
653 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000654 }
655 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000656}
Enrico Granatac1247f52014-11-06 21:23:20 +0000657
658const char *
Enrico Granata49bfafb2014-11-18 23:36:25 +0000659SBValue::GetSummary (lldb::SBStream& stream,
660 lldb::SBTypeSummaryOptions& options)
Enrico Granatac1247f52014-11-06 21:23:20 +0000661{
662 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granatac1247f52014-11-06 21:23:20 +0000663 ValueLocker locker;
664 lldb::ValueObjectSP value_sp(GetSP(locker));
665 if (value_sp)
666 {
Enrico Granata49bfafb2014-11-18 23:36:25 +0000667 std::string buffer;
668 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
669 stream.Printf("%s",buffer.c_str());
Enrico Granatac1247f52014-11-06 21:23:20 +0000670 }
Enrico Granata49bfafb2014-11-18 23:36:25 +0000671 const char* cstr = stream.GetData();
Enrico Granatac1247f52014-11-06 21:23:20 +0000672 if (log)
673 {
674 if (cstr)
675 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
676 static_cast<void*>(value_sp.get()), cstr);
677 else
678 log->Printf ("SBValue(%p)::GetSummary() => NULL",
679 static_cast<void*>(value_sp.get()));
680 }
681 return cstr;
682}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683
684const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000685SBValue::GetLocation ()
686{
Greg Clayton5160ce52013-03-27 23:08:40 +0000687 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000688 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000689 ValueLocker locker;
690 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000691 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000692 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000693 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000694 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000695 if (log)
696 {
697 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000698 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
699 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000700 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000701 log->Printf ("SBValue(%p)::GetLocation() => NULL",
702 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000703 }
704 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705}
706
Enrico Granata07a4ac22012-05-08 21:25:06 +0000707// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708bool
Jim Ingham6035b672011-03-31 00:19:25 +0000709SBValue::SetValueFromCString (const char *value_str)
710{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000711 lldb::SBError dummy;
712 return SetValueFromCString(value_str,dummy);
713}
714
715bool
716SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
717{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000718 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000719 ValueLocker locker;
720 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000721 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000722 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000723 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000724 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000725 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000726 else
727 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000728
Greg Claytonc9858e42012-04-06 02:17:47 +0000729 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000730 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
731 static_cast<void*>(value_sp.get()), value_str, success);
732
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000733 return success;
734}
735
Enrico Granata864e3e82012-02-17 03:18:30 +0000736lldb::SBTypeFormat
737SBValue::GetTypeFormat ()
738{
739 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000740 ValueLocker locker;
741 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000742 if (value_sp)
743 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000744 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000745 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000746 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
747 if (format_sp)
748 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000749 }
750 }
751 return format;
752}
753
754lldb::SBTypeSummary
755SBValue::GetTypeSummary ()
756{
757 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000758 ValueLocker locker;
759 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000760 if (value_sp)
761 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000762 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000763 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000764 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
765 if (summary_sp)
766 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000767 }
768 }
769 return summary;
770}
771
772lldb::SBTypeFilter
773SBValue::GetTypeFilter ()
774{
775 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000776 ValueLocker locker;
777 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000778 if (value_sp)
779 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000780 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000781 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000782 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
783
784 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000785 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000786 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
787 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000788 }
789 }
790 }
791 return filter;
792}
793
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000794#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000795lldb::SBTypeSynthetic
796SBValue::GetTypeSynthetic ()
797{
798 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000799 ValueLocker locker;
800 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000801 if (value_sp)
802 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000803 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000804 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000805 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
806
807 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000808 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000809 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
810 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000811 }
812 }
813 }
814 return synthetic;
815}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000816#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000817
Enrico Granata6f3533f2011-07-29 19:53:35 +0000818lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000819SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000820{
Greg Clayton81e871e2012-02-04 02:27:34 +0000821 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000822 ValueLocker locker;
823 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000824 lldb::ValueObjectSP new_value_sp;
825 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000826 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000827 TypeImplSP type_sp (type.GetSP());
828 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000829 {
Greg Claytona1e5dc82015-08-11 22:53:00 +0000830 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetCompilerType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000831 }
832 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000833 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000834 if (log)
835 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000836 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000837 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000838 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000839 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000840 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000841 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000842 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000843 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000844 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000845}
846
847lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000848SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000849{
Greg Claytonef496d52012-01-31 04:25:15 +0000850 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000851 ValueLocker locker;
852 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000853 TypeImplSP type_sp (type.GetSP());
854 if (value_sp && type_sp)
Greg Claytona1e5dc82015-08-11 22:53:00 +0000855 sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000856 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000857}
858
859lldb::SBValue
860SBValue::CreateValueFromExpression (const char *name, const char* expression)
861{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000862 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000863 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000864 return CreateValueFromExpression (name, expression, options);
865}
866
867lldb::SBValue
868SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
869{
Greg Clayton5160ce52013-03-27 23:08:40 +0000870 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000871 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000872 ValueLocker locker;
873 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000874 lldb::ValueObjectSP new_value_sp;
875 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000876 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000877 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000878 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
879 if (new_value_sp)
880 new_value_sp->SetName(ConstString(name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000881 }
Enrico Granata972be532014-12-17 21:18:43 +0000882 sb_value.SetSP(new_value_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000883 if (log)
884 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000885 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000886 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000887 static_cast<void*>(value_sp.get()), name, expression,
888 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000889 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000890 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000891 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000892 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000893 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000894}
895
896lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000897SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000898{
Greg Clayton81e871e2012-02-04 02:27:34 +0000899 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000900 ValueLocker locker;
901 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000902 lldb::ValueObjectSP new_value_sp;
903 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
904 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000905 {
Greg Claytona1e5dc82015-08-11 22:53:00 +0000906 CompilerType ast_type(type_impl_sp->GetCompilerType(true));
Enrico Granata972be532014-12-17 21:18:43 +0000907 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
908 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000909 }
Enrico Granata972be532014-12-17 21:18:43 +0000910 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000911 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000912 if (log)
913 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000914 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000915 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
916 static_cast<void*>(value_sp.get()),
917 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000918 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000919 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
920 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000921 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000922 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000923}
924
Enrico Granata9128ee22011-09-06 19:20:51 +0000925lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000926SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000927{
Greg Clayton81e871e2012-02-04 02:27:34 +0000928 lldb::SBValue sb_value;
929 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000930 ValueLocker locker;
931 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000932 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000933 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000934 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Greg Claytona1e5dc82015-08-11 22:53:00 +0000935 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetCompilerType(true));
Greg Clayton81e871e2012-02-04 02:27:34 +0000936 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
Enrico Granata9128ee22011-09-06 19:20:51 +0000937 }
Enrico Granata972be532014-12-17 21:18:43 +0000938 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000939 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000940 if (log)
941 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000942 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000943 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
944 static_cast<void*>(value_sp.get()),
945 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000946 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000947 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
948 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000949 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000950 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000951}
952
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000953SBValue
954SBValue::GetChildAtIndex (uint32_t idx)
955{
Greg Claytonf66024822011-07-15 19:31:49 +0000956 const bool can_create_synthetic = false;
957 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000958 TargetSP target_sp;
959 if (m_opaque_sp)
960 target_sp = m_opaque_sp->GetTargetSP();
961
962 if (target_sp)
963 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000964
Greg Claytonf66024822011-07-15 19:31:49 +0000965 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000966}
967
968SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000969SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000970{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000971 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000972 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000973
Jim Ingham362e39a2013-05-15 02:16:21 +0000974 ValueLocker locker;
975 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000976 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000977 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000978 const bool can_create = true;
979 child_sp = value_sp->GetChildAtIndex (idx, can_create);
980 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000981 {
Bruce Mitchener11d86362015-02-26 23:55:39 +0000982 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
Jim Ingham78a685a2011-04-16 00:01:13 +0000983 }
984 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000985
Enrico Granatae3e91512012-10-22 18:18:36 +0000986 SBValue sb_value;
987 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000988 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000989 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
990 static_cast<void*>(value_sp.get()), idx,
991 static_cast<void*>(value_sp.get()));
992
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000993 return sb_value;
994}
995
996uint32_t
997SBValue::GetIndexOfChildWithName (const char *name)
998{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000999 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +00001000 ValueLocker locker;
1001 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001002 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +00001003 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001004 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +00001005 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001006 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001007 if (log)
1008 {
1009 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001010 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1011 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001012 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001013 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1014 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001015 }
1016 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017}
1018
1019SBValue
1020SBValue::GetChildMemberWithName (const char *name)
1021{
Jim Ingham362e39a2013-05-15 02:16:21 +00001022 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1023 TargetSP target_sp;
1024 if (m_opaque_sp)
1025 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001026
Jim Ingham362e39a2013-05-15 02:16:21 +00001027 if (target_sp)
1028 use_dynamic_value = target_sp->GetPreferDynamicValue();
1029 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +00001030}
1031
1032SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001033SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001034{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001035 lldb::ValueObjectSP child_sp;
1036 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001037
Greg Clayton5160ce52013-03-27 23:08:40 +00001038 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001039
Jim Ingham362e39a2013-05-15 02:16:21 +00001040 ValueLocker locker;
1041 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001042 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001044 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +00001045 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001046
Enrico Granatae3e91512012-10-22 18:18:36 +00001047 SBValue sb_value;
1048 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001049
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001050 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001051 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1052 static_cast<void*>(value_sp.get()), name,
1053 static_cast<void*>(value_sp.get()));
1054
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001055 return sb_value;
1056}
1057
Enrico Granataf2bbf712011-07-15 02:26:42 +00001058lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001059SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1060{
Enrico Granatae3e91512012-10-22 18:18:36 +00001061 SBValue value_sb;
1062 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001063 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001064 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1065 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001066 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001067 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001068}
1069
1070lldb::SBValue
1071SBValue::GetStaticValue ()
1072{
Enrico Granatae3e91512012-10-22 18:18:36 +00001073 SBValue value_sb;
1074 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001075 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001076 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1077 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001078 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001079 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001080}
1081
Enrico Granatac5bc4122012-03-27 02:35:13 +00001082lldb::SBValue
1083SBValue::GetNonSyntheticValue ()
1084{
Enrico Granatae3e91512012-10-22 18:18:36 +00001085 SBValue value_sb;
1086 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001087 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001088 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1089 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001090 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001091 return value_sb;
1092}
1093
1094lldb::DynamicValueType
1095SBValue::GetPreferDynamicValue ()
1096{
1097 if (!IsValid())
1098 return eNoDynamicValues;
1099 return m_opaque_sp->GetUseDynamic();
1100}
1101
1102void
1103SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1104{
1105 if (IsValid())
1106 return m_opaque_sp->SetUseDynamic (use_dynamic);
1107}
1108
1109bool
1110SBValue::GetPreferSyntheticValue ()
1111{
1112 if (!IsValid())
1113 return false;
1114 return m_opaque_sp->GetUseSynthetic();
1115}
1116
1117void
1118SBValue::SetPreferSyntheticValue (bool use_synthetic)
1119{
1120 if (IsValid())
1121 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001122}
1123
Jim Ingham60dbabb2011-12-08 19:44:08 +00001124bool
1125SBValue::IsDynamic()
1126{
Jim Ingham362e39a2013-05-15 02:16:21 +00001127 ValueLocker locker;
1128 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001129 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001130 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001131 return false;
1132}
1133
Enrico Granatae3e91512012-10-22 18:18:36 +00001134bool
1135SBValue::IsSynthetic ()
1136{
Jim Ingham362e39a2013-05-15 02:16:21 +00001137 ValueLocker locker;
1138 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001139 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001140 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001141 return false;
1142}
1143
Jim Ingham60dbabb2011-12-08 19:44:08 +00001144lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001145SBValue::GetValueForExpressionPath(const char* expr_path)
1146{
Greg Clayton5160ce52013-03-27 23:08:40 +00001147 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001148 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001149 ValueLocker locker;
1150 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001151 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001152 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001153 // using default values for all the fancy options, just do it if you can
1154 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001155 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001156
Enrico Granatae3e91512012-10-22 18:18:36 +00001157 SBValue sb_value;
1158 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001159
Enrico Granataf2bbf712011-07-15 02:26:42 +00001160 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001161 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1162 static_cast<void*>(value_sp.get()), expr_path,
1163 static_cast<void*>(value_sp.get()));
1164
Enrico Granataf2bbf712011-07-15 02:26:42 +00001165 return sb_value;
1166}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001167
Greg Claytonfe42ac42011-08-03 22:57:10 +00001168int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001169SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1170{
Jim Ingham16e0c682011-08-12 23:34:31 +00001171 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001172 ValueLocker locker;
1173 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001174 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001175 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001176 bool success = true;
1177 uint64_t ret_val = fail_value;
1178 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1179 if (!success)
1180 error.SetErrorString("could not resolve value");
1181 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001182 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001183 else
1184 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1185
Enrico Granata6fd87d52011-08-04 01:41:02 +00001186 return fail_value;
1187}
1188
1189uint64_t
1190SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1191{
Jim Ingham16e0c682011-08-12 23:34:31 +00001192 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001193 ValueLocker locker;
1194 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001195 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001196 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001197 bool success = true;
1198 uint64_t ret_val = fail_value;
1199 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1200 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001201 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001202 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001203 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001204 else
1205 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1206
Enrico Granata6fd87d52011-08-04 01:41:02 +00001207 return fail_value;
1208}
1209
1210int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001211SBValue::GetValueAsSigned(int64_t fail_value)
1212{
Jim Ingham362e39a2013-05-15 02:16:21 +00001213 ValueLocker locker;
1214 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001215 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001216 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001217 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001218 }
1219 return fail_value;
1220}
1221
1222uint64_t
1223SBValue::GetValueAsUnsigned(uint64_t fail_value)
1224{
Jim Ingham362e39a2013-05-15 02:16:21 +00001225 ValueLocker locker;
1226 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001227 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001228 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001229 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001230 }
1231 return fail_value;
1232}
1233
Greg Clayton4a792072012-10-23 01:50:10 +00001234bool
1235SBValue::MightHaveChildren ()
1236{
Greg Clayton5160ce52013-03-27 23:08:40 +00001237 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001238 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001239 ValueLocker locker;
1240 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001241 if (value_sp)
1242 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001243
Greg Clayton4a792072012-10-23 01:50:10 +00001244 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001245 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1246 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001247 return has_children;
1248}
1249
Enrico Granata560558e2015-02-11 02:35:39 +00001250bool
1251SBValue::IsRuntimeSupportValue ()
1252{
1253 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1254 bool is_support = false;
1255 ValueLocker locker;
1256 lldb::ValueObjectSP value_sp(GetSP(locker));
1257 if (value_sp)
1258 is_support = value_sp->IsRuntimeSupportValue();
1259
1260 if (log)
1261 log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i",
1262 static_cast<void*>(value_sp.get()), is_support);
1263 return is_support;
1264}
1265
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001266uint32_t
1267SBValue::GetNumChildren ()
1268{
Siva Chandra9ac7a6c2015-10-21 19:28:08 +00001269 return GetNumChildren (UINT32_MAX);
1270}
1271
1272uint32_t
1273SBValue::GetNumChildren (uint32_t max)
1274{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001276
Greg Clayton5160ce52013-03-27 23:08:40 +00001277 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001278 ValueLocker locker;
1279 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001280 if (value_sp)
Siva Chandra9ac7a6c2015-10-21 19:28:08 +00001281 num_children = value_sp->GetNumChildren(max);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001282
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001283 if (log)
Siva Chandra9ac7a6c2015-10-21 19:28:08 +00001284 log->Printf ("SBValue(%p)::GetNumChildren (%u) => %u",
1285 static_cast<void*>(value_sp.get()), max, num_children);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001286
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287 return num_children;
1288}
1289
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001290SBValue
1291SBValue::Dereference ()
1292{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001293 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001294 ValueLocker locker;
1295 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001296 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001297 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001298 Error error;
1299 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001301 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001302 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001303 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1304 static_cast<void*>(value_sp.get()),
1305 static_cast<void*>(value_sp.get()));
1306
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001307 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308}
1309
Chaoren Lin4630de82015-07-27 21:51:56 +00001310// Deprecated - please use GetType().IsPointerType() instead.
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001312SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001313{
Chaoren Lin4630de82015-07-27 21:51:56 +00001314 return GetType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315}
1316
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317void *
1318SBValue::GetOpaqueType()
1319{
Jim Ingham362e39a2013-05-15 02:16:21 +00001320 ValueLocker locker;
1321 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001322 if (value_sp)
Greg Clayton99558cc42015-08-24 23:46:31 +00001323 return value_sp->GetCompilerType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324 return NULL;
1325}
1326
Enrico Granata6f3533f2011-07-29 19:53:35 +00001327lldb::SBTarget
1328SBValue::GetTarget()
1329{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001330 SBTarget sb_target;
1331 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001332 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001333 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001334 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001335 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001336 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001337 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001338 if (log)
1339 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001340 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001341 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1342 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001343 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001344 log->Printf ("SBValue(%p)::GetTarget () => %p",
1345 static_cast<void*>(m_opaque_sp.get()),
1346 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001347 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001348 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001349}
1350
1351lldb::SBProcess
1352SBValue::GetProcess()
1353{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001354 SBProcess sb_process;
1355 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001356 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001357 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001358 process_sp = m_opaque_sp->GetProcessSP();
1359 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001360 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001361 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001362 if (log)
1363 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001364 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001365 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1366 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001367 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001368 log->Printf ("SBValue(%p)::GetProcess () => %p",
1369 static_cast<void*>(m_opaque_sp.get()),
1370 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001371 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001372 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001373}
1374
1375lldb::SBThread
1376SBValue::GetThread()
1377{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001378 SBThread sb_thread;
1379 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001380 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001381 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001382 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001383 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001384 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001385 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001386 if (log)
1387 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001388 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001389 log->Printf ("SBValue(%p)::GetThread () => NULL",
1390 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001391 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001392 log->Printf ("SBValue(%p)::GetThread () => %p",
1393 static_cast<void*>(m_opaque_sp.get()),
1394 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001395 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001396 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001397}
1398
1399lldb::SBFrame
1400SBValue::GetFrame()
1401{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001402 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001403 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001404 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001405 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001406 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001407 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001408 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001409 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001410 if (log)
1411 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001412 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001413 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1414 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001415 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001416 log->Printf ("SBValue(%p)::GetFrame () => %p",
1417 static_cast<void*>(m_opaque_sp.get()),
1418 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001419 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001420 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001421}
1422
1423
Greg Clayton81e871e2012-02-04 02:27:34 +00001424lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001425SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426{
Enrico Granatae3e91512012-10-22 18:18:36 +00001427 if (!m_opaque_sp || !m_opaque_sp->IsValid())
Jim Inghamd6129182015-10-30 21:43:15 +00001428 {
1429 locker.GetError().SetErrorString("No value");
Enrico Granatae3e91512012-10-22 18:18:36 +00001430 return ValueObjectSP();
Jim Inghamd6129182015-10-30 21:43:15 +00001431 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001432 return locker.GetLockedSP(*m_opaque_sp.get());
1433}
1434
1435lldb::ValueObjectSP
1436SBValue::GetSP () const
1437{
1438 ValueLocker locker;
1439 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001440}
1441
1442void
1443SBValue::SetSP (ValueImplSP impl_sp)
1444{
1445 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001446}
1447
Greg Clayton81e871e2012-02-04 02:27:34 +00001448void
1449SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001450{
Enrico Granatae3e91512012-10-22 18:18:36 +00001451 if (sp)
1452 {
1453 lldb::TargetSP target_sp(sp->GetTargetSP());
1454 if (target_sp)
1455 {
1456 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1457 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1458 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1459 }
1460 else
1461 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1462 }
1463 else
1464 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001466
Enrico Granatae3e91512012-10-22 18:18:36 +00001467void
1468SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1469{
1470 if (sp)
1471 {
1472 lldb::TargetSP target_sp(sp->GetTargetSP());
1473 if (target_sp)
1474 {
1475 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1476 SetSP (sp, use_dynamic, use_synthetic);
1477 }
1478 else
1479 SetSP (sp, use_dynamic, true);
1480 }
1481 else
1482 SetSP (sp, use_dynamic, false);
1483}
1484
1485void
1486SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1487{
1488 if (sp)
1489 {
1490 lldb::TargetSP target_sp(sp->GetTargetSP());
1491 if (target_sp)
1492 {
1493 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1494 SetSP (sp, use_dynamic, use_synthetic);
1495 }
1496 else
1497 SetSP (sp, eNoDynamicValues, use_synthetic);
1498 }
1499 else
1500 SetSP (sp, eNoDynamicValues, use_synthetic);
1501}
1502
1503void
1504SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1505{
1506 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1507}
Greg Clayton81e871e2012-02-04 02:27:34 +00001508
Jim Ingham362e39a2013-05-15 02:16:21 +00001509void
1510SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1511{
1512 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1513}
1514
Caroline Ticedde9cff2010-09-20 05:20:02 +00001515bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001516SBValue::GetExpressionPath (SBStream &description)
1517{
Jim Ingham362e39a2013-05-15 02:16:21 +00001518 ValueLocker locker;
1519 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001520 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001521 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001522 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001523 return true;
1524 }
1525 return false;
1526}
1527
1528bool
1529SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1530{
Jim Ingham362e39a2013-05-15 02:16:21 +00001531 ValueLocker locker;
1532 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001533 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001534 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001535 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001536 return true;
1537 }
1538 return false;
1539}
1540
1541bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001542SBValue::GetDescription (SBStream &description)
1543{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001544 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001545
Jim Ingham362e39a2013-05-15 02:16:21 +00001546 ValueLocker locker;
1547 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001548 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001549 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001550 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001551 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001552
Caroline Ticedde9cff2010-09-20 05:20:02 +00001553 return true;
1554}
Greg Claytondc4e9632011-01-05 18:43:15 +00001555
1556lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001557SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001558{
Jim Ingham362e39a2013-05-15 02:16:21 +00001559 ValueLocker locker;
1560 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001561 if (value_sp)
1562 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001563 return eFormatDefault;
1564}
1565
1566void
1567SBValue::SetFormat (lldb::Format format)
1568{
Jim Ingham362e39a2013-05-15 02:16:21 +00001569 ValueLocker locker;
1570 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001571 if (value_sp)
1572 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001573}
1574
Enrico Granata6f3533f2011-07-29 19:53:35 +00001575lldb::SBValue
1576SBValue::AddressOf()
1577{
1578 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001579 ValueLocker locker;
1580 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001581 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001582 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001583 Error error;
1584 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001585 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001586 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001587 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001588 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1589 static_cast<void*>(value_sp.get()),
1590 static_cast<void*>(value_sp.get()));
1591
Enrico Granata6f3533f2011-07-29 19:53:35 +00001592 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001593}
Enrico Granata9128ee22011-09-06 19:20:51 +00001594
1595lldb::addr_t
1596SBValue::GetLoadAddress()
1597{
1598 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001599 ValueLocker locker;
1600 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001601 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001602 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001603 TargetSP target_sp (value_sp->GetTargetSP());
1604 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001605 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001606 const bool scalar_is_load_address = true;
1607 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001608 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001609 if (addr_type == eAddressTypeFile)
1610 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001611 ModuleSP module_sp (value_sp->GetModule());
1612 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001613 value = LLDB_INVALID_ADDRESS;
1614 else
1615 {
1616 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001617 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001618 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001619 }
1620 }
1621 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1622 value = LLDB_INVALID_ADDRESS;
1623 }
1624 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001625 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001626 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001627 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1628 static_cast<void*>(value_sp.get()), value);
1629
Enrico Granata9128ee22011-09-06 19:20:51 +00001630 return value;
1631}
1632
1633lldb::SBAddress
1634SBValue::GetAddress()
1635{
1636 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001637 ValueLocker locker;
1638 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001639 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001640 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001641 TargetSP target_sp (value_sp->GetTargetSP());
1642 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001643 {
1644 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001645 const bool scalar_is_load_address = true;
1646 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001647 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001648 if (addr_type == eAddressTypeFile)
1649 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001650 ModuleSP module_sp (value_sp->GetModule());
1651 if (module_sp)
1652 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001653 }
1654 else if (addr_type == eAddressTypeLoad)
1655 {
1656 // no need to check the return value on this.. if it can actually do the resolve
1657 // addr will be in the form (section,offset), otherwise it will simply be returned
1658 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001659 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001660 }
1661 }
1662 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001663 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001664 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001665 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1666 static_cast<void*>(value_sp.get()),
1667 (addr.GetSection()
1668 ? addr.GetSection()->GetName().GetCString()
1669 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001670 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001671 return SBAddress(new Address(addr));
1672}
1673
1674lldb::SBData
1675SBValue::GetPointeeData (uint32_t item_idx,
1676 uint32_t item_count)
1677{
Greg Clayton5160ce52013-03-27 23:08:40 +00001678 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001679 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001680 ValueLocker locker;
1681 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001682 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001683 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001684 TargetSP target_sp (value_sp->GetTargetSP());
1685 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001686 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001687 DataExtractorSP data_sp(new DataExtractor());
1688 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1689 if (data_sp->GetByteSize() > 0)
1690 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001691 }
1692 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001693 if (log)
1694 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001695 static_cast<void*>(value_sp.get()), item_idx, item_count,
1696 static_cast<void*>(sb_data.get()));
1697
Enrico Granata9128ee22011-09-06 19:20:51 +00001698 return sb_data;
1699}
1700
1701lldb::SBData
1702SBValue::GetData ()
1703{
Greg Clayton5160ce52013-03-27 23:08:40 +00001704 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001705 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001706 ValueLocker locker;
1707 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001708 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001709 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001710 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001711 Error error;
1712 value_sp->GetData(*data_sp, error);
1713 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001714 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001715 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001716 if (log)
1717 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001718 static_cast<void*>(value_sp.get()),
1719 static_cast<void*>(sb_data.get()));
1720
Enrico Granata9128ee22011-09-06 19:20:51 +00001721 return sb_data;
1722}
Greg Clayton1b282f92011-10-13 18:08:26 +00001723
Sean Callanan389823e2013-04-13 01:21:23 +00001724bool
1725SBValue::SetData (lldb::SBData &data, SBError &error)
1726{
1727 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001728 ValueLocker locker;
1729 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001730 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001731
Sean Callanan389823e2013-04-13 01:21:23 +00001732 if (value_sp)
1733 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001734 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001735
Jim Ingham362e39a2013-05-15 02:16:21 +00001736 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001737 {
1738 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001739 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1740 static_cast<void*>(value_sp.get()));
1741
Jim Ingham362e39a2013-05-15 02:16:21 +00001742 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001743 ret = false;
1744 }
1745 else
1746 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001747 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001748
Jim Ingham362e39a2013-05-15 02:16:21 +00001749 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001750
Jim Ingham362e39a2013-05-15 02:16:21 +00001751 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001752 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001753 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001754 ret = false;
1755 }
Sean Callanan389823e2013-04-13 01:21:23 +00001756 }
1757 }
1758 else
1759 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001760 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001761 ret = false;
1762 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001763
Sean Callanan389823e2013-04-13 01:21:23 +00001764 if (log)
1765 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001766 static_cast<void*>(value_sp.get()),
1767 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001768 return ret;
1769}
1770
Enrico Granata10de0902012-10-10 22:54:17 +00001771lldb::SBDeclaration
1772SBValue::GetDeclaration ()
1773{
Jim Ingham362e39a2013-05-15 02:16:21 +00001774 ValueLocker locker;
1775 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001776 SBDeclaration decl_sb;
1777 if (value_sp)
1778 {
1779 Declaration decl;
1780 if (value_sp->GetDeclaration(decl))
1781 decl_sb.SetDeclaration(decl);
1782 }
1783 return decl_sb;
1784}
1785
Greg Clayton1b282f92011-10-13 18:08:26 +00001786lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001787SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001788{
Greg Clayton81e871e2012-02-04 02:27:34 +00001789 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001790
Greg Clayton81e871e2012-02-04 02:27:34 +00001791 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001792 ValueLocker locker;
1793 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001794 TargetSP target_sp (GetTarget().GetSP());
1795 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001796 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001797 // Read and Write cannot both be false.
1798 if (!read && !write)
1799 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001800
Greg Clayton81e871e2012-02-04 02:27:34 +00001801 // If the value is not in scope, don't try and watch and invalid value
1802 if (!IsInScope())
1803 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001804
Greg Clayton81e871e2012-02-04 02:27:34 +00001805 addr_t addr = GetLoadAddress();
1806 if (addr == LLDB_INVALID_ADDRESS)
1807 return sb_watchpoint;
1808 size_t byte_size = GetByteSize();
1809 if (byte_size == 0)
1810 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001811
Greg Clayton81e871e2012-02-04 02:27:34 +00001812 uint32_t watch_type = 0;
1813 if (read)
1814 watch_type |= LLDB_WATCH_TYPE_READ;
1815 if (write)
1816 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001817
Johnny Chenb90827e2012-06-04 23:19:54 +00001818 Error rc;
Greg Clayton99558cc42015-08-24 23:46:31 +00001819 CompilerType type (value_sp->GetCompilerType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001820 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001821 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001822
Daniel Maleae0f8f572013-08-26 23:57:52 +00001823 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001824 {
1825 sb_watchpoint.SetSP (watchpoint_sp);
1826 Declaration decl;
1827 if (value_sp->GetDeclaration (decl))
1828 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001829 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001830 {
1831 StreamString ss;
1832 // True to show fullpath for declaration file.
1833 decl.DumpStopContext(&ss, true);
1834 watchpoint_sp->SetDeclInfo(ss.GetString());
1835 }
1836 }
1837 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001838 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001839 else if (target_sp)
1840 {
1841 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1842 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001843 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1844 static_cast<void*>(value_sp.get()),
1845 locker.GetError().AsCString());
1846
Jim Ingham362e39a2013-05-15 02:16:21 +00001847 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1848 }
1849 else
1850 {
1851 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1852 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001853 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1854 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001855 error.SetErrorString("could not set watchpoint, a target is required");
1856 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001857
Greg Clayton1b282f92011-10-13 18:08:26 +00001858 return sb_watchpoint;
1859}
1860
Johnny Chend3761a72012-06-04 23:45:50 +00001861// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1862// Backward compatibility fix in the interim.
1863lldb::SBWatchpoint
1864SBValue::Watch (bool resolve_location, bool read, bool write)
1865{
Johnny Chen974759f2012-06-05 00:14:15 +00001866 SBError error;
1867 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001868}
1869
Greg Clayton1b282f92011-10-13 18:08:26 +00001870lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001871SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001872{
Greg Clayton81e871e2012-02-04 02:27:34 +00001873 SBWatchpoint sb_watchpoint;
1874 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001875 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001876 return sb_watchpoint;
1877}
Enrico Granata0c10a852014-12-08 23:13:56 +00001878
1879lldb::SBValue
1880SBValue::Persist ()
1881{
1882 ValueLocker locker;
1883 lldb::ValueObjectSP value_sp(GetSP(locker));
1884 SBValue persisted_sb;
1885 if (value_sp)
1886 {
1887 persisted_sb.SetSP(value_sp->Persist());
1888 }
1889 return persisted_sb;
1890}