blob: 3a9621b1e3bc4c6064e56e763bfbeb2b98683e17 [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 Granata6f3533f2011-07-29 19:53:35 +0000546SBType
547SBValue::GetType()
548{
Greg Clayton5160ce52013-03-27 23:08:40 +0000549 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000550 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000551 ValueLocker locker;
552 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000553 TypeImplSP type_sp;
554 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000555 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000556 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000557 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000558 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000559 if (log)
560 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000561 if (type_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000562 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
563 static_cast<void*>(value_sp.get()),
564 static_cast<void*>(type_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000565 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000566 log->Printf ("SBValue(%p)::GetType => NULL",
567 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000568 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000569 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000570}
571
Jim Ingham6035b672011-03-31 00:19:25 +0000572bool
573SBValue::GetValueDidChange ()
574{
Greg Clayton5160ce52013-03-27 23:08:40 +0000575 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000576 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000577 ValueLocker locker;
578 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000579 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000580 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000581 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000582 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000583 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000584 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
585 static_cast<void*>(value_sp.get()), result);
586
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000587 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000588}
589
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000590#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000592SBValue::GetSummary ()
593{
Greg Clayton5160ce52013-03-27 23:08:40 +0000594 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000595 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000596 ValueLocker locker;
597 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000598 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000599 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000600 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000601 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000602 if (log)
603 {
604 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000605 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
606 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000607 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000608 log->Printf ("SBValue(%p)::GetSummary() => NULL",
609 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000610 }
611 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000612}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000613#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614
615const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000616SBValue::GetLocation ()
617{
Greg Clayton5160ce52013-03-27 23:08:40 +0000618 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000619 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000620 ValueLocker locker;
621 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000622 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000623 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000624 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000625 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000626 if (log)
627 {
628 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000629 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
630 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000631 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000632 log->Printf ("SBValue(%p)::GetLocation() => NULL",
633 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000634 }
635 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000636}
637
Enrico Granata07a4ac22012-05-08 21:25:06 +0000638// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639bool
Jim Ingham6035b672011-03-31 00:19:25 +0000640SBValue::SetValueFromCString (const char *value_str)
641{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000642 lldb::SBError dummy;
643 return SetValueFromCString(value_str,dummy);
644}
645
646bool
647SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
648{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000649 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000650 ValueLocker locker;
651 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000652 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000653 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000654 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000655 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000656 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000657 else
658 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000659
Greg Claytonc9858e42012-04-06 02:17:47 +0000660 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000661 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
662 static_cast<void*>(value_sp.get()), value_str, success);
663
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000664 return success;
665}
666
Enrico Granata864e3e82012-02-17 03:18:30 +0000667lldb::SBTypeFormat
668SBValue::GetTypeFormat ()
669{
670 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000671 ValueLocker locker;
672 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000673 if (value_sp)
674 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000675 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000676 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000677 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
678 if (format_sp)
679 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000680 }
681 }
682 return format;
683}
684
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000685#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000686lldb::SBTypeSummary
687SBValue::GetTypeSummary ()
688{
689 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000690 ValueLocker locker;
691 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000692 if (value_sp)
693 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000694 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000695 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000696 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
697 if (summary_sp)
698 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000699 }
700 }
701 return summary;
702}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000703#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000704
705lldb::SBTypeFilter
706SBValue::GetTypeFilter ()
707{
708 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000709 ValueLocker locker;
710 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000711 if (value_sp)
712 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000713 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000714 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000715 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
716
717 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000718 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000719 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
720 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000721 }
722 }
723 }
724 return filter;
725}
726
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000727#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000728lldb::SBTypeSynthetic
729SBValue::GetTypeSynthetic ()
730{
731 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000732 ValueLocker locker;
733 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000734 if (value_sp)
735 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000736 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000737 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000738 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
739
740 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000741 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000742 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
743 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000744 }
745 }
746 }
747 return synthetic;
748}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000749#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000750
Enrico Granata6f3533f2011-07-29 19:53:35 +0000751lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000752SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000753{
Greg Clayton81e871e2012-02-04 02:27:34 +0000754 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000755 ValueLocker locker;
756 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000757 lldb::ValueObjectSP new_value_sp;
758 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000759 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000760 TypeImplSP type_sp (type.GetSP());
761 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000762 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000763 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000764 }
765 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000766 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000767 if (log)
768 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000769 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000770 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000771 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000772 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000773 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000774 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000775 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000776 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000777 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000778}
779
780lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000781SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000782{
Greg Claytonef496d52012-01-31 04:25:15 +0000783 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000784 ValueLocker locker;
785 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000786 TypeImplSP type_sp (type.GetSP());
787 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000788 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000789 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000790}
791
792lldb::SBValue
793SBValue::CreateValueFromExpression (const char *name, const char* expression)
794{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000795 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000796 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000797 return CreateValueFromExpression (name, expression, options);
798}
799
800lldb::SBValue
801SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
802{
Greg Clayton5160ce52013-03-27 23:08:40 +0000803 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000804 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000805 ValueLocker locker;
806 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000807 lldb::ValueObjectSP new_value_sp;
808 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000809 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000810 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Jim Ingham362e39a2013-05-15 02:16:21 +0000811 Target* target = exe_ctx.GetTargetPtr();
812 if (target)
Johnny Chen50660442011-12-20 01:52:44 +0000813 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000814 options.ref().SetKeepInMemory(true);
815 target->EvaluateExpression (expression,
816 exe_ctx.GetFramePtr(),
817 new_value_sp,
818 options.ref());
819 if (new_value_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000820 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000821 new_value_sp->SetName(ConstString(name));
822 sb_value.SetSP(new_value_sp);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000823 }
Johnny Chen50660442011-12-20 01:52:44 +0000824 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000825 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000826 if (log)
827 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000828 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000829 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000830 static_cast<void*>(value_sp.get()), name, expression,
831 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000832 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000833 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000834 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000835 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000836 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000837}
838
839lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000840SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000841{
Greg Clayton81e871e2012-02-04 02:27:34 +0000842 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000843 ValueLocker locker;
844 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000845 lldb::ValueObjectSP new_value_sp;
846 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
847 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000848 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000849 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(false).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +0000850 if (pointer_ast_type)
Enrico Granata61408e02011-08-04 17:07:02 +0000851 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000852 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000853
Greg Claytoncc4d0142012-02-17 07:49:44 +0000854 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
855 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Enrico Granata347c2aa2013-10-08 21:49:02 +0000856 pointer_ast_type,
Greg Clayton81e871e2012-02-04 02:27:34 +0000857 ConstString(name),
858 buffer,
Enrico Granata347c2aa2013-10-08 21:49:02 +0000859 exe_ctx.GetByteOrder(),
Greg Claytoncc4d0142012-02-17 07:49:44 +0000860 exe_ctx.GetAddressByteSize()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000861
Greg Clayton81e871e2012-02-04 02:27:34 +0000862 if (ptr_result_valobj_sp)
863 {
864 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
865 Error err;
866 new_value_sp = ptr_result_valobj_sp->Dereference(err);
867 if (new_value_sp)
868 new_value_sp->SetName(ConstString(name));
869 }
870 sb_value.SetSP(new_value_sp);
Enrico Granata61408e02011-08-04 17:07:02 +0000871 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000872 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000873 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000874 if (log)
875 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000876 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000877 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
878 static_cast<void*>(value_sp.get()),
879 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000880 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000881 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
882 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000883 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000884 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000885}
886
Enrico Granata9128ee22011-09-06 19:20:51 +0000887lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000888SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000889{
Greg Clayton81e871e2012-02-04 02:27:34 +0000890 lldb::SBValue sb_value;
891 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000892 ValueLocker locker;
893 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000894 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000895 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000896 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000897
Greg Claytoncc4d0142012-02-17 07:49:44 +0000898 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000899 type.m_opaque_sp->GetClangASTType(false),
Greg Clayton81e871e2012-02-04 02:27:34 +0000900 ConstString(name),
901 *data.m_opaque_sp,
902 LLDB_INVALID_ADDRESS);
903 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
904 sb_value.SetSP(new_value_sp);
Enrico Granata9128ee22011-09-06 19:20:51 +0000905 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000906 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000907 if (log)
908 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000909 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000910 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
911 static_cast<void*>(value_sp.get()),
912 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000913 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000914 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
915 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000916 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000917 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000918}
919
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000920SBValue
921SBValue::GetChildAtIndex (uint32_t idx)
922{
Greg Claytonf66024822011-07-15 19:31:49 +0000923 const bool can_create_synthetic = false;
924 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000925 TargetSP target_sp;
926 if (m_opaque_sp)
927 target_sp = m_opaque_sp->GetTargetSP();
928
929 if (target_sp)
930 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000931
Greg Claytonf66024822011-07-15 19:31:49 +0000932 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000933}
934
935SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000936SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000937{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000938 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000939 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000940
Jim Ingham362e39a2013-05-15 02:16:21 +0000941 ValueLocker locker;
942 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000943 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000944 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000945 const bool can_create = true;
946 child_sp = value_sp->GetChildAtIndex (idx, can_create);
947 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000948 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000949 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000950 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000951 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
952 }
953 else if (value_sp->IsArrayType())
954 {
955 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000956 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000957 }
958 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000959
Enrico Granatae3e91512012-10-22 18:18:36 +0000960 SBValue sb_value;
961 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000962 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000963 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
964 static_cast<void*>(value_sp.get()), idx,
965 static_cast<void*>(value_sp.get()));
966
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967 return sb_value;
968}
969
970uint32_t
971SBValue::GetIndexOfChildWithName (const char *name)
972{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000973 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000974 ValueLocker locker;
975 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000976 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000977 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000978 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +0000979 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000980 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000981 if (log)
982 {
983 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000984 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
985 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000986 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000987 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
988 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000989 }
990 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000991}
992
993SBValue
994SBValue::GetChildMemberWithName (const char *name)
995{
Jim Ingham362e39a2013-05-15 02:16:21 +0000996 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
997 TargetSP target_sp;
998 if (m_opaque_sp)
999 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001000
Jim Ingham362e39a2013-05-15 02:16:21 +00001001 if (target_sp)
1002 use_dynamic_value = target_sp->GetPreferDynamicValue();
1003 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +00001004}
1005
1006SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001007SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001008{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001009 lldb::ValueObjectSP child_sp;
1010 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001011
Greg Clayton5160ce52013-03-27 23:08:40 +00001012 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001013
Jim Ingham362e39a2013-05-15 02:16:21 +00001014 ValueLocker locker;
1015 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001016 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001017 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001018 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +00001019 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001020
Enrico Granatae3e91512012-10-22 18:18:36 +00001021 SBValue sb_value;
1022 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001023
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001024 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001025 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1026 static_cast<void*>(value_sp.get()), name,
1027 static_cast<void*>(value_sp.get()));
1028
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001029 return sb_value;
1030}
1031
Enrico Granataf2bbf712011-07-15 02:26:42 +00001032lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001033SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1034{
Enrico Granatae3e91512012-10-22 18:18:36 +00001035 SBValue value_sb;
1036 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001037 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001038 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1039 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001040 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001041 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001042}
1043
1044lldb::SBValue
1045SBValue::GetStaticValue ()
1046{
Enrico Granatae3e91512012-10-22 18:18:36 +00001047 SBValue value_sb;
1048 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001049 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001050 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1051 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001052 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001053 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001054}
1055
Enrico Granatac5bc4122012-03-27 02:35:13 +00001056lldb::SBValue
1057SBValue::GetNonSyntheticValue ()
1058{
Enrico Granatae3e91512012-10-22 18:18:36 +00001059 SBValue value_sb;
1060 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001061 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001062 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1063 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001064 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001065 return value_sb;
1066}
1067
1068lldb::DynamicValueType
1069SBValue::GetPreferDynamicValue ()
1070{
1071 if (!IsValid())
1072 return eNoDynamicValues;
1073 return m_opaque_sp->GetUseDynamic();
1074}
1075
1076void
1077SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1078{
1079 if (IsValid())
1080 return m_opaque_sp->SetUseDynamic (use_dynamic);
1081}
1082
1083bool
1084SBValue::GetPreferSyntheticValue ()
1085{
1086 if (!IsValid())
1087 return false;
1088 return m_opaque_sp->GetUseSynthetic();
1089}
1090
1091void
1092SBValue::SetPreferSyntheticValue (bool use_synthetic)
1093{
1094 if (IsValid())
1095 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001096}
1097
Jim Ingham60dbabb2011-12-08 19:44:08 +00001098bool
1099SBValue::IsDynamic()
1100{
Jim Ingham362e39a2013-05-15 02:16:21 +00001101 ValueLocker locker;
1102 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001103 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001104 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001105 return false;
1106}
1107
Enrico Granatae3e91512012-10-22 18:18:36 +00001108bool
1109SBValue::IsSynthetic ()
1110{
Jim Ingham362e39a2013-05-15 02:16:21 +00001111 ValueLocker locker;
1112 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001113 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001114 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001115 return false;
1116}
1117
Jim Ingham60dbabb2011-12-08 19:44:08 +00001118lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001119SBValue::GetValueForExpressionPath(const char* expr_path)
1120{
Greg Clayton5160ce52013-03-27 23:08:40 +00001121 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001122 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001123 ValueLocker locker;
1124 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001125 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001126 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001127 // using default values for all the fancy options, just do it if you can
1128 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001129 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001130
Enrico Granatae3e91512012-10-22 18:18:36 +00001131 SBValue sb_value;
1132 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001133
Enrico Granataf2bbf712011-07-15 02:26:42 +00001134 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001135 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1136 static_cast<void*>(value_sp.get()), expr_path,
1137 static_cast<void*>(value_sp.get()));
1138
Enrico Granataf2bbf712011-07-15 02:26:42 +00001139 return sb_value;
1140}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001141
Greg Claytonfe42ac42011-08-03 22:57:10 +00001142int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001143SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1144{
Jim Ingham16e0c682011-08-12 23:34:31 +00001145 error.Clear();
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 Granata6fd87d52011-08-04 01:41:02 +00001149 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001150 bool success = true;
1151 uint64_t ret_val = fail_value;
1152 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1153 if (!success)
1154 error.SetErrorString("could not resolve value");
1155 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001156 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001157 else
1158 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1159
Enrico Granata6fd87d52011-08-04 01:41:02 +00001160 return fail_value;
1161}
1162
1163uint64_t
1164SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1165{
Jim Ingham16e0c682011-08-12 23:34:31 +00001166 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001167 ValueLocker locker;
1168 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001169 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001170 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001171 bool success = true;
1172 uint64_t ret_val = fail_value;
1173 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1174 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001175 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001176 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001177 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001178 else
1179 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1180
Enrico Granata6fd87d52011-08-04 01:41:02 +00001181 return fail_value;
1182}
1183
1184int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001185SBValue::GetValueAsSigned(int64_t fail_value)
1186{
Jim Ingham362e39a2013-05-15 02:16:21 +00001187 ValueLocker locker;
1188 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001189 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001190 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001191 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001192 }
1193 return fail_value;
1194}
1195
1196uint64_t
1197SBValue::GetValueAsUnsigned(uint64_t fail_value)
1198{
Jim Ingham362e39a2013-05-15 02:16:21 +00001199 ValueLocker locker;
1200 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001201 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001202 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001203 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001204 }
1205 return fail_value;
1206}
1207
Greg Clayton4a792072012-10-23 01:50:10 +00001208bool
1209SBValue::MightHaveChildren ()
1210{
Greg Clayton5160ce52013-03-27 23:08:40 +00001211 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001212 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001213 ValueLocker locker;
1214 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001215 if (value_sp)
1216 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001217
Greg Clayton4a792072012-10-23 01:50:10 +00001218 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001219 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1220 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001221 return has_children;
1222}
1223
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001224uint32_t
1225SBValue::GetNumChildren ()
1226{
1227 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001228
Greg Clayton5160ce52013-03-27 23:08:40 +00001229 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001230 ValueLocker locker;
1231 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001232 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001233 num_children = value_sp->GetNumChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001234
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001235 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001236 log->Printf ("SBValue(%p)::GetNumChildren () => %u",
1237 static_cast<void*>(value_sp.get()), num_children);
1238
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001239 return num_children;
1240}
1241
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001242
1243SBValue
1244SBValue::Dereference ()
1245{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001246 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001247 ValueLocker locker;
1248 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001249 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001250 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001251 Error error;
1252 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001254 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001255 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001256 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1257 static_cast<void*>(value_sp.get()),
1258 static_cast<void*>(value_sp.get()));
1259
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001260 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261}
1262
1263bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001264SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001265{
1266 bool is_ptr_type = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001267
Jim Ingham362e39a2013-05-15 02:16:21 +00001268 ValueLocker locker;
1269 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001270 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001271 is_ptr_type = value_sp->IsPointerType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001272
Greg Clayton5160ce52013-03-27 23:08:40 +00001273 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001274 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001275 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i",
1276 static_cast<void*>(value_sp.get()), is_ptr_type);
1277
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001278 return is_ptr_type;
1279}
1280
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281void *
1282SBValue::GetOpaqueType()
1283{
Jim Ingham362e39a2013-05-15 02:16:21 +00001284 ValueLocker locker;
1285 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001286 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001287 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001288 return NULL;
1289}
1290
Enrico Granata6f3533f2011-07-29 19:53:35 +00001291lldb::SBTarget
1292SBValue::GetTarget()
1293{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001294 SBTarget sb_target;
1295 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001296 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001297 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001298 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001299 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001300 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001301 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001302 if (log)
1303 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001304 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001305 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1306 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001307 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001308 log->Printf ("SBValue(%p)::GetTarget () => %p",
1309 static_cast<void*>(m_opaque_sp.get()),
1310 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001311 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001312 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001313}
1314
1315lldb::SBProcess
1316SBValue::GetProcess()
1317{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001318 SBProcess sb_process;
1319 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001320 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001321 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001322 process_sp = m_opaque_sp->GetProcessSP();
1323 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001324 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001325 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001326 if (log)
1327 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001328 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001329 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1330 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001331 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001332 log->Printf ("SBValue(%p)::GetProcess () => %p",
1333 static_cast<void*>(m_opaque_sp.get()),
1334 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001335 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001336 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001337}
1338
1339lldb::SBThread
1340SBValue::GetThread()
1341{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001342 SBThread sb_thread;
1343 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001344 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001345 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001346 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001347 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001348 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001349 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001350 if (log)
1351 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001352 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001353 log->Printf ("SBValue(%p)::GetThread () => NULL",
1354 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001355 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001356 log->Printf ("SBValue(%p)::GetThread () => %p",
1357 static_cast<void*>(m_opaque_sp.get()),
1358 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001359 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001360 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001361}
1362
1363lldb::SBFrame
1364SBValue::GetFrame()
1365{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001366 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001367 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001368 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001369 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001370 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001371 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001372 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001373 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001374 if (log)
1375 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001376 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001377 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1378 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001379 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001380 log->Printf ("SBValue(%p)::GetFrame () => %p",
1381 static_cast<void*>(m_opaque_sp.get()),
1382 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001383 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001384 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001385}
1386
1387
Greg Clayton81e871e2012-02-04 02:27:34 +00001388lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001389SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001390{
Enrico Granatae3e91512012-10-22 18:18:36 +00001391 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1392 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001393 return locker.GetLockedSP(*m_opaque_sp.get());
1394}
1395
1396lldb::ValueObjectSP
1397SBValue::GetSP () const
1398{
1399 ValueLocker locker;
1400 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001401}
1402
1403void
1404SBValue::SetSP (ValueImplSP impl_sp)
1405{
1406 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001407}
1408
Greg Clayton81e871e2012-02-04 02:27:34 +00001409void
1410SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001411{
Enrico Granatae3e91512012-10-22 18:18:36 +00001412 if (sp)
1413 {
1414 lldb::TargetSP target_sp(sp->GetTargetSP());
1415 if (target_sp)
1416 {
1417 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1418 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1419 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1420 }
1421 else
1422 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1423 }
1424 else
1425 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001427
Enrico Granatae3e91512012-10-22 18:18:36 +00001428void
1429SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1430{
1431 if (sp)
1432 {
1433 lldb::TargetSP target_sp(sp->GetTargetSP());
1434 if (target_sp)
1435 {
1436 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1437 SetSP (sp, use_dynamic, use_synthetic);
1438 }
1439 else
1440 SetSP (sp, use_dynamic, true);
1441 }
1442 else
1443 SetSP (sp, use_dynamic, false);
1444}
1445
1446void
1447SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1448{
1449 if (sp)
1450 {
1451 lldb::TargetSP target_sp(sp->GetTargetSP());
1452 if (target_sp)
1453 {
1454 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1455 SetSP (sp, use_dynamic, use_synthetic);
1456 }
1457 else
1458 SetSP (sp, eNoDynamicValues, use_synthetic);
1459 }
1460 else
1461 SetSP (sp, eNoDynamicValues, use_synthetic);
1462}
1463
1464void
1465SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1466{
1467 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1468}
Greg Clayton81e871e2012-02-04 02:27:34 +00001469
Jim Ingham362e39a2013-05-15 02:16:21 +00001470void
1471SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1472{
1473 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1474}
1475
Caroline Ticedde9cff2010-09-20 05:20:02 +00001476bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001477SBValue::GetExpressionPath (SBStream &description)
1478{
Jim Ingham362e39a2013-05-15 02:16:21 +00001479 ValueLocker locker;
1480 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001481 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001482 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001483 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001484 return true;
1485 }
1486 return false;
1487}
1488
1489bool
1490SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1491{
Jim Ingham362e39a2013-05-15 02:16:21 +00001492 ValueLocker locker;
1493 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001494 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001495 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001496 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001497 return true;
1498 }
1499 return false;
1500}
1501
1502bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001503SBValue::GetDescription (SBStream &description)
1504{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001505 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001506
Jim Ingham362e39a2013-05-15 02:16:21 +00001507 ValueLocker locker;
1508 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001509 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001510 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001511 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001512 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001513
Caroline Ticedde9cff2010-09-20 05:20:02 +00001514 return true;
1515}
Greg Claytondc4e9632011-01-05 18:43:15 +00001516
1517lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001518SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001519{
Jim Ingham362e39a2013-05-15 02:16:21 +00001520 ValueLocker locker;
1521 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001522 if (value_sp)
1523 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001524 return eFormatDefault;
1525}
1526
1527void
1528SBValue::SetFormat (lldb::Format format)
1529{
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)
1533 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001534}
1535
Enrico Granata6f3533f2011-07-29 19:53:35 +00001536lldb::SBValue
1537SBValue::AddressOf()
1538{
1539 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001540 ValueLocker locker;
1541 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001542 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001543 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001544 Error error;
1545 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001546 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001547 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001548 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001549 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1550 static_cast<void*>(value_sp.get()),
1551 static_cast<void*>(value_sp.get()));
1552
Enrico Granata6f3533f2011-07-29 19:53:35 +00001553 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001554}
Enrico Granata9128ee22011-09-06 19:20:51 +00001555
1556lldb::addr_t
1557SBValue::GetLoadAddress()
1558{
1559 lldb::addr_t value = LLDB_INVALID_ADDRESS;
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)
Enrico Granata9128ee22011-09-06 19:20:51 +00001563 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001564 TargetSP target_sp (value_sp->GetTargetSP());
1565 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001566 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001567 const bool scalar_is_load_address = true;
1568 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001569 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001570 if (addr_type == eAddressTypeFile)
1571 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001572 ModuleSP module_sp (value_sp->GetModule());
1573 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001574 value = LLDB_INVALID_ADDRESS;
1575 else
1576 {
1577 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001578 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001579 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001580 }
1581 }
1582 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1583 value = LLDB_INVALID_ADDRESS;
1584 }
1585 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001586 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001587 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001588 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1589 static_cast<void*>(value_sp.get()), value);
1590
Enrico Granata9128ee22011-09-06 19:20:51 +00001591 return value;
1592}
1593
1594lldb::SBAddress
1595SBValue::GetAddress()
1596{
1597 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001598 ValueLocker locker;
1599 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001600 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001601 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001602 TargetSP target_sp (value_sp->GetTargetSP());
1603 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001604 {
1605 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001606 const bool scalar_is_load_address = true;
1607 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001608 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001609 if (addr_type == eAddressTypeFile)
1610 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001611 ModuleSP module_sp (value_sp->GetModule());
1612 if (module_sp)
1613 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001614 }
1615 else if (addr_type == eAddressTypeLoad)
1616 {
1617 // no need to check the return value on this.. if it can actually do the resolve
1618 // addr will be in the form (section,offset), otherwise it will simply be returned
1619 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001620 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001621 }
1622 }
1623 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001624 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001625 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001626 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1627 static_cast<void*>(value_sp.get()),
1628 (addr.GetSection()
1629 ? addr.GetSection()->GetName().GetCString()
1630 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001631 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001632 return SBAddress(new Address(addr));
1633}
1634
1635lldb::SBData
1636SBValue::GetPointeeData (uint32_t item_idx,
1637 uint32_t item_count)
1638{
Greg Clayton5160ce52013-03-27 23:08:40 +00001639 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001640 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001641 ValueLocker locker;
1642 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001643 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001644 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001645 TargetSP target_sp (value_sp->GetTargetSP());
1646 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001647 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001648 DataExtractorSP data_sp(new DataExtractor());
1649 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1650 if (data_sp->GetByteSize() > 0)
1651 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001652 }
1653 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001654 if (log)
1655 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001656 static_cast<void*>(value_sp.get()), item_idx, item_count,
1657 static_cast<void*>(sb_data.get()));
1658
Enrico Granata9128ee22011-09-06 19:20:51 +00001659 return sb_data;
1660}
1661
1662lldb::SBData
1663SBValue::GetData ()
1664{
Greg Clayton5160ce52013-03-27 23:08:40 +00001665 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001666 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001667 ValueLocker locker;
1668 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001669 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001670 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001671 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001672 Error error;
1673 value_sp->GetData(*data_sp, error);
1674 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001675 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001676 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001677 if (log)
1678 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001679 static_cast<void*>(value_sp.get()),
1680 static_cast<void*>(sb_data.get()));
1681
Enrico Granata9128ee22011-09-06 19:20:51 +00001682 return sb_data;
1683}
Greg Clayton1b282f92011-10-13 18:08:26 +00001684
Sean Callanan389823e2013-04-13 01:21:23 +00001685bool
1686SBValue::SetData (lldb::SBData &data, SBError &error)
1687{
1688 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001689 ValueLocker locker;
1690 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001691 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001692
Sean Callanan389823e2013-04-13 01:21:23 +00001693 if (value_sp)
1694 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001695 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001696
Jim Ingham362e39a2013-05-15 02:16:21 +00001697 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001698 {
1699 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001700 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1701 static_cast<void*>(value_sp.get()));
1702
Jim Ingham362e39a2013-05-15 02:16:21 +00001703 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001704 ret = false;
1705 }
1706 else
1707 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001708 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001709
Jim Ingham362e39a2013-05-15 02:16:21 +00001710 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001711
Jim Ingham362e39a2013-05-15 02:16:21 +00001712 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001713 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001714 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001715 ret = false;
1716 }
Sean Callanan389823e2013-04-13 01:21:23 +00001717 }
1718 }
1719 else
1720 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001721 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001722 ret = false;
1723 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001724
Sean Callanan389823e2013-04-13 01:21:23 +00001725 if (log)
1726 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001727 static_cast<void*>(value_sp.get()),
1728 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001729 return ret;
1730}
1731
Enrico Granata10de0902012-10-10 22:54:17 +00001732lldb::SBDeclaration
1733SBValue::GetDeclaration ()
1734{
Jim Ingham362e39a2013-05-15 02:16:21 +00001735 ValueLocker locker;
1736 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001737 SBDeclaration decl_sb;
1738 if (value_sp)
1739 {
1740 Declaration decl;
1741 if (value_sp->GetDeclaration(decl))
1742 decl_sb.SetDeclaration(decl);
1743 }
1744 return decl_sb;
1745}
1746
Greg Clayton1b282f92011-10-13 18:08:26 +00001747lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001748SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001749{
Greg Clayton81e871e2012-02-04 02:27:34 +00001750 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001751
Greg Clayton81e871e2012-02-04 02:27:34 +00001752 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001753 ValueLocker locker;
1754 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001755 TargetSP target_sp (GetTarget().GetSP());
1756 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001757 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001758 // Read and Write cannot both be false.
1759 if (!read && !write)
1760 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001761
Greg Clayton81e871e2012-02-04 02:27:34 +00001762 // If the value is not in scope, don't try and watch and invalid value
1763 if (!IsInScope())
1764 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001765
Greg Clayton81e871e2012-02-04 02:27:34 +00001766 addr_t addr = GetLoadAddress();
1767 if (addr == LLDB_INVALID_ADDRESS)
1768 return sb_watchpoint;
1769 size_t byte_size = GetByteSize();
1770 if (byte_size == 0)
1771 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001772
Greg Clayton81e871e2012-02-04 02:27:34 +00001773 uint32_t watch_type = 0;
1774 if (read)
1775 watch_type |= LLDB_WATCH_TYPE_READ;
1776 if (write)
1777 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001778
Johnny Chenb90827e2012-06-04 23:19:54 +00001779 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001780 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001781 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001782 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001783
Daniel Maleae0f8f572013-08-26 23:57:52 +00001784 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001785 {
1786 sb_watchpoint.SetSP (watchpoint_sp);
1787 Declaration decl;
1788 if (value_sp->GetDeclaration (decl))
1789 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001790 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001791 {
1792 StreamString ss;
1793 // True to show fullpath for declaration file.
1794 decl.DumpStopContext(&ss, true);
1795 watchpoint_sp->SetDeclInfo(ss.GetString());
1796 }
1797 }
1798 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001799 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001800 else if (target_sp)
1801 {
1802 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1803 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001804 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1805 static_cast<void*>(value_sp.get()),
1806 locker.GetError().AsCString());
1807
Jim Ingham362e39a2013-05-15 02:16:21 +00001808 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1809 }
1810 else
1811 {
1812 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1813 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001814 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1815 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001816 error.SetErrorString("could not set watchpoint, a target is required");
1817 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001818
Greg Clayton1b282f92011-10-13 18:08:26 +00001819 return sb_watchpoint;
1820}
1821
Johnny Chend3761a72012-06-04 23:45:50 +00001822// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1823// Backward compatibility fix in the interim.
1824lldb::SBWatchpoint
1825SBValue::Watch (bool resolve_location, bool read, bool write)
1826{
Johnny Chen974759f2012-06-05 00:14:15 +00001827 SBError error;
1828 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001829}
1830
Greg Clayton1b282f92011-10-13 18:08:26 +00001831lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001832SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001833{
Greg Clayton81e871e2012-02-04 02:27:34 +00001834 SBWatchpoint sb_watchpoint;
1835 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001836 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001837 return sb_watchpoint;
1838}