blob: 0d3d7ad956ee2b83a18cc6f54723423eb9369efa [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBValue.cpp ---------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedman4c5de692010-06-09 07:44:37 +000012#include "lldb/API/SBValue.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000013
Enrico Granata10de0902012-10-10 22:54:17 +000014#include "lldb/API/SBDeclaration.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000015#include "lldb/API/SBStream.h"
Enrico Granata864e3e82012-02-17 03:18:30 +000016#include "lldb/API/SBTypeFilter.h"
17#include "lldb/API/SBTypeFormat.h"
18#include "lldb/API/SBTypeSummary.h"
19#include "lldb/API/SBTypeSynthetic.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
Johnny Chen01a67862011-10-14 00:42:25 +000021#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022#include "lldb/Core/DataExtractor.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000023#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024#include "lldb/Core/Module.h"
Greg Claytonfe42ac42011-08-03 22:57:10 +000025#include "lldb/Core/Scalar.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Section.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/Stream.h"
28#include "lldb/Core/StreamFile.h"
29#include "lldb/Core/Value.h"
30#include "lldb/Core/ValueObject.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000031#include "lldb/Core/ValueObjectConstResult.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000032#include "lldb/DataFormatters/DataVisualization.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033#include "lldb/Symbol/Block.h"
Enrico Granata10de0902012-10-10 22:54:17 +000034#include "lldb/Symbol/Declaration.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035#include "lldb/Symbol/ObjectFile.h"
Greg Clayton81e871e2012-02-04 02:27:34 +000036#include "lldb/Symbol/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000037#include "lldb/Symbol/Variable.h"
Johnny Chen01a67862011-10-14 00:42:25 +000038#include "lldb/Symbol/VariableList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039#include "lldb/Target/ExecutionContext.h"
40#include "lldb/Target/Process.h"
Jason Molendab57e4a12013-11-04 09:33:30 +000041#include "lldb/Target/StackFrame.h"
Greg Claytonaf67cec2010-12-20 20:49:23 +000042#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000043#include "lldb/Target/Thread.h"
44
Jim Ingham35e1bda2012-10-16 21:41:58 +000045#include "lldb/API/SBDebugger.h"
46#include "lldb/API/SBExpressionOptions.h"
47#include "lldb/API/SBFrame.h"
Eli Friedman4c5de692010-06-09 07:44:37 +000048#include "lldb/API/SBProcess.h"
49#include "lldb/API/SBTarget.h"
50#include "lldb/API/SBThread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051
52using namespace lldb;
53using namespace lldb_private;
54
Enrico Granata19f0e8c2013-04-22 22:57:56 +000055class ValueImpl
56{
57public:
58 ValueImpl ()
Enrico Granatae3e91512012-10-22 18:18:36 +000059 {
Enrico Granata19f0e8c2013-04-22 22:57:56 +000060 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000061
Jim Ingham362e39a2013-05-15 02:16:21 +000062 ValueImpl (lldb::ValueObjectSP in_valobj_sp,
Enrico Granata19f0e8c2013-04-22 22:57:56 +000063 lldb::DynamicValueType use_dynamic,
Jim Ingham362e39a2013-05-15 02:16:21 +000064 bool use_synthetic,
65 const char *name = NULL) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000066 m_valobj_sp(in_valobj_sp),
67 m_use_dynamic(use_dynamic),
68 m_use_synthetic(use_synthetic),
69 m_name (name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000070 {
Jim Ingham362e39a2013-05-15 02:16:21 +000071 if (!m_name.IsEmpty() && m_valobj_sp)
72 m_valobj_sp->SetName(m_name);
Enrico Granata19f0e8c2013-04-22 22:57:56 +000073 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000074
Enrico Granata19f0e8c2013-04-22 22:57:56 +000075 ValueImpl (const ValueImpl& rhs) :
Daniel Maleae0f8f572013-08-26 23:57:52 +000076 m_valobj_sp(rhs.m_valobj_sp),
77 m_use_dynamic(rhs.m_use_dynamic),
78 m_use_synthetic(rhs.m_use_synthetic),
79 m_name (rhs.m_name)
Enrico Granata19f0e8c2013-04-22 22:57:56 +000080 {
81 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000082
Enrico Granata19f0e8c2013-04-22 22:57:56 +000083 ValueImpl &
84 operator = (const ValueImpl &rhs)
85 {
86 if (this != &rhs)
Enrico Granatae3e91512012-10-22 18:18:36 +000087 {
Jim Ingham362e39a2013-05-15 02:16:21 +000088 m_valobj_sp = rhs.m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +000089 m_use_dynamic = rhs.m_use_dynamic;
90 m_use_synthetic = rhs.m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +000091 m_name = rhs.m_name;
Enrico Granatae3e91512012-10-22 18:18:36 +000092 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +000093 return *this;
94 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000095
Enrico Granata19f0e8c2013-04-22 22:57:56 +000096 bool
97 IsValid ()
98 {
Jim Ingham793d8d92013-12-06 22:21:04 +000099 if (m_valobj_sp.get() == NULL)
100 return false;
101 else
102 {
103 // FIXME: This check is necessary but not sufficient. We for sure don't want to touch SBValues whose owning
104 // targets have gone away. This check is a little weak in that it enforces that restriction when you call
105 // IsValid, but since IsValid doesn't lock the target, you have no guarantee that the SBValue won't go
106 // invalid after you call this...
107 // Also, an SBValue could depend on data from one of the modules in the target, and those could go away
108 // independently of the target, for instance if a module is unloaded. But right now, neither SBValues
109 // nor ValueObjects know which modules they depend on. So I have no good way to make that check without
110 // tracking that in all the ValueObject subclasses.
111 TargetSP target_sp = m_valobj_sp->GetTargetSP();
112 if (target_sp && target_sp->IsValid())
113 return true;
114 else
115 return false;
116 }
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000117 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000118
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000119 lldb::ValueObjectSP
120 GetRootSP ()
121 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000122 return m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000123 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000124
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000125 lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000126 GetSP (Process::StopLocker &stop_locker, Mutex::Locker &api_locker, Error &error)
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000127 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000128 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
129 if (!m_valobj_sp)
130 {
131 error.SetErrorString("invalid value object");
132 return m_valobj_sp;
133 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000134
Jim Ingham362e39a2013-05-15 02:16:21 +0000135 lldb::ValueObjectSP value_sp = m_valobj_sp;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000136
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000137 Target *target = value_sp->GetTargetSP().get();
138 if (target)
Jim Ingham362e39a2013-05-15 02:16:21 +0000139 api_locker.Lock(target->GetAPIMutex());
Jim Ingham793d8d92013-12-06 22:21:04 +0000140 else
141 return ValueObjectSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000142
Jim Ingham362e39a2013-05-15 02:16:21 +0000143 ProcessSP process_sp(value_sp->GetProcessSP());
144 if (process_sp && !stop_locker.TryLock (&process_sp->GetRunLock()))
145 {
146 // We don't allow people to play around with ValueObject if the process is running.
147 // If you want to look at values, pause the process, then look.
148 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000149 log->Printf ("SBValue(%p)::GetSP() => error: process is running",
150 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000151 error.SetErrorString ("process must be stopped.");
152 return ValueObjectSP();
153 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000154
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000155 if (value_sp->GetDynamicValue(m_use_dynamic))
156 value_sp = value_sp->GetDynamicValue(m_use_dynamic);
157 if (value_sp->GetSyntheticValue(m_use_synthetic))
158 value_sp = value_sp->GetSyntheticValue(m_use_synthetic);
Jim Ingham362e39a2013-05-15 02:16:21 +0000159 if (!value_sp)
160 error.SetErrorString("invalid value object");
161 if (!m_name.IsEmpty())
162 value_sp->SetName(m_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000163
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000164 return value_sp;
165 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000166
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000167 void
168 SetUseDynamic (lldb::DynamicValueType use_dynamic)
169 {
170 m_use_dynamic = use_dynamic;
171 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000172
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000173 void
174 SetUseSynthetic (bool use_synthetic)
175 {
176 m_use_synthetic = use_synthetic;
177 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000178
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000179 lldb::DynamicValueType
180 GetUseDynamic ()
181 {
182 return m_use_dynamic;
183 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000184
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000185 bool
186 GetUseSynthetic ()
187 {
188 return m_use_synthetic;
189 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000190
Jim Ingham362e39a2013-05-15 02:16:21 +0000191 // All the derived values that we would make from the m_valobj_sp will share
192 // the ExecutionContext with m_valobj_sp, so we don't need to do the calculations
193 // in GetSP to return the Target, Process, Thread or Frame. It is convenient to
194 // provide simple accessors for these, which I do here.
195 TargetSP
196 GetTargetSP ()
197 {
198 if (m_valobj_sp)
199 return m_valobj_sp->GetTargetSP();
200 else
201 return TargetSP();
202 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000203
Jim Ingham362e39a2013-05-15 02:16:21 +0000204 ProcessSP
205 GetProcessSP ()
206 {
207 if (m_valobj_sp)
208 return m_valobj_sp->GetProcessSP();
209 else
210 return ProcessSP();
211 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000212
Jim Ingham362e39a2013-05-15 02:16:21 +0000213 ThreadSP
214 GetThreadSP ()
215 {
216 if (m_valobj_sp)
217 return m_valobj_sp->GetThreadSP();
218 else
219 return ThreadSP();
220 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000221
Jason Molendab57e4a12013-11-04 09:33:30 +0000222 StackFrameSP
Jim Ingham362e39a2013-05-15 02:16:21 +0000223 GetFrameSP ()
224 {
225 if (m_valobj_sp)
226 return m_valobj_sp->GetFrameSP();
227 else
Jason Molendab57e4a12013-11-04 09:33:30 +0000228 return StackFrameSP();
Jim Ingham362e39a2013-05-15 02:16:21 +0000229 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000230
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000231private:
Jim Ingham362e39a2013-05-15 02:16:21 +0000232 lldb::ValueObjectSP m_valobj_sp;
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000233 lldb::DynamicValueType m_use_dynamic;
234 bool m_use_synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000235 ConstString m_name;
236};
237
238class ValueLocker
239{
240public:
241 ValueLocker ()
242 {
243 }
244
245 ValueObjectSP
246 GetLockedSP(ValueImpl &in_value)
247 {
248 return in_value.GetSP(m_stop_locker, m_api_locker, m_lock_error);
249 }
Daniel Maleae0f8f572013-08-26 23:57:52 +0000250
Jim Ingham362e39a2013-05-15 02:16:21 +0000251 Error &
252 GetError()
253 {
254 return m_lock_error;
255 }
256
257private:
258 Process::StopLocker m_stop_locker;
259 Mutex::Locker m_api_locker;
260 Error m_lock_error;
Daniel Maleae0f8f572013-08-26 23:57:52 +0000261
Enrico Granata19f0e8c2013-04-22 22:57:56 +0000262};
Enrico Granatae3e91512012-10-22 18:18:36 +0000263
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000264SBValue::SBValue () :
Daniel Maleae0f8f572013-08-26 23:57:52 +0000265m_opaque_sp ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000266{
267}
268
Enrico Granatac5bc4122012-03-27 02:35:13 +0000269SBValue::SBValue (const lldb::ValueObjectSP &value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000270{
Enrico Granatae3e91512012-10-22 18:18:36 +0000271 SetSP(value_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000272}
273
Enrico Granatac5bc4122012-03-27 02:35:13 +0000274SBValue::SBValue(const SBValue &rhs)
Greg Claytonefabb122010-11-05 23:17:00 +0000275{
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 SetSP(rhs.m_opaque_sp);
Greg Claytonefabb122010-11-05 23:17:00 +0000277}
278
Greg Claytonbf2331c2011-09-09 23:04:00 +0000279SBValue &
Greg Claytonefabb122010-11-05 23:17:00 +0000280SBValue::operator = (const SBValue &rhs)
281{
282 if (this != &rhs)
Enrico Granatac5bc4122012-03-27 02:35:13 +0000283 {
Enrico Granatae3e91512012-10-22 18:18:36 +0000284 SetSP(rhs.m_opaque_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +0000285 }
Greg Claytonefabb122010-11-05 23:17:00 +0000286 return *this;
287}
288
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000289SBValue::~SBValue()
290{
291}
292
293bool
Greg Claytonbf2331c2011-09-09 23:04:00 +0000294SBValue::IsValid ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000295{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000296 // If this function ever changes to anything that does more than just
297 // check if the opaque shared pointer is non NULL, then we need to update
298 // all "if (m_opaque_sp)" code in this file.
Jim Ingham793d8d92013-12-06 22:21:04 +0000299 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && m_opaque_sp->GetRootSP().get() != NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300}
301
Jim Ingham5d3bca42011-12-19 20:39:44 +0000302void
303SBValue::Clear()
304{
305 m_opaque_sp.reset();
306}
307
Greg Clayton524e60b2010-10-06 22:10:17 +0000308SBError
309SBValue::GetError()
310{
311 SBError sb_error;
312
Jim Ingham362e39a2013-05-15 02:16:21 +0000313 ValueLocker locker;
314 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000315 if (value_sp)
316 sb_error.SetError(value_sp->GetError());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000317 else
Jim Ingham362e39a2013-05-15 02:16:21 +0000318 sb_error.SetErrorStringWithFormat ("error: %s", locker.GetError().AsCString());
Greg Clayton524e60b2010-10-06 22:10:17 +0000319
320 return sb_error;
321}
322
Johnny Chenb0b8be72011-07-07 20:46:23 +0000323user_id_t
324SBValue::GetID()
325{
Jim Ingham362e39a2013-05-15 02:16:21 +0000326 ValueLocker locker;
327 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000328 if (value_sp)
329 return value_sp->GetID();
Johnny Chenb0b8be72011-07-07 20:46:23 +0000330 return LLDB_INVALID_UID;
331}
332
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000333const char *
334SBValue::GetName()
335{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000336 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000337 ValueLocker locker;
338 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000339 if (value_sp)
340 name = value_sp->GetName().GetCString();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000341
Greg Clayton5160ce52013-03-27 23:08:40 +0000342 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton93aa84e2010-10-29 04:59:35 +0000343 if (log)
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000344 {
345 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000346 log->Printf ("SBValue(%p)::GetName () => \"%s\"",
347 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000348 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000349 log->Printf ("SBValue(%p)::GetName () => NULL",
350 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000351 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000352
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000353 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000354}
355
356const char *
357SBValue::GetTypeName ()
358{
Greg Clayton5160ce52013-03-27 23:08:40 +0000359 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000360 const char *name = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000361 ValueLocker locker;
362 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000363 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000364 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000365 name = value_sp->GetQualifiedTypeName().GetCString();
Jim Ingham48cdc582012-08-21 01:46:35 +0000366 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000367
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000368 if (log)
369 {
370 if (name)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000371 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
372 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000373 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000374 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
375 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000376 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000377
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000378 return name;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379}
380
Enrico Granatae8daa2f2014-05-17 19:14:17 +0000381const char *
382SBValue::GetDisplayTypeName ()
383{
384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
385 const char *name = NULL;
386 ValueLocker locker;
387 lldb::ValueObjectSP value_sp(GetSP(locker));
388 if (value_sp)
389 {
390 name = value_sp->GetDisplayTypeName().GetCString();
391 }
392
393 if (log)
394 {
395 if (name)
396 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
397 static_cast<void*>(value_sp.get()), name);
398 else
399 log->Printf ("SBValue(%p)::GetTypeName () => NULL",
400 static_cast<void*>(value_sp.get()));
401 }
402
403 return name;
404}
405
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406size_t
407SBValue::GetByteSize ()
408{
Greg Clayton5160ce52013-03-27 23:08:40 +0000409 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000410 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000411
Jim Ingham362e39a2013-05-15 02:16:21 +0000412 ValueLocker locker;
413 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000414 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000415 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000416 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000417 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000418
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000419 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000420 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
421 static_cast<void*>(value_sp.get()),
422 static_cast<uint64_t>(result));
423
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 return result;
425}
426
427bool
Jim Ingham6035b672011-03-31 00:19:25 +0000428SBValue::IsInScope ()
429{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000431
Jim Ingham362e39a2013-05-15 02:16:21 +0000432 ValueLocker locker;
433 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000434 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000435 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000436 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000437 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000438
Greg Clayton5160ce52013-03-27 23:08:40 +0000439 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000440 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000441 log->Printf ("SBValue(%p)::IsInScope () => %i",
442 static_cast<void*>(value_sp.get()), result);
443
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000444 return result;
445}
446
447const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000448SBValue::GetValue ()
449{
Greg Clayton5160ce52013-03-27 23:08:40 +0000450 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000451
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000452 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000453 ValueLocker locker;
454 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000455 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000456 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000457 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000458 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000459 if (log)
460 {
461 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000462 log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
463 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000464 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000465 log->Printf ("SBValue(%p)::GetValue() => NULL",
466 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000467 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000468
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000469 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470}
471
Greg Clayton73b472d2010-10-27 03:32:59 +0000472ValueType
473SBValue::GetValueType ()
474{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000475 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000476 ValueLocker locker;
477 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000478 if (value_sp)
479 result = value_sp->GetValueType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000480
Greg Clayton5160ce52013-03-27 23:08:40 +0000481 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000482 if (log)
483 {
484 switch (result)
485 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000486 case eValueTypeInvalid:
487 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
488 static_cast<void*>(value_sp.get()));
489 break;
490 case eValueTypeVariableGlobal:
491 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
492 static_cast<void*>(value_sp.get()));
493 break;
494 case eValueTypeVariableStatic:
495 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
496 static_cast<void*>(value_sp.get()));
497 break;
498 case eValueTypeVariableArgument:
499 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
500 static_cast<void*>(value_sp.get()));
501 break;
502 case eValueTypeVariableLocal:
503 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
504 static_cast<void*>(value_sp.get()));
505 break;
506 case eValueTypeRegister:
507 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
508 static_cast<void*>(value_sp.get()));
509 break;
510 case eValueTypeRegisterSet:
511 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
512 static_cast<void*>(value_sp.get()));
513 break;
514 case eValueTypeConstResult:
515 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
516 static_cast<void*>(value_sp.get()));
517 break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000518 }
519 }
520 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000521}
522
Jim Ingham53c47f12010-09-10 23:12:17 +0000523const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000524SBValue::GetObjectDescription ()
525{
Greg Clayton5160ce52013-03-27 23:08:40 +0000526 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000527 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000528 ValueLocker locker;
529 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000530 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000531 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000532 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000533 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000534 if (log)
535 {
536 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000537 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
538 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000539 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000540 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
541 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000542 }
543 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000544}
545
Enrico Granataedc44142014-09-06 01:30:04 +0000546const char *
547SBValue::GetTypeValidatorResult ()
548{
549 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
550 const char *cstr = NULL;
551 ValueLocker locker;
552 lldb::ValueObjectSP value_sp(GetSP(locker));
553 if (value_sp)
554 {
555 const auto& validation(value_sp->GetValidationStatus());
556 if (TypeValidatorResult::Failure == validation.first)
557 {
558 if (validation.second.empty())
559 cstr = "unknown error";
560 else
561 cstr = validation.second.c_str();
562 }
563 }
564 if (log)
565 {
566 if (cstr)
567 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"",
568 static_cast<void*>(value_sp.get()), cstr);
569 else
570 log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL",
571 static_cast<void*>(value_sp.get()));
572 }
573 return cstr;
574}
575
Enrico Granata6f3533f2011-07-29 19:53:35 +0000576SBType
577SBValue::GetType()
578{
Greg Clayton5160ce52013-03-27 23:08:40 +0000579 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000580 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000581 ValueLocker locker;
582 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000583 TypeImplSP type_sp;
584 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000585 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000586 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000587 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000588 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000589 if (log)
590 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000591 if (type_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000592 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
593 static_cast<void*>(value_sp.get()),
594 static_cast<void*>(type_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000595 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000596 log->Printf ("SBValue(%p)::GetType => NULL",
597 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000598 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000599 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000600}
601
Jim Ingham6035b672011-03-31 00:19:25 +0000602bool
603SBValue::GetValueDidChange ()
604{
Greg Clayton5160ce52013-03-27 23:08:40 +0000605 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000606 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000607 ValueLocker locker;
608 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000609 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000610 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000611 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000612 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000613 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000614 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
615 static_cast<void*>(value_sp.get()), result);
616
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000617 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000618}
619
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000620#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000621const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000622SBValue::GetSummary ()
623{
Greg Clayton5160ce52013-03-27 23:08:40 +0000624 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000625 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000626 ValueLocker locker;
627 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000628 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000629 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000630 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000631 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000632 if (log)
633 {
634 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000635 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
636 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000637 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000638 log->Printf ("SBValue(%p)::GetSummary() => NULL",
639 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000640 }
641 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000642}
Enrico Granatac1247f52014-11-06 21:23:20 +0000643
644const char *
Enrico Granata49bfafb2014-11-18 23:36:25 +0000645SBValue::GetSummary (lldb::SBStream& stream,
646 lldb::SBTypeSummaryOptions& options)
Enrico Granatac1247f52014-11-06 21:23:20 +0000647{
648 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granatac1247f52014-11-06 21:23:20 +0000649 ValueLocker locker;
650 lldb::ValueObjectSP value_sp(GetSP(locker));
651 if (value_sp)
652 {
Enrico Granata49bfafb2014-11-18 23:36:25 +0000653 std::string buffer;
654 if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty())
655 stream.Printf("%s",buffer.c_str());
Enrico Granatac1247f52014-11-06 21:23:20 +0000656 }
Enrico Granata49bfafb2014-11-18 23:36:25 +0000657 const char* cstr = stream.GetData();
Enrico Granatac1247f52014-11-06 21:23:20 +0000658 if (log)
659 {
660 if (cstr)
661 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
662 static_cast<void*>(value_sp.get()), cstr);
663 else
664 log->Printf ("SBValue(%p)::GetSummary() => NULL",
665 static_cast<void*>(value_sp.get()));
666 }
667 return cstr;
668}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000669#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000670
671const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000672SBValue::GetLocation ()
673{
Greg Clayton5160ce52013-03-27 23:08:40 +0000674 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000675 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000676 ValueLocker locker;
677 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000678 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000679 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000680 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000681 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000682 if (log)
683 {
684 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000685 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
686 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000687 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000688 log->Printf ("SBValue(%p)::GetLocation() => NULL",
689 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000690 }
691 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692}
693
Enrico Granata07a4ac22012-05-08 21:25:06 +0000694// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000695bool
Jim Ingham6035b672011-03-31 00:19:25 +0000696SBValue::SetValueFromCString (const char *value_str)
697{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000698 lldb::SBError dummy;
699 return SetValueFromCString(value_str,dummy);
700}
701
702bool
703SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
704{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000706 ValueLocker locker;
707 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000708 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000709 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000710 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000711 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000712 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000713 else
714 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000715
Greg Claytonc9858e42012-04-06 02:17:47 +0000716 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000717 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
718 static_cast<void*>(value_sp.get()), value_str, success);
719
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 return success;
721}
722
Enrico Granata864e3e82012-02-17 03:18:30 +0000723lldb::SBTypeFormat
724SBValue::GetTypeFormat ()
725{
726 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000727 ValueLocker locker;
728 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000729 if (value_sp)
730 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000731 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000732 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000733 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
734 if (format_sp)
735 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000736 }
737 }
738 return format;
739}
740
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000741#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000742lldb::SBTypeSummary
743SBValue::GetTypeSummary ()
744{
745 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000746 ValueLocker locker;
747 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000748 if (value_sp)
749 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000750 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000751 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000752 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
753 if (summary_sp)
754 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000755 }
756 }
757 return summary;
758}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000759#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000760
761lldb::SBTypeFilter
762SBValue::GetTypeFilter ()
763{
764 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000765 ValueLocker locker;
766 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000767 if (value_sp)
768 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000769 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000770 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000771 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
772
773 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000774 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000775 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
776 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000777 }
778 }
779 }
780 return filter;
781}
782
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000783#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000784lldb::SBTypeSynthetic
785SBValue::GetTypeSynthetic ()
786{
787 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000788 ValueLocker locker;
789 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000790 if (value_sp)
791 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000792 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000793 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000794 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
795
796 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000797 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000798 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
799 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000800 }
801 }
802 }
803 return synthetic;
804}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000805#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000806
Enrico Granata6f3533f2011-07-29 19:53:35 +0000807lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000808SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000809{
Greg Clayton81e871e2012-02-04 02:27:34 +0000810 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000811 ValueLocker locker;
812 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000813 lldb::ValueObjectSP new_value_sp;
814 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000815 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000816 TypeImplSP type_sp (type.GetSP());
817 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000818 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000819 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000820 }
821 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000822 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000823 if (log)
824 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000825 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000826 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000827 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000828 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000829 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000830 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000831 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000832 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000833 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000834}
835
836lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000837SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000838{
Greg Claytonef496d52012-01-31 04:25:15 +0000839 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000840 ValueLocker locker;
841 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000842 TypeImplSP type_sp (type.GetSP());
843 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000844 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000845 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000846}
847
848lldb::SBValue
849SBValue::CreateValueFromExpression (const char *name, const char* expression)
850{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000851 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000852 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000853 return CreateValueFromExpression (name, expression, options);
854}
855
856lldb::SBValue
857SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
858{
Greg Clayton5160ce52013-03-27 23:08:40 +0000859 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000860 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000861 ValueLocker locker;
862 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000863 lldb::ValueObjectSP new_value_sp;
864 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000865 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000866 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000867 new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref());
868 if (new_value_sp)
869 new_value_sp->SetName(ConstString(name));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000870 }
Enrico Granata972be532014-12-17 21:18:43 +0000871 sb_value.SetSP(new_value_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000872 if (log)
873 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000874 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000875 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000876 static_cast<void*>(value_sp.get()), name, expression,
877 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000878 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000879 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000880 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000881 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000882 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000883}
884
885lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000886SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000887{
Greg Clayton81e871e2012-02-04 02:27:34 +0000888 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000889 ValueLocker locker;
890 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000891 lldb::ValueObjectSP new_value_sp;
892 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
893 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000894 {
Enrico Granata972be532014-12-17 21:18:43 +0000895 ClangASTType ast_type(type_impl_sp->GetClangASTType(true));
896 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
897 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000898 }
Enrico Granata972be532014-12-17 21:18:43 +0000899 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000900 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000901 if (log)
902 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000903 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000904 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
905 static_cast<void*>(value_sp.get()),
906 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000907 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000908 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
909 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000910 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000911 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000912}
913
Enrico Granata9128ee22011-09-06 19:20:51 +0000914lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000915SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000916{
Greg Clayton81e871e2012-02-04 02:27:34 +0000917 lldb::SBValue sb_value;
918 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000919 ValueLocker locker;
920 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000921 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000922 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000923 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Enrico Granata972be532014-12-17 21:18:43 +0000924 new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true));
Greg Clayton81e871e2012-02-04 02:27:34 +0000925 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
Enrico Granata9128ee22011-09-06 19:20:51 +0000926 }
Enrico Granata972be532014-12-17 21:18:43 +0000927 sb_value.SetSP(new_value_sp);
Greg Clayton5160ce52013-03-27 23:08:40 +0000928 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000929 if (log)
930 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000931 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000932 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
933 static_cast<void*>(value_sp.get()),
934 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000935 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000936 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
937 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000938 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000939 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000940}
941
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000942SBValue
943SBValue::GetChildAtIndex (uint32_t idx)
944{
Greg Claytonf66024822011-07-15 19:31:49 +0000945 const bool can_create_synthetic = false;
946 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000947 TargetSP target_sp;
948 if (m_opaque_sp)
949 target_sp = m_opaque_sp->GetTargetSP();
950
951 if (target_sp)
952 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000953
Greg Claytonf66024822011-07-15 19:31:49 +0000954 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000955}
956
957SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000958SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000959{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000960 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000961 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000962
Jim Ingham362e39a2013-05-15 02:16:21 +0000963 ValueLocker locker;
964 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000965 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000967 const bool can_create = true;
968 child_sp = value_sp->GetChildAtIndex (idx, can_create);
969 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000970 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000971 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000972 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000973 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
974 }
975 else if (value_sp->IsArrayType())
976 {
977 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000978 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000979 }
980 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000981
Enrico Granatae3e91512012-10-22 18:18:36 +0000982 SBValue sb_value;
983 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000984 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000985 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
986 static_cast<void*>(value_sp.get()), idx,
987 static_cast<void*>(value_sp.get()));
988
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000989 return sb_value;
990}
991
992uint32_t
993SBValue::GetIndexOfChildWithName (const char *name)
994{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000995 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000996 ValueLocker locker;
997 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000998 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000999 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001000 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +00001001 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001002 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001003 if (log)
1004 {
1005 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001006 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
1007 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001008 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001009 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
1010 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001011 }
1012 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001013}
1014
1015SBValue
1016SBValue::GetChildMemberWithName (const char *name)
1017{
Jim Ingham362e39a2013-05-15 02:16:21 +00001018 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
1019 TargetSP target_sp;
1020 if (m_opaque_sp)
1021 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001022
Jim Ingham362e39a2013-05-15 02:16:21 +00001023 if (target_sp)
1024 use_dynamic_value = target_sp->GetPreferDynamicValue();
1025 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +00001026}
1027
1028SBValue
Jim Ingham2837b762011-05-04 03:43:18 +00001029SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +00001030{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001031 lldb::ValueObjectSP child_sp;
1032 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001033
Greg Clayton5160ce52013-03-27 23:08:40 +00001034 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001035
Jim Ingham362e39a2013-05-15 02:16:21 +00001036 ValueLocker locker;
1037 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001038 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001039 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001040 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +00001041 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001042
Enrico Granatae3e91512012-10-22 18:18:36 +00001043 SBValue sb_value;
1044 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001045
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001046 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001047 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1048 static_cast<void*>(value_sp.get()), name,
1049 static_cast<void*>(value_sp.get()));
1050
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001051 return sb_value;
1052}
1053
Enrico Granataf2bbf712011-07-15 02:26:42 +00001054lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001055SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1056{
Enrico Granatae3e91512012-10-22 18:18:36 +00001057 SBValue value_sb;
1058 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001059 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001060 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1061 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001062 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001063 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001064}
1065
1066lldb::SBValue
1067SBValue::GetStaticValue ()
1068{
Enrico Granatae3e91512012-10-22 18:18:36 +00001069 SBValue value_sb;
1070 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001071 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001072 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1073 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001074 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001075 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001076}
1077
Enrico Granatac5bc4122012-03-27 02:35:13 +00001078lldb::SBValue
1079SBValue::GetNonSyntheticValue ()
1080{
Enrico Granatae3e91512012-10-22 18:18:36 +00001081 SBValue value_sb;
1082 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001083 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001084 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1085 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001086 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001087 return value_sb;
1088}
1089
1090lldb::DynamicValueType
1091SBValue::GetPreferDynamicValue ()
1092{
1093 if (!IsValid())
1094 return eNoDynamicValues;
1095 return m_opaque_sp->GetUseDynamic();
1096}
1097
1098void
1099SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1100{
1101 if (IsValid())
1102 return m_opaque_sp->SetUseDynamic (use_dynamic);
1103}
1104
1105bool
1106SBValue::GetPreferSyntheticValue ()
1107{
1108 if (!IsValid())
1109 return false;
1110 return m_opaque_sp->GetUseSynthetic();
1111}
1112
1113void
1114SBValue::SetPreferSyntheticValue (bool use_synthetic)
1115{
1116 if (IsValid())
1117 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001118}
1119
Jim Ingham60dbabb2011-12-08 19:44:08 +00001120bool
1121SBValue::IsDynamic()
1122{
Jim Ingham362e39a2013-05-15 02:16:21 +00001123 ValueLocker locker;
1124 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001125 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001126 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001127 return false;
1128}
1129
Enrico Granatae3e91512012-10-22 18:18:36 +00001130bool
1131SBValue::IsSynthetic ()
1132{
Jim Ingham362e39a2013-05-15 02:16:21 +00001133 ValueLocker locker;
1134 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001135 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001136 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001137 return false;
1138}
1139
Jim Ingham60dbabb2011-12-08 19:44:08 +00001140lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001141SBValue::GetValueForExpressionPath(const char* expr_path)
1142{
Greg Clayton5160ce52013-03-27 23:08:40 +00001143 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001144 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001145 ValueLocker locker;
1146 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001147 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001148 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001149 // using default values for all the fancy options, just do it if you can
1150 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001151 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001152
Enrico Granatae3e91512012-10-22 18:18:36 +00001153 SBValue sb_value;
1154 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001155
Enrico Granataf2bbf712011-07-15 02:26:42 +00001156 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001157 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1158 static_cast<void*>(value_sp.get()), expr_path,
1159 static_cast<void*>(value_sp.get()));
1160
Enrico Granataf2bbf712011-07-15 02:26:42 +00001161 return sb_value;
1162}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001163
Greg Claytonfe42ac42011-08-03 22:57:10 +00001164int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001165SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1166{
Jim Ingham16e0c682011-08-12 23:34:31 +00001167 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001168 ValueLocker locker;
1169 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001170 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001171 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001172 bool success = true;
1173 uint64_t ret_val = fail_value;
1174 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1175 if (!success)
1176 error.SetErrorString("could not resolve value");
1177 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001178 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001179 else
1180 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1181
Enrico Granata6fd87d52011-08-04 01:41:02 +00001182 return fail_value;
1183}
1184
1185uint64_t
1186SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1187{
Jim Ingham16e0c682011-08-12 23:34:31 +00001188 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001189 ValueLocker locker;
1190 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001191 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001192 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001193 bool success = true;
1194 uint64_t ret_val = fail_value;
1195 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1196 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001197 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001198 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001199 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001200 else
1201 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1202
Enrico Granata6fd87d52011-08-04 01:41:02 +00001203 return fail_value;
1204}
1205
1206int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001207SBValue::GetValueAsSigned(int64_t fail_value)
1208{
Jim Ingham362e39a2013-05-15 02:16:21 +00001209 ValueLocker locker;
1210 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001211 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001212 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001213 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001214 }
1215 return fail_value;
1216}
1217
1218uint64_t
1219SBValue::GetValueAsUnsigned(uint64_t fail_value)
1220{
Jim Ingham362e39a2013-05-15 02:16:21 +00001221 ValueLocker locker;
1222 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001223 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001224 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001225 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001226 }
1227 return fail_value;
1228}
1229
Greg Clayton4a792072012-10-23 01:50:10 +00001230bool
1231SBValue::MightHaveChildren ()
1232{
Greg Clayton5160ce52013-03-27 23:08:40 +00001233 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001234 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001235 ValueLocker locker;
1236 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001237 if (value_sp)
1238 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001239
Greg Clayton4a792072012-10-23 01:50:10 +00001240 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001241 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1242 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001243 return has_children;
1244}
1245
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001246uint32_t
1247SBValue::GetNumChildren ()
1248{
1249 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001250
Greg Clayton5160ce52013-03-27 23:08:40 +00001251 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001252 ValueLocker locker;
1253 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001254 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001255 num_children = value_sp->GetNumChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001256
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001257 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001258 log->Printf ("SBValue(%p)::GetNumChildren () => %u",
1259 static_cast<void*>(value_sp.get()), num_children);
1260
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001261 return num_children;
1262}
1263
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001264
1265SBValue
1266SBValue::Dereference ()
1267{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001268 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001269 ValueLocker locker;
1270 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001271 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001272 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001273 Error error;
1274 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001275 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001276 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001277 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001278 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1279 static_cast<void*>(value_sp.get()),
1280 static_cast<void*>(value_sp.get()));
1281
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001282 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001283}
1284
1285bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001286SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001287{
1288 bool is_ptr_type = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001289
Jim Ingham362e39a2013-05-15 02:16:21 +00001290 ValueLocker locker;
1291 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001292 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001293 is_ptr_type = value_sp->IsPointerType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001294
Greg Clayton5160ce52013-03-27 23:08:40 +00001295 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001296 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001297 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i",
1298 static_cast<void*>(value_sp.get()), is_ptr_type);
1299
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001300 return is_ptr_type;
1301}
1302
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001303void *
1304SBValue::GetOpaqueType()
1305{
Jim Ingham362e39a2013-05-15 02:16:21 +00001306 ValueLocker locker;
1307 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001308 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001309 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001310 return NULL;
1311}
1312
Enrico Granata6f3533f2011-07-29 19:53:35 +00001313lldb::SBTarget
1314SBValue::GetTarget()
1315{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001316 SBTarget sb_target;
1317 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001318 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001319 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001320 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001321 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001322 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001323 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001324 if (log)
1325 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001326 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001327 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1328 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001329 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001330 log->Printf ("SBValue(%p)::GetTarget () => %p",
1331 static_cast<void*>(m_opaque_sp.get()),
1332 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001333 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001334 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001335}
1336
1337lldb::SBProcess
1338SBValue::GetProcess()
1339{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001340 SBProcess sb_process;
1341 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001342 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001343 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001344 process_sp = m_opaque_sp->GetProcessSP();
1345 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001346 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001347 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001348 if (log)
1349 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001350 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001351 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1352 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001353 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001354 log->Printf ("SBValue(%p)::GetProcess () => %p",
1355 static_cast<void*>(m_opaque_sp.get()),
1356 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001357 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001358 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001359}
1360
1361lldb::SBThread
1362SBValue::GetThread()
1363{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001364 SBThread sb_thread;
1365 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001366 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001367 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001368 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001369 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001370 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001371 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001372 if (log)
1373 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001374 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001375 log->Printf ("SBValue(%p)::GetThread () => NULL",
1376 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001377 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001378 log->Printf ("SBValue(%p)::GetThread () => %p",
1379 static_cast<void*>(m_opaque_sp.get()),
1380 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001381 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001382 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001383}
1384
1385lldb::SBFrame
1386SBValue::GetFrame()
1387{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001388 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001389 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001390 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001391 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001392 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001393 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001394 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001395 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001396 if (log)
1397 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001398 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001399 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1400 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001401 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001402 log->Printf ("SBValue(%p)::GetFrame () => %p",
1403 static_cast<void*>(m_opaque_sp.get()),
1404 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001405 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001406 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001407}
1408
1409
Greg Clayton81e871e2012-02-04 02:27:34 +00001410lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001411SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001412{
Enrico Granatae3e91512012-10-22 18:18:36 +00001413 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1414 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001415 return locker.GetLockedSP(*m_opaque_sp.get());
1416}
1417
1418lldb::ValueObjectSP
1419SBValue::GetSP () const
1420{
1421 ValueLocker locker;
1422 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001423}
1424
1425void
1426SBValue::SetSP (ValueImplSP impl_sp)
1427{
1428 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429}
1430
Greg Clayton81e871e2012-02-04 02:27:34 +00001431void
1432SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001433{
Enrico Granatae3e91512012-10-22 18:18:36 +00001434 if (sp)
1435 {
1436 lldb::TargetSP target_sp(sp->GetTargetSP());
1437 if (target_sp)
1438 {
1439 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1440 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1441 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1442 }
1443 else
1444 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1445 }
1446 else
1447 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001448}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001449
Enrico Granatae3e91512012-10-22 18:18:36 +00001450void
1451SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1452{
1453 if (sp)
1454 {
1455 lldb::TargetSP target_sp(sp->GetTargetSP());
1456 if (target_sp)
1457 {
1458 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1459 SetSP (sp, use_dynamic, use_synthetic);
1460 }
1461 else
1462 SetSP (sp, use_dynamic, true);
1463 }
1464 else
1465 SetSP (sp, use_dynamic, false);
1466}
1467
1468void
1469SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1470{
1471 if (sp)
1472 {
1473 lldb::TargetSP target_sp(sp->GetTargetSP());
1474 if (target_sp)
1475 {
1476 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1477 SetSP (sp, use_dynamic, use_synthetic);
1478 }
1479 else
1480 SetSP (sp, eNoDynamicValues, use_synthetic);
1481 }
1482 else
1483 SetSP (sp, eNoDynamicValues, use_synthetic);
1484}
1485
1486void
1487SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1488{
1489 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1490}
Greg Clayton81e871e2012-02-04 02:27:34 +00001491
Jim Ingham362e39a2013-05-15 02:16:21 +00001492void
1493SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1494{
1495 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1496}
1497
Caroline Ticedde9cff2010-09-20 05:20:02 +00001498bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001499SBValue::GetExpressionPath (SBStream &description)
1500{
Jim Ingham362e39a2013-05-15 02:16:21 +00001501 ValueLocker locker;
1502 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001503 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001504 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001505 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001506 return true;
1507 }
1508 return false;
1509}
1510
1511bool
1512SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1513{
Jim Ingham362e39a2013-05-15 02:16:21 +00001514 ValueLocker locker;
1515 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001516 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001517 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001518 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001519 return true;
1520 }
1521 return false;
1522}
1523
1524bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001525SBValue::GetDescription (SBStream &description)
1526{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001527 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001528
Jim Ingham362e39a2013-05-15 02:16:21 +00001529 ValueLocker locker;
1530 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001531 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001532 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001533 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001534 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001535
Caroline Ticedde9cff2010-09-20 05:20:02 +00001536 return true;
1537}
Greg Claytondc4e9632011-01-05 18:43:15 +00001538
1539lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001540SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001541{
Jim Ingham362e39a2013-05-15 02:16:21 +00001542 ValueLocker locker;
1543 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001544 if (value_sp)
1545 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001546 return eFormatDefault;
1547}
1548
1549void
1550SBValue::SetFormat (lldb::Format format)
1551{
Jim Ingham362e39a2013-05-15 02:16:21 +00001552 ValueLocker locker;
1553 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001554 if (value_sp)
1555 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001556}
1557
Enrico Granata6f3533f2011-07-29 19:53:35 +00001558lldb::SBValue
1559SBValue::AddressOf()
1560{
1561 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001562 ValueLocker locker;
1563 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001564 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001565 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001566 Error error;
1567 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001568 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001569 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001570 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001571 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1572 static_cast<void*>(value_sp.get()),
1573 static_cast<void*>(value_sp.get()));
1574
Enrico Granata6f3533f2011-07-29 19:53:35 +00001575 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001576}
Enrico Granata9128ee22011-09-06 19:20:51 +00001577
1578lldb::addr_t
1579SBValue::GetLoadAddress()
1580{
1581 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001582 ValueLocker locker;
1583 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001584 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001585 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001586 TargetSP target_sp (value_sp->GetTargetSP());
1587 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001588 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001589 const bool scalar_is_load_address = true;
1590 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001591 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001592 if (addr_type == eAddressTypeFile)
1593 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001594 ModuleSP module_sp (value_sp->GetModule());
1595 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001596 value = LLDB_INVALID_ADDRESS;
1597 else
1598 {
1599 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001600 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001601 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001602 }
1603 }
1604 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1605 value = LLDB_INVALID_ADDRESS;
1606 }
1607 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001608 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001609 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001610 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1611 static_cast<void*>(value_sp.get()), value);
1612
Enrico Granata9128ee22011-09-06 19:20:51 +00001613 return value;
1614}
1615
1616lldb::SBAddress
1617SBValue::GetAddress()
1618{
1619 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001620 ValueLocker locker;
1621 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001622 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001623 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001624 TargetSP target_sp (value_sp->GetTargetSP());
1625 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001626 {
1627 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001628 const bool scalar_is_load_address = true;
1629 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001630 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001631 if (addr_type == eAddressTypeFile)
1632 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001633 ModuleSP module_sp (value_sp->GetModule());
1634 if (module_sp)
1635 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001636 }
1637 else if (addr_type == eAddressTypeLoad)
1638 {
1639 // no need to check the return value on this.. if it can actually do the resolve
1640 // addr will be in the form (section,offset), otherwise it will simply be returned
1641 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001642 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001643 }
1644 }
1645 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001646 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001647 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001648 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1649 static_cast<void*>(value_sp.get()),
1650 (addr.GetSection()
1651 ? addr.GetSection()->GetName().GetCString()
1652 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001653 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001654 return SBAddress(new Address(addr));
1655}
1656
1657lldb::SBData
1658SBValue::GetPointeeData (uint32_t item_idx,
1659 uint32_t item_count)
1660{
Greg Clayton5160ce52013-03-27 23:08:40 +00001661 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001662 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001663 ValueLocker locker;
1664 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001665 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001666 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001667 TargetSP target_sp (value_sp->GetTargetSP());
1668 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001669 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001670 DataExtractorSP data_sp(new DataExtractor());
1671 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1672 if (data_sp->GetByteSize() > 0)
1673 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001674 }
1675 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001676 if (log)
1677 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001678 static_cast<void*>(value_sp.get()), item_idx, item_count,
1679 static_cast<void*>(sb_data.get()));
1680
Enrico Granata9128ee22011-09-06 19:20:51 +00001681 return sb_data;
1682}
1683
1684lldb::SBData
1685SBValue::GetData ()
1686{
Greg Clayton5160ce52013-03-27 23:08:40 +00001687 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001688 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001689 ValueLocker locker;
1690 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001691 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001692 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001693 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001694 Error error;
1695 value_sp->GetData(*data_sp, error);
1696 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001697 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001698 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001699 if (log)
1700 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001701 static_cast<void*>(value_sp.get()),
1702 static_cast<void*>(sb_data.get()));
1703
Enrico Granata9128ee22011-09-06 19:20:51 +00001704 return sb_data;
1705}
Greg Clayton1b282f92011-10-13 18:08:26 +00001706
Sean Callanan389823e2013-04-13 01:21:23 +00001707bool
1708SBValue::SetData (lldb::SBData &data, SBError &error)
1709{
1710 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001711 ValueLocker locker;
1712 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001713 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001714
Sean Callanan389823e2013-04-13 01:21:23 +00001715 if (value_sp)
1716 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001717 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001718
Jim Ingham362e39a2013-05-15 02:16:21 +00001719 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001720 {
1721 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001722 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1723 static_cast<void*>(value_sp.get()));
1724
Jim Ingham362e39a2013-05-15 02:16:21 +00001725 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001726 ret = false;
1727 }
1728 else
1729 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001730 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001731
Jim Ingham362e39a2013-05-15 02:16:21 +00001732 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001733
Jim Ingham362e39a2013-05-15 02:16:21 +00001734 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001735 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001736 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001737 ret = false;
1738 }
Sean Callanan389823e2013-04-13 01:21:23 +00001739 }
1740 }
1741 else
1742 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001743 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001744 ret = false;
1745 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001746
Sean Callanan389823e2013-04-13 01:21:23 +00001747 if (log)
1748 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001749 static_cast<void*>(value_sp.get()),
1750 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001751 return ret;
1752}
1753
Enrico Granata10de0902012-10-10 22:54:17 +00001754lldb::SBDeclaration
1755SBValue::GetDeclaration ()
1756{
Jim Ingham362e39a2013-05-15 02:16:21 +00001757 ValueLocker locker;
1758 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001759 SBDeclaration decl_sb;
1760 if (value_sp)
1761 {
1762 Declaration decl;
1763 if (value_sp->GetDeclaration(decl))
1764 decl_sb.SetDeclaration(decl);
1765 }
1766 return decl_sb;
1767}
1768
Greg Clayton1b282f92011-10-13 18:08:26 +00001769lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001770SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001771{
Greg Clayton81e871e2012-02-04 02:27:34 +00001772 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001773
Greg Clayton81e871e2012-02-04 02:27:34 +00001774 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001775 ValueLocker locker;
1776 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001777 TargetSP target_sp (GetTarget().GetSP());
1778 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001779 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001780 // Read and Write cannot both be false.
1781 if (!read && !write)
1782 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001783
Greg Clayton81e871e2012-02-04 02:27:34 +00001784 // If the value is not in scope, don't try and watch and invalid value
1785 if (!IsInScope())
1786 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001787
Greg Clayton81e871e2012-02-04 02:27:34 +00001788 addr_t addr = GetLoadAddress();
1789 if (addr == LLDB_INVALID_ADDRESS)
1790 return sb_watchpoint;
1791 size_t byte_size = GetByteSize();
1792 if (byte_size == 0)
1793 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001794
Greg Clayton81e871e2012-02-04 02:27:34 +00001795 uint32_t watch_type = 0;
1796 if (read)
1797 watch_type |= LLDB_WATCH_TYPE_READ;
1798 if (write)
1799 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001800
Johnny Chenb90827e2012-06-04 23:19:54 +00001801 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001802 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001803 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001804 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001805
Daniel Maleae0f8f572013-08-26 23:57:52 +00001806 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001807 {
1808 sb_watchpoint.SetSP (watchpoint_sp);
1809 Declaration decl;
1810 if (value_sp->GetDeclaration (decl))
1811 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001812 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001813 {
1814 StreamString ss;
1815 // True to show fullpath for declaration file.
1816 decl.DumpStopContext(&ss, true);
1817 watchpoint_sp->SetDeclInfo(ss.GetString());
1818 }
1819 }
1820 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001821 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001822 else if (target_sp)
1823 {
1824 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1825 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001826 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1827 static_cast<void*>(value_sp.get()),
1828 locker.GetError().AsCString());
1829
Jim Ingham362e39a2013-05-15 02:16:21 +00001830 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1831 }
1832 else
1833 {
1834 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1835 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001836 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1837 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001838 error.SetErrorString("could not set watchpoint, a target is required");
1839 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001840
Greg Clayton1b282f92011-10-13 18:08:26 +00001841 return sb_watchpoint;
1842}
1843
Johnny Chend3761a72012-06-04 23:45:50 +00001844// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1845// Backward compatibility fix in the interim.
1846lldb::SBWatchpoint
1847SBValue::Watch (bool resolve_location, bool read, bool write)
1848{
Johnny Chen974759f2012-06-05 00:14:15 +00001849 SBError error;
1850 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001851}
1852
Greg Clayton1b282f92011-10-13 18:08:26 +00001853lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001854SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001855{
Greg Clayton81e871e2012-02-04 02:27:34 +00001856 SBWatchpoint sb_watchpoint;
1857 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001858 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001859 return sb_watchpoint;
1860}
Enrico Granata0c10a852014-12-08 23:13:56 +00001861
1862lldb::SBValue
1863SBValue::Persist ()
1864{
1865 ValueLocker locker;
1866 lldb::ValueObjectSP value_sp(GetSP(locker));
1867 SBValue persisted_sb;
1868 if (value_sp)
1869 {
1870 persisted_sb.SetSP(value_sp->Persist());
1871 }
1872 return persisted_sb;
1873}