blob: 112954ebc21738c50d251dc4c0d05355aa6d808c [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) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000064 m_valobj_sp(in_valobj_sp),
65 m_use_dynamic(use_dynamic),
66 m_use_synthetic(use_synthetic),
67 m_name (name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000068 {
Jim Ingham362e39a2013-05-15 02:16:21 +000069 if (!m_name.IsEmpty() && m_valobj_sp)
70 m_valobj_sp->SetName(m_name);
Enrico Granata19f0e8c2013-04-22 22:57:56 +000071 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000072
Enrico Granata19f0e8c2013-04-22 22:57:56 +000073 ValueImpl (const ValueImpl& rhs) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000074 m_valobj_sp(rhs.m_valobj_sp),
75 m_use_dynamic(rhs.m_use_dynamic),
76 m_use_synthetic(rhs.m_use_synthetic),
77 m_name (rhs.m_name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000078 {
79 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000080
Enrico Granata19f0e8c2013-04-22 22:57:56 +000081 ValueImpl &
82 operator = (const ValueImpl &rhs)
83 {
84 if (this != &rhs)
Enrico Granatae3e91512012-10-22 18:18:36 +000085 {
Jim Ingham362e39a2013-05-15 02:16:21 +000086 m_valobj_sp = rhs.m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +000087 m_use_dynamic = rhs.m_use_dynamic;
88 m_use_synthetic = rhs.m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +000089 m_name = rhs.m_name;
Enrico Granatae3e91512012-10-22 18:18:36 +000090 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +000091 return *this;
92 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000093
Enrico Granata19f0e8c2013-04-22 22:57:56 +000094 bool
95 IsValid ()
96 {
Jim Ingham793d8d92013-12-06 22:21:04 +000097 if (m_valobj_sp.get() == NULL)
98 return false;
99 else
100 {
101 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
102 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
103 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
104 // invalid after you call this...
105 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
106 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
107 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
108 // tracking that in all the ValueObject subclasses.
109 TargetSP target_sp = m_valobj_sp->GetTargetSP();
110 if (target_sp && target_sp->IsValid())
111 return true;
112 else
113 return false;
114 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000115 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000116
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000117 lldb::ValueObjectSP
118 GetRootSP ()
119 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000120 return m_valobj_sp;
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
Jim Ingham362e39a2013-05-15 02:16:21 +0000124 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000125 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000126 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
127 if (!m_valobj_sp)
128 {
129 error.SetErrorString("invalid value object");
130 return m_valobj_sp;
131 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000132
Jim Ingham362e39a2013-05-15 02:16:21 +0000133 lldb::ValueObjectSP value_sp = m_valobj_sp;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000134
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000135 Target *target = value_sp->GetTargetSP().get();
136 if (target)
Jim Ingham362e39a2013-05-15 02:16:21 +0000137 api_locker.Lock(target->GetAPIMutex());
Jim Ingham793d8d92013-12-06 22:21:04 +0000138 else
139 return ValueObjectSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000140
Jim Ingham362e39a2013-05-15 02:16:21 +0000141 ProcessSP process_sp(value_sp->GetProcessSP());
142 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
143 {
144 // We don't allow people to play around with ValueObject if the process is running.
145 // If you want to look at values, pause the process, then look.
146 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000147 log->Printf ("SBValue(%p)::GetSP() => error: process is running",
148 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000149 error.SetErrorString ("process must be stopped.");
150 return ValueObjectSP();
151 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000152
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000153 if (value_sp->GetDynamicValue(m_use_dynamic))
154 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
155 if (value_sp->GetSyntheticValue(m_use_synthetic))
156 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
Jim Ingham362e39a2013-05-15 02:16:21 +0000157 if (!value_sp)
158 error.SetErrorString("invalid value object");
159 if (!m_name.IsEmpty())
160 value_sp->SetName(m_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000161
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000162 return value_sp;
163 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000164
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000165 void
166 SetUseDynamic (lldb::DynamicValueType use_dynamic)
167 {
168 m_use_dynamic = use_dynamic;
169 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000170
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000171 void
172 SetUseSynthetic (bool use_synthetic)
173 {
174 m_use_synthetic = use_synthetic;
175 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000176
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000177 lldb::DynamicValueType
178 GetUseDynamic ()
179 {
180 return m_use_dynamic;
181 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000182
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000183 bool
184 GetUseSynthetic ()
185 {
186 return m_use_synthetic;
187 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000188
Jim Ingham362e39a2013-05-15 02:16:21 +0000189 // All the derived values that we would make from the m_valobj_sp will share
190 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
191 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
192 // provide simple accessors for these, which I do here.
193 TargetSP
194 GetTargetSP ()
195 {
196 if (m_valobj_sp)
197 return m_valobj_sp->GetTargetSP();
198 else
199 return TargetSP();
200 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000201
Jim Ingham362e39a2013-05-15 02:16:21 +0000202 ProcessSP
203 GetProcessSP ()
204 {
205 if (m_valobj_sp)
206 return m_valobj_sp->GetProcessSP();
207 else
208 return ProcessSP();
209 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000210
Jim Ingham362e39a2013-05-15 02:16:21 +0000211 ThreadSP
212 GetThreadSP ()
213 {
214 if (m_valobj_sp)
215 return m_valobj_sp->GetThreadSP();
216 else
217 return ThreadSP();
218 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000219
Jason Molendab57e4a12013-11-04 09:33:30 +0000220 StackFrameSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000221 GetFrameSP ()
222 {
223 if (m_valobj_sp)
224 return m_valobj_sp->GetFrameSP();
225 else
Jason Molendab57e4a12013-11-04 09:33:30 +0000226 return StackFrameSP();
Jim Ingham362e39a2013-05-15 02:16:21 +0000227 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000228
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000229private:
Jim Ingham362e39a2013-05-15 02:16:21 +0000230 lldb::ValueObjectSP m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000231 lldb::DynamicValueType m_use_dynamic;
232 bool m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000233 ConstString m_name;
234};
235
236class ValueLocker
237{
238public:
239 ValueLocker ()
240 {
241 }
242
243 ValueObjectSP
244 GetLockedSP(ValueImpl &in_value)
245 {
246 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
247 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000248
Jim Ingham362e39a2013-05-15 02:16:21 +0000249 Error &
250 GetError()
251 {
252 return m_lock_error;
253 }
254
255private:
256 Process::StopLocker m_stop_locker;
257 Mutex::Locker m_api_locker;
258 Error m_lock_error;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000259
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000260};
Enrico Granatae3e91512012-10-22 18:18:36 +0000261
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000262SBValue::SBValue () :
Daniel Maleae0f8f572013-08-26 23:57:52 +0000263m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264{
265}
266
Enrico Granatac5bc4122012-03-27 02:35:13 +0000267SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000268{
Enrico Granatae3e91512012-10-22 18:18:36 +0000269 SetSP(value_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270}
271
Enrico Granatac5bc4122012-03-27 02:35:13 +0000272SBValue::SBValue(const SBValue &rhs)
Greg Claytonefabb122010-11-05 23:17:00 +0000273{
Enrico Granatae3e91512012-10-22 18:18:36 +0000274 SetSP(rhs.m_opaque_sp);
Greg Claytonefabb122010-11-05 23:17:00 +0000275}
276
Greg Claytonbf2331c2011-09-09 23:04:00 +0000277SBValue &
Greg Claytonefabb122010-11-05 23:17:00 +0000278SBValue::operator = (const SBValue &rhs)
279{
280 if (this != &rhs)
Enrico Granatac5bc4122012-03-27 02:35:13 +0000281 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000282 SetSP(rhs.m_opaque_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000283 }
Greg Claytonefabb122010-11-05 23:17:00 +0000284 return *this;
285}
286
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000287SBValue::~SBValue()
288{
289}
290
291bool
Greg Claytonbf2331c2011-09-09 23:04:00 +0000292SBValue::IsValid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000293{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000294 // If this function ever changes to anything that does more than just
295 // check if the opaque shared pointer is non NULL, then we need to update
296 // all "if (m_opaque_sp)" code in this file.
Jim Ingham793d8d92013-12-06 22:21:04 +0000297 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298}
299
Jim Ingham5d3bca42011-12-19 20:39:44 +0000300void
301SBValue::Clear()
302{
303 m_opaque_sp.reset();
304}
305
Greg Clayton524e60b2010-10-06 22:10:17 +0000306SBError
307SBValue::GetError()
308{
309 SBError sb_error;
310
Jim Ingham362e39a2013-05-15 02:16:21 +0000311 ValueLocker locker;
312 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000313 if (value_sp)
314 sb_error.SetError(value_sp->GetError());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000315 else
Jim Ingham362e39a2013-05-15 02:16:21 +0000316 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
Greg Clayton524e60b2010-10-06 22:10:17 +0000317
318 return sb_error;
319}
320
Johnny Chenb0b8be72011-07-07 20:46:23 +0000321user_id_t
322SBValue::GetID()
323{
Jim Ingham362e39a2013-05-15 02:16:21 +0000324 ValueLocker locker;
325 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000326 if (value_sp)
327 return value_sp->GetID();
Johnny Chenb0b8be72011-07-07 20:46:23 +0000328 return LLDB_INVALID_UID;
329}
330
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000331const char *
332SBValue::GetName()
333{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000334 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000335 ValueLocker locker;
336 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000337 if (value_sp)
338 name = value_sp->GetName().GetCString();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000339
Greg Clayton5160ce52013-03-27 23:08:40 +0000340 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton93aa84e2010-10-29 04:59:35 +0000341 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000342 {
343 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000344 log->Printf ("SBValue(%p)::GetName () => \"%s\"",
345 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000346 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000347 log->Printf ("SBValue(%p)::GetName () => NULL",
348 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000349 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000350
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000351 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352}
353
354const char *
355SBValue::GetTypeName ()
356{
Greg Clayton5160ce52013-03-27 23:08:40 +0000357 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000358 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000359 ValueLocker locker;
360 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000361 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000362 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000363 name = value_sp->GetQualifiedTypeName().GetCString();
Jim Ingham48cdc582012-08-21 01:46:35 +0000364 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000365
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000366 if (log)
367 {
368 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000369 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
370 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000371 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000372 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
373 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000374 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000375
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000376 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000377}
378
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000379const char *
380SBValue::GetDisplayTypeName ()
381{
382 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
383 const char *name = NULL;
384 ValueLocker locker;
385 lldb::ValueObjectSP value_sp(GetSP(locker));
386 if (value_sp)
387 {
388 name = value_sp->GetDisplayTypeName().GetCString();
389 }
390
391 if (log)
392 {
393 if (name)
394 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
395 static_cast<void*>(value_sp.get()), name);
396 else
397 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
398 static_cast<void*>(value_sp.get()));
399 }
400
401 return name;
402}
403
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404size_t
405SBValue::GetByteSize ()
406{
Greg Clayton5160ce52013-03-27 23:08:40 +0000407 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000409
Jim Ingham362e39a2013-05-15 02:16:21 +0000410 ValueLocker locker;
411 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000412 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000413 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000414 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000415 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000416
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000417 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000418 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
419 static_cast<void*>(value_sp.get()),
420 static_cast<uint64_t>(result));
421
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000422 return result;
423}
424
425bool
Jim Ingham6035b672011-03-31 00:19:25 +0000426SBValue::IsInScope ()
427{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000429
Jim Ingham362e39a2013-05-15 02:16:21 +0000430 ValueLocker locker;
431 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000432 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000433 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000434 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000435 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000436
Greg Clayton5160ce52013-03-27 23:08:40 +0000437 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000438 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000439 log->Printf ("SBValue(%p)::IsInScope () => %i",
440 static_cast<void*>(value_sp.get()), result);
441
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 return result;
443}
444
445const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000446SBValue::GetValue ()
447{
Greg Clayton5160ce52013-03-27 23:08:40 +0000448 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000449
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000450 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000451 ValueLocker locker;
452 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000453 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000454 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000455 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000456 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000457 if (log)
458 {
459 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000460 log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
461 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000462 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000463 log->Printf ("SBValue(%p)::GetValue() => NULL",
464 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000465 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000466
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000467 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000468}
469
Greg Clayton73b472d2010-10-27 03:32:59 +0000470ValueType
471SBValue::GetValueType ()
472{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000473 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000474 ValueLocker locker;
475 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000476 if (value_sp)
477 result = value_sp->GetValueType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000478
Greg Clayton5160ce52013-03-27 23:08:40 +0000479 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000480 if (log)
481 {
482 switch (result)
483 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000484 case eValueTypeInvalid:
485 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
486 static_cast<void*>(value_sp.get()));
487 break;
488 case eValueTypeVariableGlobal:
489 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
490 static_cast<void*>(value_sp.get()));
491 break;
492 case eValueTypeVariableStatic:
493 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
494 static_cast<void*>(value_sp.get()));
495 break;
496 case eValueTypeVariableArgument:
497 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
498 static_cast<void*>(value_sp.get()));
499 break;
500 case eValueTypeVariableLocal:
501 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
502 static_cast<void*>(value_sp.get()));
503 break;
504 case eValueTypeRegister:
505 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
506 static_cast<void*>(value_sp.get()));
507 break;
508 case eValueTypeRegisterSet:
509 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
510 static_cast<void*>(value_sp.get()));
511 break;
512 case eValueTypeConstResult:
513 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
514 static_cast<void*>(value_sp.get()));
515 break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000516 }
517 }
518 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000519}
520
Jim Ingham53c47f12010-09-10 23:12:17 +0000521const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000522SBValue::GetObjectDescription ()
523{
Greg Clayton5160ce52013-03-27 23:08:40 +0000524 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000525 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000526 ValueLocker locker;
527 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000528 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000529 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000530 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000531 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000532 if (log)
533 {
534 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000535 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
536 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000537 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000538 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
539 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000540 }
541 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000542}
543
Enrico Granataedc44142014-09-06 01:30:04 +0000544const char *
545SBValue::GetTypeValidatorResult ()
546{
547 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
548 const char *cstr = NULL;
549 ValueLocker locker;
550 lldb::ValueObjectSP value_sp(GetSP(locker));
551 if (value_sp)
552 {
553 const auto& validation(value_sp->GetValidationStatus());
554 if (TypeValidatorResult::Failure == validation.first)
555 {
556 if (validation.second.empty())
557 cstr = "unknown error";
558 else
559 cstr = validation.second.c_str();
560 }
561 }
562 if (log)
563 {
564 if (cstr)
565 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
566 static_cast<void*>(value_sp.get()), cstr);
567 else
568 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
569 static_cast<void*>(value_sp.get()));
570 }
571 return cstr;
572}
573
Enrico Granata6f3533f2011-07-29 19:53:35 +0000574SBType
575SBValue::GetType()
576{
Greg Clayton5160ce52013-03-27 23:08:40 +0000577 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000578 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000579 ValueLocker locker;
580 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000581 TypeImplSP type_sp;
582 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000583 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000584 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000585 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000586 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000587 if (log)
588 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000589 if (type_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000590 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
591 static_cast<void*>(value_sp.get()),
592 static_cast<void*>(type_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000593 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000594 log->Printf ("SBValue(%p)::GetType => NULL",
595 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000596 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000597 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000598}
599
Jim Ingham6035b672011-03-31 00:19:25 +0000600bool
601SBValue::GetValueDidChange ()
602{
Greg Clayton5160ce52013-03-27 23:08:40 +0000603 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000604 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000605 ValueLocker locker;
606 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000607 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000608 {
Ilia K761a7a42015-02-06 18:10:30 +0000609 if (value_sp->UpdateValueIfNeeded(false))
610 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000611 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000612 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000613 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
614 static_cast<void*>(value_sp.get()), result);
615
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000616 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000617}
618
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000619#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000620const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000621SBValue::GetSummary ()
622{
Greg Clayton5160ce52013-03-27 23:08:40 +0000623 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000624 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000625 ValueLocker locker;
626 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000627 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000628 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000629 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000630 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000631 if (log)
632 {
633 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000634 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
635 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000636 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000637 log->Printf ("SBValue(%p)::GetSummary() => NULL",
638 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000639 }
640 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000641}
Enrico Granatac1247f52014-11-06 21:23:20 +0000642
643const char *
Enrico Granata49bfafb2014-11-18 23:36:25 +0000644SBValue::GetSummary (lldb::SBStream& stream,
645 lldb::SBTypeSummaryOptions& options)
Enrico Granatac1247f52014-11-06 21:23:20 +0000646{
647 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granatac1247f52014-11-06 21:23:20 +0000648 ValueLocker locker;
649 lldb::ValueObjectSP value_sp(GetSP(locker));
650 if (value_sp)
651 {
Enrico Granata49bfafb2014-11-18 23:36:25 +0000652 std::string buffer;
653 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
654 stream.Printf("%s",buffer.c_str());
Enrico Granatac1247f52014-11-06 21:23:20 +0000655 }
Enrico Granata49bfafb2014-11-18 23:36:25 +0000656 const char* cstr = stream.GetData();
Enrico Granatac1247f52014-11-06 21:23:20 +0000657 if (log)
658 {
659 if (cstr)
660 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
661 static_cast<void*>(value_sp.get()), cstr);
662 else
663 log->Printf ("SBValue(%p)::GetSummary() => NULL",
664 static_cast<void*>(value_sp.get()));
665 }
666 return cstr;
667}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000668#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000669
670const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000671SBValue::GetLocation ()
672{
Greg Clayton5160ce52013-03-27 23:08:40 +0000673 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000674 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000675 ValueLocker locker;
676 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000677 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000678 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000679 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000680 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000681 if (log)
682 {
683 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000684 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
685 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000686 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000687 log->Printf ("SBValue(%p)::GetLocation() => NULL",
688 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000689 }
690 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691}
692
Enrico Granata07a4ac22012-05-08 21:25:06 +0000693// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000694bool
Jim Ingham6035b672011-03-31 00:19:25 +0000695SBValue::SetValueFromCString (const char *value_str)
696{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000697 lldb::SBError dummy;
698 return SetValueFromCString(value_str,dummy);
699}
700
701bool
702SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
703{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000705 ValueLocker locker;
706 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000707 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000708 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000709 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000710 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000711 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000712 else
713 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000714
Greg Claytonc9858e42012-04-06 02:17:47 +0000715 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000716 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
717 static_cast<void*>(value_sp.get()), value_str, success);
718
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000719 return success;
720}
721
Enrico Granata864e3e82012-02-17 03:18:30 +0000722lldb::SBTypeFormat
723SBValue::GetTypeFormat ()
724{
725 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000726 ValueLocker locker;
727 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000728 if (value_sp)
729 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000730 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000731 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000732 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
733 if (format_sp)
734 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000735 }
736 }
737 return format;
738}
739
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000740#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000741lldb::SBTypeSummary
742SBValue::GetTypeSummary ()
743{
744 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000745 ValueLocker locker;
746 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000747 if (value_sp)
748 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000749 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000750 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000751 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
752 if (summary_sp)
753 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000754 }
755 }
756 return summary;
757}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000758#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000759
760lldb::SBTypeFilter
761SBValue::GetTypeFilter ()
762{
763 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000764 ValueLocker locker;
765 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000766 if (value_sp)
767 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000768 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000769 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000770 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
771
772 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000773 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000774 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
775 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000776 }
777 }
778 }
779 return filter;
780}
781
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000782#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000783lldb::SBTypeSynthetic
784SBValue::GetTypeSynthetic ()
785{
786 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000787 ValueLocker locker;
788 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000789 if (value_sp)
790 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000791 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000792 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000793 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
794
795 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000796 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000797 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
798 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000799 }
800 }
801 }
802 return synthetic;
803}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000804#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000805
Enrico Granata6f3533f2011-07-29 19:53:35 +0000806lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000807SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000808{
Greg Clayton81e871e2012-02-04 02:27:34 +0000809 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000810 ValueLocker locker;
811 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000812 lldb::ValueObjectSP new_value_sp;
813 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000814 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000815 TypeImplSP type_sp (type.GetSP());
816 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000817 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000818 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000819 }
820 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000821 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000822 if (log)
823 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000824 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000825 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000826 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000827 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000828 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000829 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000830 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000831 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000832 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000833}
834
835lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000836SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000837{
Greg Claytonef496d52012-01-31 04:25:15 +0000838 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000839 ValueLocker locker;
840 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000841 TypeImplSP type_sp (type.GetSP());
842 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000843 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000844 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000845}
846
847lldb::SBValue
848SBValue::CreateValueFromExpression (const char *name, const char* expression)
849{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000850 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000851 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000852 return CreateValueFromExpression (name, expression, options);
853}
854
855lldb::SBValue
856SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
857{
Greg Clayton5160ce52013-03-27 23:08:40 +0000858 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000859 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000860 ValueLocker locker;
861 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000862 lldb::ValueObjectSP new_value_sp;
863 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000864 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000865 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000866 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
867 if (new_value_sp)
868 new_value_sp->SetName(ConstString(name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000869 }
Enrico Granata972be532014-12-17 21:18:43 +0000870 sb_value.SetSP(new_value_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000871 if (log)
872 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000873 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000874 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000875 static_cast<void*>(value_sp.get()), name, expression,
876 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000877 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000878 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000879 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000880 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000881 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000882}
883
884lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000885SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000886{
Greg Clayton81e871e2012-02-04 02:27:34 +0000887 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000888 ValueLocker locker;
889 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000890 lldb::ValueObjectSP new_value_sp;
891 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
892 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000893 {
Enrico Granata972be532014-12-17 21:18:43 +0000894 ClangASTType ast_type(type_impl_sp->GetClangASTType(true));
895 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
896 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000897 }
Enrico Granata972be532014-12-17 21:18:43 +0000898 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000899 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000900 if (log)
901 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000902 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000903 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
904 static_cast<void*>(value_sp.get()),
905 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000906 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000907 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
908 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000909 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000910 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000911}
912
Enrico Granata9128ee22011-09-06 19:20:51 +0000913lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000914SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000915{
Greg Clayton81e871e2012-02-04 02:27:34 +0000916 lldb::SBValue sb_value;
917 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000918 ValueLocker locker;
919 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000920 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000921 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000922 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000923 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true));
Greg Clayton81e871e2012-02-04 02:27:34 +0000924 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
Enrico Granata9128ee22011-09-06 19:20:51 +0000925 }
Enrico Granata972be532014-12-17 21:18:43 +0000926 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000927 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000928 if (log)
929 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000930 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000931 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
932 static_cast<void*>(value_sp.get()),
933 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000934 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000935 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
936 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000937 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000938 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000939}
940
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000941SBValue
942SBValue::GetChildAtIndex (uint32_t idx)
943{
Greg Claytonf66024822011-07-15 19:31:49 +0000944 const bool can_create_synthetic = false;
945 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000946 TargetSP target_sp;
947 if (m_opaque_sp)
948 target_sp = m_opaque_sp->GetTargetSP();
949
950 if (target_sp)
951 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000952
Greg Claytonf66024822011-07-15 19:31:49 +0000953 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000954}
955
956SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000957SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000958{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000959 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000960 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000961
Jim Ingham362e39a2013-05-15 02:16:21 +0000962 ValueLocker locker;
963 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000964 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000965 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000966 const bool can_create = true;
967 child_sp = value_sp->GetChildAtIndex (idx, can_create);
968 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000969 {
Bruce Mitchener11d86362015-02-26 23:55:39 +0000970 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create);
Jim Ingham78a685a2011-04-16 00:01:13 +0000971 }
972 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000973
Enrico Granatae3e91512012-10-22 18:18:36 +0000974 SBValue sb_value;
975 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000976 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000977 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
978 static_cast<void*>(value_sp.get()), idx,
979 static_cast<void*>(value_sp.get()));
980
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000981 return sb_value;
982}
983
984uint32_t
985SBValue::GetIndexOfChildWithName (const char *name)
986{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000987 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000988 ValueLocker locker;
989 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000990 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000991 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000992 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +0000993 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000994 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000995 if (log)
996 {
997 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000998 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
999 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001000 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001001 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1002 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001003 }
1004 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001005}
1006
1007SBValue
1008SBValue::GetChildMemberWithName (const char *name)
1009{
Jim Ingham362e39a2013-05-15 02:16:21 +00001010 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1011 TargetSP target_sp;
1012 if (m_opaque_sp)
1013 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001014
Jim Ingham362e39a2013-05-15 02:16:21 +00001015 if (target_sp)
1016 use_dynamic_value = target_sp->GetPreferDynamicValue();
1017 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +00001018}
1019
1020SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001021SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001022{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001023 lldb::ValueObjectSP child_sp;
1024 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001025
Greg Clayton5160ce52013-03-27 23:08:40 +00001026 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001027
Jim Ingham362e39a2013-05-15 02:16:21 +00001028 ValueLocker locker;
1029 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001030 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001032 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +00001033 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001034
Enrico Granatae3e91512012-10-22 18:18:36 +00001035 SBValue sb_value;
1036 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001037
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001038 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001039 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1040 static_cast<void*>(value_sp.get()), name,
1041 static_cast<void*>(value_sp.get()));
1042
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001043 return sb_value;
1044}
1045
Enrico Granataf2bbf712011-07-15 02:26:42 +00001046lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001047SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1048{
Enrico Granatae3e91512012-10-22 18:18:36 +00001049 SBValue value_sb;
1050 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001051 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001052 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1053 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001054 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001055 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001056}
1057
1058lldb::SBValue
1059SBValue::GetStaticValue ()
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(),eNoDynamicValues,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
Enrico Granatac5bc4122012-03-27 02:35:13 +00001070lldb::SBValue
1071SBValue::GetNonSyntheticValue ()
1072{
Enrico Granatae3e91512012-10-22 18:18:36 +00001073 SBValue value_sb;
1074 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001075 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001076 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1077 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001078 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001079 return value_sb;
1080}
1081
1082lldb::DynamicValueType
1083SBValue::GetPreferDynamicValue ()
1084{
1085 if (!IsValid())
1086 return eNoDynamicValues;
1087 return m_opaque_sp->GetUseDynamic();
1088}
1089
1090void
1091SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1092{
1093 if (IsValid())
1094 return m_opaque_sp->SetUseDynamic (use_dynamic);
1095}
1096
1097bool
1098SBValue::GetPreferSyntheticValue ()
1099{
1100 if (!IsValid())
1101 return false;
1102 return m_opaque_sp->GetUseSynthetic();
1103}
1104
1105void
1106SBValue::SetPreferSyntheticValue (bool use_synthetic)
1107{
1108 if (IsValid())
1109 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001110}
1111
Jim Ingham60dbabb2011-12-08 19:44:08 +00001112bool
1113SBValue::IsDynamic()
1114{
Jim Ingham362e39a2013-05-15 02:16:21 +00001115 ValueLocker locker;
1116 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001117 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001118 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001119 return false;
1120}
1121
Enrico Granatae3e91512012-10-22 18:18:36 +00001122bool
1123SBValue::IsSynthetic ()
1124{
Jim Ingham362e39a2013-05-15 02:16:21 +00001125 ValueLocker locker;
1126 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001127 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001128 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001129 return false;
1130}
1131
Jim Ingham60dbabb2011-12-08 19:44:08 +00001132lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001133SBValue::GetValueForExpressionPath(const char* expr_path)
1134{
Greg Clayton5160ce52013-03-27 23:08:40 +00001135 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001136 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001137 ValueLocker locker;
1138 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001139 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001140 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001141 // using default values for all the fancy options, just do it if you can
1142 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001143 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001144
Enrico Granatae3e91512012-10-22 18:18:36 +00001145 SBValue sb_value;
1146 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001147
Enrico Granataf2bbf712011-07-15 02:26:42 +00001148 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001149 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1150 static_cast<void*>(value_sp.get()), expr_path,
1151 static_cast<void*>(value_sp.get()));
1152
Enrico Granataf2bbf712011-07-15 02:26:42 +00001153 return sb_value;
1154}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155
Greg Claytonfe42ac42011-08-03 22:57:10 +00001156int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001157SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1158{
Jim Ingham16e0c682011-08-12 23:34:31 +00001159 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001160 ValueLocker locker;
1161 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001162 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001163 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001164 bool success = true;
1165 uint64_t ret_val = fail_value;
1166 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1167 if (!success)
1168 error.SetErrorString("could not resolve value");
1169 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001170 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001171 else
1172 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1173
Enrico Granata6fd87d52011-08-04 01:41:02 +00001174 return fail_value;
1175}
1176
1177uint64_t
1178SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1179{
Jim Ingham16e0c682011-08-12 23:34:31 +00001180 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001181 ValueLocker locker;
1182 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001183 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001184 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001185 bool success = true;
1186 uint64_t ret_val = fail_value;
1187 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1188 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001189 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001190 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001191 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001192 else
1193 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1194
Enrico Granata6fd87d52011-08-04 01:41:02 +00001195 return fail_value;
1196}
1197
1198int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001199SBValue::GetValueAsSigned(int64_t fail_value)
1200{
Jim Ingham362e39a2013-05-15 02:16:21 +00001201 ValueLocker locker;
1202 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001203 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001204 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001205 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001206 }
1207 return fail_value;
1208}
1209
1210uint64_t
1211SBValue::GetValueAsUnsigned(uint64_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->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001218 }
1219 return fail_value;
1220}
1221
Greg Clayton4a792072012-10-23 01:50:10 +00001222bool
1223SBValue::MightHaveChildren ()
1224{
Greg Clayton5160ce52013-03-27 23:08:40 +00001225 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001226 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001227 ValueLocker locker;
1228 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001229 if (value_sp)
1230 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001231
Greg Clayton4a792072012-10-23 01:50:10 +00001232 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001233 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1234 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001235 return has_children;
1236}
1237
Enrico Granata560558e2015-02-11 02:35:39 +00001238bool
1239SBValue::IsRuntimeSupportValue ()
1240{
1241 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1242 bool is_support = false;
1243 ValueLocker locker;
1244 lldb::ValueObjectSP value_sp(GetSP(locker));
1245 if (value_sp)
1246 is_support = value_sp->IsRuntimeSupportValue();
1247
1248 if (log)
1249 log->Printf ("SBValue(%p)::IsRuntimeSupportValue() => %i",
1250 static_cast<void*>(value_sp.get()), is_support);
1251 return is_support;
1252}
1253
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001254uint32_t
1255SBValue::GetNumChildren ()
1256{
1257 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001258
Greg Clayton5160ce52013-03-27 23:08:40 +00001259 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001260 ValueLocker locker;
1261 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001262 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001263 num_children = value_sp->GetNumChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001264
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001265 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001266 log->Printf ("SBValue(%p)::GetNumChildren () => %u",
1267 static_cast<void*>(value_sp.get()), num_children);
1268
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001269 return num_children;
1270}
1271
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001272
1273SBValue
1274SBValue::Dereference ()
1275{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001276 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001277 ValueLocker locker;
1278 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001279 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001280 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001281 Error error;
1282 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001283 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001284 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001285 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001286 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1287 static_cast<void*>(value_sp.get()),
1288 static_cast<void*>(value_sp.get()));
1289
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001290 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001291}
1292
1293bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001294SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001295{
1296 bool is_ptr_type = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001297
Jim Ingham362e39a2013-05-15 02:16:21 +00001298 ValueLocker locker;
1299 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001300 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001301 is_ptr_type = value_sp->IsPointerType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001302
Greg Clayton5160ce52013-03-27 23:08:40 +00001303 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001304 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001305 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i",
1306 static_cast<void*>(value_sp.get()), is_ptr_type);
1307
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001308 return is_ptr_type;
1309}
1310
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311void *
1312SBValue::GetOpaqueType()
1313{
Jim Ingham362e39a2013-05-15 02:16:21 +00001314 ValueLocker locker;
1315 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001316 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001317 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001318 return NULL;
1319}
1320
Enrico Granata6f3533f2011-07-29 19:53:35 +00001321lldb::SBTarget
1322SBValue::GetTarget()
1323{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001324 SBTarget sb_target;
1325 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001326 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001327 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001328 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001329 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001330 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001331 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001332 if (log)
1333 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001334 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001335 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1336 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001337 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001338 log->Printf ("SBValue(%p)::GetTarget () => %p",
1339 static_cast<void*>(m_opaque_sp.get()),
1340 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001341 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001342 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001343}
1344
1345lldb::SBProcess
1346SBValue::GetProcess()
1347{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001348 SBProcess sb_process;
1349 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001350 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001351 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001352 process_sp = m_opaque_sp->GetProcessSP();
1353 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001354 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001355 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001356 if (log)
1357 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001358 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001359 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1360 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001361 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001362 log->Printf ("SBValue(%p)::GetProcess () => %p",
1363 static_cast<void*>(m_opaque_sp.get()),
1364 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001365 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001366 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001367}
1368
1369lldb::SBThread
1370SBValue::GetThread()
1371{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001372 SBThread sb_thread;
1373 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001374 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001375 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001376 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001377 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001378 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001379 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001380 if (log)
1381 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001382 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001383 log->Printf ("SBValue(%p)::GetThread () => NULL",
1384 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001385 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001386 log->Printf ("SBValue(%p)::GetThread () => %p",
1387 static_cast<void*>(m_opaque_sp.get()),
1388 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001389 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001390 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001391}
1392
1393lldb::SBFrame
1394SBValue::GetFrame()
1395{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001396 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001397 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001398 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001399 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001400 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001401 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001402 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001403 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001404 if (log)
1405 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001406 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001407 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1408 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001409 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001410 log->Printf ("SBValue(%p)::GetFrame () => %p",
1411 static_cast<void*>(m_opaque_sp.get()),
1412 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001413 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001414 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001415}
1416
1417
Greg Clayton81e871e2012-02-04 02:27:34 +00001418lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001419SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001420{
Enrico Granatae3e91512012-10-22 18:18:36 +00001421 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1422 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001423 return locker.GetLockedSP(*m_opaque_sp.get());
1424}
1425
1426lldb::ValueObjectSP
1427SBValue::GetSP () const
1428{
1429 ValueLocker locker;
1430 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001431}
1432
1433void
1434SBValue::SetSP (ValueImplSP impl_sp)
1435{
1436 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001437}
1438
Greg Clayton81e871e2012-02-04 02:27:34 +00001439void
1440SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001441{
Enrico Granatae3e91512012-10-22 18:18:36 +00001442 if (sp)
1443 {
1444 lldb::TargetSP target_sp(sp->GetTargetSP());
1445 if (target_sp)
1446 {
1447 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1448 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1449 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1450 }
1451 else
1452 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1453 }
1454 else
1455 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001456}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001457
Enrico Granatae3e91512012-10-22 18:18:36 +00001458void
1459SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1460{
1461 if (sp)
1462 {
1463 lldb::TargetSP target_sp(sp->GetTargetSP());
1464 if (target_sp)
1465 {
1466 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1467 SetSP (sp, use_dynamic, use_synthetic);
1468 }
1469 else
1470 SetSP (sp, use_dynamic, true);
1471 }
1472 else
1473 SetSP (sp, use_dynamic, false);
1474}
1475
1476void
1477SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1478{
1479 if (sp)
1480 {
1481 lldb::TargetSP target_sp(sp->GetTargetSP());
1482 if (target_sp)
1483 {
1484 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1485 SetSP (sp, use_dynamic, use_synthetic);
1486 }
1487 else
1488 SetSP (sp, eNoDynamicValues, use_synthetic);
1489 }
1490 else
1491 SetSP (sp, eNoDynamicValues, use_synthetic);
1492}
1493
1494void
1495SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1496{
1497 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1498}
Greg Clayton81e871e2012-02-04 02:27:34 +00001499
Jim Ingham362e39a2013-05-15 02:16:21 +00001500void
1501SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1502{
1503 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1504}
1505
Caroline Ticedde9cff2010-09-20 05:20:02 +00001506bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001507SBValue::GetExpressionPath (SBStream &description)
1508{
Jim Ingham362e39a2013-05-15 02:16:21 +00001509 ValueLocker locker;
1510 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001511 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001512 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001513 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001514 return true;
1515 }
1516 return false;
1517}
1518
1519bool
1520SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1521{
Jim Ingham362e39a2013-05-15 02:16:21 +00001522 ValueLocker locker;
1523 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001524 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001525 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001526 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001527 return true;
1528 }
1529 return false;
1530}
1531
1532bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001533SBValue::GetDescription (SBStream &description)
1534{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001535 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001536
Jim Ingham362e39a2013-05-15 02:16:21 +00001537 ValueLocker locker;
1538 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001539 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001540 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001541 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001542 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001543
Caroline Ticedde9cff2010-09-20 05:20:02 +00001544 return true;
1545}
Greg Claytondc4e9632011-01-05 18:43:15 +00001546
1547lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001548SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001549{
Jim Ingham362e39a2013-05-15 02:16:21 +00001550 ValueLocker locker;
1551 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001552 if (value_sp)
1553 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001554 return eFormatDefault;
1555}
1556
1557void
1558SBValue::SetFormat (lldb::Format format)
1559{
Jim Ingham362e39a2013-05-15 02:16:21 +00001560 ValueLocker locker;
1561 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001562 if (value_sp)
1563 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001564}
1565
Enrico Granata6f3533f2011-07-29 19:53:35 +00001566lldb::SBValue
1567SBValue::AddressOf()
1568{
1569 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001570 ValueLocker locker;
1571 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001572 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001573 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001574 Error error;
1575 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001576 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001577 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001578 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001579 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1580 static_cast<void*>(value_sp.get()),
1581 static_cast<void*>(value_sp.get()));
1582
Enrico Granata6f3533f2011-07-29 19:53:35 +00001583 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001584}
Enrico Granata9128ee22011-09-06 19:20:51 +00001585
1586lldb::addr_t
1587SBValue::GetLoadAddress()
1588{
1589 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001590 ValueLocker locker;
1591 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001592 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001593 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001594 TargetSP target_sp (value_sp->GetTargetSP());
1595 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001596 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001597 const bool scalar_is_load_address = true;
1598 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001599 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001600 if (addr_type == eAddressTypeFile)
1601 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001602 ModuleSP module_sp (value_sp->GetModule());
1603 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001604 value = LLDB_INVALID_ADDRESS;
1605 else
1606 {
1607 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001608 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001609 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001610 }
1611 }
1612 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1613 value = LLDB_INVALID_ADDRESS;
1614 }
1615 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001616 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001617 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001618 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1619 static_cast<void*>(value_sp.get()), value);
1620
Enrico Granata9128ee22011-09-06 19:20:51 +00001621 return value;
1622}
1623
1624lldb::SBAddress
1625SBValue::GetAddress()
1626{
1627 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001628 ValueLocker locker;
1629 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001630 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001631 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001632 TargetSP target_sp (value_sp->GetTargetSP());
1633 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001634 {
1635 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001636 const bool scalar_is_load_address = true;
1637 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001638 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001639 if (addr_type == eAddressTypeFile)
1640 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001641 ModuleSP module_sp (value_sp->GetModule());
1642 if (module_sp)
1643 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001644 }
1645 else if (addr_type == eAddressTypeLoad)
1646 {
1647 // no need to check the return value on this.. if it can actually do the resolve
1648 // addr will be in the form (section,offset), otherwise it will simply be returned
1649 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001650 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001651 }
1652 }
1653 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001654 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001655 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001656 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1657 static_cast<void*>(value_sp.get()),
1658 (addr.GetSection()
1659 ? addr.GetSection()->GetName().GetCString()
1660 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001661 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001662 return SBAddress(new Address(addr));
1663}
1664
1665lldb::SBData
1666SBValue::GetPointeeData (uint32_t item_idx,
1667 uint32_t item_count)
1668{
Greg Clayton5160ce52013-03-27 23:08:40 +00001669 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001670 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001671 ValueLocker locker;
1672 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001673 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001674 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001675 TargetSP target_sp (value_sp->GetTargetSP());
1676 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001677 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001678 DataExtractorSP data_sp(new DataExtractor());
1679 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1680 if (data_sp->GetByteSize() > 0)
1681 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001682 }
1683 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001684 if (log)
1685 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001686 static_cast<void*>(value_sp.get()), item_idx, item_count,
1687 static_cast<void*>(sb_data.get()));
1688
Enrico Granata9128ee22011-09-06 19:20:51 +00001689 return sb_data;
1690}
1691
1692lldb::SBData
1693SBValue::GetData ()
1694{
Greg Clayton5160ce52013-03-27 23:08:40 +00001695 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001696 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001697 ValueLocker locker;
1698 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001699 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001700 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001701 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001702 Error error;
1703 value_sp->GetData(*data_sp, error);
1704 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001705 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001706 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001707 if (log)
1708 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001709 static_cast<void*>(value_sp.get()),
1710 static_cast<void*>(sb_data.get()));
1711
Enrico Granata9128ee22011-09-06 19:20:51 +00001712 return sb_data;
1713}
Greg Clayton1b282f92011-10-13 18:08:26 +00001714
Sean Callanan389823e2013-04-13 01:21:23 +00001715bool
1716SBValue::SetData (lldb::SBData &data, SBError &error)
1717{
1718 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001719 ValueLocker locker;
1720 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001721 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001722
Sean Callanan389823e2013-04-13 01:21:23 +00001723 if (value_sp)
1724 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001725 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001726
Jim Ingham362e39a2013-05-15 02:16:21 +00001727 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001728 {
1729 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001730 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1731 static_cast<void*>(value_sp.get()));
1732
Jim Ingham362e39a2013-05-15 02:16:21 +00001733 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001734 ret = false;
1735 }
1736 else
1737 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001738 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001739
Jim Ingham362e39a2013-05-15 02:16:21 +00001740 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001741
Jim Ingham362e39a2013-05-15 02:16:21 +00001742 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001743 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001744 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001745 ret = false;
1746 }
Sean Callanan389823e2013-04-13 01:21:23 +00001747 }
1748 }
1749 else
1750 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001751 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001752 ret = false;
1753 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001754
Sean Callanan389823e2013-04-13 01:21:23 +00001755 if (log)
1756 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001757 static_cast<void*>(value_sp.get()),
1758 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001759 return ret;
1760}
1761
Enrico Granata10de0902012-10-10 22:54:17 +00001762lldb::SBDeclaration
1763SBValue::GetDeclaration ()
1764{
Jim Ingham362e39a2013-05-15 02:16:21 +00001765 ValueLocker locker;
1766 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001767 SBDeclaration decl_sb;
1768 if (value_sp)
1769 {
1770 Declaration decl;
1771 if (value_sp->GetDeclaration(decl))
1772 decl_sb.SetDeclaration(decl);
1773 }
1774 return decl_sb;
1775}
1776
Greg Clayton1b282f92011-10-13 18:08:26 +00001777lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001778SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001779{
Greg Clayton81e871e2012-02-04 02:27:34 +00001780 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001781
Greg Clayton81e871e2012-02-04 02:27:34 +00001782 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001783 ValueLocker locker;
1784 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001785 TargetSP target_sp (GetTarget().GetSP());
1786 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001787 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001788 // Read and Write cannot both be false.
1789 if (!read && !write)
1790 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001791
Greg Clayton81e871e2012-02-04 02:27:34 +00001792 // If the value is not in scope, don't try and watch and invalid value
1793 if (!IsInScope())
1794 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001795
Greg Clayton81e871e2012-02-04 02:27:34 +00001796 addr_t addr = GetLoadAddress();
1797 if (addr == LLDB_INVALID_ADDRESS)
1798 return sb_watchpoint;
1799 size_t byte_size = GetByteSize();
1800 if (byte_size == 0)
1801 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001802
Greg Clayton81e871e2012-02-04 02:27:34 +00001803 uint32_t watch_type = 0;
1804 if (read)
1805 watch_type |= LLDB_WATCH_TYPE_READ;
1806 if (write)
1807 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001808
Johnny Chenb90827e2012-06-04 23:19:54 +00001809 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001810 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001811 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001812 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001813
Daniel Maleae0f8f572013-08-26 23:57:52 +00001814 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001815 {
1816 sb_watchpoint.SetSP (watchpoint_sp);
1817 Declaration decl;
1818 if (value_sp->GetDeclaration (decl))
1819 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001820 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001821 {
1822 StreamString ss;
1823 // True to show fullpath for declaration file.
1824 decl.DumpStopContext(&ss, true);
1825 watchpoint_sp->SetDeclInfo(ss.GetString());
1826 }
1827 }
1828 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001829 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001830 else if (target_sp)
1831 {
1832 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1833 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001834 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1835 static_cast<void*>(value_sp.get()),
1836 locker.GetError().AsCString());
1837
Jim Ingham362e39a2013-05-15 02:16:21 +00001838 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1839 }
1840 else
1841 {
1842 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1843 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001844 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1845 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001846 error.SetErrorString("could not set watchpoint, a target is required");
1847 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001848
Greg Clayton1b282f92011-10-13 18:08:26 +00001849 return sb_watchpoint;
1850}
1851
Johnny Chend3761a72012-06-04 23:45:50 +00001852// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1853// Backward compatibility fix in the interim.
1854lldb::SBWatchpoint
1855SBValue::Watch (bool resolve_location, bool read, bool write)
1856{
Johnny Chen974759f2012-06-05 00:14:15 +00001857 SBError error;
1858 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001859}
1860
Greg Clayton1b282f92011-10-13 18:08:26 +00001861lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001862SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001863{
Greg Clayton81e871e2012-02-04 02:27:34 +00001864 SBWatchpoint sb_watchpoint;
1865 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001866 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001867 return sb_watchpoint;
1868}
Enrico Granata0c10a852014-12-08 23:13:56 +00001869
1870lldb::SBValue
1871SBValue::Persist ()
1872{
1873 ValueLocker locker;
1874 lldb::ValueObjectSP value_sp(GetSP(locker));
1875 SBValue persisted_sb;
1876 if (value_sp)
1877 {
1878 persisted_sb.SetSP(value_sp->Persist());
1879 }
1880 return persisted_sb;
1881}