blob: f171d2399135e2192e05f701b434bfb296233aca [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
381size_t
382SBValue::GetByteSize ()
383{
Greg Clayton5160ce52013-03-27 23:08:40 +0000384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000385 size_t result = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000386
Jim Ingham362e39a2013-05-15 02:16:21 +0000387 ValueLocker locker;
388 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000389 if (value_sp)
Jim Ingham48cdc582012-08-21 01:46:35 +0000390 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000391 result = value_sp->GetByteSize();
Jim Ingham48cdc582012-08-21 01:46:35 +0000392 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000393
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000394 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000395 log->Printf ("SBValue(%p)::GetByteSize () => %" PRIu64,
396 static_cast<void*>(value_sp.get()),
397 static_cast<uint64_t>(result));
398
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000399 return result;
400}
401
402bool
Jim Ingham6035b672011-03-31 00:19:25 +0000403SBValue::IsInScope ()
404{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405 bool result = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000406
Jim Ingham362e39a2013-05-15 02:16:21 +0000407 ValueLocker locker;
408 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000409 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000410 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000411 result = value_sp->IsInScope ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000412 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000413
Greg Clayton5160ce52013-03-27 23:08:40 +0000414 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000415 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000416 log->Printf ("SBValue(%p)::IsInScope () => %i",
417 static_cast<void*>(value_sp.get()), result);
418
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 return result;
420}
421
422const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000423SBValue::GetValue ()
424{
Greg Clayton5160ce52013-03-27 23:08:40 +0000425 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000426
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000427 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000428 ValueLocker locker;
429 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000430 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000431 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000432 cstr = value_sp->GetValueAsCString ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000433 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000434 if (log)
435 {
436 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000437 log->Printf ("SBValue(%p)::GetValue() => \"%s\"",
438 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000439 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000440 log->Printf ("SBValue(%p)::GetValue() => NULL",
441 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000442 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000443
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000444 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445}
446
Greg Clayton73b472d2010-10-27 03:32:59 +0000447ValueType
448SBValue::GetValueType ()
449{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000450 ValueType result = eValueTypeInvalid;
Jim Ingham362e39a2013-05-15 02:16:21 +0000451 ValueLocker locker;
452 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000453 if (value_sp)
454 result = value_sp->GetValueType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000455
Greg Clayton5160ce52013-03-27 23:08:40 +0000456 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000457 if (log)
458 {
459 switch (result)
460 {
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000461 case eValueTypeInvalid:
462 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid",
463 static_cast<void*>(value_sp.get()));
464 break;
465 case eValueTypeVariableGlobal:
466 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal",
467 static_cast<void*>(value_sp.get()));
468 break;
469 case eValueTypeVariableStatic:
470 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic",
471 static_cast<void*>(value_sp.get()));
472 break;
473 case eValueTypeVariableArgument:
474 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument",
475 static_cast<void*>(value_sp.get()));
476 break;
477 case eValueTypeVariableLocal:
478 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal",
479 static_cast<void*>(value_sp.get()));
480 break;
481 case eValueTypeRegister:
482 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister",
483 static_cast<void*>(value_sp.get()));
484 break;
485 case eValueTypeRegisterSet:
486 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet",
487 static_cast<void*>(value_sp.get()));
488 break;
489 case eValueTypeConstResult:
490 log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult",
491 static_cast<void*>(value_sp.get()));
492 break;
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000493 }
494 }
495 return result;
Greg Clayton73b472d2010-10-27 03:32:59 +0000496}
497
Jim Ingham53c47f12010-09-10 23:12:17 +0000498const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000499SBValue::GetObjectDescription ()
500{
Greg Clayton5160ce52013-03-27 23:08:40 +0000501 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000502 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000503 ValueLocker locker;
504 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000505 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000506 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000507 cstr = value_sp->GetObjectDescription ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000508 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000509 if (log)
510 {
511 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000512 log->Printf ("SBValue(%p)::GetObjectDescription() => \"%s\"",
513 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000514 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000515 log->Printf ("SBValue(%p)::GetObjectDescription() => NULL",
516 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000517 }
518 return cstr;
Jim Ingham53c47f12010-09-10 23:12:17 +0000519}
520
Enrico Granata6f3533f2011-07-29 19:53:35 +0000521SBType
522SBValue::GetType()
523{
Greg Clayton5160ce52013-03-27 23:08:40 +0000524 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000525 SBType sb_type;
Jim Ingham362e39a2013-05-15 02:16:21 +0000526 ValueLocker locker;
527 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000528 TypeImplSP type_sp;
529 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000530 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000531 type_sp.reset (new TypeImpl(value_sp->GetTypeImpl()));
Jim Ingham362e39a2013-05-15 02:16:21 +0000532 sb_type.SetSP(type_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000533 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000534 if (log)
535 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000536 if (type_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000537 log->Printf ("SBValue(%p)::GetType => SBType(%p)",
538 static_cast<void*>(value_sp.get()),
539 static_cast<void*>(type_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000540 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000541 log->Printf ("SBValue(%p)::GetType => NULL",
542 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000543 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000544 return sb_type;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000545}
546
Jim Ingham6035b672011-03-31 00:19:25 +0000547bool
548SBValue::GetValueDidChange ()
549{
Greg Clayton5160ce52013-03-27 23:08:40 +0000550 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000551 bool result = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000552 ValueLocker locker;
553 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000554 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000555 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000556 result = value_sp->GetValueDidChange ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000557 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000558 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000559 log->Printf ("SBValue(%p)::GetValueDidChange() => %i",
560 static_cast<void*>(value_sp.get()), result);
561
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000562 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000563}
564
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000565#ifndef LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000566const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000567SBValue::GetSummary ()
568{
Greg Clayton5160ce52013-03-27 23:08:40 +0000569 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000570 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000571 ValueLocker locker;
572 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000573 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000574 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000575 cstr = value_sp->GetSummaryAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000576 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000577 if (log)
578 {
579 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000580 log->Printf ("SBValue(%p)::GetSummary() => \"%s\"",
581 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000582 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000583 log->Printf ("SBValue(%p)::GetSummary() => NULL",
584 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000585 }
586 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000588#endif // LLDB_DISABLE_PYTHON
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589
590const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000591SBValue::GetLocation ()
592{
Greg Clayton5160ce52013-03-27 23:08:40 +0000593 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000594 const char *cstr = NULL;
Jim Ingham362e39a2013-05-15 02:16:21 +0000595 ValueLocker locker;
596 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000597 if (value_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000598 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000599 cstr = value_sp->GetLocationAsCString();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000600 }
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000601 if (log)
602 {
603 if (cstr)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000604 log->Printf ("SBValue(%p)::GetLocation() => \"%s\"",
605 static_cast<void*>(value_sp.get()), cstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000606 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000607 log->Printf ("SBValue(%p)::GetLocation() => NULL",
608 static_cast<void*>(value_sp.get()));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000609 }
610 return cstr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611}
612
Enrico Granata07a4ac22012-05-08 21:25:06 +0000613// Deprecated - use the one that takes an lldb::SBError
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000614bool
Jim Ingham6035b672011-03-31 00:19:25 +0000615SBValue::SetValueFromCString (const char *value_str)
616{
Enrico Granata07a4ac22012-05-08 21:25:06 +0000617 lldb::SBError dummy;
618 return SetValueFromCString(value_str,dummy);
619}
620
621bool
622SBValue::SetValueFromCString (const char *value_str, lldb::SBError& error)
623{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000624 bool success = false;
Jim Ingham362e39a2013-05-15 02:16:21 +0000625 ValueLocker locker;
626 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton5160ce52013-03-27 23:08:40 +0000627 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
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 success = value_sp->SetValueFromCString (value_str,error.ref());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000631 }
Jim Ingham362e39a2013-05-15 02:16:21 +0000632 else
633 error.SetErrorStringWithFormat ("Could not get value: %s", locker.GetError().AsCString());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000634
Greg Claytonc9858e42012-04-06 02:17:47 +0000635 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000636 log->Printf ("SBValue(%p)::SetValueFromCString(\"%s\") => %i",
637 static_cast<void*>(value_sp.get()), value_str, success);
638
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000639 return success;
640}
641
Enrico Granata864e3e82012-02-17 03:18:30 +0000642lldb::SBTypeFormat
643SBValue::GetTypeFormat ()
644{
645 lldb::SBTypeFormat format;
Jim Ingham362e39a2013-05-15 02:16:21 +0000646 ValueLocker locker;
647 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000648 if (value_sp)
649 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000650 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000651 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000652 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat();
653 if (format_sp)
654 format.SetSP(format_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000655 }
656 }
657 return format;
658}
659
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000660#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000661lldb::SBTypeSummary
662SBValue::GetTypeSummary ()
663{
664 lldb::SBTypeSummary summary;
Jim Ingham362e39a2013-05-15 02:16:21 +0000665 ValueLocker locker;
666 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000667 if (value_sp)
668 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000669 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000670 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000671 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat();
672 if (summary_sp)
673 summary.SetSP(summary_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000674 }
675 }
676 return summary;
677}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000678#endif // LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000679
680lldb::SBTypeFilter
681SBValue::GetTypeFilter ()
682{
683 lldb::SBTypeFilter filter;
Jim Ingham362e39a2013-05-15 02:16:21 +0000684 ValueLocker locker;
685 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000686 if (value_sp)
687 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000688 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000689 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000690 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren();
691
692 if (synthetic_sp && !synthetic_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000693 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000694 TypeFilterImplSP filter_sp = std::static_pointer_cast<TypeFilterImpl>(synthetic_sp);
695 filter.SetSP(filter_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000696 }
697 }
698 }
699 return filter;
700}
701
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000702#ifndef LLDB_DISABLE_PYTHON
Enrico Granata864e3e82012-02-17 03:18:30 +0000703lldb::SBTypeSynthetic
704SBValue::GetTypeSynthetic ()
705{
706 lldb::SBTypeSynthetic synthetic;
Jim Ingham362e39a2013-05-15 02:16:21 +0000707 ValueLocker locker;
708 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata864e3e82012-02-17 03:18:30 +0000709 if (value_sp)
710 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000711 if (value_sp->UpdateValueIfNeeded(true))
Enrico Granata864e3e82012-02-17 03:18:30 +0000712 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000713 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren();
714
715 if (children_sp && children_sp->IsScripted())
Enrico Granata864e3e82012-02-17 03:18:30 +0000716 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000717 ScriptedSyntheticChildrenSP synth_sp = std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp);
718 synthetic.SetSP(synth_sp);
Enrico Granata864e3e82012-02-17 03:18:30 +0000719 }
720 }
721 }
722 return synthetic;
723}
Jason Molendacf7e2dc2012-02-21 05:33:55 +0000724#endif
Enrico Granata864e3e82012-02-17 03:18:30 +0000725
Enrico Granata6f3533f2011-07-29 19:53:35 +0000726lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000727SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000728{
Greg Clayton81e871e2012-02-04 02:27:34 +0000729 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000730 ValueLocker locker;
731 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000732 lldb::ValueObjectSP new_value_sp;
733 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000734 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000735 TypeImplSP type_sp (type.GetSP());
736 if (type.IsValid())
Enrico Granata6f3533f2011-07-29 19:53:35 +0000737 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000738 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(false), true),GetPreferDynamicValue(),GetPreferSyntheticValue(), name);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000739 }
740 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000741 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000742 if (log)
743 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000744 if (new_value_sp)
Jim Ingham35e1bda2012-10-16 21:41:58 +0000745 log->Printf ("SBValue(%p)::CreateChildAtOffset => \"%s\"",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000746 static_cast<void*>(value_sp.get()),
Jim Ingham35e1bda2012-10-16 21:41:58 +0000747 new_value_sp->GetName().AsCString());
Enrico Granata6f3533f2011-07-29 19:53:35 +0000748 else
Jim Ingham35e1bda2012-10-16 21:41:58 +0000749 log->Printf ("SBValue(%p)::CreateChildAtOffset => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000750 static_cast<void*>(value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000751 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000752 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000753}
754
755lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000756SBValue::Cast (SBType type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000757{
Greg Claytonef496d52012-01-31 04:25:15 +0000758 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000759 ValueLocker locker;
760 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000761 TypeImplSP type_sp (type.GetSP());
762 if (value_sp && type_sp)
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000763 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType(false)),GetPreferDynamicValue(),GetPreferSyntheticValue());
Greg Claytonef496d52012-01-31 04:25:15 +0000764 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000765}
766
767lldb::SBValue
768SBValue::CreateValueFromExpression (const char *name, const char* expression)
769{
Jim Ingham35e1bda2012-10-16 21:41:58 +0000770 SBExpressionOptions options;
Greg Claytoncced1562012-10-16 22:58:25 +0000771 options.ref().SetKeepInMemory(true);
Jim Ingham35e1bda2012-10-16 21:41:58 +0000772 return CreateValueFromExpression (name, expression, options);
773}
774
775lldb::SBValue
776SBValue::CreateValueFromExpression (const char *name, const char *expression, SBExpressionOptions &options)
777{
Greg Clayton5160ce52013-03-27 23:08:40 +0000778 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton81e871e2012-02-04 02:27:34 +0000779 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000780 ValueLocker locker;
781 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000782 lldb::ValueObjectSP new_value_sp;
783 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000784 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000785 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Jim Ingham362e39a2013-05-15 02:16:21 +0000786 Target* target = exe_ctx.GetTargetPtr();
787 if (target)
Johnny Chen50660442011-12-20 01:52:44 +0000788 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000789 options.ref().SetKeepInMemory(true);
790 target->EvaluateExpression (expression,
791 exe_ctx.GetFramePtr(),
792 new_value_sp,
793 options.ref());
794 if (new_value_sp)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000795 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000796 new_value_sp->SetName(ConstString(name));
797 sb_value.SetSP(new_value_sp);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000798 }
Johnny Chen50660442011-12-20 01:52:44 +0000799 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000800 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000801 if (log)
802 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000803 if (new_value_sp)
Greg Claytoneac87f82012-06-04 20:13:23 +0000804 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => SBValue (%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000805 static_cast<void*>(value_sp.get()), name, expression,
806 static_cast<void*>(new_value_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000807 else
Greg Claytoneac87f82012-06-04 20:13:23 +0000808 log->Printf ("SBValue(%p)::CreateValueFromExpression(name=\"%s\", expression=\"%s\") => NULL",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000809 static_cast<void*>(value_sp.get()), name, expression);
Enrico Granata6f3533f2011-07-29 19:53:35 +0000810 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000811 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000812}
813
814lldb::SBValue
Greg Clayton81e871e2012-02-04 02:27:34 +0000815SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000816{
Greg Clayton81e871e2012-02-04 02:27:34 +0000817 lldb::SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +0000818 ValueLocker locker;
819 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000820 lldb::ValueObjectSP new_value_sp;
821 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
822 if (value_sp && type_impl_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +0000823 {
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000824 ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(false).GetPointerType ());
Enrico Granata347c2aa2013-10-08 21:49:02 +0000825 if (pointer_ast_type)
Enrico Granata61408e02011-08-04 17:07:02 +0000826 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000827 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000828
Greg Claytoncc4d0142012-02-17 07:49:44 +0000829 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
830 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Enrico Granata347c2aa2013-10-08 21:49:02 +0000831 pointer_ast_type,
Greg Clayton81e871e2012-02-04 02:27:34 +0000832 ConstString(name),
833 buffer,
Enrico Granata347c2aa2013-10-08 21:49:02 +0000834 exe_ctx.GetByteOrder(),
Greg Claytoncc4d0142012-02-17 07:49:44 +0000835 exe_ctx.GetAddressByteSize()));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000836
Greg Clayton81e871e2012-02-04 02:27:34 +0000837 if (ptr_result_valobj_sp)
838 {
839 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
840 Error err;
841 new_value_sp = ptr_result_valobj_sp->Dereference(err);
842 if (new_value_sp)
843 new_value_sp->SetName(ConstString(name));
844 }
845 sb_value.SetSP(new_value_sp);
Enrico Granata61408e02011-08-04 17:07:02 +0000846 }
Enrico Granata6f3533f2011-07-29 19:53:35 +0000847 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000848 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000849 if (log)
850 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000851 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000852 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"",
853 static_cast<void*>(value_sp.get()),
854 new_value_sp->GetName().AsCString());
Johnny Chen4a871f92011-08-09 22:38:07 +0000855 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000856 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL",
857 static_cast<void*>(value_sp.get()));
Johnny Chen4a871f92011-08-09 22:38:07 +0000858 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000859 return sb_value;
Enrico Granata6f3533f2011-07-29 19:53:35 +0000860}
861
Enrico Granata9128ee22011-09-06 19:20:51 +0000862lldb::SBValue
Greg Claytonbf2331c2011-09-09 23:04:00 +0000863SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000864{
Greg Clayton81e871e2012-02-04 02:27:34 +0000865 lldb::SBValue sb_value;
866 lldb::ValueObjectSP new_value_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +0000867 ValueLocker locker;
868 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000869 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000870 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000871 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000872
Greg Claytoncc4d0142012-02-17 07:49:44 +0000873 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000874 type.m_opaque_sp->GetClangASTType(false),
Greg Clayton81e871e2012-02-04 02:27:34 +0000875 ConstString(name),
876 *data.m_opaque_sp,
877 LLDB_INVALID_ADDRESS);
878 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
879 sb_value.SetSP(new_value_sp);
Enrico Granata9128ee22011-09-06 19:20:51 +0000880 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000881 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +0000882 if (log)
883 {
Greg Clayton81e871e2012-02-04 02:27:34 +0000884 if (new_value_sp)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000885 log->Printf ("SBValue(%p)::CreateValueFromData => \"%s\"",
886 static_cast<void*>(value_sp.get()),
887 new_value_sp->GetName().AsCString());
Enrico Granata9128ee22011-09-06 19:20:51 +0000888 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000889 log->Printf ("SBValue(%p)::CreateValueFromData => NULL",
890 static_cast<void*>(value_sp.get()));
Enrico Granata9128ee22011-09-06 19:20:51 +0000891 }
Greg Clayton81e871e2012-02-04 02:27:34 +0000892 return sb_value;
Enrico Granata9128ee22011-09-06 19:20:51 +0000893}
894
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000895SBValue
896SBValue::GetChildAtIndex (uint32_t idx)
897{
Greg Claytonf66024822011-07-15 19:31:49 +0000898 const bool can_create_synthetic = false;
899 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Jim Ingham362e39a2013-05-15 02:16:21 +0000900 TargetSP target_sp;
901 if (m_opaque_sp)
902 target_sp = m_opaque_sp->GetTargetSP();
903
904 if (target_sp)
905 use_dynamic = target_sp->GetPreferDynamicValue();
Daniel Maleae0f8f572013-08-26 23:57:52 +0000906
Greg Claytonf66024822011-07-15 19:31:49 +0000907 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Ingham78a685a2011-04-16 00:01:13 +0000908}
909
910SBValue
Greg Claytonf66024822011-07-15 19:31:49 +0000911SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Ingham78a685a2011-04-16 00:01:13 +0000912{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000913 lldb::ValueObjectSP child_sp;
Greg Clayton5160ce52013-03-27 23:08:40 +0000914 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000915
Jim Ingham362e39a2013-05-15 02:16:21 +0000916 ValueLocker locker;
917 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000918 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000919 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000920 const bool can_create = true;
921 child_sp = value_sp->GetChildAtIndex (idx, can_create);
922 if (can_create_synthetic && !child_sp)
Greg Clayton626f4a12011-06-29 18:28:50 +0000923 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000924 if (value_sp->IsPointerType())
Greg Clayton21c5ab42011-05-20 23:51:26 +0000925 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000926 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
927 }
928 else if (value_sp->IsArrayType())
929 {
930 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton21c5ab42011-05-20 23:51:26 +0000931 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000932 }
933 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000934
Enrico Granatae3e91512012-10-22 18:18:36 +0000935 SBValue sb_value;
936 sb_value.SetSP (child_sp, use_dynamic, GetPreferSyntheticValue());
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000937 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000938 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)",
939 static_cast<void*>(value_sp.get()), idx,
940 static_cast<void*>(value_sp.get()));
941
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000942 return sb_value;
943}
944
945uint32_t
946SBValue::GetIndexOfChildWithName (const char *name)
947{
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000948 uint32_t idx = UINT32_MAX;
Jim Ingham362e39a2013-05-15 02:16:21 +0000949 ValueLocker locker;
950 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000951 if (value_sp)
Greg Clayton21c5ab42011-05-20 23:51:26 +0000952 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000953 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Clayton21c5ab42011-05-20 23:51:26 +0000954 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000955 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000956 if (log)
957 {
958 if (idx == UINT32_MAX)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000959 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND",
960 static_cast<void*>(value_sp.get()), name);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000961 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000962 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u",
963 static_cast<void*>(value_sp.get()), name, idx);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000964 }
965 return idx;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966}
967
968SBValue
969SBValue::GetChildMemberWithName (const char *name)
970{
Jim Ingham362e39a2013-05-15 02:16:21 +0000971 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
972 TargetSP target_sp;
973 if (m_opaque_sp)
974 target_sp = m_opaque_sp->GetTargetSP();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000975
Jim Ingham362e39a2013-05-15 02:16:21 +0000976 if (target_sp)
977 use_dynamic_value = target_sp->GetPreferDynamicValue();
978 return GetChildMemberWithName (name, use_dynamic_value);
Jim Ingham78a685a2011-04-16 00:01:13 +0000979}
980
981SBValue
Jim Ingham2837b762011-05-04 03:43:18 +0000982SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Ingham78a685a2011-04-16 00:01:13 +0000983{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000984 lldb::ValueObjectSP child_sp;
985 const ConstString str_name (name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000986
Greg Clayton5160ce52013-03-27 23:08:40 +0000987 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000988
Jim Ingham362e39a2013-05-15 02:16:21 +0000989 ValueLocker locker;
990 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +0000991 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000992 {
Jim Ingham362e39a2013-05-15 02:16:21 +0000993 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Jim Ingham78a685a2011-04-16 00:01:13 +0000994 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000995
Enrico Granatae3e91512012-10-22 18:18:36 +0000996 SBValue sb_value;
997 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000998
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000999 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001000 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)",
1001 static_cast<void*>(value_sp.get()), name,
1002 static_cast<void*>(value_sp.get()));
1003
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001004 return sb_value;
1005}
1006
Enrico Granataf2bbf712011-07-15 02:26:42 +00001007lldb::SBValue
Jim Ingham60dbabb2011-12-08 19:44:08 +00001008SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
1009{
Enrico Granatae3e91512012-10-22 18:18:36 +00001010 SBValue value_sb;
1011 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001012 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001013 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),use_dynamic,m_opaque_sp->GetUseSynthetic()));
1014 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001015 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001016 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001017}
1018
1019lldb::SBValue
1020SBValue::GetStaticValue ()
1021{
Enrico Granatae3e91512012-10-22 18:18:36 +00001022 SBValue value_sb;
1023 if (IsValid())
Jim Ingham60dbabb2011-12-08 19:44:08 +00001024 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001025 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),eNoDynamicValues,m_opaque_sp->GetUseSynthetic()));
1026 value_sb.SetSP(proxy_sp);
Jim Ingham60dbabb2011-12-08 19:44:08 +00001027 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001028 return value_sb;
Jim Ingham60dbabb2011-12-08 19:44:08 +00001029}
1030
Enrico Granatac5bc4122012-03-27 02:35:13 +00001031lldb::SBValue
1032SBValue::GetNonSyntheticValue ()
1033{
Enrico Granatae3e91512012-10-22 18:18:36 +00001034 SBValue value_sb;
1035 if (IsValid())
Enrico Granatac5bc4122012-03-27 02:35:13 +00001036 {
Enrico Granatae3e91512012-10-22 18:18:36 +00001037 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(),m_opaque_sp->GetUseDynamic(),false));
1038 value_sb.SetSP(proxy_sp);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001039 }
Enrico Granatae3e91512012-10-22 18:18:36 +00001040 return value_sb;
1041}
1042
1043lldb::DynamicValueType
1044SBValue::GetPreferDynamicValue ()
1045{
1046 if (!IsValid())
1047 return eNoDynamicValues;
1048 return m_opaque_sp->GetUseDynamic();
1049}
1050
1051void
1052SBValue::SetPreferDynamicValue (lldb::DynamicValueType use_dynamic)
1053{
1054 if (IsValid())
1055 return m_opaque_sp->SetUseDynamic (use_dynamic);
1056}
1057
1058bool
1059SBValue::GetPreferSyntheticValue ()
1060{
1061 if (!IsValid())
1062 return false;
1063 return m_opaque_sp->GetUseSynthetic();
1064}
1065
1066void
1067SBValue::SetPreferSyntheticValue (bool use_synthetic)
1068{
1069 if (IsValid())
1070 return m_opaque_sp->SetUseSynthetic (use_synthetic);
Enrico Granatac5bc4122012-03-27 02:35:13 +00001071}
1072
Jim Ingham60dbabb2011-12-08 19:44:08 +00001073bool
1074SBValue::IsDynamic()
1075{
Jim Ingham362e39a2013-05-15 02:16:21 +00001076 ValueLocker locker;
1077 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001078 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001079 return value_sp->IsDynamic();
Jim Ingham60dbabb2011-12-08 19:44:08 +00001080 return false;
1081}
1082
Enrico Granatae3e91512012-10-22 18:18:36 +00001083bool
1084SBValue::IsSynthetic ()
1085{
Jim Ingham362e39a2013-05-15 02:16:21 +00001086 ValueLocker locker;
1087 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granatae3e91512012-10-22 18:18:36 +00001088 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001089 return value_sp->IsSynthetic();
Enrico Granatae3e91512012-10-22 18:18:36 +00001090 return false;
1091}
1092
Jim Ingham60dbabb2011-12-08 19:44:08 +00001093lldb::SBValue
Enrico Granataf2bbf712011-07-15 02:26:42 +00001094SBValue::GetValueForExpressionPath(const char* expr_path)
1095{
Greg Clayton5160ce52013-03-27 23:08:40 +00001096 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granataf2bbf712011-07-15 02:26:42 +00001097 lldb::ValueObjectSP child_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001098 ValueLocker locker;
1099 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001100 if (value_sp)
Enrico Granataf2bbf712011-07-15 02:26:42 +00001101 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001102 // using default values for all the fancy options, just do it if you can
1103 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf2bbf712011-07-15 02:26:42 +00001104 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001105
Enrico Granatae3e91512012-10-22 18:18:36 +00001106 SBValue sb_value;
1107 sb_value.SetSP(child_sp,GetPreferDynamicValue(),GetPreferSyntheticValue());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001108
Enrico Granataf2bbf712011-07-15 02:26:42 +00001109 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001110 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)",
1111 static_cast<void*>(value_sp.get()), expr_path,
1112 static_cast<void*>(value_sp.get()));
1113
Enrico Granataf2bbf712011-07-15 02:26:42 +00001114 return sb_value;
1115}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001116
Greg Claytonfe42ac42011-08-03 22:57:10 +00001117int64_t
Enrico Granata6fd87d52011-08-04 01:41:02 +00001118SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
1119{
Jim Ingham16e0c682011-08-12 23:34:31 +00001120 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001121 ValueLocker locker;
1122 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001123 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001124 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001125 bool success = true;
1126 uint64_t ret_val = fail_value;
1127 ret_val = value_sp->GetValueAsSigned(fail_value, &success);
1128 if (!success)
1129 error.SetErrorString("could not resolve value");
1130 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001131 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001132 else
1133 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1134
Enrico Granata6fd87d52011-08-04 01:41:02 +00001135 return fail_value;
1136}
1137
1138uint64_t
1139SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
1140{
Jim Ingham16e0c682011-08-12 23:34:31 +00001141 error.Clear();
Jim Ingham362e39a2013-05-15 02:16:21 +00001142 ValueLocker locker;
1143 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001144 if (value_sp)
Enrico Granata6fd87d52011-08-04 01:41:02 +00001145 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001146 bool success = true;
1147 uint64_t ret_val = fail_value;
1148 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success);
1149 if (!success)
Jim Ingham362e39a2013-05-15 02:16:21 +00001150 error.SetErrorString("could not resolve value");
Enrico Granatad7373f62013-10-31 18:57:50 +00001151 return ret_val;
Enrico Granata6fd87d52011-08-04 01:41:02 +00001152 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001153 else
1154 error.SetErrorStringWithFormat ("could not get SBValue: %s", locker.GetError().AsCString());
1155
Enrico Granata6fd87d52011-08-04 01:41:02 +00001156 return fail_value;
1157}
1158
1159int64_t
Greg Claytonfe42ac42011-08-03 22:57:10 +00001160SBValue::GetValueAsSigned(int64_t fail_value)
1161{
Jim Ingham362e39a2013-05-15 02:16:21 +00001162 ValueLocker locker;
1163 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001164 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001165 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001166 return value_sp->GetValueAsSigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001167 }
1168 return fail_value;
1169}
1170
1171uint64_t
1172SBValue::GetValueAsUnsigned(uint64_t fail_value)
1173{
Jim Ingham362e39a2013-05-15 02:16:21 +00001174 ValueLocker locker;
1175 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001176 if (value_sp)
Greg Claytonfe42ac42011-08-03 22:57:10 +00001177 {
Enrico Granatad7373f62013-10-31 18:57:50 +00001178 return value_sp->GetValueAsUnsigned(fail_value);
Greg Claytonfe42ac42011-08-03 22:57:10 +00001179 }
1180 return fail_value;
1181}
1182
Greg Clayton4a792072012-10-23 01:50:10 +00001183bool
1184SBValue::MightHaveChildren ()
1185{
Greg Clayton5160ce52013-03-27 23:08:40 +00001186 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton4a792072012-10-23 01:50:10 +00001187 bool has_children = false;
Jim Ingham362e39a2013-05-15 02:16:21 +00001188 ValueLocker locker;
1189 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton4a792072012-10-23 01:50:10 +00001190 if (value_sp)
1191 has_children = value_sp->MightHaveChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001192
Greg Clayton4a792072012-10-23 01:50:10 +00001193 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001194 log->Printf ("SBValue(%p)::MightHaveChildren() => %i",
1195 static_cast<void*>(value_sp.get()), has_children);
Greg Clayton4a792072012-10-23 01:50:10 +00001196 return has_children;
1197}
1198
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001199uint32_t
1200SBValue::GetNumChildren ()
1201{
1202 uint32_t num_children = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001203
Greg Clayton5160ce52013-03-27 23:08:40 +00001204 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001205 ValueLocker locker;
1206 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001207 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001208 num_children = value_sp->GetNumChildren();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001209
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001210 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001211 log->Printf ("SBValue(%p)::GetNumChildren () => %u",
1212 static_cast<void*>(value_sp.get()), num_children);
1213
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001214 return num_children;
1215}
1216
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001217
1218SBValue
1219SBValue::Dereference ()
1220{
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001221 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001222 ValueLocker locker;
1223 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001224 if (value_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001225 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001226 Error error;
1227 sb_value = value_sp->Dereference (error);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001228 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001229 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001230 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001231 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)",
1232 static_cast<void*>(value_sp.get()),
1233 static_cast<void*>(value_sp.get()));
1234
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001235 return sb_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001236}
1237
1238bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001239SBValue::TypeIsPointerType ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001240{
1241 bool is_ptr_type = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001242
Jim Ingham362e39a2013-05-15 02:16:21 +00001243 ValueLocker locker;
1244 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001245 if (value_sp)
Jim Ingham362e39a2013-05-15 02:16:21 +00001246 is_ptr_type = value_sp->IsPointerType();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001247
Greg Clayton5160ce52013-03-27 23:08:40 +00001248 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001249 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001250 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i",
1251 static_cast<void*>(value_sp.get()), is_ptr_type);
1252
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001253 return is_ptr_type;
1254}
1255
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001256void *
1257SBValue::GetOpaqueType()
1258{
Jim Ingham362e39a2013-05-15 02:16:21 +00001259 ValueLocker locker;
1260 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001261 if (value_sp)
Greg Clayton57ee3062013-07-11 22:46:58 +00001262 return value_sp->GetClangType().GetOpaqueQualType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001263 return NULL;
1264}
1265
Enrico Granata6f3533f2011-07-29 19:53:35 +00001266lldb::SBTarget
1267SBValue::GetTarget()
1268{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001269 SBTarget sb_target;
1270 TargetSP target_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001271 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001272 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001273 target_sp = m_opaque_sp->GetTargetSP();
Greg Claytonb9556ac2012-01-30 07:41:31 +00001274 sb_target.SetSP (target_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001275 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001276 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001277 if (log)
1278 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001279 if (target_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001280 log->Printf ("SBValue(%p)::GetTarget () => NULL",
1281 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001282 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001283 log->Printf ("SBValue(%p)::GetTarget () => %p",
1284 static_cast<void*>(m_opaque_sp.get()),
1285 static_cast<void*>(target_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001286 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001287 return sb_target;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001288}
1289
1290lldb::SBProcess
1291SBValue::GetProcess()
1292{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001293 SBProcess sb_process;
1294 ProcessSP process_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001295 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001296 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001297 process_sp = m_opaque_sp->GetProcessSP();
1298 sb_process.SetSP (process_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001299 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001300 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001301 if (log)
1302 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001303 if (process_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001304 log->Printf ("SBValue(%p)::GetProcess () => NULL",
1305 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001306 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001307 log->Printf ("SBValue(%p)::GetProcess () => %p",
1308 static_cast<void*>(m_opaque_sp.get()),
1309 static_cast<void*>(process_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001310 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001311 return sb_process;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001312}
1313
1314lldb::SBThread
1315SBValue::GetThread()
1316{
Greg Clayton17a6ad02012-01-30 02:53:15 +00001317 SBThread sb_thread;
1318 ThreadSP thread_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001319 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001320 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001321 thread_sp = m_opaque_sp->GetThreadSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001322 sb_thread.SetThread(thread_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001323 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001324 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001325 if (log)
1326 {
Greg Clayton17a6ad02012-01-30 02:53:15 +00001327 if (thread_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001328 log->Printf ("SBValue(%p)::GetThread () => NULL",
1329 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001330 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001331 log->Printf ("SBValue(%p)::GetThread () => %p",
1332 static_cast<void*>(m_opaque_sp.get()),
1333 static_cast<void*>(thread_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001334 }
Greg Clayton17a6ad02012-01-30 02:53:15 +00001335 return sb_thread;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001336}
1337
1338lldb::SBFrame
1339SBValue::GetFrame()
1340{
Greg Claytonb9556ac2012-01-30 07:41:31 +00001341 SBFrame sb_frame;
Jason Molendab57e4a12013-11-04 09:33:30 +00001342 StackFrameSP frame_sp;
Jim Ingham362e39a2013-05-15 02:16:21 +00001343 if (m_opaque_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001344 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001345 frame_sp = m_opaque_sp->GetFrameSP();
Greg Claytoncc4d0142012-02-17 07:49:44 +00001346 sb_frame.SetFrameSP (frame_sp);
Enrico Granata6f3533f2011-07-29 19:53:35 +00001347 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001348 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001349 if (log)
1350 {
Greg Claytonb9556ac2012-01-30 07:41:31 +00001351 if (frame_sp.get() == NULL)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001352 log->Printf ("SBValue(%p)::GetFrame () => NULL",
1353 static_cast<void*>(m_opaque_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001354 else
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001355 log->Printf ("SBValue(%p)::GetFrame () => %p",
1356 static_cast<void*>(m_opaque_sp.get()),
1357 static_cast<void*>(frame_sp.get()));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001358 }
Greg Claytonb9556ac2012-01-30 07:41:31 +00001359 return sb_frame;
Enrico Granata6f3533f2011-07-29 19:53:35 +00001360}
1361
1362
Greg Clayton81e871e2012-02-04 02:27:34 +00001363lldb::ValueObjectSP
Jim Ingham362e39a2013-05-15 02:16:21 +00001364SBValue::GetSP (ValueLocker &locker) const
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001365{
Enrico Granatae3e91512012-10-22 18:18:36 +00001366 if (!m_opaque_sp || !m_opaque_sp->IsValid())
1367 return ValueObjectSP();
Jim Ingham362e39a2013-05-15 02:16:21 +00001368 return locker.GetLockedSP(*m_opaque_sp.get());
1369}
1370
1371lldb::ValueObjectSP
1372SBValue::GetSP () const
1373{
1374 ValueLocker locker;
1375 return GetSP(locker);
Enrico Granatae3e91512012-10-22 18:18:36 +00001376}
1377
1378void
1379SBValue::SetSP (ValueImplSP impl_sp)
1380{
1381 m_opaque_sp = impl_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001382}
1383
Greg Clayton81e871e2012-02-04 02:27:34 +00001384void
1385SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001386{
Enrico Granatae3e91512012-10-22 18:18:36 +00001387 if (sp)
1388 {
1389 lldb::TargetSP target_sp(sp->GetTargetSP());
1390 if (target_sp)
1391 {
1392 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1393 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1394 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic));
1395 }
1396 else
1397 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,true));
1398 }
1399 else
1400 m_opaque_sp = ValueImplSP(new ValueImpl(sp,eNoDynamicValues,false));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001401}
Caroline Ticedde9cff2010-09-20 05:20:02 +00001402
Enrico Granatae3e91512012-10-22 18:18:36 +00001403void
1404SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic)
1405{
1406 if (sp)
1407 {
1408 lldb::TargetSP target_sp(sp->GetTargetSP());
1409 if (target_sp)
1410 {
1411 bool use_synthetic = target_sp->TargetProperties::GetEnableSyntheticValue();
1412 SetSP (sp, use_dynamic, use_synthetic);
1413 }
1414 else
1415 SetSP (sp, use_dynamic, true);
1416 }
1417 else
1418 SetSP (sp, use_dynamic, false);
1419}
1420
1421void
1422SBValue::SetSP (const lldb::ValueObjectSP &sp, bool use_synthetic)
1423{
1424 if (sp)
1425 {
1426 lldb::TargetSP target_sp(sp->GetTargetSP());
1427 if (target_sp)
1428 {
1429 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue();
1430 SetSP (sp, use_dynamic, use_synthetic);
1431 }
1432 else
1433 SetSP (sp, eNoDynamicValues, use_synthetic);
1434 }
1435 else
1436 SetSP (sp, eNoDynamicValues, use_synthetic);
1437}
1438
1439void
1440SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic)
1441{
1442 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic));
1443}
Greg Clayton81e871e2012-02-04 02:27:34 +00001444
Jim Ingham362e39a2013-05-15 02:16:21 +00001445void
1446SBValue::SetSP (const lldb::ValueObjectSP &sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, const char *name)
1447{
1448 m_opaque_sp = ValueImplSP(new ValueImpl(sp,use_dynamic,use_synthetic, name));
1449}
1450
Caroline Ticedde9cff2010-09-20 05:20:02 +00001451bool
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001452SBValue::GetExpressionPath (SBStream &description)
1453{
Jim Ingham362e39a2013-05-15 02:16:21 +00001454 ValueLocker locker;
1455 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001456 if (value_sp)
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001457 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001458 value_sp->GetExpressionPath (description.ref(), false);
Greg Clayton6beaaa62011-01-17 03:46:26 +00001459 return true;
1460 }
1461 return false;
1462}
1463
1464bool
1465SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1466{
Jim Ingham362e39a2013-05-15 02:16:21 +00001467 ValueLocker locker;
1468 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001469 if (value_sp)
Greg Clayton6beaaa62011-01-17 03:46:26 +00001470 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001471 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Claytoncfd1ace2010-10-31 03:01:06 +00001472 return true;
1473 }
1474 return false;
1475}
1476
1477bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001478SBValue::GetDescription (SBStream &description)
1479{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001480 Stream &strm = description.ref();
Daniel Maleae0f8f572013-08-26 23:57:52 +00001481
Jim Ingham362e39a2013-05-15 02:16:21 +00001482 ValueLocker locker;
1483 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001484 if (value_sp)
Enrico Granata4d93b8c2013-09-30 19:11:51 +00001485 value_sp->Dump(strm);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001486 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001487 strm.PutCString ("No value");
Daniel Maleae0f8f572013-08-26 23:57:52 +00001488
Caroline Ticedde9cff2010-09-20 05:20:02 +00001489 return true;
1490}
Greg Claytondc4e9632011-01-05 18:43:15 +00001491
1492lldb::Format
Greg Claytonbf2331c2011-09-09 23:04:00 +00001493SBValue::GetFormat ()
Greg Claytondc4e9632011-01-05 18:43:15 +00001494{
Jim Ingham362e39a2013-05-15 02:16:21 +00001495 ValueLocker locker;
1496 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001497 if (value_sp)
1498 return value_sp->GetFormat();
Greg Claytondc4e9632011-01-05 18:43:15 +00001499 return eFormatDefault;
1500}
1501
1502void
1503SBValue::SetFormat (lldb::Format format)
1504{
Jim Ingham362e39a2013-05-15 02:16:21 +00001505 ValueLocker locker;
1506 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001507 if (value_sp)
1508 value_sp->SetFormat(format);
Greg Claytondc4e9632011-01-05 18:43:15 +00001509}
1510
Enrico Granata6f3533f2011-07-29 19:53:35 +00001511lldb::SBValue
1512SBValue::AddressOf()
1513{
1514 SBValue sb_value;
Jim Ingham362e39a2013-05-15 02:16:21 +00001515 ValueLocker locker;
1516 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001517 if (value_sp)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001518 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001519 Error error;
1520 sb_value.SetSP(value_sp->AddressOf (error),GetPreferDynamicValue(), GetPreferSyntheticValue());
Enrico Granata6f3533f2011-07-29 19:53:35 +00001521 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001522 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata6f3533f2011-07-29 19:53:35 +00001523 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001524 log->Printf ("SBValue(%p)::AddressOf () => SBValue(%p)",
1525 static_cast<void*>(value_sp.get()),
1526 static_cast<void*>(value_sp.get()));
1527
Enrico Granata6f3533f2011-07-29 19:53:35 +00001528 return sb_value;
Johnny Chen4a871f92011-08-09 22:38:07 +00001529}
Enrico Granata9128ee22011-09-06 19:20:51 +00001530
1531lldb::addr_t
1532SBValue::GetLoadAddress()
1533{
1534 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Jim Ingham362e39a2013-05-15 02:16:21 +00001535 ValueLocker locker;
1536 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001537 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001538 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001539 TargetSP target_sp (value_sp->GetTargetSP());
1540 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001541 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001542 const bool scalar_is_load_address = true;
1543 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001544 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001545 if (addr_type == eAddressTypeFile)
1546 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001547 ModuleSP module_sp (value_sp->GetModule());
1548 if (!module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001549 value = LLDB_INVALID_ADDRESS;
1550 else
1551 {
1552 Address addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001553 module_sp->ResolveFileAddress(value, addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001554 value = addr.GetLoadAddress(target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001555 }
1556 }
1557 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1558 value = LLDB_INVALID_ADDRESS;
1559 }
1560 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001561 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001562 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001563 log->Printf ("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")",
1564 static_cast<void*>(value_sp.get()), value);
1565
Enrico Granata9128ee22011-09-06 19:20:51 +00001566 return value;
1567}
1568
1569lldb::SBAddress
1570SBValue::GetAddress()
1571{
1572 Address addr;
Jim Ingham362e39a2013-05-15 02:16:21 +00001573 ValueLocker locker;
1574 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001575 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001576 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001577 TargetSP target_sp (value_sp->GetTargetSP());
1578 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001579 {
1580 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001581 const bool scalar_is_load_address = true;
1582 AddressType addr_type;
Greg Clayton81e871e2012-02-04 02:27:34 +00001583 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001584 if (addr_type == eAddressTypeFile)
1585 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001586 ModuleSP module_sp (value_sp->GetModule());
1587 if (module_sp)
1588 module_sp->ResolveFileAddress(value, addr);
Enrico Granata9128ee22011-09-06 19:20:51 +00001589 }
1590 else if (addr_type == eAddressTypeLoad)
1591 {
1592 // no need to check the return value on this.. if it can actually do the resolve
1593 // addr will be in the form (section,offset), otherwise it will simply be returned
1594 // as (NULL, value)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001595 addr.SetLoadAddress(value, target_sp.get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001596 }
1597 }
1598 }
Greg Clayton5160ce52013-03-27 23:08:40 +00001599 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001600 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001601 log->Printf ("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")",
1602 static_cast<void*>(value_sp.get()),
1603 (addr.GetSection()
1604 ? addr.GetSection()->GetName().GetCString()
1605 : "NULL"),
Jim Ingham35e1bda2012-10-16 21:41:58 +00001606 addr.GetOffset());
Enrico Granata9128ee22011-09-06 19:20:51 +00001607 return SBAddress(new Address(addr));
1608}
1609
1610lldb::SBData
1611SBValue::GetPointeeData (uint32_t item_idx,
1612 uint32_t item_count)
1613{
Greg Clayton5160ce52013-03-27 23:08:40 +00001614 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001615 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001616 ValueLocker locker;
1617 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001618 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001619 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001620 TargetSP target_sp (value_sp->GetTargetSP());
1621 if (target_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001622 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001623 DataExtractorSP data_sp(new DataExtractor());
1624 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
1625 if (data_sp->GetByteSize() > 0)
1626 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001627 }
1628 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001629 if (log)
1630 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001631 static_cast<void*>(value_sp.get()), item_idx, item_count,
1632 static_cast<void*>(sb_data.get()));
1633
Enrico Granata9128ee22011-09-06 19:20:51 +00001634 return sb_data;
1635}
1636
1637lldb::SBData
1638SBValue::GetData ()
1639{
Greg Clayton5160ce52013-03-27 23:08:40 +00001640 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Enrico Granata9128ee22011-09-06 19:20:51 +00001641 lldb::SBData sb_data;
Jim Ingham362e39a2013-05-15 02:16:21 +00001642 ValueLocker locker;
1643 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001644 if (value_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001645 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001646 DataExtractorSP data_sp(new DataExtractor());
Sean Callanan866e91c2014-02-28 22:27:53 +00001647 Error error;
1648 value_sp->GetData(*data_sp, error);
1649 if (error.Success())
Jim Ingham362e39a2013-05-15 02:16:21 +00001650 *sb_data = data_sp;
Enrico Granata9128ee22011-09-06 19:20:51 +00001651 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001652 if (log)
1653 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001654 static_cast<void*>(value_sp.get()),
1655 static_cast<void*>(sb_data.get()));
1656
Enrico Granata9128ee22011-09-06 19:20:51 +00001657 return sb_data;
1658}
Greg Clayton1b282f92011-10-13 18:08:26 +00001659
Sean Callanan389823e2013-04-13 01:21:23 +00001660bool
1661SBValue::SetData (lldb::SBData &data, SBError &error)
1662{
1663 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Ingham362e39a2013-05-15 02:16:21 +00001664 ValueLocker locker;
1665 lldb::ValueObjectSP value_sp(GetSP(locker));
Sean Callanan389823e2013-04-13 01:21:23 +00001666 bool ret = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001667
Sean Callanan389823e2013-04-13 01:21:23 +00001668 if (value_sp)
1669 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001670 DataExtractor *data_extractor = data.get();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001671
Jim Ingham362e39a2013-05-15 02:16:21 +00001672 if (!data_extractor)
Sean Callanan389823e2013-04-13 01:21:23 +00001673 {
1674 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001675 log->Printf ("SBValue(%p)::SetData() => error: no data to set",
1676 static_cast<void*>(value_sp.get()));
1677
Jim Ingham362e39a2013-05-15 02:16:21 +00001678 error.SetErrorString("No data to set");
Sean Callanan389823e2013-04-13 01:21:23 +00001679 ret = false;
1680 }
1681 else
1682 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001683 Error set_error;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001684
Jim Ingham362e39a2013-05-15 02:16:21 +00001685 value_sp->SetData(*data_extractor, set_error);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001686
Jim Ingham362e39a2013-05-15 02:16:21 +00001687 if (!set_error.Success())
Sean Callanan389823e2013-04-13 01:21:23 +00001688 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001689 error.SetErrorStringWithFormat("Couldn't set data: %s", set_error.AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001690 ret = false;
1691 }
Sean Callanan389823e2013-04-13 01:21:23 +00001692 }
1693 }
1694 else
1695 {
Jim Ingham362e39a2013-05-15 02:16:21 +00001696 error.SetErrorStringWithFormat ("Couldn't set data: could not get SBValue: %s", locker.GetError().AsCString());
Sean Callanan389823e2013-04-13 01:21:23 +00001697 ret = false;
1698 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001699
Sean Callanan389823e2013-04-13 01:21:23 +00001700 if (log)
1701 log->Printf ("SBValue(%p)::SetData (%p) => %s",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001702 static_cast<void*>(value_sp.get()),
1703 static_cast<void*>(data.get()), ret ? "true" : "false");
Sean Callanan389823e2013-04-13 01:21:23 +00001704 return ret;
1705}
1706
Enrico Granata10de0902012-10-10 22:54:17 +00001707lldb::SBDeclaration
1708SBValue::GetDeclaration ()
1709{
Jim Ingham362e39a2013-05-15 02:16:21 +00001710 ValueLocker locker;
1711 lldb::ValueObjectSP value_sp(GetSP(locker));
Enrico Granata10de0902012-10-10 22:54:17 +00001712 SBDeclaration decl_sb;
1713 if (value_sp)
1714 {
1715 Declaration decl;
1716 if (value_sp->GetDeclaration(decl))
1717 decl_sb.SetDeclaration(decl);
1718 }
1719 return decl_sb;
1720}
1721
Greg Clayton1b282f92011-10-13 18:08:26 +00001722lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001723SBValue::Watch (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001724{
Greg Clayton81e871e2012-02-04 02:27:34 +00001725 SBWatchpoint sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001726
Greg Clayton81e871e2012-02-04 02:27:34 +00001727 // If the SBValue is not valid, there's no point in even trying to watch it.
Jim Ingham362e39a2013-05-15 02:16:21 +00001728 ValueLocker locker;
1729 lldb::ValueObjectSP value_sp(GetSP(locker));
Greg Clayton81e871e2012-02-04 02:27:34 +00001730 TargetSP target_sp (GetTarget().GetSP());
1731 if (value_sp && target_sp)
Greg Clayton1b282f92011-10-13 18:08:26 +00001732 {
Greg Clayton81e871e2012-02-04 02:27:34 +00001733 // Read and Write cannot both be false.
1734 if (!read && !write)
1735 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001736
Greg Clayton81e871e2012-02-04 02:27:34 +00001737 // If the value is not in scope, don't try and watch and invalid value
1738 if (!IsInScope())
1739 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001740
Greg Clayton81e871e2012-02-04 02:27:34 +00001741 addr_t addr = GetLoadAddress();
1742 if (addr == LLDB_INVALID_ADDRESS)
1743 return sb_watchpoint;
1744 size_t byte_size = GetByteSize();
1745 if (byte_size == 0)
1746 return sb_watchpoint;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001747
Greg Clayton81e871e2012-02-04 02:27:34 +00001748 uint32_t watch_type = 0;
1749 if (read)
1750 watch_type |= LLDB_WATCH_TYPE_READ;
1751 if (write)
1752 watch_type |= LLDB_WATCH_TYPE_WRITE;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001753
Johnny Chenb90827e2012-06-04 23:19:54 +00001754 Error rc;
Greg Clayton57ee3062013-07-11 22:46:58 +00001755 ClangASTType type (value_sp->GetClangType());
Jim Inghama7dfb662012-10-23 07:20:06 +00001756 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc);
Johnny Chenb90827e2012-06-04 23:19:54 +00001757 error.SetError(rc);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001758
Daniel Maleae0f8f572013-08-26 23:57:52 +00001759 if (watchpoint_sp)
Greg Clayton81e871e2012-02-04 02:27:34 +00001760 {
1761 sb_watchpoint.SetSP (watchpoint_sp);
1762 Declaration decl;
1763 if (value_sp->GetDeclaration (decl))
1764 {
Daniel Maleae0f8f572013-08-26 23:57:52 +00001765 if (decl.GetFile())
Greg Clayton81e871e2012-02-04 02:27:34 +00001766 {
1767 StreamString ss;
1768 // True to show fullpath for declaration file.
1769 decl.DumpStopContext(&ss, true);
1770 watchpoint_sp->SetDeclInfo(ss.GetString());
1771 }
1772 }
1773 }
Greg Clayton1b282f92011-10-13 18:08:26 +00001774 }
Jim Ingham362e39a2013-05-15 02:16:21 +00001775 else if (target_sp)
1776 {
1777 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1778 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001779 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: %s",
1780 static_cast<void*>(value_sp.get()),
1781 locker.GetError().AsCString());
1782
Jim Ingham362e39a2013-05-15 02:16:21 +00001783 error.SetErrorStringWithFormat("could not get SBValue: %s", locker.GetError().AsCString());
1784 }
1785 else
1786 {
1787 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1788 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001789 log->Printf ("SBValue(%p)::Watch() => error getting SBValue: no target",
1790 static_cast<void*>(value_sp.get()));
Jim Ingham362e39a2013-05-15 02:16:21 +00001791 error.SetErrorString("could not set watchpoint, a target is required");
1792 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001793
Greg Clayton1b282f92011-10-13 18:08:26 +00001794 return sb_watchpoint;
1795}
1796
Johnny Chend3761a72012-06-04 23:45:50 +00001797// FIXME: Remove this method impl (as well as the decl in .h) once it is no longer needed.
1798// Backward compatibility fix in the interim.
1799lldb::SBWatchpoint
1800SBValue::Watch (bool resolve_location, bool read, bool write)
1801{
Johnny Chen974759f2012-06-05 00:14:15 +00001802 SBError error;
1803 return Watch(resolve_location, read, write, error);
Johnny Chend3761a72012-06-04 23:45:50 +00001804}
1805
Greg Clayton1b282f92011-10-13 18:08:26 +00001806lldb::SBWatchpoint
Johnny Chenb90827e2012-06-04 23:19:54 +00001807SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &error)
Greg Clayton1b282f92011-10-13 18:08:26 +00001808{
Greg Clayton81e871e2012-02-04 02:27:34 +00001809 SBWatchpoint sb_watchpoint;
1810 if (IsInScope() && GetType().IsPointerType())
Johnny Chenb90827e2012-06-04 23:19:54 +00001811 sb_watchpoint = Dereference().Watch (resolve_location, read, write, error);
Greg Clayton1b282f92011-10-13 18:08:26 +00001812 return sb_watchpoint;
1813}