blob: c379508ab05b6c53eca6e50b164e9a2e432515f4 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBValue.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000013
Enrico Granata10de0902012-10-10 22:54:17 +000014#include "lldb/API/SBDeclaration.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000016#include "lldb/API/SBTypeFilter.h"
17#include "lldb/API/SBTypeFormat.h"
18#include "lldb/API/SBTypeSummary.h"
19#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
Johnny Chen01a67862011-10-14 00:42:25 +000021#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/DataExtractor.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/Module.h"
Greg Claytonfe42ac42011-08-03 22:57:10 +000025#include "lldb/Core/Scalar.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Stream.h"
28#include "lldb/Core/StreamFile.h"
29#include "lldb/Core/Value.h"
30#include "lldb/Core/ValueObject.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000031#include "lldb/Core/ValueObjectConstResult.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000032#include "lldb/DataFormatters/DataVisualization.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Symbol/Block.h"
Enrico Granata10de0902012-10-10 22:54:17 +000034#include "lldb/Symbol/Declaration.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Symbol/ObjectFile.h"
Greg Clayton81e871e2012-02-04 02:27:34 +000036#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Symbol/Variable.h"
Johnny Chen01a67862011-10-14 00:42:25 +000038#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/ExecutionContext.h"
40#include "lldb/Target/Process.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000041#include "lldb/Target/StackFrame.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000042#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Thread.h"
44
Jim Ingham35e1bda2012-10-16 21:41:58 +000045#include "lldb/API/SBDebugger.h"
46#include "lldb/API/SBExpressionOptions.h"
47#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000048#include "lldb/API/SBProcess.h"
49#include "lldb/API/SBTarget.h"
50#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
Enrico Granata19f0e8c2013-04-22 22:57:56 +000055class ValueImpl
56{
57public:
58 ValueImpl ()
Enrico Granatae3e91512012-10-22 18:18:36 +000059 {
Enrico Granata19f0e8c2013-04-22 22:57:56 +000060 }
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) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000066 m_valobj_sp(in_valobj_sp),
67 m_use_dynamic(use_dynamic),
68 m_use_synthetic(use_synthetic),
69 m_name (name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000070 {
Jim Ingham362e39a2013-05-15 02:16:21 +000071 if (!m_name.IsEmpty() && m_valobj_sp)
72 m_valobj_sp->SetName(m_name);
Enrico Granata19f0e8c2013-04-22 22:57:56 +000073 }
74
75 ValueImpl (const ValueImpl& rhs) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000076 m_valobj_sp(rhs.m_valobj_sp),
77 m_use_dynamic(rhs.m_use_dynamic),
78 m_use_synthetic(rhs.m_use_synthetic),
79 m_name (rhs.m_name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000080 {
81 }
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 Ingham793d8d92013-12-06 22:21:04 +000099 if (m_valobj_sp.get() == NULL)
100 return false;
101 else
102 {
103 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
104 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
105 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
106 // invalid after you call this...
107 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
108 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
109 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
110 // tracking that in all the ValueObject subclasses.
111 TargetSP target_sp = m_valobj_sp->GetTargetSP();
112 if (target_sp && target_sp->IsValid())
113 return true;
114 else
115 return false;
116 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000117 }
118
119 lldb::ValueObjectSP
120 GetRootSP ()
121 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000122 return m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000123 }
124
125 lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000126 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000127 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000128 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
129 if (!m_valobj_sp)
130 {
131 error.SetErrorString("invalid value object");
132 return m_valobj_sp;
133 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000134
Jim Ingham362e39a2013-05-15 02:16:21 +0000135 lldb::ValueObjectSP value_sp = m_valobj_sp;
136
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000137 Target *target = value_sp->GetTargetSP().get();
138 if (target)
Jim Ingham362e39a2013-05-15 02:16:21 +0000139 api_locker.Lock(target->GetAPIMutex());
Jim Ingham793d8d92013-12-06 22:21:04 +0000140 else
141 return ValueObjectSP();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000142
Jim Ingham362e39a2013-05-15 02:16:21 +0000143 ProcessSP process_sp(value_sp->GetProcessSP());
144 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
145 {
146 // We don't allow people to play around with ValueObject if the process is running.
147 // If you want to look at values, pause the process, then look.
148 if (log)
149 log->Printf ("SBValue(%p)::GetSP() => error: process is running", value_sp.get());
150 error.SetErrorString ("process must be stopped.");
151 return ValueObjectSP();
152 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000153
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000154 if (value_sp->GetDynamicValue(m_use_dynamic))
155 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
156 if (value_sp->GetSyntheticValue(m_use_synthetic))
157 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
Jim Ingham362e39a2013-05-15 02:16:21 +0000158 if (!value_sp)
159 error.SetErrorString("invalid value object");
160 if (!m_name.IsEmpty())
161 value_sp->SetName(m_name);
162
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000163 return value_sp;
164 }
165
166 void
167 SetUseDynamic (lldb::DynamicValueType use_dynamic)
168 {
169 m_use_dynamic = use_dynamic;
170 }
171
172 void
173 SetUseSynthetic (bool use_synthetic)
174 {
175 m_use_synthetic = use_synthetic;
176 }
177
178 lldb::DynamicValueType
179 GetUseDynamic ()
180 {
181 return m_use_dynamic;
182 }
183
184 bool
185 GetUseSynthetic ()
186 {
187 return m_use_synthetic;
188 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000189
Jim Ingham362e39a2013-05-15 02:16:21 +0000190 // All the derived values that we would make from the m_valobj_sp will share
191 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
192 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
193 // provide simple accessors for these, which I do here.
194 TargetSP
195 GetTargetSP ()
196 {
197 if (m_valobj_sp)
198 return m_valobj_sp->GetTargetSP();
199 else
200 return TargetSP();
201 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000202
Jim Ingham362e39a2013-05-15 02:16:21 +0000203 ProcessSP
204 GetProcessSP ()
205 {
206 if (m_valobj_sp)
207 return m_valobj_sp->GetProcessSP();
208 else
209 return ProcessSP();
210 }
211
212 ThreadSP
213 GetThreadSP ()
214 {
215 if (m_valobj_sp)
216 return m_valobj_sp->GetThreadSP();
217 else
218 return ThreadSP();
219 }
220
Jason Molendab57e4a12013-11-04 09:33:30 +0000221 StackFrameSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000222 GetFrameSP ()
223 {
224 if (m_valobj_sp)
225 return m_valobj_sp->GetFrameSP();
226 else
Jason Molendab57e4a12013-11-04 09:33:30 +0000227 return StackFrameSP();
Jim Ingham362e39a2013-05-15 02:16:21 +0000228 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000229
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000230private:
Jim Ingham362e39a2013-05-15 02:16:21 +0000231 lldb::ValueObjectSP m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000232 lldb::DynamicValueType m_use_dynamic;
233 bool m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000234 ConstString m_name;
235};
236
237class ValueLocker
238{
239public:
240 ValueLocker ()
241 {
242 }
243
244 ValueObjectSP
245 GetLockedSP(ValueImpl &in_value)
246 {
247 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
248 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000249
Jim Ingham362e39a2013-05-15 02:16:21 +0000250 Error &
251 GetError()
252 {
253 return m_lock_error;
254 }
255
256private:
257 Process::StopLocker m_stop_locker;
258 Mutex::Locker m_api_locker;
259 Error m_lock_error;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000260
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000261};
Enrico Granatae3e91512012-10-22 18:18:36 +0000262
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000263SBValue::SBValue () :
Daniel Maleae0f8f572013-08-26 23:57:52 +0000264m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000265{
266}
267
Enrico Granatac5bc4122012-03-27 02:35:13 +0000268SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000269{
Enrico Granatae3e91512012-10-22 18:18:36 +0000270 SetSP(value_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000271}
272
Enrico Granatac5bc4122012-03-27 02:35:13 +0000273SBValue::SBValue(const SBValue &rhs)
Greg Claytonefabb122010-11-05 23:17:00 +0000274{
Enrico Granatae3e91512012-10-22 18:18:36 +0000275 SetSP(rhs.m_opaque_sp);
Greg Claytonefabb122010-11-05 23:17:00 +0000276}
277
Greg Claytonbf2331c2011-09-09 23:04:00 +0000278SBValue &
Greg Claytonefabb122010-11-05 23:17:00 +0000279SBValue::operator = (const SBValue &rhs)
280{
281 if (this != &rhs)
Enrico Granatac5bc4122012-03-27 02:35:13 +0000282 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000283 SetSP(rhs.m_opaque_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000284 }
Greg Claytonefabb122010-11-05 23:17:00 +0000285 return *this;
286}
287
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000288SBValue::~SBValue()
289{
290}
291
292bool
Greg Claytonbf2331c2011-09-09 23:04:00 +0000293SBValue::IsValid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000294{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000295 // If this function ever changes to anything that does more than just
296 // check if the opaque shared pointer is non NULL, then we need to update
297 // all "if (m_opaque_sp)" code in this file.
Jim Ingham793d8d92013-12-06 22:21:04 +0000298 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000299}
300
Jim Ingham5d3bca42011-12-19 20:39:44 +0000301void
302SBValue::Clear()
303{
304 m_opaque_sp.reset();
305}
306
Greg Clayton524e60b2010-10-06 22:10:17 +0000307SBError
308SBValue::GetError()
309{
310 SBError sb_error;
311
Jim Ingham362e39a2013-05-15 02:16:21 +0000312 ValueLocker locker;
313 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000314 if (value_sp)
315 sb_error.SetError(value_sp->GetError());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000316 else
Jim Ingham362e39a2013-05-15 02:16:21 +0000317 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
Greg Clayton524e60b2010-10-06 22:10:17 +0000318
319 return sb_error;
320}
321
Johnny Chenb0b8be72011-07-07 20:46:23 +0000322user_id_t
323SBValue::GetID()
324{
Jim Ingham362e39a2013-05-15 02:16:21 +0000325 ValueLocker locker;
326 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000327 if (value_sp)
328 return value_sp->GetID();
Johnny Chenb0b8be72011-07-07 20:46:23 +0000329 return LLDB_INVALID_UID;
330}
331
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000332const char *
333SBValue::GetName()
334{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000335 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000336 ValueLocker locker;
337 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000338 if (value_sp)
339 name = value_sp->GetName().GetCString();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000340
Greg Clayton5160ce52013-03-27 23:08:40 +0000341 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton93aa84e2010-10-29 04:59:35 +0000342 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000343 {
344 if (name)
Greg Clayton81e871e2012-02-04 02:27:34 +0000345 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000346 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000347 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000348 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000349
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000350 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351}
352
353const char *
354SBValue::GetTypeName ()
355{
Greg Clayton5160ce52013-03-27 23:08:40 +0000356 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000357 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000358 ValueLocker locker;
359 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000360 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000361 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000362 name = value_sp->GetQualifiedTypeName().GetCString();
Jim Ingham48cdc582012-08-21 01:46:35 +0000363 }
364
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000365 if (log)
366 {
367 if (name)
Greg Clayton81e871e2012-02-04 02:27:34 +0000368 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000369 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000370 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000371 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000372
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000373 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374}
375
376size_t
377SBValue::GetByteSize ()
378{
Greg Clayton5160ce52013-03-27 23:08:40 +0000379 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000380 size_t result = 0;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000381
Jim Ingham362e39a2013-05-15 02:16:21 +0000382 ValueLocker locker;
383 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000384 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000385 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000386 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000387 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000388
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000389 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000390 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64, value_sp.get(), (uint64_t)result);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000391
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000392 return result;
393}
394
395bool
Jim Ingham6035b672011-03-31 00:19:25 +0000396SBValue::IsInScope ()
397{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000398 bool result = false;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000399
Jim Ingham362e39a2013-05-15 02:16:21 +0000400 ValueLocker locker;
401 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000402 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000403 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000404 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000405 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000406
Greg Clayton5160ce52013-03-27 23:08:40 +0000407 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000408 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000409 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000410
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 return result;
412}
413
414const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000415SBValue::GetValue ()
416{
Greg Clayton5160ce52013-03-27 23:08:40 +0000417 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Daniel Maleae0f8f572013-08-26 23:57:52 +0000418
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000419 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000420 ValueLocker locker;
421 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000422 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000423 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000424 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000425 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000426 if (log)
427 {
428 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000429 log->Printf ("SBValue(%p)::GetValue() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000430 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000431 log->Printf ("SBValue(%p)::GetValue() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000432 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000433
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000434 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000435}
436
Greg Clayton73b472d2010-10-27 03:32:59 +0000437ValueType
438SBValue::GetValueType ()
439{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000440 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000441 ValueLocker locker;
442 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000443 if (value_sp)
444 result = value_sp->GetValueType();
Jim Ingham362e39a2013-05-15 02:16:21 +0000445
Greg Clayton5160ce52013-03-27 23:08:40 +0000446 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000447 if (log)
448 {
449 switch (result)
450 {
Daniel Maleae0f8f572013-08-26 23:57:52 +0000451 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
452 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
453 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
454 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
455 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
456 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
457 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
458 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000459 }
460 }
461 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000462}
463
Jim Ingham53c47f12010-09-10 23:12:17 +0000464const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000465SBValue::GetObjectDescription ()
466{
Greg Clayton5160ce52013-03-27 23:08:40 +0000467 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000468 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000469 ValueLocker locker;
470 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000471 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000472 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000473 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000474 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000475 if (log)
476 {
477 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000478 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000479 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000480 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000481 }
482 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000483}
484
Enrico Granata6f3533f2011-07-29 19:53:35 +0000485SBType
486SBValue::GetType()
487{
Greg Clayton5160ce52013-03-27 23:08:40 +0000488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000489 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000490 ValueLocker locker;
491 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000492 TypeImplSP type_sp;
493 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000494 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000495 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000496 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000497 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000498 if (log)
499 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000500 if (type_sp)
501 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000502 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000503 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000504 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000505 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000506}
507
Jim Ingham6035b672011-03-31 00:19:25 +0000508bool
509SBValue::GetValueDidChange ()
510{
Greg Clayton5160ce52013-03-27 23:08:40 +0000511 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000512 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000513 ValueLocker locker;
514 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000515 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000516 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000517 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000518 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000519 if (log)
Greg Claytonc9858e42012-04-06 02:17:47 +0000520 log->Printf ("SBValue(%p)::GetValueDidChange() => %i", value_sp.get(), result);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000521
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000522 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523}
524
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000525#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000527SBValue::GetSummary ()
528{
Greg Clayton5160ce52013-03-27 23:08:40 +0000529 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000530 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000531 ValueLocker locker;
532 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000533 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000534 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000535 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000536 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000537 if (log)
538 {
539 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000540 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000541 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000542 log->Printf ("SBValue(%p)::GetSummary() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000543 }
544 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000545}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000546#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000547
548const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000549SBValue::GetLocation ()
550{
Greg Clayton5160ce52013-03-27 23:08:40 +0000551 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000552 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000553 ValueLocker locker;
554 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000555 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000556 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000557 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000558 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000559 if (log)
560 {
561 if (cstr)
Greg Claytonc9858e42012-04-06 02:17:47 +0000562 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"", value_sp.get(), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000563 else
Greg Claytonc9858e42012-04-06 02:17:47 +0000564 log->Printf ("SBValue(%p)::GetLocation() => NULL", value_sp.get());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000565 }
566 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000567}
568
Enrico Granata07a4ac22012-05-08 21:25:06 +0000569// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570bool
Jim Ingham6035b672011-03-31 00:19:25 +0000571SBValue::SetValueFromCString (const char *value_str)
572{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000573 lldb::SBError dummy;
574 return SetValueFromCString(value_str,dummy);
575}
576
577bool
578SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
579{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000581 ValueLocker locker;
582 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000583 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000584 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000585 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000586 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000587 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000588 else
589 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
590
Greg Claytonc9858e42012-04-06 02:17:47 +0000591 if (log)
592 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i", value_sp.get(), value_str, success);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000593
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000594 return success;
595}
596
Enrico Granata864e3e82012-02-17 03:18:30 +0000597lldb::SBTypeFormat
598SBValue::GetTypeFormat ()
599{
600 lldb::SBTypeFormat format;
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::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
608 if (format_sp)
609 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000610 }
611 }
612 return format;
613}
614
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000615#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000616lldb::SBTypeSummary
617SBValue::GetTypeSummary ()
618{
619 lldb::SBTypeSummary summary;
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::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
627 if (summary_sp)
628 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000629 }
630 }
631 return summary;
632}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000633#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000634
635lldb::SBTypeFilter
636SBValue::GetTypeFilter ()
637{
638 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000639 ValueLocker locker;
640 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000641 if (value_sp)
642 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000643 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000644 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000645 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
646
647 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000648 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000649 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
650 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000651 }
652 }
653 }
654 return filter;
655}
656
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000657#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000658lldb::SBTypeSynthetic
659SBValue::GetTypeSynthetic ()
660{
661 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000662 ValueLocker locker;
663 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000664 if (value_sp)
665 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000666 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000667 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000668 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
669
670 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000671 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000672 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
673 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000674 }
675 }
676 }
677 return synthetic;
678}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000679#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000680
Enrico Granata6f3533f2011-07-29 19:53:35 +0000681lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000682SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000683{
Greg Clayton81e871e2012-02-04 02:27:34 +0000684 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000685 ValueLocker locker;
686 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000687 lldb::ValueObjectSP new_value_sp;
688 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000689 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000690 TypeImplSP type_sp (type.GetSP());
691 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000692 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000693 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000694 }
695 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000696 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000697 if (log)
698 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000699 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000700 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
701 value_sp.get(),
702 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000703 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000704 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
705 value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000706 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000707 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000708}
709
710lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000711SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000712{
Greg Claytonef496d52012-01-31 04:25:15 +0000713 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000714 ValueLocker locker;
715 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000716 TypeImplSP type_sp (type.GetSP());
717 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000718 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000719 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000720}
721
722lldb::SBValue
723SBValue::CreateValueFromExpression (const char *name, const char* expression)
724{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000725 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000726 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000727 return CreateValueFromExpression (name, expression, options);
728}
729
730lldb::SBValue
731SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
732{
Greg Clayton5160ce52013-03-27 23:08:40 +0000733 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000734 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000735 ValueLocker locker;
736 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000737 lldb::ValueObjectSP new_value_sp;
738 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000739 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000740 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Jim Ingham362e39a2013-05-15 02:16:21 +0000741 Target* target = exe_ctx.GetTargetPtr();
742 if (target)
Johnny Chen50660442011-12-20 01:52:44 +0000743 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000744 options.ref().SetKeepInMemory(true);
745 target->EvaluateExpression (expression,
746 exe_ctx.GetFramePtr(),
747 new_value_sp,
748 options.ref());
749 if (new_value_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000750 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000751 new_value_sp->SetName(ConstString(name));
752 sb_value.SetSP(new_value_sp);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000753 }
Johnny Chen50660442011-12-20 01:52:44 +0000754 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000755 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000756 if (log)
757 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000758 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000759 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Greg Claytonc9858e42012-04-06 02:17:47 +0000760 value_sp.get(),
761 name,
762 expression,
763 new_value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000764 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000765 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Greg Claytonc9858e42012-04-06 02:17:47 +0000766 value_sp.get(),
767 name,
768 expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000769 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000770 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000771}
772
773lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000774SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000775{
Greg Clayton81e871e2012-02-04 02:27:34 +0000776 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000777 ValueLocker locker;
778 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000779 lldb::ValueObjectSP new_value_sp;
780 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
781 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000782 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000783 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(false).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +0000784 if (pointer_ast_type)
Enrico Granata61408e02011-08-04 17:07:02 +0000785 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000786 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Daniel Maleae0f8f572013-08-26 23:57:52 +0000787
Greg Claytoncc4d0142012-02-17 07:49:44 +0000788 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
789 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Enrico Granata347c2aa2013-10-08 21:49:02 +0000790 pointer_ast_type,
Greg Clayton81e871e2012-02-04 02:27:34 +0000791 ConstString(name),
792 buffer,
Enrico Granata347c2aa2013-10-08 21:49:02 +0000793 exe_ctx.GetByteOrder(),
Greg Claytoncc4d0142012-02-17 07:49:44 +0000794 exe_ctx.GetAddressByteSize()));
Daniel Maleae0f8f572013-08-26 23:57:52 +0000795
Greg Clayton81e871e2012-02-04 02:27:34 +0000796 if (ptr_result_valobj_sp)
797 {
798 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
799 Error err;
800 new_value_sp = ptr_result_valobj_sp->Dereference(err);
801 if (new_value_sp)
802 new_value_sp->SetName(ConstString(name));
803 }
804 sb_value.SetSP(new_value_sp);
Enrico Granata61408e02011-08-04 17:07:02 +0000805 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000806 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000807 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000808 if (log)
809 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000810 if (new_value_sp)
811 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000812 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000813 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chen4a871f92011-08-09 22:38:07 +0000814 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000815 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000816}
817
Enrico Granata9128ee22011-09-06 19:20:51 +0000818lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000819SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000820{
Greg Clayton81e871e2012-02-04 02:27:34 +0000821 lldb::SBValue sb_value;
822 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000823 ValueLocker locker;
824 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000825 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000826 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000827 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Daniel Maleae0f8f572013-08-26 23:57:52 +0000828
Greg Claytoncc4d0142012-02-17 07:49:44 +0000829 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000830 type.m_opaque_sp->GetClangASTType(false),
Greg Clayton81e871e2012-02-04 02:27:34 +0000831 ConstString(name),
832 *data.m_opaque_sp,
833 LLDB_INVALID_ADDRESS);
834 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
835 sb_value.SetSP(new_value_sp);
Enrico Granata9128ee22011-09-06 19:20:51 +0000836 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000837 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000838 if (log)
839 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000840 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000841 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000842 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000843 log->Printf ("SBValue(%p)::CreateValueFromData => NULL", value_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000844 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000845 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000846}
847
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848SBValue
849SBValue::GetChildAtIndex (uint32_t idx)
850{
Greg Claytonf66024822011-07-15 19:31:49 +0000851 const bool can_create_synthetic = false;
852 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000853 TargetSP target_sp;
854 if (m_opaque_sp)
855 target_sp = m_opaque_sp->GetTargetSP();
856
857 if (target_sp)
858 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000859
Greg Claytonf66024822011-07-15 19:31:49 +0000860 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000861}
862
863SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000864SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000865{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000866 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000867 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Daniel Maleae0f8f572013-08-26 23:57:52 +0000868
Jim Ingham362e39a2013-05-15 02:16:21 +0000869 ValueLocker locker;
870 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000871 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000872 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000873 const bool can_create = true;
874 child_sp = value_sp->GetChildAtIndex (idx, can_create);
875 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000876 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000877 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000878 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000879 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
880 }
881 else if (value_sp->IsArrayType())
882 {
883 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000884 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000885 }
886 }
887
Enrico Granatae3e91512012-10-22 18:18:36 +0000888 SBValue sb_value;
889 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000890 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000891 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Daniel Maleae0f8f572013-08-26 23:57:52 +0000892
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000893 return sb_value;
894}
895
896uint32_t
897SBValue::GetIndexOfChildWithName (const char *name)
898{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000899 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000900 ValueLocker locker;
901 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000902 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000903 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000904 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +0000905 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000906 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000907 if (log)
908 {
909 if (idx == UINT32_MAX)
Greg Clayton81e871e2012-02-04 02:27:34 +0000910 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000911 else
Greg Clayton81e871e2012-02-04 02:27:34 +0000912 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000913 }
914 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000915}
916
917SBValue
918SBValue::GetChildMemberWithName (const char *name)
919{
Jim Ingham362e39a2013-05-15 02:16:21 +0000920 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
921 TargetSP target_sp;
922 if (m_opaque_sp)
923 target_sp = m_opaque_sp->GetTargetSP();
924
925 if (target_sp)
926 use_dynamic_value = target_sp->GetPreferDynamicValue();
927 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +0000928}
929
930SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000931SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +0000932{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000933 lldb::ValueObjectSP child_sp;
934 const ConstString str_name (name);
Daniel Maleae0f8f572013-08-26 23:57:52 +0000935
Greg Clayton5160ce52013-03-27 23:08:40 +0000936 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Daniel Maleae0f8f572013-08-26 23:57:52 +0000937
Jim Ingham362e39a2013-05-15 02:16:21 +0000938 ValueLocker locker;
939 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000940 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000941 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000942 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +0000943 }
944
Enrico Granatae3e91512012-10-22 18:18:36 +0000945 SBValue sb_value;
946 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Daniel Maleae0f8f572013-08-26 23:57:52 +0000947
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000948 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +0000949 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Daniel Maleae0f8f572013-08-26 23:57:52 +0000950
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000951 return sb_value;
952}
953
Enrico Granataf2bbf712011-07-15 02:26:42 +0000954lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +0000955SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
956{
Enrico Granatae3e91512012-10-22 18:18:36 +0000957 SBValue value_sb;
958 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +0000959 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000960 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
961 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +0000962 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000963 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +0000964}
965
966lldb::SBValue
967SBValue::GetStaticValue ()
968{
Enrico Granatae3e91512012-10-22 18:18:36 +0000969 SBValue value_sb;
970 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +0000971 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000972 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
973 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +0000974 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000975 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +0000976}
977
Enrico Granatac5bc4122012-03-27 02:35:13 +0000978lldb::SBValue
979SBValue::GetNonSyntheticValue ()
980{
Enrico Granatae3e91512012-10-22 18:18:36 +0000981 SBValue value_sb;
982 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +0000983 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000984 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
985 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000986 }
Enrico Granatae3e91512012-10-22 18:18:36 +0000987 return value_sb;
988}
989
990lldb::DynamicValueType
991SBValue::GetPreferDynamicValue ()
992{
993 if (!IsValid())
994 return eNoDynamicValues;
995 return m_opaque_sp->GetUseDynamic();
996}
997
998void
999SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1000{
1001 if (IsValid())
1002 return m_opaque_sp->SetUseDynamic (use_dynamic);
1003}
1004
1005bool
1006SBValue::GetPreferSyntheticValue ()
1007{
1008 if (!IsValid())
1009 return false;
1010 return m_opaque_sp->GetUseSynthetic();
1011}
1012
1013void
1014SBValue::SetPreferSyntheticValue (bool use_synthetic)
1015{
1016 if (IsValid())
1017 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001018}
1019
Jim Ingham60dbabb2011-12-08 19:44:08 +00001020bool
1021SBValue::IsDynamic()
1022{
Jim Ingham362e39a2013-05-15 02:16:21 +00001023 ValueLocker locker;
1024 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001025 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001026 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001027 return false;
1028}
1029
Enrico Granatae3e91512012-10-22 18:18:36 +00001030bool
1031SBValue::IsSynthetic ()
1032{
Jim Ingham362e39a2013-05-15 02:16:21 +00001033 ValueLocker locker;
1034 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001035 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001036 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001037 return false;
1038}
1039
Jim Ingham60dbabb2011-12-08 19:44:08 +00001040lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001041SBValue::GetValueForExpressionPath(const char* expr_path)
1042{
Greg Clayton5160ce52013-03-27 23:08:40 +00001043 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001044 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001045 ValueLocker locker;
1046 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001047 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001048 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001049 // using default values for all the fancy options, just do it if you can
1050 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001051 }
1052
Enrico Granatae3e91512012-10-22 18:18:36 +00001053 SBValue sb_value;
1054 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Enrico Granataf2bbf712011-07-15 02:26:42 +00001055
Enrico Granataf2bbf712011-07-15 02:26:42 +00001056 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001057 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 +00001058
1059 return sb_value;
1060}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001061
Greg Claytonfe42ac42011-08-03 22:57:10 +00001062int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001063SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1064{
Jim Ingham16e0c682011-08-12 23:34:31 +00001065 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001066 ValueLocker locker;
1067 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001068 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001069 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001070 bool success = true;
1071 uint64_t ret_val = fail_value;
1072 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1073 if (!success)
1074 error.SetErrorString("could not resolve value");
1075 return ret_val;
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
1083uint64_t
1084SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1085{
Jim Ingham16e0c682011-08-12 23:34:31 +00001086 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001087 ValueLocker locker;
1088 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001089 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001090 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001091 bool success = true;
1092 uint64_t ret_val = fail_value;
1093 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1094 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001095 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001096 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001097 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001098 else
1099 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1100
Enrico Granata6fd87d52011-08-04 01:41:02 +00001101 return fail_value;
1102}
1103
1104int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001105SBValue::GetValueAsSigned(int64_t fail_value)
1106{
Jim Ingham362e39a2013-05-15 02:16:21 +00001107 ValueLocker locker;
1108 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001109 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001110 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001111 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001112 }
1113 return fail_value;
1114}
1115
1116uint64_t
1117SBValue::GetValueAsUnsigned(uint64_t fail_value)
1118{
Jim Ingham362e39a2013-05-15 02:16:21 +00001119 ValueLocker locker;
1120 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001121 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001122 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001123 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001124 }
1125 return fail_value;
1126}
1127
Greg Clayton4a792072012-10-23 01:50:10 +00001128bool
1129SBValue::MightHaveChildren ()
1130{
Greg Clayton5160ce52013-03-27 23:08:40 +00001131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001132 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001133 ValueLocker locker;
1134 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001135 if (value_sp)
1136 has_children = value_sp->MightHaveChildren();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001137
Greg Clayton4a792072012-10-23 01:50:10 +00001138 if (log)
Enrico Granata1ddbd8a2013-02-28 02:26:12 +00001139 log->Printf ("SBValue(%p)::MightHaveChildren() => %i", value_sp.get(), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001140 return has_children;
1141}
1142
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001143uint32_t
1144SBValue::GetNumChildren ()
1145{
1146 uint32_t num_children = 0;
Daniel Maleae0f8f572013-08-26 23:57:52 +00001147
Greg Clayton5160ce52013-03-27 23:08:40 +00001148 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001149 ValueLocker locker;
1150 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001151 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001152 num_children = value_sp->GetNumChildren();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001153
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001154 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001155 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001156
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001157 return num_children;
1158}
1159
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001160
1161SBValue
1162SBValue::Dereference ()
1163{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001164 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001165 ValueLocker locker;
1166 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001167 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001168 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001169 Error error;
1170 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +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)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Daniel Maleae0f8f572013-08-26 23:57:52 +00001175
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001176 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001177}
1178
1179bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001180SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001181{
1182 bool is_ptr_type = false;
Daniel Maleae0f8f572013-08-26 23:57:52 +00001183
Jim Ingham362e39a2013-05-15 02:16:21 +00001184 ValueLocker locker;
1185 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001186 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001187 is_ptr_type = value_sp->IsPointerType();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001188
Greg Clayton5160ce52013-03-27 23:08:40 +00001189 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001190 if (log)
Greg Clayton81e871e2012-02-04 02:27:34 +00001191 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001192
1193
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001194 return is_ptr_type;
1195}
1196
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001197void *
1198SBValue::GetOpaqueType()
1199{
Jim Ingham362e39a2013-05-15 02:16:21 +00001200 ValueLocker locker;
1201 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001202 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001203 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204 return NULL;
1205}
1206
Enrico Granata6f3533f2011-07-29 19:53:35 +00001207lldb::SBTarget
1208SBValue::GetTarget()
1209{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001210 SBTarget sb_target;
1211 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001212 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001213 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001214 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001215 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001216 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001217 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001218 if (log)
1219 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001220 if (target_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001221 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001222 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001223 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), target_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001224 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001225 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001226}
1227
1228lldb::SBProcess
1229SBValue::GetProcess()
1230{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001231 SBProcess sb_process;
1232 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001233 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001234 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001235 process_sp = m_opaque_sp->GetProcessSP();
1236 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001237 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001238 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001239 if (log)
1240 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001241 if (process_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001242 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001243 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001244 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), process_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001245 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001246 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001247}
1248
1249lldb::SBThread
1250SBValue::GetThread()
1251{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001252 SBThread sb_thread;
1253 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001254 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001255 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001256 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001257 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001258 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001259 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001260 if (log)
1261 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001262 if (thread_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001263 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001264 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001265 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), thread_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001266 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001267 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001268}
1269
1270lldb::SBFrame
1271SBValue::GetFrame()
1272{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001273 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001274 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001275 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001276 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001277 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001278 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001279 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001280 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001281 if (log)
1282 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001283 if (frame_sp.get() == NULL)
Jim Ingham362e39a2013-05-15 02:16:21 +00001284 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001285 else
Jim Ingham362e39a2013-05-15 02:16:21 +00001286 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), frame_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001287 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001288 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001289}
1290
1291
Greg Clayton81e871e2012-02-04 02:27:34 +00001292lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001293SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001294{
Enrico Granatae3e91512012-10-22 18:18:36 +00001295 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1296 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001297 return locker.GetLockedSP(*m_opaque_sp.get());
1298}
1299
1300lldb::ValueObjectSP
1301SBValue::GetSP () const
1302{
1303 ValueLocker locker;
1304 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001305}
1306
1307void
1308SBValue::SetSP (ValueImplSP impl_sp)
1309{
1310 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001311}
1312
Greg Clayton81e871e2012-02-04 02:27:34 +00001313void
1314SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001315{
Enrico Granatae3e91512012-10-22 18:18:36 +00001316 if (sp)
1317 {
1318 lldb::TargetSP target_sp(sp->GetTargetSP());
1319 if (target_sp)
1320 {
1321 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1322 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1323 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1324 }
1325 else
1326 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1327 }
1328 else
1329 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001331
Enrico Granatae3e91512012-10-22 18:18:36 +00001332void
1333SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1334{
1335 if (sp)
1336 {
1337 lldb::TargetSP target_sp(sp->GetTargetSP());
1338 if (target_sp)
1339 {
1340 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1341 SetSP (sp, use_dynamic, use_synthetic);
1342 }
1343 else
1344 SetSP (sp, use_dynamic, true);
1345 }
1346 else
1347 SetSP (sp, use_dynamic, false);
1348}
1349
1350void
1351SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1352{
1353 if (sp)
1354 {
1355 lldb::TargetSP target_sp(sp->GetTargetSP());
1356 if (target_sp)
1357 {
1358 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1359 SetSP (sp, use_dynamic, use_synthetic);
1360 }
1361 else
1362 SetSP (sp, eNoDynamicValues, use_synthetic);
1363 }
1364 else
1365 SetSP (sp, eNoDynamicValues, use_synthetic);
1366}
1367
1368void
1369SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1370{
1371 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1372}
Greg Clayton81e871e2012-02-04 02:27:34 +00001373
Jim Ingham362e39a2013-05-15 02:16:21 +00001374void
1375SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1376{
1377 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1378}
1379
Caroline Ticedde9cff2010-09-20 05:20:02 +00001380bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001381SBValue::GetExpressionPath (SBStream &description)
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 Claytoncfd1ace2010-10-31 03:01:06 +00001386 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001387 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001388 return true;
1389 }
1390 return false;
1391}
1392
1393bool
1394SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1395{
Jim Ingham362e39a2013-05-15 02:16:21 +00001396 ValueLocker locker;
1397 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001398 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001399 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001400 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001401 return true;
1402 }
1403 return false;
1404}
1405
1406bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001407SBValue::GetDescription (SBStream &description)
1408{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001409 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001410
Jim Ingham362e39a2013-05-15 02:16:21 +00001411 ValueLocker locker;
1412 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001413 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001414 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001415 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001416 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001417
Caroline Ticedde9cff2010-09-20 05:20:02 +00001418 return true;
1419}
Greg Claytondc4e9632011-01-05 18:43:15 +00001420
1421lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001422SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001423{
Jim Ingham362e39a2013-05-15 02:16:21 +00001424 ValueLocker locker;
1425 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001426 if (value_sp)
1427 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001428 return eFormatDefault;
1429}
1430
1431void
1432SBValue::SetFormat (lldb::Format format)
1433{
Jim Ingham362e39a2013-05-15 02:16:21 +00001434 ValueLocker locker;
1435 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001436 if (value_sp)
1437 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001438}
1439
Enrico Granata6f3533f2011-07-29 19:53:35 +00001440lldb::SBValue
1441SBValue::AddressOf()
1442{
1443 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001444 ValueLocker locker;
1445 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001446 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001447 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001448 Error error;
1449 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001450 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001451 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001452 if (log)
Greg Claytoneac87f82012-06-04 20:13:23 +00001453 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001454
1455 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001456}
Enrico Granata9128ee22011-09-06 19:20:51 +00001457
1458lldb::addr_t
1459SBValue::GetLoadAddress()
1460{
1461 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001462 ValueLocker locker;
1463 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001464 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001465 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001466 TargetSP target_sp (value_sp->GetTargetSP());
1467 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001468 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001469 const bool scalar_is_load_address = true;
1470 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001471 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001472 if (addr_type == eAddressTypeFile)
1473 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001474 ModuleSP module_sp (value_sp->GetModule());
1475 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001476 value = LLDB_INVALID_ADDRESS;
1477 else
1478 {
1479 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001480 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001481 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001482 }
1483 }
1484 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1485 value = LLDB_INVALID_ADDRESS;
1486 }
1487 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001488 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001489 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001490 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", value_sp.get(), value);
Enrico Granata9128ee22011-09-06 19:20:51 +00001491
1492 return value;
1493}
1494
1495lldb::SBAddress
1496SBValue::GetAddress()
1497{
1498 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001499 ValueLocker locker;
1500 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001501 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001502 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001503 TargetSP target_sp (value_sp->GetTargetSP());
1504 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001505 {
1506 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001507 const bool scalar_is_load_address = true;
1508 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001509 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001510 if (addr_type == eAddressTypeFile)
1511 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001512 ModuleSP module_sp (value_sp->GetModule());
1513 if (module_sp)
1514 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001515 }
1516 else if (addr_type == eAddressTypeLoad)
1517 {
1518 // no need to check the return value on this.. if it can actually do the resolve
1519 // addr will be in the form (section,offset), otherwise it will simply be returned
1520 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001521 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001522 }
1523 }
1524 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001525 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001526 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +00001527 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", value_sp.get(),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001528 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"),
1529 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001530 return SBAddress(new Address(addr));
1531}
1532
1533lldb::SBData
1534SBValue::GetPointeeData (uint32_t item_idx,
1535 uint32_t item_count)
1536{
Greg Clayton5160ce52013-03-27 23:08:40 +00001537 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001538 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001539 ValueLocker locker;
1540 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001541 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001542 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001543 TargetSP target_sp (value_sp->GetTargetSP());
1544 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001545 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001546 DataExtractorSP data_sp(new DataExtractor());
1547 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1548 if (data_sp->GetByteSize() > 0)
1549 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001550 }
1551 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001552 if (log)
1553 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001554 value_sp.get(),
Enrico Granata9128ee22011-09-06 19:20:51 +00001555 item_idx,
1556 item_count,
1557 sb_data.get());
1558
1559 return sb_data;
1560}
1561
1562lldb::SBData
1563SBValue::GetData ()
1564{
Greg Clayton5160ce52013-03-27 23:08:40 +00001565 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001566 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001567 ValueLocker locker;
1568 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001569 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001570 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001571 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001572 Error error;
1573 value_sp->GetData(*data_sp, error);
1574 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001575 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001576 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001577 if (log)
1578 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton81e871e2012-02-04 02:27:34 +00001579 value_sp.get(),
Enrico Granata9128ee22011-09-06 19:20:51 +00001580 sb_data.get());
1581
1582 return sb_data;
1583}
Greg Clayton1b282f92011-10-13 18:08:26 +00001584
Sean Callanan389823e2013-04-13 01:21:23 +00001585bool
1586SBValue::SetData (lldb::SBData &data, SBError &error)
1587{
1588 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001589 ValueLocker locker;
1590 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001591 bool ret = true;
1592
1593 if (value_sp)
1594 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001595 DataExtractor *data_extractor = data.get();
1596
1597 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001598 {
1599 if (log)
Jim Ingham362e39a2013-05-15 02:16:21 +00001600 log->Printf ("SBValue(%p)::SetData() => error: no data to set", value_sp.get());
Sean Callanan389823e2013-04-13 01:21:23 +00001601
Jim Ingham362e39a2013-05-15 02:16:21 +00001602 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001603 ret = false;
1604 }
1605 else
1606 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001607 Error set_error;
Sean Callanan389823e2013-04-13 01:21:23 +00001608
Jim Ingham362e39a2013-05-15 02:16:21 +00001609 value_sp->SetData(*data_extractor, set_error);
1610
1611 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001612 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001613 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001614 ret = false;
1615 }
Sean Callanan389823e2013-04-13 01:21:23 +00001616 }
1617 }
1618 else
1619 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001620 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001621 ret = false;
1622 }
1623
1624 if (log)
1625 log->Printf ("SBValue(%p)::SetData (%p) => %s",
1626 value_sp.get(),
1627 data.get(),
1628 ret ? "true" : "false");
1629 return ret;
1630}
1631
Enrico Granata10de0902012-10-10 22:54:17 +00001632lldb::SBDeclaration
1633SBValue::GetDeclaration ()
1634{
Jim Ingham362e39a2013-05-15 02:16:21 +00001635 ValueLocker locker;
1636 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001637 SBDeclaration decl_sb;
1638 if (value_sp)
1639 {
1640 Declaration decl;
1641 if (value_sp->GetDeclaration(decl))
1642 decl_sb.SetDeclaration(decl);
1643 }
1644 return decl_sb;
1645}
1646
Greg Clayton1b282f92011-10-13 18:08:26 +00001647lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001648SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001649{
Greg Clayton81e871e2012-02-04 02:27:34 +00001650 SBWatchpoint sb_watchpoint;
1651
1652 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001653 ValueLocker locker;
1654 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001655 TargetSP target_sp (GetTarget().GetSP());
1656 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001657 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001658 // Read and Write cannot both be false.
1659 if (!read && !write)
1660 return sb_watchpoint;
1661
1662 // If the value is not in scope, don't try and watch and invalid value
1663 if (!IsInScope())
1664 return sb_watchpoint;
1665
1666 addr_t addr = GetLoadAddress();
1667 if (addr == LLDB_INVALID_ADDRESS)
1668 return sb_watchpoint;
1669 size_t byte_size = GetByteSize();
1670 if (byte_size == 0)
1671 return sb_watchpoint;
Daniel Maleae0f8f572013-08-26 23:57:52 +00001672
Greg Clayton81e871e2012-02-04 02:27:34 +00001673 uint32_t watch_type = 0;
1674 if (read)
1675 watch_type |= LLDB_WATCH_TYPE_READ;
1676 if (write)
1677 watch_type |= LLDB_WATCH_TYPE_WRITE;
1678
Johnny Chenb90827e2012-06-04 23:19:54 +00001679 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001680 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001681 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001682 error.SetError(rc);
Daniel Maleae0f8f572013-08-26 23:57:52 +00001683
1684 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001685 {
1686 sb_watchpoint.SetSP (watchpoint_sp);
1687 Declaration decl;
1688 if (value_sp->GetDeclaration (decl))
1689 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001690 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001691 {
1692 StreamString ss;
1693 // True to show fullpath for declaration file.
1694 decl.DumpStopContext(&ss, true);
1695 watchpoint_sp->SetDeclInfo(ss.GetString());
1696 }
1697 }
1698 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001699 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001700 else if (target_sp)
1701 {
1702 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1703 if (log)
1704 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s", value_sp.get(), locker.GetError().AsCString());
1705
1706 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1707 }
1708 else
1709 {
1710 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1711 if (log)
1712 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target", value_sp.get());
1713 error.SetErrorString("could not set watchpoint, a target is required");
1714 }
1715
Greg Clayton1b282f92011-10-13 18:08:26 +00001716 return sb_watchpoint;
1717}
1718
Johnny Chend3761a72012-06-04 23:45:50 +00001719// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1720// Backward compatibility fix in the interim.
1721lldb::SBWatchpoint
1722SBValue::Watch (bool resolve_location, bool read, bool write)
1723{
Johnny Chen974759f2012-06-05 00:14:15 +00001724 SBError error;
1725 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001726}
1727
Greg Clayton1b282f92011-10-13 18:08:26 +00001728lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001729SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001730{
Greg Clayton81e871e2012-02-04 02:27:34 +00001731 SBWatchpoint sb_watchpoint;
1732 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001733 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001734 return sb_watchpoint;
1735}