blob: 33608f3ebeb7a4bb7d3f875f58058ed35df277cc [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 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000476 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
477 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 Clayton81e871e2012-02-04 02:27:34 +0000764 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
765 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
766 if (pointee_type_impl_sp)
Enrico Granata61408e02011-08-04 17:07:02 +0000767 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000768
769 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
770
Greg Claytoncc4d0142012-02-17 07:49:44 +0000771 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
772 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton81e871e2012-02-04 02:27:34 +0000773 pointee_type_impl_sp->GetASTContext(),
774 pointee_type_impl_sp->GetOpaqueQualType(),
775 ConstString(name),
776 buffer,
777 lldb::endian::InlHostByteOrder(),
Greg Claytoncc4d0142012-02-17 07:49:44 +0000778 exe_ctx.GetAddressByteSize()));
Greg Clayton81e871e2012-02-04 02:27:34 +0000779
780 if (ptr_result_valobj_sp)
781 {
782 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
783 Error err;
784 new_value_sp = ptr_result_valobj_sp->Dereference(err);
785 if (new_value_sp)
786 new_value_sp->SetName(ConstString(name));
787 }
788 sb_value.SetSP(new_value_sp);
Enrico Granata61408e02011-08-04 17:07:02 +0000789 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000790 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000791 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000792 if (log)
793 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000794 if (new_value_sp)
795 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000796 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000797 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chen4a871f92011-08-09 22:38:07 +0000798 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000799 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000800}
801
Enrico Granata9128ee22011-09-06 19:20:51 +0000802lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000803SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000804{
Greg Clayton81e871e2012-02-04 02:27:34 +0000805 lldb::SBValue sb_value;
806 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000807 ValueLocker locker;
808 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000809 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000810 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000811 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
812
813 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton81e871e2012-02-04 02:27:34 +0000814 type.m_opaque_sp->GetASTContext() ,
815 type.m_opaque_sp->GetOpaqueQualType(),
816 ConstString(name),
817 *data.m_opaque_sp,
818 LLDB_INVALID_ADDRESS);
819 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
820 sb_value.SetSP(new_value_sp);
Enrico Granata9128ee22011-09-06 19:20:51 +0000821 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000822 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000823 if (log)
824 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000825 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000826 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000827 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000828 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000829 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000830 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000831}
832
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833SBValue
834SBValue::GetChildAtIndex (uint32_t idx)
835{
Greg Claytonf66024822011-07-15 19:31:49 +0000836 const bool can_create_synthetic = false;
837 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000838 TargetSP target_sp;
839 if (m_opaque_sp)
840 target_sp = m_opaque_sp->GetTargetSP();
841
842 if (target_sp)
843 use_dynamic = target_sp->GetPreferDynamicValue();
844
Greg Claytonf66024822011-07-15 19:31:49 +0000845 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000846}
847
848SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000849SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000850{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000851 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000852 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000853
Jim Ingham362e39a2013-05-15 02:16:21 +0000854 ValueLocker locker;
855 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000856 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000857 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000858 const bool can_create = true;
859 child_sp = value_sp->GetChildAtIndex (idx, can_create);
860 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000861 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000862 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000863 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000864 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
865 }
866 else if (value_sp->IsArrayType())
867 {
868 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000869 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000870 }
871 }
872
Enrico Granatae3e91512012-10-22 18:18:36 +0000873 SBValue sb_value;
874 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000875 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000876 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000877
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000878 return sb_value;
879}
880
881uint32_t
882SBValue::GetIndexOfChildWithName (const char *name)
883{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000884 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000885 ValueLocker locker;
886 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000887 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000888 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000889 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +0000890 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000891 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000892 if (log)
893 {
894 if (idx == UINT32_MAX)
Greg Clayton81e871e2012-02-04 02:27:34 +0000895 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000896 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000897 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000898 }
899 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000900}
901
902SBValue
903SBValue::GetChildMemberWithName (const char *name)
904{
Jim Ingham362e39a2013-05-15 02:16:21 +0000905 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
906 TargetSP target_sp;
907 if (m_opaque_sp)
908 target_sp = m_opaque_sp->GetTargetSP();
909
910 if (target_sp)
911 use_dynamic_value = target_sp->GetPreferDynamicValue();
912 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +0000913}
914
915SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000916SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +0000917{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000918 lldb::ValueObjectSP child_sp;
919 const ConstString str_name (name);
920
Greg Clayton5160ce52013-03-27 23:08:40 +0000921 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton43479732011-05-20 22:07:17 +0000922
Jim Ingham362e39a2013-05-15 02:16:21 +0000923 ValueLocker locker;
924 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000925 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000926 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000927 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +0000928 }
929
Enrico Granatae3e91512012-10-22 18:18:36 +0000930 SBValue sb_value;
931 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000932
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000933 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000934 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000935
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000936 return sb_value;
937}
938
Enrico Granataf2bbf712011-07-15 02:26:42 +0000939lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +0000940SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
941{
Enrico Granatae3e91512012-10-22 18:18:36 +0000942 SBValue value_sb;
943 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +0000944 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000945 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
946 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +0000947 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000948 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +0000949}
950
951lldb::SBValue
952SBValue::GetStaticValue ()
953{
Enrico Granatae3e91512012-10-22 18:18:36 +0000954 SBValue value_sb;
955 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +0000956 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000957 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
958 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +0000959 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000960 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +0000961}
962
Enrico Granatac5bc4122012-03-27 02:35:13 +0000963lldb::SBValue
964SBValue::GetNonSyntheticValue ()
965{
Enrico Granatae3e91512012-10-22 18:18:36 +0000966 SBValue value_sb;
967 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +0000968 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000969 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
970 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000971 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000972 return value_sb;
973}
974
975lldb::DynamicValueType
976SBValue::GetPreferDynamicValue ()
977{
978 if (!IsValid())
979 return eNoDynamicValues;
980 return m_opaque_sp->GetUseDynamic();
981}
982
983void
984SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
985{
986 if (IsValid())
987 return m_opaque_sp->SetUseDynamic (use_dynamic);
988}
989
990bool
991SBValue::GetPreferSyntheticValue ()
992{
993 if (!IsValid())
994 return false;
995 return m_opaque_sp->GetUseSynthetic();
996}
997
998void
999SBValue::SetPreferSyntheticValue (bool use_synthetic)
1000{
1001 if (IsValid())
1002 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001003}
1004
Jim Ingham60dbabb2011-12-08 19:44:08 +00001005bool
1006SBValue::IsDynamic()
1007{
Jim Ingham362e39a2013-05-15 02:16:21 +00001008 ValueLocker locker;
1009 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001010 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001011 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001012 return false;
1013}
1014
Enrico Granatae3e91512012-10-22 18:18:36 +00001015bool
1016SBValue::IsSynthetic ()
1017{
Jim Ingham362e39a2013-05-15 02:16:21 +00001018 ValueLocker locker;
1019 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001020 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001021 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001022 return false;
1023}
1024
Jim Ingham60dbabb2011-12-08 19:44:08 +00001025lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001026SBValue::GetValueForExpressionPath(const char* expr_path)
1027{
Greg Clayton5160ce52013-03-27 23:08:40 +00001028 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001029 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001030 ValueLocker locker;
1031 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001032 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001033 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001034 // using default values for all the fancy options, just do it if you can
1035 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001036 }
1037
Enrico Granatae3e91512012-10-22 18:18:36 +00001038 SBValue sb_value;
1039 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Enrico Granataf2bbf712011-07-15 02:26:42 +00001040
Enrico Granataf2bbf712011-07-15 02:26:42 +00001041 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001042 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 +00001043
1044 return sb_value;
1045}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001046
Greg Claytonfe42ac42011-08-03 22:57:10 +00001047int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001048SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1049{
Jim Ingham16e0c682011-08-12 23:34:31 +00001050 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001051 ValueLocker locker;
1052 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001053 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001054 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001055 Scalar scalar;
1056 if (value_sp->ResolveValue (scalar))
1057 return scalar.SLongLong (fail_value);
Enrico Granata6fd87d52011-08-04 01:41:02 +00001058 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001059 error.SetErrorString ("could not resolve value");
Enrico Granata6fd87d52011-08-04 01:41:02 +00001060 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001061 else
1062 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1063
Enrico Granata6fd87d52011-08-04 01:41:02 +00001064 return fail_value;
1065}
1066
1067uint64_t
1068SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1069{
Jim Ingham16e0c682011-08-12 23:34:31 +00001070 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001071 ValueLocker locker;
1072 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001073 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001074 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001075 Scalar scalar;
1076 if (value_sp->ResolveValue (scalar))
1077 return scalar.ULongLong(fail_value);
Enrico Granata6fd87d52011-08-04 01:41:02 +00001078 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001079 error.SetErrorString("could not resolve value");
Enrico Granata6fd87d52011-08-04 01:41:02 +00001080 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001081 else
1082 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1083
Enrico Granata6fd87d52011-08-04 01:41:02 +00001084 return fail_value;
1085}
1086
1087int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001088SBValue::GetValueAsSigned(int64_t fail_value)
1089{
Jim Ingham362e39a2013-05-15 02:16:21 +00001090 ValueLocker locker;
1091 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001092 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001093 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001094 Scalar scalar;
1095 if (value_sp->ResolveValue (scalar))
1096 return scalar.SLongLong(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001097 }
1098 return fail_value;
1099}
1100
1101uint64_t
1102SBValue::GetValueAsUnsigned(uint64_t fail_value)
1103{
Jim Ingham362e39a2013-05-15 02:16:21 +00001104 ValueLocker locker;
1105 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001106 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001107 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001108 Scalar scalar;
1109 if (value_sp->ResolveValue (scalar))
1110 return scalar.ULongLong(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001111 }
1112 return fail_value;
1113}
1114
Greg Clayton4a792072012-10-23 01:50:10 +00001115bool
1116SBValue::MightHaveChildren ()
1117{
Greg Clayton5160ce52013-03-27 23:08:40 +00001118 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001119 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001120 ValueLocker locker;
1121 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001122 if (value_sp)
1123 has_children = value_sp->MightHaveChildren();
1124
1125 if (log)
Enrico Granata1ddbd8a2013-02-28 02:26:12 +00001126 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", value_sp.get(), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001127 return has_children;
1128}
1129
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001130uint32_t
1131SBValue::GetNumChildren ()
1132{
1133 uint32_t num_children = 0;
1134
Greg Clayton5160ce52013-03-27 23:08:40 +00001135 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001136 ValueLocker locker;
1137 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001138 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001139 num_children = value_sp->GetNumChildren();
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001140
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001141 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001142 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143
1144 return num_children;
1145}
1146
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001147
1148SBValue
1149SBValue::Dereference ()
1150{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001151 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001152 ValueLocker locker;
1153 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001154 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001155 {
Greg Clayton626f4a12011-06-29 18:28:50 +00001156 Error error;
Greg Clayton81e871e2012-02-04 02:27:34 +00001157 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001158 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001159 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001160 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001161 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001162
1163 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001164}
1165
1166bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001167SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001168{
1169 bool is_ptr_type = false;
1170
Jim Ingham362e39a2013-05-15 02:16:21 +00001171 ValueLocker locker;
1172 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001173 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001174 is_ptr_type = value_sp->IsPointerType();
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001175
Greg Clayton5160ce52013-03-27 23:08:40 +00001176 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001177 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001178 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001179
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001180
1181 return is_ptr_type;
1182}
1183
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001184void *
1185SBValue::GetOpaqueType()
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)
Jim Ingham362e39a2013-05-15 02:16:21 +00001190 return value_sp->GetClangType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001191 return NULL;
1192}
1193
Enrico Granata6f3533f2011-07-29 19:53:35 +00001194lldb::SBTarget
1195SBValue::GetTarget()
1196{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001197 SBTarget sb_target;
1198 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001199 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001200 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001201 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001202 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001203 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001204 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001205 if (log)
1206 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001207 if (target_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001208 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001209 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001210 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001211 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001212 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001213}
1214
1215lldb::SBProcess
1216SBValue::GetProcess()
1217{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001218 SBProcess sb_process;
1219 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001220 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001221 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001222 process_sp = m_opaque_sp->GetProcessSP();
1223 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001224 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001225 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001226 if (log)
1227 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001228 if (process_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001229 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001230 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001231 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001232 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001233 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001234}
1235
1236lldb::SBThread
1237SBValue::GetThread()
1238{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001239 SBThread sb_thread;
1240 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001241 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001242 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001243 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001244 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001245 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001246 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001247 if (log)
1248 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001249 if (thread_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001250 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001251 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001252 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001253 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001254 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001255}
1256
1257lldb::SBFrame
1258SBValue::GetFrame()
1259{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001260 SBFrame sb_frame;
1261 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001262 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001263 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001264 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001265 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001266 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001267 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001268 if (log)
1269 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001270 if (frame_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001271 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001272 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001273 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001274 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001275 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001276}
1277
1278
Greg Clayton81e871e2012-02-04 02:27:34 +00001279lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001280SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001281{
Enrico Granatae3e91512012-10-22 18:18:36 +00001282 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1283 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001284 return locker.GetLockedSP(*m_opaque_sp.get());
1285}
1286
1287lldb::ValueObjectSP
1288SBValue::GetSP () const
1289{
1290 ValueLocker locker;
1291 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001292}
1293
1294void
1295SBValue::SetSP (ValueImplSP impl_sp)
1296{
1297 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001298}
1299
Greg Clayton81e871e2012-02-04 02:27:34 +00001300void
1301SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302{
Enrico Granatae3e91512012-10-22 18:18:36 +00001303 if (sp)
1304 {
1305 lldb::TargetSP target_sp(sp->GetTargetSP());
1306 if (target_sp)
1307 {
1308 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1309 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1310 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1311 }
1312 else
1313 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1314 }
1315 else
1316 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001317}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001318
Enrico Granatae3e91512012-10-22 18:18:36 +00001319void
1320SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1321{
1322 if (sp)
1323 {
1324 lldb::TargetSP target_sp(sp->GetTargetSP());
1325 if (target_sp)
1326 {
1327 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1328 SetSP (sp, use_dynamic, use_synthetic);
1329 }
1330 else
1331 SetSP (sp, use_dynamic, true);
1332 }
1333 else
1334 SetSP (sp, use_dynamic, false);
1335}
1336
1337void
1338SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1339{
1340 if (sp)
1341 {
1342 lldb::TargetSP target_sp(sp->GetTargetSP());
1343 if (target_sp)
1344 {
1345 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1346 SetSP (sp, use_dynamic, use_synthetic);
1347 }
1348 else
1349 SetSP (sp, eNoDynamicValues, use_synthetic);
1350 }
1351 else
1352 SetSP (sp, eNoDynamicValues, use_synthetic);
1353}
1354
1355void
1356SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1357{
1358 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1359}
Greg Clayton81e871e2012-02-04 02:27:34 +00001360
Jim Ingham362e39a2013-05-15 02:16:21 +00001361void
1362SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1363{
1364 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1365}
1366
Caroline Ticedde9cff2010-09-20 05:20:02 +00001367bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001368SBValue::GetExpressionPath (SBStream &description)
1369{
Jim Ingham362e39a2013-05-15 02:16:21 +00001370 ValueLocker locker;
1371 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001372 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001373 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001374 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001375 return true;
1376 }
1377 return false;
1378}
1379
1380bool
1381SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1382{
Jim Ingham362e39a2013-05-15 02:16:21 +00001383 ValueLocker locker;
1384 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001385 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001386 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001387 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001388 return true;
1389 }
1390 return false;
1391}
1392
1393bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001394SBValue::GetDescription (SBStream &description)
1395{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001396 Stream &strm = description.ref();
1397
Jim Ingham362e39a2013-05-15 02:16:21 +00001398 ValueLocker locker;
1399 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001400 if (value_sp)
Caroline Ticedde9cff2010-09-20 05:20:02 +00001401 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001402 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Ticedde9cff2010-09-20 05:20:02 +00001403 }
1404 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001405 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001406
1407 return true;
1408}
Greg Claytondc4e9632011-01-05 18:43:15 +00001409
1410lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001411SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001412{
Jim Ingham362e39a2013-05-15 02:16:21 +00001413 ValueLocker locker;
1414 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001415 if (value_sp)
1416 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001417 return eFormatDefault;
1418}
1419
1420void
1421SBValue::SetFormat (lldb::Format format)
1422{
Jim Ingham362e39a2013-05-15 02:16:21 +00001423 ValueLocker locker;
1424 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001425 if (value_sp)
1426 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001427}
1428
Enrico Granata6f3533f2011-07-29 19:53:35 +00001429lldb::SBValue
1430SBValue::AddressOf()
1431{
1432 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001433 ValueLocker locker;
1434 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001435 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001436 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001437 Error error;
1438 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001439 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001440 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001441 if (log)
Greg Claytoneac87f82012-06-04 20:13:23 +00001442 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001443
1444 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001445}
Enrico Granata9128ee22011-09-06 19:20:51 +00001446
1447lldb::addr_t
1448SBValue::GetLoadAddress()
1449{
1450 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001451 ValueLocker locker;
1452 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001453 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001454 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001455 TargetSP target_sp (value_sp->GetTargetSP());
1456 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001457 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001458 const bool scalar_is_load_address = true;
1459 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001460 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001461 if (addr_type == eAddressTypeFile)
1462 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001463 ModuleSP module_sp (value_sp->GetModule());
1464 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001465 value = LLDB_INVALID_ADDRESS;
1466 else
1467 {
1468 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001469 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001470 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001471 }
1472 }
1473 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1474 value = LLDB_INVALID_ADDRESS;
1475 }
1476 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001477 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001478 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001479 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", value_sp.get(), value);
Enrico Granata9128ee22011-09-06 19:20:51 +00001480
1481 return value;
1482}
1483
1484lldb::SBAddress
1485SBValue::GetAddress()
1486{
1487 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001488 ValueLocker locker;
1489 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001490 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001491 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001492 TargetSP target_sp (value_sp->GetTargetSP());
1493 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001494 {
1495 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001496 const bool scalar_is_load_address = true;
1497 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001498 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001499 if (addr_type == eAddressTypeFile)
1500 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001501 ModuleSP module_sp (value_sp->GetModule());
1502 if (module_sp)
1503 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001504 }
1505 else if (addr_type == eAddressTypeLoad)
1506 {
1507 // no need to check the return value on this.. if it can actually do the resolve
1508 // addr will be in the form (section,offset), otherwise it will simply be returned
1509 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001510 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001511 }
1512 }
1513 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001514 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001515 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001516 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", value_sp.get(),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001517 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"),
1518 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001519 return SBAddress(new Address(addr));
1520}
1521
1522lldb::SBData
1523SBValue::GetPointeeData (uint32_t item_idx,
1524 uint32_t item_count)
1525{
Greg Clayton5160ce52013-03-27 23:08:40 +00001526 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001527 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001528 ValueLocker locker;
1529 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001530 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001531 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001532 TargetSP target_sp (value_sp->GetTargetSP());
1533 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001534 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001535 DataExtractorSP data_sp(new DataExtractor());
1536 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1537 if (data_sp->GetByteSize() > 0)
1538 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001539 }
1540 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001541 if (log)
1542 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001543 value_sp.get(),
Enrico Granata9128ee22011-09-06 19:20:51 +00001544 item_idx,
1545 item_count,
1546 sb_data.get());
1547
1548 return sb_data;
1549}
1550
1551lldb::SBData
1552SBValue::GetData ()
1553{
Greg Clayton5160ce52013-03-27 23:08:40 +00001554 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001555 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001556 ValueLocker locker;
1557 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001558 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001559 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001560 DataExtractorSP data_sp(new DataExtractor());
1561 value_sp->GetData(*data_sp);
1562 if (data_sp->GetByteSize() > 0)
1563 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001564 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001565 if (log)
1566 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001567 value_sp.get(),
Enrico Granata9128ee22011-09-06 19:20:51 +00001568 sb_data.get());
1569
1570 return sb_data;
1571}
Greg Clayton1b282f92011-10-13 18:08:26 +00001572
Sean Callanan389823e2013-04-13 01:21:23 +00001573bool
1574SBValue::SetData (lldb::SBData &data, SBError &error)
1575{
1576 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001577 ValueLocker locker;
1578 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001579 bool ret = true;
1580
1581 if (value_sp)
1582 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001583 DataExtractor *data_extractor = data.get();
1584
1585 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001586 {
1587 if (log)
Jim Ingham362e39a2013-05-15 02:16:21 +00001588 log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
Sean Callanan389823e2013-04-13 01:21:23 +00001589
Jim Ingham362e39a2013-05-15 02:16:21 +00001590 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001591 ret = false;
1592 }
1593 else
1594 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001595 Error set_error;
Sean Callanan389823e2013-04-13 01:21:23 +00001596
Jim Ingham362e39a2013-05-15 02:16:21 +00001597 value_sp->SetData(*data_extractor, set_error);
1598
1599 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001600 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001601 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001602 ret = false;
1603 }
Sean Callanan389823e2013-04-13 01:21:23 +00001604 }
1605 }
1606 else
1607 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001608 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001609 ret = false;
1610 }
1611
1612 if (log)
1613 log->Printf ("SBValue(%p)::SetData (%p) => %s",
1614 value_sp.get(),
1615 data.get(),
1616 ret ? "true" : "false");
1617 return ret;
1618}
1619
Enrico Granata10de0902012-10-10 22:54:17 +00001620lldb::SBDeclaration
1621SBValue::GetDeclaration ()
1622{
Jim Ingham362e39a2013-05-15 02:16:21 +00001623 ValueLocker locker;
1624 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001625 SBDeclaration decl_sb;
1626 if (value_sp)
1627 {
1628 Declaration decl;
1629 if (value_sp->GetDeclaration(decl))
1630 decl_sb.SetDeclaration(decl);
1631 }
1632 return decl_sb;
1633}
1634
Greg Clayton1b282f92011-10-13 18:08:26 +00001635lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001636SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001637{
Greg Clayton81e871e2012-02-04 02:27:34 +00001638 SBWatchpoint sb_watchpoint;
1639
1640 // If the SBValue is not valid, there's no point in even trying to watch it.
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 TargetSP target_sp (GetTarget().GetSP());
1644 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001645 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001646 // Read and Write cannot both be false.
1647 if (!read && !write)
1648 return sb_watchpoint;
1649
1650 // If the value is not in scope, don't try and watch and invalid value
1651 if (!IsInScope())
1652 return sb_watchpoint;
1653
1654 addr_t addr = GetLoadAddress();
1655 if (addr == LLDB_INVALID_ADDRESS)
1656 return sb_watchpoint;
1657 size_t byte_size = GetByteSize();
1658 if (byte_size == 0)
1659 return sb_watchpoint;
1660
1661 uint32_t watch_type = 0;
1662 if (read)
1663 watch_type |= LLDB_WATCH_TYPE_READ;
1664 if (write)
1665 watch_type |= LLDB_WATCH_TYPE_WRITE;
1666
Johnny Chenb90827e2012-06-04 23:19:54 +00001667 Error rc;
Jim Inghama7dfb662012-10-23 07:20:06 +00001668 ClangASTType type (value_sp->GetClangAST(), value_sp->GetClangType());
1669 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001670 error.SetError(rc);
Greg Clayton81e871e2012-02-04 02:27:34 +00001671
1672 if (watchpoint_sp)
1673 {
1674 sb_watchpoint.SetSP (watchpoint_sp);
1675 Declaration decl;
1676 if (value_sp->GetDeclaration (decl))
1677 {
1678 if (decl.GetFile())
1679 {
1680 StreamString ss;
1681 // True to show fullpath for declaration file.
1682 decl.DumpStopContext(&ss, true);
1683 watchpoint_sp->SetDeclInfo(ss.GetString());
1684 }
1685 }
1686 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001687 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001688 else if (target_sp)
1689 {
1690 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1691 if (log)
1692 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
1693
1694 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1695 }
1696 else
1697 {
1698 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1699 if (log)
1700 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
1701 error.SetErrorString("could not set watchpoint, a target is required");
1702 }
1703
Greg Clayton1b282f92011-10-13 18:08:26 +00001704 return sb_watchpoint;
1705}
1706
Johnny Chend3761a72012-06-04 23:45:50 +00001707// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1708// Backward compatibility fix in the interim.
1709lldb::SBWatchpoint
1710SBValue::Watch (bool resolve_location, bool read, bool write)
1711{
Johnny Chen974759f2012-06-05 00:14:15 +00001712 SBError error;
1713 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001714}
1715
Greg Clayton1b282f92011-10-13 18:08:26 +00001716lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001717SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001718{
Greg Clayton81e871e2012-02-04 02:27:34 +00001719 SBWatchpoint sb_watchpoint;
1720 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001721 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001722 return sb_watchpoint;
1723}