blob: edecb93944ad4522ea82ae4006bcf477843d0554 [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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBValue.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000013
Enrico Granata10de0902012-10-10 22:54:17 +000014#include "lldb/API/SBDeclaration.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000016#include "lldb/API/SBTypeFilter.h"
17#include "lldb/API/SBTypeFormat.h"
18#include "lldb/API/SBTypeSummary.h"
19#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
Johnny Chen01a67862011-10-14 00:42:25 +000021#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/DataExtractor.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/Module.h"
Greg Claytonfe42ac42011-08-03 22:57:10 +000025#include "lldb/Core/Scalar.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Stream.h"
28#include "lldb/Core/StreamFile.h"
29#include "lldb/Core/Value.h"
30#include "lldb/Core/ValueObject.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000031#include "lldb/Core/ValueObjectConstResult.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000032#include "lldb/DataFormatters/DataVisualization.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Symbol/Block.h"
Enrico Granata10de0902012-10-10 22:54:17 +000034#include "lldb/Symbol/Declaration.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Symbol/ObjectFile.h"
Greg Clayton81e871e2012-02-04 02:27:34 +000036#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Symbol/Variable.h"
Johnny Chen01a67862011-10-14 00:42:25 +000038#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/ExecutionContext.h"
40#include "lldb/Target/Process.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000041#include "lldb/Target/StackFrame.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000042#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Thread.h"
44
Jim Ingham35e1bda2012-10-16 21:41:58 +000045#include "lldb/API/SBDebugger.h"
46#include "lldb/API/SBExpressionOptions.h"
47#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000048#include "lldb/API/SBProcess.h"
49#include "lldb/API/SBTarget.h"
50#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
Enrico Granata19f0e8c2013-04-22 22:57:56 +000055class ValueImpl
56{
57public:
58 ValueImpl ()
Enrico Granatae3e91512012-10-22 18:18:36 +000059 {
Enrico Granata19f0e8c2013-04-22 22:57:56 +000060 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000061
Jim Ingham362e39a2013-05-15 02:16:21 +000062 ValueImpl (lldb::ValueObjectSP in_valobj_sp,
Enrico Granata19f0e8c2013-04-22 22:57:56 +000063 lldb::DynamicValueType use_dynamic,
Jim Ingham362e39a2013-05-15 02:16:21 +000064 bool use_synthetic,
65 const char *name = NULL) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000066 m_valobj_sp(in_valobj_sp),
67 m_use_dynamic(use_dynamic),
68 m_use_synthetic(use_synthetic),
69 m_name (name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000070 {
Jim Ingham362e39a2013-05-15 02:16:21 +000071 if (!m_name.IsEmpty() && m_valobj_sp)
72 m_valobj_sp->SetName(m_name);
Enrico Granata19f0e8c2013-04-22 22:57:56 +000073 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000074
Enrico Granata19f0e8c2013-04-22 22:57:56 +000075 ValueImpl (const ValueImpl& rhs) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000076 m_valobj_sp(rhs.m_valobj_sp),
77 m_use_dynamic(rhs.m_use_dynamic),
78 m_use_synthetic(rhs.m_use_synthetic),
79 m_name (rhs.m_name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000080 {
81 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000082
Enrico Granata19f0e8c2013-04-22 22:57:56 +000083 ValueImpl &
84 operator = (const ValueImpl &rhs)
85 {
86 if (this != &rhs)
Enrico Granatae3e91512012-10-22 18:18:36 +000087 {
Jim Ingham362e39a2013-05-15 02:16:21 +000088 m_valobj_sp = rhs.m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +000089 m_use_dynamic = rhs.m_use_dynamic;
90 m_use_synthetic = rhs.m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +000091 m_name = rhs.m_name;
Enrico Granatae3e91512012-10-22 18:18:36 +000092 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +000093 return *this;
94 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000095
Enrico Granata19f0e8c2013-04-22 22:57:56 +000096 bool
97 IsValid ()
98 {
Jim Ingham793d8d92013-12-06 22:21:04 +000099 if (m_valobj_sp.get() == NULL)
100 return false;
101 else
102 {
103 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
104 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
105 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
106 // invalid after you call this...
107 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
108 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
109 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
110 // tracking that in all the ValueObject subclasses.
111 TargetSP target_sp = m_valobj_sp->GetTargetSP();
112 if (target_sp && target_sp->IsValid())
113 return true;
114 else
115 return false;
116 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000117 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000118
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000119 lldb::ValueObjectSP
120 GetRootSP ()
121 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000122 return m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000123 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000124
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000125 lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000126 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000127 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000128 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
129 if (!m_valobj_sp)
130 {
131 error.SetErrorString("invalid value object");
132 return m_valobj_sp;
133 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000134
Jim Ingham362e39a2013-05-15 02:16:21 +0000135 lldb::ValueObjectSP value_sp = m_valobj_sp;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000136
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000137 Target *target = value_sp->GetTargetSP().get();
138 if (target)
Jim Ingham362e39a2013-05-15 02:16:21 +0000139 api_locker.Lock(target->GetAPIMutex());
Jim Ingham793d8d92013-12-06 22:21:04 +0000140 else
141 return ValueObjectSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000142
Jim Ingham362e39a2013-05-15 02:16:21 +0000143 ProcessSP process_sp(value_sp->GetProcessSP());
144 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
145 {
146 // We don't allow people to play around with ValueObject if the process is running.
147 // If you want to look at values, pause the process, then look.
148 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000149 log->Printf ("SBValue(%p)::GetSP() => error: process is running",
150 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000151 error.SetErrorString ("process must be stopped.");
152 return ValueObjectSP();
153 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000154
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000155 if (value_sp->GetDynamicValue(m_use_dynamic))
156 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
157 if (value_sp->GetSyntheticValue(m_use_synthetic))
158 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
Jim Ingham362e39a2013-05-15 02:16:21 +0000159 if (!value_sp)
160 error.SetErrorString("invalid value object");
161 if (!m_name.IsEmpty())
162 value_sp->SetName(m_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000163
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000164 return value_sp;
165 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000166
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000167 void
168 SetUseDynamic (lldb::DynamicValueType use_dynamic)
169 {
170 m_use_dynamic = use_dynamic;
171 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000172
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000173 void
174 SetUseSynthetic (bool use_synthetic)
175 {
176 m_use_synthetic = use_synthetic;
177 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000178
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000179 lldb::DynamicValueType
180 GetUseDynamic ()
181 {
182 return m_use_dynamic;
183 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000184
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000185 bool
186 GetUseSynthetic ()
187 {
188 return m_use_synthetic;
189 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000190
Jim Ingham362e39a2013-05-15 02:16:21 +0000191 // All the derived values that we would make from the m_valobj_sp will share
192 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
193 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
194 // provide simple accessors for these, which I do here.
195 TargetSP
196 GetTargetSP ()
197 {
198 if (m_valobj_sp)
199 return m_valobj_sp->GetTargetSP();
200 else
201 return TargetSP();
202 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000203
Jim Ingham362e39a2013-05-15 02:16:21 +0000204 ProcessSP
205 GetProcessSP ()
206 {
207 if (m_valobj_sp)
208 return m_valobj_sp->GetProcessSP();
209 else
210 return ProcessSP();
211 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000212
Jim Ingham362e39a2013-05-15 02:16:21 +0000213 ThreadSP
214 GetThreadSP ()
215 {
216 if (m_valobj_sp)
217 return m_valobj_sp->GetThreadSP();
218 else
219 return ThreadSP();
220 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000221
Jason Molendab57e4a12013-11-04 09:33:30 +0000222 StackFrameSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000223 GetFrameSP ()
224 {
225 if (m_valobj_sp)
226 return m_valobj_sp->GetFrameSP();
227 else
Jason Molendab57e4a12013-11-04 09:33:30 +0000228 return StackFrameSP();
Jim Ingham362e39a2013-05-15 02:16:21 +0000229 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000230
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000231private:
Jim Ingham362e39a2013-05-15 02:16:21 +0000232 lldb::ValueObjectSP m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000233 lldb::DynamicValueType m_use_dynamic;
234 bool m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000235 ConstString m_name;
236};
237
238class ValueLocker
239{
240public:
241 ValueLocker ()
242 {
243 }
244
245 ValueObjectSP
246 GetLockedSP(ValueImpl &in_value)
247 {
248 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
249 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000250
Jim Ingham362e39a2013-05-15 02:16:21 +0000251 Error &
252 GetError()
253 {
254 return m_lock_error;
255 }
256
257private:
258 Process::StopLocker m_stop_locker;
259 Mutex::Locker m_api_locker;
260 Error m_lock_error;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000261
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000262};
Enrico Granatae3e91512012-10-22 18:18:36 +0000263
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264SBValue::SBValue () :
Daniel Maleae0f8f572013-08-26 23:57:52 +0000265m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266{
267}
268
Enrico Granatac5bc4122012-03-27 02:35:13 +0000269SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270{
Enrico Granatae3e91512012-10-22 18:18:36 +0000271 SetSP(value_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272}
273
Enrico Granatac5bc4122012-03-27 02:35:13 +0000274SBValue::SBValue(const SBValue &rhs)
Greg Claytonefabb122010-11-05 23:17:00 +0000275{
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 SetSP(rhs.m_opaque_sp);
Greg Claytonefabb122010-11-05 23:17:00 +0000277}
278
Greg Claytonbf2331c2011-09-09 23:04:00 +0000279SBValue &
Greg Claytonefabb122010-11-05 23:17:00 +0000280SBValue::operator = (const SBValue &rhs)
281{
282 if (this != &rhs)
Enrico Granatac5bc4122012-03-27 02:35:13 +0000283 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000284 SetSP(rhs.m_opaque_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000285 }
Greg Claytonefabb122010-11-05 23:17:00 +0000286 return *this;
287}
288
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289SBValue::~SBValue()
290{
291}
292
293bool
Greg Claytonbf2331c2011-09-09 23:04:00 +0000294SBValue::IsValid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000296 // If this function ever changes to anything that does more than just
297 // check if the opaque shared pointer is non NULL, then we need to update
298 // all "if (m_opaque_sp)" code in this file.
Jim Ingham793d8d92013-12-06 22:21:04 +0000299 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300}
301
Jim Ingham5d3bca42011-12-19 20:39:44 +0000302void
303SBValue::Clear()
304{
305 m_opaque_sp.reset();
306}
307
Greg Clayton524e60b2010-10-06 22:10:17 +0000308SBError
309SBValue::GetError()
310{
311 SBError sb_error;
312
Jim Ingham362e39a2013-05-15 02:16:21 +0000313 ValueLocker locker;
314 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000315 if (value_sp)
316 sb_error.SetError(value_sp->GetError());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000317 else
Jim Ingham362e39a2013-05-15 02:16:21 +0000318 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
Greg Clayton524e60b2010-10-06 22:10:17 +0000319
320 return sb_error;
321}
322
Johnny Chenb0b8be72011-07-07 20:46:23 +0000323user_id_t
324SBValue::GetID()
325{
Jim Ingham362e39a2013-05-15 02:16:21 +0000326 ValueLocker locker;
327 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000328 if (value_sp)
329 return value_sp->GetID();
Johnny Chenb0b8be72011-07-07 20:46:23 +0000330 return LLDB_INVALID_UID;
331}
332
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333const char *
334SBValue::GetName()
335{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000336 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000337 ValueLocker locker;
338 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000339 if (value_sp)
340 name = value_sp->GetName().GetCString();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000341
Greg Clayton5160ce52013-03-27 23:08:40 +0000342 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton93aa84e2010-10-29 04:59:35 +0000343 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000344 {
345 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000346 log->Printf ("SBValue(%p)::GetName () => \"%s\"",
347 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000348 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000349 log->Printf ("SBValue(%p)::GetName () => NULL",
350 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000351 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000352
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000353 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354}
355
356const char *
357SBValue::GetTypeName ()
358{
Greg Clayton5160ce52013-03-27 23:08:40 +0000359 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000360 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000361 ValueLocker locker;
362 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000363 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000364 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000365 name = value_sp->GetQualifiedTypeName().GetCString();
Jim Ingham48cdc582012-08-21 01:46:35 +0000366 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000367
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000368 if (log)
369 {
370 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000371 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
372 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000373 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000374 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
375 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000376 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000377
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000378 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379}
380
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000381const char *
382SBValue::GetDisplayTypeName ()
383{
384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
385 const char *name = NULL;
386 ValueLocker locker;
387 lldb::ValueObjectSP value_sp(GetSP(locker));
388 if (value_sp)
389 {
390 name = value_sp->GetDisplayTypeName().GetCString();
391 }
392
393 if (log)
394 {
395 if (name)
396 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
397 static_cast<void*>(value_sp.get()), name);
398 else
399 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
400 static_cast<void*>(value_sp.get()));
401 }
402
403 return name;
404}
405
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406size_t
407SBValue::GetByteSize ()
408{
Greg Clayton5160ce52013-03-27 23:08:40 +0000409 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000411
Jim Ingham362e39a2013-05-15 02:16:21 +0000412 ValueLocker locker;
413 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000414 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000415 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000416 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000417 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000418
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000419 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000420 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
421 static_cast<void*>(value_sp.get()),
422 static_cast<uint64_t>(result));
423
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 return result;
425}
426
427bool
Jim Ingham6035b672011-03-31 00:19:25 +0000428SBValue::IsInScope ()
429{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000431
Jim Ingham362e39a2013-05-15 02:16:21 +0000432 ValueLocker locker;
433 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000434 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000435 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000436 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000437 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000438
Greg Clayton5160ce52013-03-27 23:08:40 +0000439 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000440 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000441 log->Printf ("SBValue(%p)::IsInScope () => %i",
442 static_cast<void*>(value_sp.get()), result);
443
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 return result;
445}
446
447const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000448SBValue::GetValue ()
449{
Greg Clayton5160ce52013-03-27 23:08:40 +0000450 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000451
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000452 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000453 ValueLocker locker;
454 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000455 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000456 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000457 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000458 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000459 if (log)
460 {
461 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000462 log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
463 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000464 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000465 log->Printf ("SBValue(%p)::GetValue() => NULL",
466 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000467 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000468
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000469 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470}
471
Greg Clayton73b472d2010-10-27 03:32:59 +0000472ValueType
473SBValue::GetValueType ()
474{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000475 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000476 ValueLocker locker;
477 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000478 if (value_sp)
479 result = value_sp->GetValueType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000480
Greg Clayton5160ce52013-03-27 23:08:40 +0000481 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000482 if (log)
483 {
484 switch (result)
485 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000486 case eValueTypeInvalid:
487 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
488 static_cast<void*>(value_sp.get()));
489 break;
490 case eValueTypeVariableGlobal:
491 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
492 static_cast<void*>(value_sp.get()));
493 break;
494 case eValueTypeVariableStatic:
495 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
496 static_cast<void*>(value_sp.get()));
497 break;
498 case eValueTypeVariableArgument:
499 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
500 static_cast<void*>(value_sp.get()));
501 break;
502 case eValueTypeVariableLocal:
503 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
504 static_cast<void*>(value_sp.get()));
505 break;
506 case eValueTypeRegister:
507 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
508 static_cast<void*>(value_sp.get()));
509 break;
510 case eValueTypeRegisterSet:
511 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
512 static_cast<void*>(value_sp.get()));
513 break;
514 case eValueTypeConstResult:
515 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
516 static_cast<void*>(value_sp.get()));
517 break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000518 }
519 }
520 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000521}
522
Jim Ingham53c47f12010-09-10 23:12:17 +0000523const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000524SBValue::GetObjectDescription ()
525{
Greg Clayton5160ce52013-03-27 23:08:40 +0000526 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000527 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000528 ValueLocker locker;
529 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000530 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000531 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000532 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000533 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000534 if (log)
535 {
536 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000537 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
538 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000539 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000540 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
541 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000542 }
543 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000544}
545
Enrico Granataedc44142014-09-06 01:30:04 +0000546const char *
547SBValue::GetTypeValidatorResult ()
548{
549 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
550 const char *cstr = NULL;
551 ValueLocker locker;
552 lldb::ValueObjectSP value_sp(GetSP(locker));
553 if (value_sp)
554 {
555 const auto& validation(value_sp->GetValidationStatus());
556 if (TypeValidatorResult::Failure == validation.first)
557 {
558 if (validation.second.empty())
559 cstr = "unknown error";
560 else
561 cstr = validation.second.c_str();
562 }
563 }
564 if (log)
565 {
566 if (cstr)
567 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
568 static_cast<void*>(value_sp.get()), cstr);
569 else
570 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
571 static_cast<void*>(value_sp.get()));
572 }
573 return cstr;
574}
575
Enrico Granata6f3533f2011-07-29 19:53:35 +0000576SBType
577SBValue::GetType()
578{
Greg Clayton5160ce52013-03-27 23:08:40 +0000579 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000580 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000581 ValueLocker locker;
582 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000583 TypeImplSP type_sp;
584 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000585 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000586 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000587 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000588 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000589 if (log)
590 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000591 if (type_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000592 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
593 static_cast<void*>(value_sp.get()),
594 static_cast<void*>(type_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000595 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000596 log->Printf ("SBValue(%p)::GetType => NULL",
597 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000598 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000599 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000600}
601
Jim Ingham6035b672011-03-31 00:19:25 +0000602bool
603SBValue::GetValueDidChange ()
604{
Greg Clayton5160ce52013-03-27 23:08:40 +0000605 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000606 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000607 ValueLocker locker;
608 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000609 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000610 {
Ilia K761a7a42015-02-06 18:10:30 +0000611 if (value_sp->UpdateValueIfNeeded(false))
612 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000613 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000614 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000615 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
616 static_cast<void*>(value_sp.get()), result);
617
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000618 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000619}
620
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000621#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000622const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000623SBValue::GetSummary ()
624{
Greg Clayton5160ce52013-03-27 23:08:40 +0000625 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000626 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000627 ValueLocker locker;
628 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000629 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000630 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000631 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000632 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000633 if (log)
634 {
635 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000636 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
637 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000638 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000639 log->Printf ("SBValue(%p)::GetSummary() => NULL",
640 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000641 }
642 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000643}
Enrico Granatac1247f52014-11-06 21:23:20 +0000644
645const char *
Enrico Granata49bfafb2014-11-18 23:36:25 +0000646SBValue::GetSummary (lldb::SBStream& stream,
647 lldb::SBTypeSummaryOptions& options)
Enrico Granatac1247f52014-11-06 21:23:20 +0000648{
649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granatac1247f52014-11-06 21:23:20 +0000650 ValueLocker locker;
651 lldb::ValueObjectSP value_sp(GetSP(locker));
652 if (value_sp)
653 {
Enrico Granata49bfafb2014-11-18 23:36:25 +0000654 std::string buffer;
655 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
656 stream.Printf("%s",buffer.c_str());
Enrico Granatac1247f52014-11-06 21:23:20 +0000657 }
Enrico Granata49bfafb2014-11-18 23:36:25 +0000658 const char* cstr = stream.GetData();
Enrico Granatac1247f52014-11-06 21:23:20 +0000659 if (log)
660 {
661 if (cstr)
662 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
663 static_cast<void*>(value_sp.get()), cstr);
664 else
665 log->Printf ("SBValue(%p)::GetSummary() => NULL",
666 static_cast<void*>(value_sp.get()));
667 }
668 return cstr;
669}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000670#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000671
672const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000673SBValue::GetLocation ()
674{
Greg Clayton5160ce52013-03-27 23:08:40 +0000675 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000676 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000677 ValueLocker locker;
678 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000679 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000680 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000681 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000682 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000683 if (log)
684 {
685 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000686 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
687 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000688 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000689 log->Printf ("SBValue(%p)::GetLocation() => NULL",
690 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000691 }
692 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693}
694
Enrico Granata07a4ac22012-05-08 21:25:06 +0000695// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696bool
Jim Ingham6035b672011-03-31 00:19:25 +0000697SBValue::SetValueFromCString (const char *value_str)
698{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000699 lldb::SBError dummy;
700 return SetValueFromCString(value_str,dummy);
701}
702
703bool
704SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
705{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000707 ValueLocker locker;
708 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000709 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000710 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000711 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000712 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000713 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000714 else
715 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000716
Greg Claytonc9858e42012-04-06 02:17:47 +0000717 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000718 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
719 static_cast<void*>(value_sp.get()), value_str, success);
720
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000721 return success;
722}
723
Enrico Granata864e3e82012-02-17 03:18:30 +0000724lldb::SBTypeFormat
725SBValue::GetTypeFormat ()
726{
727 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000728 ValueLocker locker;
729 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000730 if (value_sp)
731 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000732 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000733 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000734 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
735 if (format_sp)
736 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000737 }
738 }
739 return format;
740}
741
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000742#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000743lldb::SBTypeSummary
744SBValue::GetTypeSummary ()
745{
746 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000747 ValueLocker locker;
748 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000749 if (value_sp)
750 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000751 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000752 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000753 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
754 if (summary_sp)
755 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000756 }
757 }
758 return summary;
759}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000760#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000761
762lldb::SBTypeFilter
763SBValue::GetTypeFilter ()
764{
765 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000766 ValueLocker locker;
767 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000768 if (value_sp)
769 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000770 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000771 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000772 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
773
774 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000775 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000776 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
777 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000778 }
779 }
780 }
781 return filter;
782}
783
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000784#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000785lldb::SBTypeSynthetic
786SBValue::GetTypeSynthetic ()
787{
788 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000789 ValueLocker locker;
790 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000791 if (value_sp)
792 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000793 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000794 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000795 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
796
797 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000798 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000799 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
800 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000801 }
802 }
803 }
804 return synthetic;
805}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000806#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000807
Enrico Granata6f3533f2011-07-29 19:53:35 +0000808lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000809SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000810{
Greg Clayton81e871e2012-02-04 02:27:34 +0000811 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000812 ValueLocker locker;
813 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000814 lldb::ValueObjectSP new_value_sp;
815 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000816 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000817 TypeImplSP type_sp (type.GetSP());
818 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000819 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000820 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000821 }
822 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000823 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000824 if (log)
825 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000826 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000827 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000828 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000829 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000830 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000831 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000832 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000833 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000834 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000835}
836
837lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000838SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000839{
Greg Claytonef496d52012-01-31 04:25:15 +0000840 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000841 ValueLocker locker;
842 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000843 TypeImplSP type_sp (type.GetSP());
844 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000845 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000846 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000847}
848
849lldb::SBValue
850SBValue::CreateValueFromExpression (const char *name, const char* expression)
851{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000852 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000853 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000854 return CreateValueFromExpression (name, expression, options);
855}
856
857lldb::SBValue
858SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
859{
Greg Clayton5160ce52013-03-27 23:08:40 +0000860 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000861 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000862 ValueLocker locker;
863 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000864 lldb::ValueObjectSP new_value_sp;
865 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000866 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000867 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000868 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
869 if (new_value_sp)
870 new_value_sp->SetName(ConstString(name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000871 }
Enrico Granata972be532014-12-17 21:18:43 +0000872 sb_value.SetSP(new_value_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000873 if (log)
874 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000875 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000876 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000877 static_cast<void*>(value_sp.get()), name, expression,
878 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000879 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000880 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000881 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000882 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000883 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000884}
885
886lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000887SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000888{
Greg Clayton81e871e2012-02-04 02:27:34 +0000889 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000890 ValueLocker locker;
891 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000892 lldb::ValueObjectSP new_value_sp;
893 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
894 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000895 {
Enrico Granata972be532014-12-17 21:18:43 +0000896 ClangASTType ast_type(type_impl_sp->GetClangASTType(true));
897 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
898 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000899 }
Enrico Granata972be532014-12-17 21:18:43 +0000900 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000901 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000902 if (log)
903 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000904 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000905 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
906 static_cast<void*>(value_sp.get()),
907 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000908 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000909 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
910 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000911 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000912 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000913}
914
Enrico Granata9128ee22011-09-06 19:20:51 +0000915lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000916SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000917{
Greg Clayton81e871e2012-02-04 02:27:34 +0000918 lldb::SBValue sb_value;
919 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000920 ValueLocker locker;
921 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000922 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000923 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000924 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000925 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true));
Greg Clayton81e871e2012-02-04 02:27:34 +0000926 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
Enrico Granata9128ee22011-09-06 19:20:51 +0000927 }
Enrico Granata972be532014-12-17 21:18:43 +0000928 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000929 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000930 if (log)
931 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000932 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000933 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
934 static_cast<void*>(value_sp.get()),
935 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000936 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000937 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
938 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000939 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000940 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000941}
942
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000943SBValue
944SBValue::GetChildAtIndex (uint32_t idx)
945{
Greg Claytonf66024822011-07-15 19:31:49 +0000946 const bool can_create_synthetic = false;
947 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000948 TargetSP target_sp;
949 if (m_opaque_sp)
950 target_sp = m_opaque_sp->GetTargetSP();
951
952 if (target_sp)
953 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000954
Greg Claytonf66024822011-07-15 19:31:49 +0000955 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000956}
957
958SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000959SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000960{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000961 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000962 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000963
Jim Ingham362e39a2013-05-15 02:16:21 +0000964 ValueLocker locker;
965 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000966 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000968 const bool can_create = true;
969 child_sp = value_sp->GetChildAtIndex (idx, can_create);
970 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000971 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000972 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000973 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000974 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
975 }
976 else if (value_sp->IsArrayType())
977 {
978 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000979 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000980 }
981 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000982
Enrico Granatae3e91512012-10-22 18:18:36 +0000983 SBValue sb_value;
984 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000985 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000986 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
987 static_cast<void*>(value_sp.get()), idx,
988 static_cast<void*>(value_sp.get()));
989
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000990 return sb_value;
991}
992
993uint32_t
994SBValue::GetIndexOfChildWithName (const char *name)
995{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000996 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000997 ValueLocker locker;
998 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000999 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +00001000 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001001 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +00001002 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001003 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001004 if (log)
1005 {
1006 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001007 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1008 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001009 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001010 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1011 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001012 }
1013 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001014}
1015
1016SBValue
1017SBValue::GetChildMemberWithName (const char *name)
1018{
Jim Ingham362e39a2013-05-15 02:16:21 +00001019 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1020 TargetSP target_sp;
1021 if (m_opaque_sp)
1022 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001023
Jim Ingham362e39a2013-05-15 02:16:21 +00001024 if (target_sp)
1025 use_dynamic_value = target_sp->GetPreferDynamicValue();
1026 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +00001027}
1028
1029SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001030SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001031{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001032 lldb::ValueObjectSP child_sp;
1033 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001034
Greg Clayton5160ce52013-03-27 23:08:40 +00001035 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001036
Jim Ingham362e39a2013-05-15 02:16:21 +00001037 ValueLocker locker;
1038 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001039 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001040 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001041 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +00001042 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001043
Enrico Granatae3e91512012-10-22 18:18:36 +00001044 SBValue sb_value;
1045 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001046
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001047 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001048 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1049 static_cast<void*>(value_sp.get()), name,
1050 static_cast<void*>(value_sp.get()));
1051
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001052 return sb_value;
1053}
1054
Enrico Granataf2bbf712011-07-15 02:26:42 +00001055lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001056SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1057{
Enrico Granatae3e91512012-10-22 18:18:36 +00001058 SBValue value_sb;
1059 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001060 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001061 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1062 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001063 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001064 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001065}
1066
1067lldb::SBValue
1068SBValue::GetStaticValue ()
1069{
Enrico Granatae3e91512012-10-22 18:18:36 +00001070 SBValue value_sb;
1071 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001072 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001073 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1074 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001075 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001076 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001077}
1078
Enrico Granatac5bc4122012-03-27 02:35:13 +00001079lldb::SBValue
1080SBValue::GetNonSyntheticValue ()
1081{
Enrico Granatae3e91512012-10-22 18:18:36 +00001082 SBValue value_sb;
1083 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001084 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001085 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1086 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001087 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001088 return value_sb;
1089}
1090
1091lldb::DynamicValueType
1092SBValue::GetPreferDynamicValue ()
1093{
1094 if (!IsValid())
1095 return eNoDynamicValues;
1096 return m_opaque_sp->GetUseDynamic();
1097}
1098
1099void
1100SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1101{
1102 if (IsValid())
1103 return m_opaque_sp->SetUseDynamic (use_dynamic);
1104}
1105
1106bool
1107SBValue::GetPreferSyntheticValue ()
1108{
1109 if (!IsValid())
1110 return false;
1111 return m_opaque_sp->GetUseSynthetic();
1112}
1113
1114void
1115SBValue::SetPreferSyntheticValue (bool use_synthetic)
1116{
1117 if (IsValid())
1118 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001119}
1120
Jim Ingham60dbabb2011-12-08 19:44:08 +00001121bool
1122SBValue::IsDynamic()
1123{
Jim Ingham362e39a2013-05-15 02:16:21 +00001124 ValueLocker locker;
1125 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001126 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001127 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001128 return false;
1129}
1130
Enrico Granatae3e91512012-10-22 18:18:36 +00001131bool
1132SBValue::IsSynthetic ()
1133{
Jim Ingham362e39a2013-05-15 02:16:21 +00001134 ValueLocker locker;
1135 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001136 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001137 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001138 return false;
1139}
1140
Jim Ingham60dbabb2011-12-08 19:44:08 +00001141lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001142SBValue::GetValueForExpressionPath(const char* expr_path)
1143{
Greg Clayton5160ce52013-03-27 23:08:40 +00001144 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001145 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001146 ValueLocker locker;
1147 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001148 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001149 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001150 // using default values for all the fancy options, just do it if you can
1151 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001152 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001153
Enrico Granatae3e91512012-10-22 18:18:36 +00001154 SBValue sb_value;
1155 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001156
Enrico Granataf2bbf712011-07-15 02:26:42 +00001157 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001158 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1159 static_cast<void*>(value_sp.get()), expr_path,
1160 static_cast<void*>(value_sp.get()));
1161
Enrico Granataf2bbf712011-07-15 02:26:42 +00001162 return sb_value;
1163}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164
Greg Claytonfe42ac42011-08-03 22:57:10 +00001165int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001166SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1167{
Jim Ingham16e0c682011-08-12 23:34:31 +00001168 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001169 ValueLocker locker;
1170 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001171 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001172 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001173 bool success = true;
1174 uint64_t ret_val = fail_value;
1175 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1176 if (!success)
1177 error.SetErrorString("could not resolve value");
1178 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001179 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001180 else
1181 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1182
Enrico Granata6fd87d52011-08-04 01:41:02 +00001183 return fail_value;
1184}
1185
1186uint64_t
1187SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1188{
Jim Ingham16e0c682011-08-12 23:34:31 +00001189 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001190 ValueLocker locker;
1191 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001192 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001193 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001194 bool success = true;
1195 uint64_t ret_val = fail_value;
1196 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1197 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001198 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001199 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001200 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001201 else
1202 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1203
Enrico Granata6fd87d52011-08-04 01:41:02 +00001204 return fail_value;
1205}
1206
1207int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001208SBValue::GetValueAsSigned(int64_t fail_value)
1209{
Jim Ingham362e39a2013-05-15 02:16:21 +00001210 ValueLocker locker;
1211 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001212 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001213 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001214 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001215 }
1216 return fail_value;
1217}
1218
1219uint64_t
1220SBValue::GetValueAsUnsigned(uint64_t fail_value)
1221{
Jim Ingham362e39a2013-05-15 02:16:21 +00001222 ValueLocker locker;
1223 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001224 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001225 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001226 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001227 }
1228 return fail_value;
1229}
1230
Greg Clayton4a792072012-10-23 01:50:10 +00001231bool
1232SBValue::MightHaveChildren ()
1233{
Greg Clayton5160ce52013-03-27 23:08:40 +00001234 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001235 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001236 ValueLocker locker;
1237 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001238 if (value_sp)
1239 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001240
Greg Clayton4a792072012-10-23 01:50:10 +00001241 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001242 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1243 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001244 return has_children;
1245}
1246
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001247uint32_t
1248SBValue::GetNumChildren ()
1249{
1250 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001251
Greg Clayton5160ce52013-03-27 23:08:40 +00001252 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001253 ValueLocker locker;
1254 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001255 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001256 num_children = value_sp->GetNumChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001257
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001258 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001259 log->Printf ("SBValue(%p)::GetNumChildren () => %u",
1260 static_cast<void*>(value_sp.get()), num_children);
1261
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001262 return num_children;
1263}
1264
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265
1266SBValue
1267SBValue::Dereference ()
1268{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001269 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001270 ValueLocker locker;
1271 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001272 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001273 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001274 Error error;
1275 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001276 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001277 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001278 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001279 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1280 static_cast<void*>(value_sp.get()),
1281 static_cast<void*>(value_sp.get()));
1282
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001283 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001284}
1285
1286bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001287SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288{
1289 bool is_ptr_type = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001290
Jim Ingham362e39a2013-05-15 02:16:21 +00001291 ValueLocker locker;
1292 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001293 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001294 is_ptr_type = value_sp->IsPointerType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001295
Greg Clayton5160ce52013-03-27 23:08:40 +00001296 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001297 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001298 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i",
1299 static_cast<void*>(value_sp.get()), is_ptr_type);
1300
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001301 return is_ptr_type;
1302}
1303
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001304void *
1305SBValue::GetOpaqueType()
1306{
Jim Ingham362e39a2013-05-15 02:16:21 +00001307 ValueLocker locker;
1308 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001309 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001310 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311 return NULL;
1312}
1313
Enrico Granata6f3533f2011-07-29 19:53:35 +00001314lldb::SBTarget
1315SBValue::GetTarget()
1316{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001317 SBTarget sb_target;
1318 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001319 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001320 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001321 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001322 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001323 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001324 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001325 if (log)
1326 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001327 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001328 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1329 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001330 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001331 log->Printf ("SBValue(%p)::GetTarget () => %p",
1332 static_cast<void*>(m_opaque_sp.get()),
1333 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001334 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001335 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001336}
1337
1338lldb::SBProcess
1339SBValue::GetProcess()
1340{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001341 SBProcess sb_process;
1342 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001343 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001344 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001345 process_sp = m_opaque_sp->GetProcessSP();
1346 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001347 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001348 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001349 if (log)
1350 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001351 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001352 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1353 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001354 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001355 log->Printf ("SBValue(%p)::GetProcess () => %p",
1356 static_cast<void*>(m_opaque_sp.get()),
1357 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001358 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001359 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001360}
1361
1362lldb::SBThread
1363SBValue::GetThread()
1364{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001365 SBThread sb_thread;
1366 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001367 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001368 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001369 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001370 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001371 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001372 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001373 if (log)
1374 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001375 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001376 log->Printf ("SBValue(%p)::GetThread () => NULL",
1377 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001378 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001379 log->Printf ("SBValue(%p)::GetThread () => %p",
1380 static_cast<void*>(m_opaque_sp.get()),
1381 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001382 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001383 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001384}
1385
1386lldb::SBFrame
1387SBValue::GetFrame()
1388{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001389 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001390 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001391 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001392 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001393 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001394 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001395 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001396 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001397 if (log)
1398 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001399 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001400 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1401 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001402 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001403 log->Printf ("SBValue(%p)::GetFrame () => %p",
1404 static_cast<void*>(m_opaque_sp.get()),
1405 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001406 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001407 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001408}
1409
1410
Greg Clayton81e871e2012-02-04 02:27:34 +00001411lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001412SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001413{
Enrico Granatae3e91512012-10-22 18:18:36 +00001414 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1415 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001416 return locker.GetLockedSP(*m_opaque_sp.get());
1417}
1418
1419lldb::ValueObjectSP
1420SBValue::GetSP () const
1421{
1422 ValueLocker locker;
1423 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001424}
1425
1426void
1427SBValue::SetSP (ValueImplSP impl_sp)
1428{
1429 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001430}
1431
Greg Clayton81e871e2012-02-04 02:27:34 +00001432void
1433SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001434{
Enrico Granatae3e91512012-10-22 18:18:36 +00001435 if (sp)
1436 {
1437 lldb::TargetSP target_sp(sp->GetTargetSP());
1438 if (target_sp)
1439 {
1440 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1441 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1442 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1443 }
1444 else
1445 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1446 }
1447 else
1448 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001450
Enrico Granatae3e91512012-10-22 18:18:36 +00001451void
1452SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1453{
1454 if (sp)
1455 {
1456 lldb::TargetSP target_sp(sp->GetTargetSP());
1457 if (target_sp)
1458 {
1459 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1460 SetSP (sp, use_dynamic, use_synthetic);
1461 }
1462 else
1463 SetSP (sp, use_dynamic, true);
1464 }
1465 else
1466 SetSP (sp, use_dynamic, false);
1467}
1468
1469void
1470SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1471{
1472 if (sp)
1473 {
1474 lldb::TargetSP target_sp(sp->GetTargetSP());
1475 if (target_sp)
1476 {
1477 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1478 SetSP (sp, use_dynamic, use_synthetic);
1479 }
1480 else
1481 SetSP (sp, eNoDynamicValues, use_synthetic);
1482 }
1483 else
1484 SetSP (sp, eNoDynamicValues, use_synthetic);
1485}
1486
1487void
1488SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1489{
1490 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1491}
Greg Clayton81e871e2012-02-04 02:27:34 +00001492
Jim Ingham362e39a2013-05-15 02:16:21 +00001493void
1494SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1495{
1496 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1497}
1498
Caroline Ticedde9cff2010-09-20 05:20:02 +00001499bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001500SBValue::GetExpressionPath (SBStream &description)
1501{
Jim Ingham362e39a2013-05-15 02:16:21 +00001502 ValueLocker locker;
1503 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001504 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001505 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001506 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001507 return true;
1508 }
1509 return false;
1510}
1511
1512bool
1513SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1514{
Jim Ingham362e39a2013-05-15 02:16:21 +00001515 ValueLocker locker;
1516 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001517 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001518 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001519 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001520 return true;
1521 }
1522 return false;
1523}
1524
1525bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001526SBValue::GetDescription (SBStream &description)
1527{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001528 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001529
Jim Ingham362e39a2013-05-15 02:16:21 +00001530 ValueLocker locker;
1531 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001532 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001533 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001534 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001535 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001536
Caroline Ticedde9cff2010-09-20 05:20:02 +00001537 return true;
1538}
Greg Claytondc4e9632011-01-05 18:43:15 +00001539
1540lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001541SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001542{
Jim Ingham362e39a2013-05-15 02:16:21 +00001543 ValueLocker locker;
1544 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001545 if (value_sp)
1546 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001547 return eFormatDefault;
1548}
1549
1550void
1551SBValue::SetFormat (lldb::Format format)
1552{
Jim Ingham362e39a2013-05-15 02:16:21 +00001553 ValueLocker locker;
1554 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001555 if (value_sp)
1556 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001557}
1558
Enrico Granata6f3533f2011-07-29 19:53:35 +00001559lldb::SBValue
1560SBValue::AddressOf()
1561{
1562 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001563 ValueLocker locker;
1564 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001565 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001566 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001567 Error error;
1568 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001569 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001570 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001571 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001572 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1573 static_cast<void*>(value_sp.get()),
1574 static_cast<void*>(value_sp.get()));
1575
Enrico Granata6f3533f2011-07-29 19:53:35 +00001576 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001577}
Enrico Granata9128ee22011-09-06 19:20:51 +00001578
1579lldb::addr_t
1580SBValue::GetLoadAddress()
1581{
1582 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001583 ValueLocker locker;
1584 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001585 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001586 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001587 TargetSP target_sp (value_sp->GetTargetSP());
1588 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001589 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001590 const bool scalar_is_load_address = true;
1591 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001592 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001593 if (addr_type == eAddressTypeFile)
1594 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001595 ModuleSP module_sp (value_sp->GetModule());
1596 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001597 value = LLDB_INVALID_ADDRESS;
1598 else
1599 {
1600 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001601 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001602 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001603 }
1604 }
1605 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1606 value = LLDB_INVALID_ADDRESS;
1607 }
1608 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001609 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001610 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001611 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1612 static_cast<void*>(value_sp.get()), value);
1613
Enrico Granata9128ee22011-09-06 19:20:51 +00001614 return value;
1615}
1616
1617lldb::SBAddress
1618SBValue::GetAddress()
1619{
1620 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001621 ValueLocker locker;
1622 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001623 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001624 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001625 TargetSP target_sp (value_sp->GetTargetSP());
1626 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001627 {
1628 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001629 const bool scalar_is_load_address = true;
1630 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001631 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001632 if (addr_type == eAddressTypeFile)
1633 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001634 ModuleSP module_sp (value_sp->GetModule());
1635 if (module_sp)
1636 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001637 }
1638 else if (addr_type == eAddressTypeLoad)
1639 {
1640 // no need to check the return value on this.. if it can actually do the resolve
1641 // addr will be in the form (section,offset), otherwise it will simply be returned
1642 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001643 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001644 }
1645 }
1646 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001647 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001648 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001649 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1650 static_cast<void*>(value_sp.get()),
1651 (addr.GetSection()
1652 ? addr.GetSection()->GetName().GetCString()
1653 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001654 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001655 return SBAddress(new Address(addr));
1656}
1657
1658lldb::SBData
1659SBValue::GetPointeeData (uint32_t item_idx,
1660 uint32_t item_count)
1661{
Greg Clayton5160ce52013-03-27 23:08:40 +00001662 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001663 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001664 ValueLocker locker;
1665 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001666 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001667 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001668 TargetSP target_sp (value_sp->GetTargetSP());
1669 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001670 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001671 DataExtractorSP data_sp(new DataExtractor());
1672 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1673 if (data_sp->GetByteSize() > 0)
1674 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001675 }
1676 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001677 if (log)
1678 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001679 static_cast<void*>(value_sp.get()), item_idx, item_count,
1680 static_cast<void*>(sb_data.get()));
1681
Enrico Granata9128ee22011-09-06 19:20:51 +00001682 return sb_data;
1683}
1684
1685lldb::SBData
1686SBValue::GetData ()
1687{
Greg Clayton5160ce52013-03-27 23:08:40 +00001688 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001689 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001690 ValueLocker locker;
1691 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001692 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001693 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001694 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001695 Error error;
1696 value_sp->GetData(*data_sp, error);
1697 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001698 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001699 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001700 if (log)
1701 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001702 static_cast<void*>(value_sp.get()),
1703 static_cast<void*>(sb_data.get()));
1704
Enrico Granata9128ee22011-09-06 19:20:51 +00001705 return sb_data;
1706}
Greg Clayton1b282f92011-10-13 18:08:26 +00001707
Sean Callanan389823e2013-04-13 01:21:23 +00001708bool
1709SBValue::SetData (lldb::SBData &data, SBError &error)
1710{
1711 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001712 ValueLocker locker;
1713 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001714 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001715
Sean Callanan389823e2013-04-13 01:21:23 +00001716 if (value_sp)
1717 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001718 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001719
Jim Ingham362e39a2013-05-15 02:16:21 +00001720 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001721 {
1722 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001723 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1724 static_cast<void*>(value_sp.get()));
1725
Jim Ingham362e39a2013-05-15 02:16:21 +00001726 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001727 ret = false;
1728 }
1729 else
1730 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001731 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001732
Jim Ingham362e39a2013-05-15 02:16:21 +00001733 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001734
Jim Ingham362e39a2013-05-15 02:16:21 +00001735 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001736 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001737 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001738 ret = false;
1739 }
Sean Callanan389823e2013-04-13 01:21:23 +00001740 }
1741 }
1742 else
1743 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001744 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001745 ret = false;
1746 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001747
Sean Callanan389823e2013-04-13 01:21:23 +00001748 if (log)
1749 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001750 static_cast<void*>(value_sp.get()),
1751 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001752 return ret;
1753}
1754
Enrico Granata10de0902012-10-10 22:54:17 +00001755lldb::SBDeclaration
1756SBValue::GetDeclaration ()
1757{
Jim Ingham362e39a2013-05-15 02:16:21 +00001758 ValueLocker locker;
1759 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001760 SBDeclaration decl_sb;
1761 if (value_sp)
1762 {
1763 Declaration decl;
1764 if (value_sp->GetDeclaration(decl))
1765 decl_sb.SetDeclaration(decl);
1766 }
1767 return decl_sb;
1768}
1769
Greg Clayton1b282f92011-10-13 18:08:26 +00001770lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001771SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001772{
Greg Clayton81e871e2012-02-04 02:27:34 +00001773 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001774
Greg Clayton81e871e2012-02-04 02:27:34 +00001775 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001776 ValueLocker locker;
1777 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001778 TargetSP target_sp (GetTarget().GetSP());
1779 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001780 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001781 // Read and Write cannot both be false.
1782 if (!read && !write)
1783 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001784
Greg Clayton81e871e2012-02-04 02:27:34 +00001785 // If the value is not in scope, don't try and watch and invalid value
1786 if (!IsInScope())
1787 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001788
Greg Clayton81e871e2012-02-04 02:27:34 +00001789 addr_t addr = GetLoadAddress();
1790 if (addr == LLDB_INVALID_ADDRESS)
1791 return sb_watchpoint;
1792 size_t byte_size = GetByteSize();
1793 if (byte_size == 0)
1794 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001795
Greg Clayton81e871e2012-02-04 02:27:34 +00001796 uint32_t watch_type = 0;
1797 if (read)
1798 watch_type |= LLDB_WATCH_TYPE_READ;
1799 if (write)
1800 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001801
Johnny Chenb90827e2012-06-04 23:19:54 +00001802 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001803 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001804 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001805 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001806
Daniel Maleae0f8f572013-08-26 23:57:52 +00001807 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001808 {
1809 sb_watchpoint.SetSP (watchpoint_sp);
1810 Declaration decl;
1811 if (value_sp->GetDeclaration (decl))
1812 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001813 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001814 {
1815 StreamString ss;
1816 // True to show fullpath for declaration file.
1817 decl.DumpStopContext(&ss, true);
1818 watchpoint_sp->SetDeclInfo(ss.GetString());
1819 }
1820 }
1821 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001822 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001823 else if (target_sp)
1824 {
1825 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1826 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001827 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1828 static_cast<void*>(value_sp.get()),
1829 locker.GetError().AsCString());
1830
Jim Ingham362e39a2013-05-15 02:16:21 +00001831 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1832 }
1833 else
1834 {
1835 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1836 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001837 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1838 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001839 error.SetErrorString("could not set watchpoint, a target is required");
1840 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001841
Greg Clayton1b282f92011-10-13 18:08:26 +00001842 return sb_watchpoint;
1843}
1844
Johnny Chend3761a72012-06-04 23:45:50 +00001845// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1846// Backward compatibility fix in the interim.
1847lldb::SBWatchpoint
1848SBValue::Watch (bool resolve_location, bool read, bool write)
1849{
Johnny Chen974759f2012-06-05 00:14:15 +00001850 SBError error;
1851 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001852}
1853
Greg Clayton1b282f92011-10-13 18:08:26 +00001854lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001855SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001856{
Greg Clayton81e871e2012-02-04 02:27:34 +00001857 SBWatchpoint sb_watchpoint;
1858 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001859 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001860 return sb_watchpoint;
1861}
Enrico Granata0c10a852014-12-08 23:13:56 +00001862
1863lldb::SBValue
1864SBValue::Persist ()
1865{
1866 ValueLocker locker;
1867 lldb::ValueObjectSP value_sp(GetSP(locker));
1868 SBValue persisted_sb;
1869 if (value_sp)
1870 {
1871 persisted_sb.SetSP(value_sp->Persist());
1872 }
1873 return persisted_sb;
1874}