blob: aa9b23ac7c69f8f950163a8e5a5f68d70eaf4b14 [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"
41#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 }
61
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) :
66 m_valobj_sp(in_valobj_sp),
Enrico Granata19f0e8c2013-04-22 22:57:56 +000067 m_use_dynamic(use_dynamic),
Jim Ingham362e39a2013-05-15 02:16:21 +000068 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 }
74
75 ValueImpl (const ValueImpl& rhs) :
Jim Ingham362e39a2013-05-15 02:16:21 +000076 m_valobj_sp(rhs.m_valobj_sp),
Enrico Granata19f0e8c2013-04-22 22:57:56 +000077 m_use_dynamic(rhs.m_use_dynamic),
Jim Ingham362e39a2013-05-15 02:16:21 +000078 m_use_synthetic(rhs.m_use_synthetic),
79 m_name (rhs.m_name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000080 {
81 }
82
83 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 }
95
96 bool
97 IsValid ()
98 {
Jim Ingham362e39a2013-05-15 02:16:21 +000099 return m_valobj_sp.get() != NULL;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000100 }
101
102 lldb::ValueObjectSP
103 GetRootSP ()
104 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000105 return m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000106 }
107
108 lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000109 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000110 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000111 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
112 if (!m_valobj_sp)
113 {
114 error.SetErrorString("invalid value object");
115 return m_valobj_sp;
116 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000117
Jim Ingham362e39a2013-05-15 02:16:21 +0000118 lldb::ValueObjectSP value_sp = m_valobj_sp;
119
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000120 Target *target = value_sp->GetTargetSP().get();
121 if (target)
Jim Ingham362e39a2013-05-15 02:16:21 +0000122 api_locker.Lock(target->GetAPIMutex());
123
124 ProcessSP process_sp(value_sp->GetProcessSP());
125 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
126 {
127 // We don't allow people to play around with ValueObject if the process is running.
128 // If you want to look at values, pause the process, then look.
129 if (log)
130 log->Printf ("SBValue(%p)::GetSP() => error: process is running", value_sp.get());
131 error.SetErrorString ("process must be stopped.");
132 return ValueObjectSP();
133 }
134
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000135 if (value_sp->GetDynamicValue(m_use_dynamic))
136 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
137 if (value_sp->GetSyntheticValue(m_use_synthetic))
138 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
Jim Ingham362e39a2013-05-15 02:16:21 +0000139 if (!value_sp)
140 error.SetErrorString("invalid value object");
141 if (!m_name.IsEmpty())
142 value_sp->SetName(m_name);
143
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000144 return value_sp;
145 }
146
147 void
148 SetUseDynamic (lldb::DynamicValueType use_dynamic)
149 {
150 m_use_dynamic = use_dynamic;
151 }
152
153 void
154 SetUseSynthetic (bool use_synthetic)
155 {
156 m_use_synthetic = use_synthetic;
157 }
158
159 lldb::DynamicValueType
160 GetUseDynamic ()
161 {
162 return m_use_dynamic;
163 }
164
165 bool
166 GetUseSynthetic ()
167 {
168 return m_use_synthetic;
169 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000170
171 // All the derived values that we would make from the m_valobj_sp will share
172 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
173 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
174 // provide simple accessors for these, which I do here.
175 TargetSP
176 GetTargetSP ()
177 {
178 if (m_valobj_sp)
179 return m_valobj_sp->GetTargetSP();
180 else
181 return TargetSP();
182 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000183
Jim Ingham362e39a2013-05-15 02:16:21 +0000184 ProcessSP
185 GetProcessSP ()
186 {
187 if (m_valobj_sp)
188 return m_valobj_sp->GetProcessSP();
189 else
190 return ProcessSP();
191 }
192
193 ThreadSP
194 GetThreadSP ()
195 {
196 if (m_valobj_sp)
197 return m_valobj_sp->GetThreadSP();
198 else
199 return ThreadSP();
200 }
201
202 StackFrameSP
203 GetFrameSP ()
204 {
205 if (m_valobj_sp)
206 return m_valobj_sp->GetFrameSP();
207 else
208 return StackFrameSP();
209 }
210
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000211private:
Jim Ingham362e39a2013-05-15 02:16:21 +0000212 lldb::ValueObjectSP m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000213 lldb::DynamicValueType m_use_dynamic;
214 bool m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000215 ConstString m_name;
216};
217
218class ValueLocker
219{
220public:
221 ValueLocker ()
222 {
223 }
224
225 ValueObjectSP
226 GetLockedSP(ValueImpl &in_value)
227 {
228 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
229 }
230
231 Error &
232 GetError()
233 {
234 return m_lock_error;
235 }
236
237private:
238 Process::StopLocker m_stop_locker;
239 Mutex::Locker m_api_locker;
240 Error m_lock_error;
241
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000242};
Enrico Granatae3e91512012-10-22 18:18:36 +0000243
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000244SBValue::SBValue () :
Greg Clayton66111032010-06-23 01:19:29 +0000245 m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000246{
247}
248
Enrico Granatac5bc4122012-03-27 02:35:13 +0000249SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000250{
Enrico Granatae3e91512012-10-22 18:18:36 +0000251 SetSP(value_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000252}
253
Enrico Granatac5bc4122012-03-27 02:35:13 +0000254SBValue::SBValue(const SBValue &rhs)
Greg Claytonefabb122010-11-05 23:17:00 +0000255{
Enrico Granatae3e91512012-10-22 18:18:36 +0000256 SetSP(rhs.m_opaque_sp);
Greg Claytonefabb122010-11-05 23:17:00 +0000257}
258
Greg Claytonbf2331c2011-09-09 23:04:00 +0000259SBValue &
Greg Claytonefabb122010-11-05 23:17:00 +0000260SBValue::operator = (const SBValue &rhs)
261{
262 if (this != &rhs)
Enrico Granatac5bc4122012-03-27 02:35:13 +0000263 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000264 SetSP(rhs.m_opaque_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000265 }
Greg Claytonefabb122010-11-05 23:17:00 +0000266 return *this;
267}
268
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269SBValue::~SBValue()
270{
271}
272
273bool
Greg Claytonbf2331c2011-09-09 23:04:00 +0000274SBValue::IsValid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000275{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000276 // If this function ever changes to anything that does more than just
277 // check if the opaque shared pointer is non NULL, then we need to update
278 // all "if (m_opaque_sp)" code in this file.
Enrico Granatae3e91512012-10-22 18:18:36 +0000279 return m_opaque_sp.get() != NULL && m_opaque_sp->GetRootSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000280}
281
Jim Ingham5d3bca42011-12-19 20:39:44 +0000282void
283SBValue::Clear()
284{
285 m_opaque_sp.reset();
286}
287
Greg Clayton524e60b2010-10-06 22:10:17 +0000288SBError
289SBValue::GetError()
290{
291 SBError sb_error;
292
Jim Ingham362e39a2013-05-15 02:16:21 +0000293 ValueLocker locker;
294 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000295 if (value_sp)
296 sb_error.SetError(value_sp->GetError());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000297 else
Jim Ingham362e39a2013-05-15 02:16:21 +0000298 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
Greg Clayton524e60b2010-10-06 22:10:17 +0000299
300 return sb_error;
301}
302
Johnny Chenb0b8be72011-07-07 20:46:23 +0000303user_id_t
304SBValue::GetID()
305{
Jim Ingham362e39a2013-05-15 02:16:21 +0000306 ValueLocker locker;
307 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000308 if (value_sp)
309 return value_sp->GetID();
Johnny Chenb0b8be72011-07-07 20:46:23 +0000310 return LLDB_INVALID_UID;
311}
312
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000313const char *
314SBValue::GetName()
315{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000316 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000317 ValueLocker locker;
318 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000319 if (value_sp)
320 name = value_sp->GetName().GetCString();
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000321
Greg Clayton5160ce52013-03-27 23:08:40 +0000322 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton93aa84e2010-10-29 04:59:35 +0000323 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000324 {
325 if (name)
Greg Clayton81e871e2012-02-04 02:27:34 +0000326 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000327 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000328 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000329 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000330
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000331 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332}
333
334const char *
335SBValue::GetTypeName ()
336{
Greg Clayton5160ce52013-03-27 23:08:40 +0000337 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000338 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000339 ValueLocker locker;
340 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000341 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000342 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000343 name = value_sp->GetQualifiedTypeName().GetCString();
Jim Ingham48cdc582012-08-21 01:46:35 +0000344 }
345
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000346 if (log)
347 {
348 if (name)
Greg Clayton81e871e2012-02-04 02:27:34 +0000349 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000350 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000351 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000352 }
353
354 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000355}
356
357size_t
358SBValue::GetByteSize ()
359{
Greg Clayton5160ce52013-03-27 23:08:40 +0000360 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000361 size_t result = 0;
362
Jim Ingham362e39a2013-05-15 02:16:21 +0000363 ValueLocker locker;
364 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000365 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000366 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000367 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000368 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000369
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000370 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000371 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64, value_sp.get(), (uint64_t)result);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000372
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 return result;
374}
375
376bool
Jim Ingham6035b672011-03-31 00:19:25 +0000377SBValue::IsInScope ()
378{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379 bool result = false;
380
Jim Ingham362e39a2013-05-15 02:16:21 +0000381 ValueLocker locker;
382 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000383 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000384 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000385 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000386 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387
Greg Clayton5160ce52013-03-27 23:08:40 +0000388 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000389 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000390 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000391
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 return result;
393}
394
395const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000396SBValue::GetValue ()
397{
Greg Clayton5160ce52013-03-27 23:08:40 +0000398 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytonc9858e42012-04-06 02:17:47 +0000399
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000400 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000401 ValueLocker locker;
402 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000403 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000404 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000405 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000406 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000407 if (log)
408 {
409 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000410 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000411 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000412 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000413 }
414
415 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416}
417
Greg Clayton73b472d2010-10-27 03:32:59 +0000418ValueType
419SBValue::GetValueType ()
420{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000421 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000422 ValueLocker locker;
423 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000424 if (value_sp)
425 result = value_sp->GetValueType();
Jim Ingham362e39a2013-05-15 02:16:21 +0000426
Greg Clayton5160ce52013-03-27 23:08:40 +0000427 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000428 if (log)
429 {
430 switch (result)
431 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000432 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
433 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
434 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
435 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
436 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
437 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
438 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
439 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000440 }
441 }
442 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000443}
444
Jim Ingham53c47f12010-09-10 23:12:17 +0000445const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000446SBValue::GetObjectDescription ()
447{
Greg Clayton5160ce52013-03-27 23:08:40 +0000448 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000449 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000450 ValueLocker locker;
451 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000452 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000453 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000454 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000455 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000456 if (log)
457 {
458 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000459 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000460 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000461 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000462 }
463 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000464}
465
Enrico Granata6f3533f2011-07-29 19:53:35 +0000466SBType
467SBValue::GetType()
468{
Greg Clayton5160ce52013-03-27 23:08:40 +0000469 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000470 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000471 ValueLocker locker;
472 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000473 TypeImplSP type_sp;
474 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000475 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000476 type_sp.reset (new TypeImpl(value_sp->GetClangType()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000477 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000478 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000479 if (log)
480 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000481 if (type_sp)
482 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000483 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000484 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000485 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000486 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000487}
488
Jim Ingham6035b672011-03-31 00:19:25 +0000489bool
490SBValue::GetValueDidChange ()
491{
Greg Clayton5160ce52013-03-27 23:08:40 +0000492 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000493 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000494 ValueLocker locker;
495 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000496 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000497 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000498 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000499 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000500 if (log)
Greg Claytonc9858e42012-04-06 02:17:47 +0000501 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000502
503 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000504}
505
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000506#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000507const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000508SBValue::GetSummary ()
509{
Greg Clayton5160ce52013-03-27 23:08:40 +0000510 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000511 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000512 ValueLocker locker;
513 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000514 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000515 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000516 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000517 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000518 if (log)
519 {
520 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000521 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000522 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000523 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000524 }
525 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000527#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000528
529const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000530SBValue::GetLocation ()
531{
Greg Clayton5160ce52013-03-27 23:08:40 +0000532 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000533 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000534 ValueLocker locker;
535 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000536 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000537 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000538 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000539 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000540 if (log)
541 {
542 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000543 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000544 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000545 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000546 }
547 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000548}
549
Enrico Granata07a4ac22012-05-08 21:25:06 +0000550// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000551bool
Jim Ingham6035b672011-03-31 00:19:25 +0000552SBValue::SetValueFromCString (const char *value_str)
553{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000554 lldb::SBError dummy;
555 return SetValueFromCString(value_str,dummy);
556}
557
558bool
559SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
560{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000562 ValueLocker locker;
563 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000564 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000565 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000566 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000567 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000568 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000569 else
570 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
571
Greg Claytonc9858e42012-04-06 02:17:47 +0000572 if (log)
573 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
574
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575 return success;
576}
577
Enrico Granata864e3e82012-02-17 03:18:30 +0000578lldb::SBTypeFormat
579SBValue::GetTypeFormat ()
580{
581 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000582 ValueLocker locker;
583 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000584 if (value_sp)
585 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000586 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000587 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000588 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
589 if (format_sp)
590 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000591 }
592 }
593 return format;
594}
595
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000596#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000597lldb::SBTypeSummary
598SBValue::GetTypeSummary ()
599{
600 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000601 ValueLocker locker;
602 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000603 if (value_sp)
604 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000605 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000606 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000607 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
608 if (summary_sp)
609 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000610 }
611 }
612 return summary;
613}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000614#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000615
616lldb::SBTypeFilter
617SBValue::GetTypeFilter ()
618{
619 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000620 ValueLocker locker;
621 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000622 if (value_sp)
623 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000624 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000625 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000626 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
627
628 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000629 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000630 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
631 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000632 }
633 }
634 }
635 return filter;
636}
637
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000638#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000639lldb::SBTypeSynthetic
640SBValue::GetTypeSynthetic ()
641{
642 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000643 ValueLocker locker;
644 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000645 if (value_sp)
646 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000647 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000648 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000649 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
650
651 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000652 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000653 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
654 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000655 }
656 }
657 }
658 return synthetic;
659}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000660#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000661
Enrico Granata6f3533f2011-07-29 19:53:35 +0000662lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000663SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000664{
Greg Clayton81e871e2012-02-04 02:27:34 +0000665 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000666 ValueLocker locker;
667 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000668 lldb::ValueObjectSP new_value_sp;
669 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000670 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000671 TypeImplSP type_sp (type.GetSP());
672 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000673 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000674 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000675 }
676 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000677 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000678 if (log)
679 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000680 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000681 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
682 value_sp.get(),
683 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000684 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000685 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
686 value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000687 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000688 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000689}
690
691lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000692SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000693{
Greg Claytonef496d52012-01-31 04:25:15 +0000694 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000695 ValueLocker locker;
696 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000697 TypeImplSP type_sp (type.GetSP());
698 if (value_sp && type_sp)
Enrico Granatae3e91512012-10-22 18:18:36 +0000699 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000700 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000701}
702
703lldb::SBValue
704SBValue::CreateValueFromExpression (const char *name, const char* expression)
705{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000706 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000707 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000708 return CreateValueFromExpression (name, expression, options);
709}
710
711lldb::SBValue
712SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
713{
Greg Clayton5160ce52013-03-27 23:08:40 +0000714 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000715 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000716 ValueLocker locker;
717 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000718 lldb::ValueObjectSP new_value_sp;
719 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000720 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000721 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Jim Ingham362e39a2013-05-15 02:16:21 +0000722 Target* target = exe_ctx.GetTargetPtr();
723 if (target)
Johnny Chen50660442011-12-20 01:52:44 +0000724 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000725 options.ref().SetKeepInMemory(true);
726 target->EvaluateExpression (expression,
727 exe_ctx.GetFramePtr(),
728 new_value_sp,
729 options.ref());
730 if (new_value_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000731 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000732 new_value_sp->SetName(ConstString(name));
733 sb_value.SetSP(new_value_sp);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000734 }
Johnny Chen50660442011-12-20 01:52:44 +0000735 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000736 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000737 if (log)
738 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000739 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000740 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Claytonc9858e42012-04-06 02:17:47 +0000741 value_sp.get(),
742 name,
743 expression,
744 new_value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000745 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000746 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Claytonc9858e42012-04-06 02:17:47 +0000747 value_sp.get(),
748 name,
749 expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000750 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000751 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000752}
753
754lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000755SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000756{
Greg Clayton81e871e2012-02-04 02:27:34 +0000757 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000758 ValueLocker locker;
759 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000760 lldb::ValueObjectSP new_value_sp;
761 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
762 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000763 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000764 ClangASTType pointee_ast_type(type_impl_sp->GetClangASTType().GetPointerType ());
765 if (pointee_ast_type)
Enrico Granata61408e02011-08-04 17:07:02 +0000766 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000767 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
768
Greg Claytoncc4d0142012-02-17 07:49:44 +0000769 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
770 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000771 pointee_ast_type,
Greg Clayton81e871e2012-02-04 02:27:34 +0000772 ConstString(name),
773 buffer,
774 lldb::endian::InlHostByteOrder(),
Greg Claytoncc4d0142012-02-17 07:49:44 +0000775 exe_ctx.GetAddressByteSize()));
Greg Clayton81e871e2012-02-04 02:27:34 +0000776
777 if (ptr_result_valobj_sp)
778 {
779 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
780 Error err;
781 new_value_sp = ptr_result_valobj_sp->Dereference(err);
782 if (new_value_sp)
783 new_value_sp->SetName(ConstString(name));
784 }
785 sb_value.SetSP(new_value_sp);
Enrico Granata61408e02011-08-04 17:07:02 +0000786 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000787 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000788 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000789 if (log)
790 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000791 if (new_value_sp)
792 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000793 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000794 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chen4a871f92011-08-09 22:38:07 +0000795 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000796 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000797}
798
Enrico Granata9128ee22011-09-06 19:20:51 +0000799lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000800SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000801{
Greg Clayton81e871e2012-02-04 02:27:34 +0000802 lldb::SBValue sb_value;
803 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000804 ValueLocker locker;
805 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000806 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000807 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000808 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
809
810 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +0000811 type.m_opaque_sp->GetClangASTType(),
Greg Clayton81e871e2012-02-04 02:27:34 +0000812 ConstString(name),
813 *data.m_opaque_sp,
814 LLDB_INVALID_ADDRESS);
815 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
816 sb_value.SetSP(new_value_sp);
Enrico Granata9128ee22011-09-06 19:20:51 +0000817 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000818 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000819 if (log)
820 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000821 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000822 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000823 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000824 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000825 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000826 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000827}
828
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000829SBValue
830SBValue::GetChildAtIndex (uint32_t idx)
831{
Greg Claytonf66024822011-07-15 19:31:49 +0000832 const bool can_create_synthetic = false;
833 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000834 TargetSP target_sp;
835 if (m_opaque_sp)
836 target_sp = m_opaque_sp->GetTargetSP();
837
838 if (target_sp)
839 use_dynamic = target_sp->GetPreferDynamicValue();
840
Greg Claytonf66024822011-07-15 19:31:49 +0000841 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000842}
843
844SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000845SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000846{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000848 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849
Jim Ingham362e39a2013-05-15 02:16:21 +0000850 ValueLocker locker;
851 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000852 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000854 const bool can_create = true;
855 child_sp = value_sp->GetChildAtIndex (idx, can_create);
856 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000857 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000858 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000859 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000860 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
861 }
862 else if (value_sp->IsArrayType())
863 {
864 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000865 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000866 }
867 }
868
Enrico Granatae3e91512012-10-22 18:18:36 +0000869 SBValue sb_value;
870 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000871 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000872 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000873
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000874 return sb_value;
875}
876
877uint32_t
878SBValue::GetIndexOfChildWithName (const char *name)
879{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000880 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000881 ValueLocker locker;
882 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000883 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000884 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000885 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +0000886 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000887 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000888 if (log)
889 {
890 if (idx == UINT32_MAX)
Greg Clayton81e871e2012-02-04 02:27:34 +0000891 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000892 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000893 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000894 }
895 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000896}
897
898SBValue
899SBValue::GetChildMemberWithName (const char *name)
900{
Jim Ingham362e39a2013-05-15 02:16:21 +0000901 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
902 TargetSP target_sp;
903 if (m_opaque_sp)
904 target_sp = m_opaque_sp->GetTargetSP();
905
906 if (target_sp)
907 use_dynamic_value = target_sp->GetPreferDynamicValue();
908 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +0000909}
910
911SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000912SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +0000913{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000914 lldb::ValueObjectSP child_sp;
915 const ConstString str_name (name);
916
Greg Clayton5160ce52013-03-27 23:08:40 +0000917 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton43479732011-05-20 22:07:17 +0000918
Jim Ingham362e39a2013-05-15 02:16:21 +0000919 ValueLocker locker;
920 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000921 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000922 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000923 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +0000924 }
925
Enrico Granatae3e91512012-10-22 18:18:36 +0000926 SBValue sb_value;
927 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000928
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000929 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000930 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000931
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000932 return sb_value;
933}
934
Enrico Granataf2bbf712011-07-15 02:26:42 +0000935lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +0000936SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
937{
Enrico Granatae3e91512012-10-22 18:18:36 +0000938 SBValue value_sb;
939 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +0000940 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000941 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
942 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +0000943 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000944 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +0000945}
946
947lldb::SBValue
948SBValue::GetStaticValue ()
949{
Enrico Granatae3e91512012-10-22 18:18:36 +0000950 SBValue value_sb;
951 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +0000952 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000953 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
954 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +0000955 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000956 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +0000957}
958
Enrico Granatac5bc4122012-03-27 02:35:13 +0000959lldb::SBValue
960SBValue::GetNonSyntheticValue ()
961{
Enrico Granatae3e91512012-10-22 18:18:36 +0000962 SBValue value_sb;
963 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +0000964 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000965 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
966 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000967 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000968 return value_sb;
969}
970
971lldb::DynamicValueType
972SBValue::GetPreferDynamicValue ()
973{
974 if (!IsValid())
975 return eNoDynamicValues;
976 return m_opaque_sp->GetUseDynamic();
977}
978
979void
980SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
981{
982 if (IsValid())
983 return m_opaque_sp->SetUseDynamic (use_dynamic);
984}
985
986bool
987SBValue::GetPreferSyntheticValue ()
988{
989 if (!IsValid())
990 return false;
991 return m_opaque_sp->GetUseSynthetic();
992}
993
994void
995SBValue::SetPreferSyntheticValue (bool use_synthetic)
996{
997 if (IsValid())
998 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000999}
1000
Jim Ingham60dbabb2011-12-08 19:44:08 +00001001bool
1002SBValue::IsDynamic()
1003{
Jim Ingham362e39a2013-05-15 02:16:21 +00001004 ValueLocker locker;
1005 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001006 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001007 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001008 return false;
1009}
1010
Enrico Granatae3e91512012-10-22 18:18:36 +00001011bool
1012SBValue::IsSynthetic ()
1013{
Jim Ingham362e39a2013-05-15 02:16:21 +00001014 ValueLocker locker;
1015 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001016 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001017 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001018 return false;
1019}
1020
Jim Ingham60dbabb2011-12-08 19:44:08 +00001021lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001022SBValue::GetValueForExpressionPath(const char* expr_path)
1023{
Greg Clayton5160ce52013-03-27 23:08:40 +00001024 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001025 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001026 ValueLocker locker;
1027 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001028 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001029 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001030 // using default values for all the fancy options, just do it if you can
1031 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001032 }
1033
Enrico Granatae3e91512012-10-22 18:18:36 +00001034 SBValue sb_value;
1035 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Enrico Granataf2bbf712011-07-15 02:26:42 +00001036
Enrico Granataf2bbf712011-07-15 02:26:42 +00001037 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001038 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
Enrico Granataf2bbf712011-07-15 02:26:42 +00001039
1040 return sb_value;
1041}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001042
Greg Claytonfe42ac42011-08-03 22:57:10 +00001043int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001044SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1045{
Jim Ingham16e0c682011-08-12 23:34:31 +00001046 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001047 ValueLocker locker;
1048 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001049 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001050 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001051 Scalar scalar;
1052 if (value_sp->ResolveValue (scalar))
1053 return scalar.SLongLong (fail_value);
Enrico Granata6fd87d52011-08-04 01:41:02 +00001054 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001055 error.SetErrorString ("could not resolve value");
Enrico Granata6fd87d52011-08-04 01:41:02 +00001056 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001057 else
1058 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1059
Enrico Granata6fd87d52011-08-04 01:41:02 +00001060 return fail_value;
1061}
1062
1063uint64_t
1064SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1065{
Jim Ingham16e0c682011-08-12 23:34:31 +00001066 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001067 ValueLocker locker;
1068 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001069 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001070 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001071 Scalar scalar;
1072 if (value_sp->ResolveValue (scalar))
1073 return scalar.ULongLong(fail_value);
Enrico Granata6fd87d52011-08-04 01:41:02 +00001074 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001075 error.SetErrorString("could not resolve value");
Enrico Granata6fd87d52011-08-04 01:41:02 +00001076 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001077 else
1078 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1079
Enrico Granata6fd87d52011-08-04 01:41:02 +00001080 return fail_value;
1081}
1082
1083int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001084SBValue::GetValueAsSigned(int64_t fail_value)
1085{
Jim Ingham362e39a2013-05-15 02:16:21 +00001086 ValueLocker locker;
1087 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001088 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001089 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001090 Scalar scalar;
1091 if (value_sp->ResolveValue (scalar))
1092 return scalar.SLongLong(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001093 }
1094 return fail_value;
1095}
1096
1097uint64_t
1098SBValue::GetValueAsUnsigned(uint64_t fail_value)
1099{
Jim Ingham362e39a2013-05-15 02:16:21 +00001100 ValueLocker locker;
1101 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001102 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001103 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001104 Scalar scalar;
1105 if (value_sp->ResolveValue (scalar))
1106 return scalar.ULongLong(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001107 }
1108 return fail_value;
1109}
1110
Greg Clayton4a792072012-10-23 01:50:10 +00001111bool
1112SBValue::MightHaveChildren ()
1113{
Greg Clayton5160ce52013-03-27 23:08:40 +00001114 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001115 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001116 ValueLocker locker;
1117 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001118 if (value_sp)
1119 has_children = value_sp->MightHaveChildren();
1120
1121 if (log)
Enrico Granata1ddbd8a2013-02-28 02:26:12 +00001122 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", value_sp.get(), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001123 return has_children;
1124}
1125
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001126uint32_t
1127SBValue::GetNumChildren ()
1128{
1129 uint32_t num_children = 0;
1130
Greg Clayton5160ce52013-03-27 23:08:40 +00001131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001132 ValueLocker locker;
1133 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001134 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001135 num_children = value_sp->GetNumChildren();
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001136
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001137 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001138 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001139
1140 return num_children;
1141}
1142
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143
1144SBValue
1145SBValue::Dereference ()
1146{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001147 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001148 ValueLocker locker;
1149 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001150 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001151 {
Greg Clayton626f4a12011-06-29 18:28:50 +00001152 Error error;
Greg Clayton81e871e2012-02-04 02:27:34 +00001153 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001154 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001155 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001156 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001157 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001158
1159 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160}
1161
1162bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001163SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164{
1165 bool is_ptr_type = false;
1166
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)
Jim Ingham362e39a2013-05-15 02:16:21 +00001170 is_ptr_type = value_sp->IsPointerType();
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001171
Greg Clayton5160ce52013-03-27 23:08:40 +00001172 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001173 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001174 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001175
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001176
1177 return is_ptr_type;
1178}
1179
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180void *
1181SBValue::GetOpaqueType()
1182{
Jim Ingham362e39a2013-05-15 02:16:21 +00001183 ValueLocker locker;
1184 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001185 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001186 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187 return NULL;
1188}
1189
Enrico Granata6f3533f2011-07-29 19:53:35 +00001190lldb::SBTarget
1191SBValue::GetTarget()
1192{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001193 SBTarget sb_target;
1194 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001195 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001196 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001197 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001198 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001199 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001200 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001201 if (log)
1202 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001203 if (target_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001204 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001205 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001206 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001207 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001208 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001209}
1210
1211lldb::SBProcess
1212SBValue::GetProcess()
1213{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001214 SBProcess sb_process;
1215 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001216 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001217 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001218 process_sp = m_opaque_sp->GetProcessSP();
1219 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001220 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001221 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001222 if (log)
1223 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001224 if (process_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001225 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001226 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001227 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001228 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001229 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001230}
1231
1232lldb::SBThread
1233SBValue::GetThread()
1234{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001235 SBThread sb_thread;
1236 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001237 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001238 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001239 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001240 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001241 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001242 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001243 if (log)
1244 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001245 if (thread_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001246 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001247 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001248 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001249 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001250 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001251}
1252
1253lldb::SBFrame
1254SBValue::GetFrame()
1255{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001256 SBFrame sb_frame;
1257 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001258 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001259 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001260 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001261 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001262 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001263 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001264 if (log)
1265 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001266 if (frame_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001267 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001268 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001269 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001270 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001271 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001272}
1273
1274
Greg Clayton81e871e2012-02-04 02:27:34 +00001275lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001276SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277{
Enrico Granatae3e91512012-10-22 18:18:36 +00001278 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1279 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001280 return locker.GetLockedSP(*m_opaque_sp.get());
1281}
1282
1283lldb::ValueObjectSP
1284SBValue::GetSP () const
1285{
1286 ValueLocker locker;
1287 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001288}
1289
1290void
1291SBValue::SetSP (ValueImplSP impl_sp)
1292{
1293 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294}
1295
Greg Clayton81e871e2012-02-04 02:27:34 +00001296void
1297SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298{
Enrico Granatae3e91512012-10-22 18:18:36 +00001299 if (sp)
1300 {
1301 lldb::TargetSP target_sp(sp->GetTargetSP());
1302 if (target_sp)
1303 {
1304 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1305 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1306 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1307 }
1308 else
1309 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1310 }
1311 else
1312 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001313}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001314
Enrico Granatae3e91512012-10-22 18:18:36 +00001315void
1316SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1317{
1318 if (sp)
1319 {
1320 lldb::TargetSP target_sp(sp->GetTargetSP());
1321 if (target_sp)
1322 {
1323 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1324 SetSP (sp, use_dynamic, use_synthetic);
1325 }
1326 else
1327 SetSP (sp, use_dynamic, true);
1328 }
1329 else
1330 SetSP (sp, use_dynamic, false);
1331}
1332
1333void
1334SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1335{
1336 if (sp)
1337 {
1338 lldb::TargetSP target_sp(sp->GetTargetSP());
1339 if (target_sp)
1340 {
1341 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1342 SetSP (sp, use_dynamic, use_synthetic);
1343 }
1344 else
1345 SetSP (sp, eNoDynamicValues, use_synthetic);
1346 }
1347 else
1348 SetSP (sp, eNoDynamicValues, use_synthetic);
1349}
1350
1351void
1352SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1353{
1354 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1355}
Greg Clayton81e871e2012-02-04 02:27:34 +00001356
Jim Ingham362e39a2013-05-15 02:16:21 +00001357void
1358SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1359{
1360 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1361}
1362
Caroline Ticedde9cff2010-09-20 05:20:02 +00001363bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001364SBValue::GetExpressionPath (SBStream &description)
1365{
Jim Ingham362e39a2013-05-15 02:16:21 +00001366 ValueLocker locker;
1367 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001368 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001369 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001370 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001371 return true;
1372 }
1373 return false;
1374}
1375
1376bool
1377SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1378{
Jim Ingham362e39a2013-05-15 02:16:21 +00001379 ValueLocker locker;
1380 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001381 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001382 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001383 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001384 return true;
1385 }
1386 return false;
1387}
1388
1389bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001390SBValue::GetDescription (SBStream &description)
1391{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001392 Stream &strm = description.ref();
1393
Jim Ingham362e39a2013-05-15 02:16:21 +00001394 ValueLocker locker;
1395 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001396 if (value_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001397 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001398 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Ticedde9cff2010-09-20 05:20:02 +00001399 }
1400 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001401 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001402
1403 return true;
1404}
Greg Claytondc4e9632011-01-05 18:43:15 +00001405
1406lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001407SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001408{
Jim Ingham362e39a2013-05-15 02:16:21 +00001409 ValueLocker locker;
1410 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001411 if (value_sp)
1412 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001413 return eFormatDefault;
1414}
1415
1416void
1417SBValue::SetFormat (lldb::Format format)
1418{
Jim Ingham362e39a2013-05-15 02:16:21 +00001419 ValueLocker locker;
1420 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001421 if (value_sp)
1422 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001423}
1424
Enrico Granata6f3533f2011-07-29 19:53:35 +00001425lldb::SBValue
1426SBValue::AddressOf()
1427{
1428 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001429 ValueLocker locker;
1430 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001431 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001432 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001433 Error error;
1434 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001435 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001436 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001437 if (log)
Greg Claytoneac87f82012-06-04 20:13:23 +00001438 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001439
1440 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001441}
Enrico Granata9128ee22011-09-06 19:20:51 +00001442
1443lldb::addr_t
1444SBValue::GetLoadAddress()
1445{
1446 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001447 ValueLocker locker;
1448 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001449 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001450 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001451 TargetSP target_sp (value_sp->GetTargetSP());
1452 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001453 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001454 const bool scalar_is_load_address = true;
1455 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001456 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001457 if (addr_type == eAddressTypeFile)
1458 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001459 ModuleSP module_sp (value_sp->GetModule());
1460 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001461 value = LLDB_INVALID_ADDRESS;
1462 else
1463 {
1464 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001465 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001466 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001467 }
1468 }
1469 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1470 value = LLDB_INVALID_ADDRESS;
1471 }
1472 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001473 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001474 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001475 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", value_sp.get(), value);
Enrico Granata9128ee22011-09-06 19:20:51 +00001476
1477 return value;
1478}
1479
1480lldb::SBAddress
1481SBValue::GetAddress()
1482{
1483 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001484 ValueLocker locker;
1485 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001486 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001487 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001488 TargetSP target_sp (value_sp->GetTargetSP());
1489 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001490 {
1491 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001492 const bool scalar_is_load_address = true;
1493 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001494 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001495 if (addr_type == eAddressTypeFile)
1496 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001497 ModuleSP module_sp (value_sp->GetModule());
1498 if (module_sp)
1499 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001500 }
1501 else if (addr_type == eAddressTypeLoad)
1502 {
1503 // no need to check the return value on this.. if it can actually do the resolve
1504 // addr will be in the form (section,offset), otherwise it will simply be returned
1505 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001506 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001507 }
1508 }
1509 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001510 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001511 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001512 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", value_sp.get(),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001513 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"),
1514 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001515 return SBAddress(new Address(addr));
1516}
1517
1518lldb::SBData
1519SBValue::GetPointeeData (uint32_t item_idx,
1520 uint32_t item_count)
1521{
Greg Clayton5160ce52013-03-27 23:08:40 +00001522 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001523 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001524 ValueLocker locker;
1525 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001526 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001527 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001528 TargetSP target_sp (value_sp->GetTargetSP());
1529 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001530 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001531 DataExtractorSP data_sp(new DataExtractor());
1532 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1533 if (data_sp->GetByteSize() > 0)
1534 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001535 }
1536 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001537 if (log)
1538 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001539 value_sp.get(),
Enrico Granata9128ee22011-09-06 19:20:51 +00001540 item_idx,
1541 item_count,
1542 sb_data.get());
1543
1544 return sb_data;
1545}
1546
1547lldb::SBData
1548SBValue::GetData ()
1549{
Greg Clayton5160ce52013-03-27 23:08:40 +00001550 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001551 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001552 ValueLocker locker;
1553 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001554 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001555 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001556 DataExtractorSP data_sp(new DataExtractor());
1557 value_sp->GetData(*data_sp);
1558 if (data_sp->GetByteSize() > 0)
1559 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001560 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001561 if (log)
1562 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001563 value_sp.get(),
Enrico Granata9128ee22011-09-06 19:20:51 +00001564 sb_data.get());
1565
1566 return sb_data;
1567}
Greg Clayton1b282f92011-10-13 18:08:26 +00001568
Sean Callanan389823e2013-04-13 01:21:23 +00001569bool
1570SBValue::SetData (lldb::SBData &data, SBError &error)
1571{
1572 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001573 ValueLocker locker;
1574 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001575 bool ret = true;
1576
1577 if (value_sp)
1578 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001579 DataExtractor *data_extractor = data.get();
1580
1581 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001582 {
1583 if (log)
Jim Ingham362e39a2013-05-15 02:16:21 +00001584 log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
Sean Callanan389823e2013-04-13 01:21:23 +00001585
Jim Ingham362e39a2013-05-15 02:16:21 +00001586 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001587 ret = false;
1588 }
1589 else
1590 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001591 Error set_error;
Sean Callanan389823e2013-04-13 01:21:23 +00001592
Jim Ingham362e39a2013-05-15 02:16:21 +00001593 value_sp->SetData(*data_extractor, set_error);
1594
1595 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001596 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001597 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001598 ret = false;
1599 }
Sean Callanan389823e2013-04-13 01:21:23 +00001600 }
1601 }
1602 else
1603 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001604 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001605 ret = false;
1606 }
1607
1608 if (log)
1609 log->Printf ("SBValue(%p)::SetData (%p) => %s",
1610 value_sp.get(),
1611 data.get(),
1612 ret ? "true" : "false");
1613 return ret;
1614}
1615
Enrico Granata10de0902012-10-10 22:54:17 +00001616lldb::SBDeclaration
1617SBValue::GetDeclaration ()
1618{
Jim Ingham362e39a2013-05-15 02:16:21 +00001619 ValueLocker locker;
1620 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001621 SBDeclaration decl_sb;
1622 if (value_sp)
1623 {
1624 Declaration decl;
1625 if (value_sp->GetDeclaration(decl))
1626 decl_sb.SetDeclaration(decl);
1627 }
1628 return decl_sb;
1629}
1630
Greg Clayton1b282f92011-10-13 18:08:26 +00001631lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001632SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001633{
Greg Clayton81e871e2012-02-04 02:27:34 +00001634 SBWatchpoint sb_watchpoint;
1635
1636 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001637 ValueLocker locker;
1638 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001639 TargetSP target_sp (GetTarget().GetSP());
1640 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001641 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001642 // Read and Write cannot both be false.
1643 if (!read && !write)
1644 return sb_watchpoint;
1645
1646 // If the value is not in scope, don't try and watch and invalid value
1647 if (!IsInScope())
1648 return sb_watchpoint;
1649
1650 addr_t addr = GetLoadAddress();
1651 if (addr == LLDB_INVALID_ADDRESS)
1652 return sb_watchpoint;
1653 size_t byte_size = GetByteSize();
1654 if (byte_size == 0)
1655 return sb_watchpoint;
1656
1657 uint32_t watch_type = 0;
1658 if (read)
1659 watch_type |= LLDB_WATCH_TYPE_READ;
1660 if (write)
1661 watch_type |= LLDB_WATCH_TYPE_WRITE;
1662
Johnny Chenb90827e2012-06-04 23:19:54 +00001663 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001664 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001665 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001666 error.SetError(rc);
Greg Clayton81e871e2012-02-04 02:27:34 +00001667
1668 if (watchpoint_sp)
1669 {
1670 sb_watchpoint.SetSP (watchpoint_sp);
1671 Declaration decl;
1672 if (value_sp->GetDeclaration (decl))
1673 {
1674 if (decl.GetFile())
1675 {
1676 StreamString ss;
1677 // True to show fullpath for declaration file.
1678 decl.DumpStopContext(&ss, true);
1679 watchpoint_sp->SetDeclInfo(ss.GetString());
1680 }
1681 }
1682 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001683 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001684 else if (target_sp)
1685 {
1686 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1687 if (log)
1688 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
1689
1690 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1691 }
1692 else
1693 {
1694 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1695 if (log)
1696 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
1697 error.SetErrorString("could not set watchpoint, a target is required");
1698 }
1699
Greg Clayton1b282f92011-10-13 18:08:26 +00001700 return sb_watchpoint;
1701}
1702
Johnny Chend3761a72012-06-04 23:45:50 +00001703// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1704// Backward compatibility fix in the interim.
1705lldb::SBWatchpoint
1706SBValue::Watch (bool resolve_location, bool read, bool write)
1707{
Johnny Chen974759f2012-06-05 00:14:15 +00001708 SBError error;
1709 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001710}
1711
Greg Clayton1b282f92011-10-13 18:08:26 +00001712lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001713SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001714{
Greg Clayton81e871e2012-02-04 02:27:34 +00001715 SBWatchpoint sb_watchpoint;
1716 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001717 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001718 return sb_watchpoint;
1719}