blob: 2369d6ba980d145449260062517875de73bd3603 [file] [log] [blame]
Chris Lattner24943d22010-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
Eli Friedman7a62c8b2010-06-09 07:44:37 +000010#include "lldb/API/SBValue.h"
Caroline Tice98f930f2010-09-20 05:20:02 +000011#include "lldb/API/SBStream.h"
Chris Lattner24943d22010-06-08 16:52:24 +000012
Johnny Chenecd4feb2011-10-14 00:42:25 +000013#include "lldb/Breakpoint/Watchpoint.h"
Chris Lattner24943d22010-06-08 16:52:24 +000014#include "lldb/Core/DataExtractor.h"
Caroline Tice7826c882010-10-26 03:11:13 +000015#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000016#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000017#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Core/Stream.h"
19#include "lldb/Core/StreamFile.h"
20#include "lldb/Core/Value.h"
21#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000022#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000023#include "lldb/Symbol/Block.h"
24#include "lldb/Symbol/ObjectFile.h"
Greg Clayton0a19a1b2012-02-04 02:27:34 +000025#include "lldb/Symbol/Type.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026#include "lldb/Symbol/Variable.h"
Johnny Chenecd4feb2011-10-14 00:42:25 +000027#include "lldb/Symbol/VariableList.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Target/ExecutionContext.h"
29#include "lldb/Target/Process.h"
30#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000031#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000032#include "lldb/Target/Thread.h"
33
Eli Friedman7a62c8b2010-06-09 07:44:37 +000034#include "lldb/API/SBProcess.h"
35#include "lldb/API/SBTarget.h"
36#include "lldb/API/SBThread.h"
37#include "lldb/API/SBFrame.h"
38#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
43SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000044 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000045{
46}
47
48SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000049 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000050{
51}
52
Greg Clayton538eb822010-11-05 23:17:00 +000053SBValue::SBValue(const SBValue &rhs) :
54 m_opaque_sp (rhs.m_opaque_sp)
55{
56}
57
Greg Claytond68e0892011-09-09 23:04:00 +000058SBValue &
Greg Clayton538eb822010-11-05 23:17:00 +000059SBValue::operator = (const SBValue &rhs)
60{
61 if (this != &rhs)
62 m_opaque_sp = rhs.m_opaque_sp;
63 return *this;
64}
65
Chris Lattner24943d22010-06-08 16:52:24 +000066SBValue::~SBValue()
67{
68}
69
70bool
Greg Claytond68e0892011-09-09 23:04:00 +000071SBValue::IsValid ()
Chris Lattner24943d22010-06-08 16:52:24 +000072{
Greg Clayton49ce6822010-10-31 03:01:06 +000073 // If this function ever changes to anything that does more than just
74 // check if the opaque shared pointer is non NULL, then we need to update
75 // all "if (m_opaque_sp)" code in this file.
76 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000077}
78
Jim Inghame0bd5712011-12-19 20:39:44 +000079void
80SBValue::Clear()
81{
82 m_opaque_sp.reset();
83}
84
Greg Claytonc5f728c2010-10-06 22:10:17 +000085SBError
86SBValue::GetError()
87{
88 SBError sb_error;
89
Greg Clayton0a19a1b2012-02-04 02:27:34 +000090 lldb::ValueObjectSP value_sp(GetSP());
91 if (value_sp)
92 sb_error.SetError(value_sp->GetError());
Greg Clayton334d33a2012-01-30 07:41:31 +000093 else
94 sb_error.SetErrorString("error: invalid value");
Greg Claytonc5f728c2010-10-06 22:10:17 +000095
96 return sb_error;
97}
98
Johnny Chen968958c2011-07-07 20:46:23 +000099user_id_t
100SBValue::GetID()
101{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000102 lldb::ValueObjectSP value_sp(GetSP());
103 if (value_sp)
104 return value_sp->GetID();
Johnny Chen968958c2011-07-07 20:46:23 +0000105 return LLDB_INVALID_UID;
106}
107
Chris Lattner24943d22010-06-08 16:52:24 +0000108const char *
109SBValue::GetName()
110{
Greg Clayton49ce6822010-10-31 03:01:06 +0000111
112 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000113 lldb::ValueObjectSP value_sp(GetSP());
114 if (value_sp)
115 name = value_sp->GetName().GetCString();
Greg Clayton49ce6822010-10-31 03:01:06 +0000116
Greg Claytone005f2c2010-11-06 01:53:30 +0000117 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000118 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000119 {
120 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000121 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000122 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000123 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000124 }
Caroline Tice7826c882010-10-26 03:11:13 +0000125
Greg Clayton49ce6822010-10-31 03:01:06 +0000126 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000127}
128
129const char *
130SBValue::GetTypeName ()
131{
Greg Clayton49ce6822010-10-31 03:01:06 +0000132 const char *name = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000133 lldb::ValueObjectSP value_sp(GetSP());
134 if (value_sp)
135 name = value_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000136 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000137 if (log)
138 {
139 if (name)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000140 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000141 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000142 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000143 }
144
145 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000146}
147
148size_t
149SBValue::GetByteSize ()
150{
151 size_t result = 0;
152
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000153 lldb::ValueObjectSP value_sp(GetSP());
154 if (value_sp)
155 result = value_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000156
Greg Claytone005f2c2010-11-06 01:53:30 +0000157 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000158 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000159 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000160
Chris Lattner24943d22010-06-08 16:52:24 +0000161 return result;
162}
163
164bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000165SBValue::IsInScope ()
166{
Chris Lattner24943d22010-06-08 16:52:24 +0000167 bool result = false;
168
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000169 lldb::ValueObjectSP value_sp(GetSP());
170 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000171 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000172 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
173 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000174 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000175 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
176 result = value_sp->IsInScope ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000177 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000178 }
Chris Lattner24943d22010-06-08 16:52:24 +0000179
Greg Claytone005f2c2010-11-06 01:53:30 +0000180 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000181 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000182 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000183
Chris Lattner24943d22010-06-08 16:52:24 +0000184 return result;
185}
186
187const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000188SBValue::GetValue ()
189{
Greg Clayton49ce6822010-10-31 03:01:06 +0000190 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000191 lldb::ValueObjectSP value_sp(GetSP());
192 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000193 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000194 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
195 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000196 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000197 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
198 cstr = value_sp->GetValueAsCString ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000199 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000200 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000201 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000202 if (log)
203 {
204 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000205 log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000206 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000207 log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 }
209
210 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000211}
212
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000213ValueType
214SBValue::GetValueType ()
215{
Greg Clayton49ce6822010-10-31 03:01:06 +0000216 ValueType result = eValueTypeInvalid;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000217 lldb::ValueObjectSP value_sp(GetSP());
218 if (value_sp)
219 result = value_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000220 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000221 if (log)
222 {
223 switch (result)
224 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000225 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break;
226 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break;
227 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break;
228 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break;
229 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break;
230 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break;
231 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break;
232 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break;
233 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break;
Greg Clayton49ce6822010-10-31 03:01:06 +0000234 }
235 }
236 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000237}
238
Jim Ingham4ae51962010-09-10 23:12:17 +0000239const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000240SBValue::GetObjectDescription ()
241{
Greg Clayton49ce6822010-10-31 03:01:06 +0000242 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000243 lldb::ValueObjectSP value_sp(GetSP());
244 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000245 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000246 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
247 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000248 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000249 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
250 cstr = value_sp->GetObjectDescription ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000251 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000252 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000253 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000254 if (log)
255 {
256 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000257 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000258 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000259 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000260 }
261 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000262}
263
Enrico Granata979e20d2011-07-29 19:53:35 +0000264SBType
265SBValue::GetType()
266{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000267 SBType sb_type;
268 lldb::ValueObjectSP value_sp(GetSP());
269 TypeImplSP type_sp;
270 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000271 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000272 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType())));
273 sb_type.SetSP(type_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000274 }
275 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
276 if (log)
277 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000278 if (type_sp)
279 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000280 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000281 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000282 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000283 return sb_type;
Enrico Granata979e20d2011-07-29 19:53:35 +0000284}
285
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000286bool
287SBValue::GetValueDidChange ()
288{
Greg Clayton49ce6822010-10-31 03:01:06 +0000289 bool result = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000290 lldb::ValueObjectSP value_sp(GetSP());
291 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000292 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000293 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
294 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000295 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000296 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
297 result = value_sp->GetValueDidChange ();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000298 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000299 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000300 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000301 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000302 log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result);
Greg Clayton49ce6822010-10-31 03:01:06 +0000303
304 return result;
Chris Lattner24943d22010-06-08 16:52:24 +0000305}
306
307const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000308SBValue::GetSummary ()
309{
Greg Clayton49ce6822010-10-31 03:01:06 +0000310 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000311 lldb::ValueObjectSP value_sp(GetSP());
312 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000313 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000314 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
315 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000316 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000317 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
318 cstr = value_sp->GetSummaryAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000319 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000320 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000321 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000322 if (log)
323 {
324 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000325 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000326 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000327 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000328 }
329 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000330}
331
332const char *
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000333SBValue::GetLocation ()
334{
Greg Clayton49ce6822010-10-31 03:01:06 +0000335 const char *cstr = NULL;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000336 lldb::ValueObjectSP value_sp(GetSP());
337 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000338 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000339 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
340 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000341 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000342 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
343 cstr = value_sp->GetLocationAsCString();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000344 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000345 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000346 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000347 if (log)
348 {
349 if (cstr)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000350 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000351 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000352 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000353 }
354 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000355}
356
357bool
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000358SBValue::SetValueFromCString (const char *value_str)
359{
Chris Lattner24943d22010-06-08 16:52:24 +0000360 bool success = false;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000361 lldb::ValueObjectSP value_sp(GetSP());
362 if (value_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000363 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000364 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
365 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000366 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000367 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
368 success = value_sp->SetValueFromCString (value_str);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000369 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000370 }
Chris Lattner24943d22010-06-08 16:52:24 +0000371 return success;
372}
373
Enrico Granata979e20d2011-07-29 19:53:35 +0000374lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000375SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000376{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000377 lldb::SBValue sb_value;
378 lldb::ValueObjectSP value_sp(GetSP());
379 lldb::ValueObjectSP new_value_sp;
380 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000381 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000382 TypeImplSP type_sp (type.GetSP());
Enrico Granata979e20d2011-07-29 19:53:35 +0000383 if (type.IsValid())
384 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000385 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true));
386 new_value_sp = sb_value.GetSP();
387 if (new_value_sp)
388 new_value_sp->SetName(ConstString(name));
Enrico Granata979e20d2011-07-29 19:53:35 +0000389 }
390 }
391 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
392 if (log)
393 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000394 if (new_value_sp)
395 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000396 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000397 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000398 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000399 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000400}
401
402lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000403SBValue::Cast (SBType type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000404{
Greg Clayton4eb01a72012-01-31 04:25:15 +0000405 lldb::SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000406 lldb::ValueObjectSP value_sp(GetSP());
407 TypeImplSP type_sp (type.GetSP());
408 if (value_sp && type_sp)
409 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType()));
Greg Clayton4eb01a72012-01-31 04:25:15 +0000410 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000411}
412
413lldb::SBValue
414SBValue::CreateValueFromExpression (const char *name, const char* expression)
415{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000416 lldb::SBValue sb_value;
417 lldb::ValueObjectSP value_sp(GetSP());
418 lldb::ValueObjectSP new_value_sp;
419 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000420 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000421 value_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression (expression,
422 value_sp->GetExecutionContextScope()->CalculateStackFrame(),
423 eExecutionPolicyOnlyWhenNeeded,
424 false, // coerce to id
425 true, // unwind on error
426 true, // keep in memory
427 eNoDynamicValues,
428 new_value_sp);
429 if (new_value_sp)
Johnny Chen9fd2e382011-12-20 01:52:44 +0000430 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000431 new_value_sp->SetName(ConstString(name));
432 sb_value.SetSP(new_value_sp);
Johnny Chen9fd2e382011-12-20 01:52:44 +0000433 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000434 }
435 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
436 if (log)
437 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000438 if (new_value_sp)
439 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata979e20d2011-07-29 19:53:35 +0000440 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000441 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000442 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000443 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000444}
445
446lldb::SBValue
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000447SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type)
Enrico Granata979e20d2011-07-29 19:53:35 +0000448{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000449 lldb::SBValue sb_value;
450 lldb::ValueObjectSP value_sp(GetSP());
451 lldb::ValueObjectSP new_value_sp;
452 lldb::TypeImplSP type_impl_sp (sb_type.GetSP());
453 if (value_sp && type_impl_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000454 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000455 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ());
456 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type));
457 if (pointee_type_impl_sp)
Enrico Granatac9310302011-08-04 17:07:02 +0000458 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000459
460 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
461
462 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (value_sp->GetExecutionContextScope(),
463 pointee_type_impl_sp->GetASTContext(),
464 pointee_type_impl_sp->GetOpaqueQualType(),
465 ConstString(name),
466 buffer,
467 lldb::endian::InlHostByteOrder(),
468 GetTarget().GetProcess().GetAddressByteSize()));
469
470 if (ptr_result_valobj_sp)
471 {
472 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
473 Error err;
474 new_value_sp = ptr_result_valobj_sp->Dereference(err);
475 if (new_value_sp)
476 new_value_sp->SetName(ConstString(name));
477 }
478 sb_value.SetSP(new_value_sp);
Enrico Granatac9310302011-08-04 17:07:02 +0000479 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000480 }
481 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
482 if (log)
483 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000484 if (new_value_sp)
485 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Johnny Chena713b862011-08-09 22:38:07 +0000486 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000487 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000488 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000489 return sb_value;
Enrico Granata979e20d2011-07-29 19:53:35 +0000490}
491
Enrico Granata91544802011-09-06 19:20:51 +0000492lldb::SBValue
Greg Claytond68e0892011-09-09 23:04:00 +0000493SBValue::CreateValueFromData (const char* name, SBData data, SBType type)
Enrico Granata91544802011-09-06 19:20:51 +0000494{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000495 lldb::SBValue sb_value;
496 lldb::ValueObjectSP new_value_sp;
497 lldb::ValueObjectSP value_sp(GetSP());
498 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +0000499 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000500 new_value_sp = ValueObjectConstResult::Create (value_sp->GetExecutionContextScope(),
501 type.m_opaque_sp->GetASTContext() ,
502 type.m_opaque_sp->GetOpaqueQualType(),
503 ConstString(name),
504 *data.m_opaque_sp,
505 LLDB_INVALID_ADDRESS);
506 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
507 sb_value.SetSP(new_value_sp);
Enrico Granata91544802011-09-06 19:20:51 +0000508 }
509 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
510 if (log)
511 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000512 if (new_value_sp)
513 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString());
Enrico Granata91544802011-09-06 19:20:51 +0000514 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000515 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get());
Enrico Granata91544802011-09-06 19:20:51 +0000516 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000517 return sb_value;
Enrico Granata91544802011-09-06 19:20:51 +0000518}
519
Chris Lattner24943d22010-06-08 16:52:24 +0000520SBValue
521SBValue::GetChildAtIndex (uint32_t idx)
522{
Greg Clayton8f64c472011-07-15 19:31:49 +0000523 const bool can_create_synthetic = false;
524 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000525 lldb::ValueObjectSP value_sp(GetSP());
526 if (value_sp)
527 use_dynamic = value_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000528 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000529}
530
531SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000532SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000533{
Chris Lattner24943d22010-06-08 16:52:24 +0000534 lldb::ValueObjectSP child_sp;
535
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000536 lldb::ValueObjectSP value_sp(GetSP());
537 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000538 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000539 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
540 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000541 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000542 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000543 const bool can_create = true;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000544 child_sp = value_sp->GetChildAtIndex (idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000545 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000546 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000547 if (value_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000548 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000549 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000550 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000551 else if (value_sp->IsArrayType())
Greg Clayton8f64c472011-07-15 19:31:49 +0000552 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000553 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
Greg Clayton8f64c472011-07-15 19:31:49 +0000554 }
555 }
556
557 if (child_sp)
558 {
559 if (use_dynamic != lldb::eNoDynamicValues)
560 {
561 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000562 if (dynamic_sp)
563 child_sp = dynamic_sp;
564 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000565 }
Jim Inghame41494a2011-04-16 00:01:13 +0000566 }
567 }
568
Chris Lattner24943d22010-06-08 16:52:24 +0000569 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000570 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000571 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000572 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000573
Chris Lattner24943d22010-06-08 16:52:24 +0000574 return sb_value;
575}
576
577uint32_t
578SBValue::GetIndexOfChildWithName (const char *name)
579{
Greg Clayton49ce6822010-10-31 03:01:06 +0000580 uint32_t idx = UINT32_MAX;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000581 lldb::ValueObjectSP value_sp(GetSP());
582 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000583 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000584 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
585 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000586 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000587 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000588
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000589 idx = value_sp->GetIndexOfChildWithName (ConstString(name));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000590 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000591 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000592 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000593 if (log)
594 {
595 if (idx == UINT32_MAX)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000596 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name);
Greg Clayton49ce6822010-10-31 03:01:06 +0000597 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000598 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx);
Greg Clayton49ce6822010-10-31 03:01:06 +0000599 }
600 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000601}
602
603SBValue
604SBValue::GetChildMemberWithName (const char *name)
605{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000606 lldb::ValueObjectSP value_sp(GetSP());
607 if (value_sp)
Johnny Chen446ccaa2011-06-29 21:19:39 +0000608 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000609 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues;
610 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
611 if (target_sp)
612 {
613 Mutex::Locker api_locker (target_sp->GetAPIMutex());
614 use_dynamic_value = target_sp->GetPreferDynamicValue();
615 }
Johnny Chen446ccaa2011-06-29 21:19:39 +0000616 return GetChildMemberWithName (name, use_dynamic_value);
617 }
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000618 return SBValue();
Jim Inghame41494a2011-04-16 00:01:13 +0000619}
620
621SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000622SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000623{
Chris Lattner24943d22010-06-08 16:52:24 +0000624 lldb::ValueObjectSP child_sp;
625 const ConstString str_name (name);
626
Greg Clayton905acaf2011-05-20 22:07:17 +0000627
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000628 lldb::ValueObjectSP value_sp(GetSP());
629 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000630 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000631 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
632 if (target_sp)
Jim Inghame41494a2011-04-16 00:01:13 +0000633 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000634 Mutex::Locker api_locker (target_sp->GetAPIMutex());
635 child_sp = value_sp->GetChildMemberWithName (str_name, true);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000636 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000637 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000638 if (child_sp)
639 {
640 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
641 if (dynamic_sp)
642 child_sp = dynamic_sp;
643 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000644 }
Jim Inghame41494a2011-04-16 00:01:13 +0000645 }
646 }
647
Chris Lattner24943d22010-06-08 16:52:24 +0000648 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000649
Greg Claytone005f2c2010-11-06 01:53:30 +0000650 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000651 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000652 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000653
Chris Lattner24943d22010-06-08 16:52:24 +0000654 return sb_value;
655}
656
Enrico Granataf7a9b142011-07-15 02:26:42 +0000657lldb::SBValue
Jim Ingham1b425752011-12-08 19:44:08 +0000658SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic)
659{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000660 lldb::ValueObjectSP value_sp(GetSP());
661 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000662 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000663 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
664 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000665 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000666 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
667 return SBValue (value_sp->GetDynamicValue(use_dynamic));
Jim Ingham1b425752011-12-08 19:44:08 +0000668 }
669 }
670
671 return SBValue();
672}
673
674lldb::SBValue
675SBValue::GetStaticValue ()
676{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000677 lldb::ValueObjectSP value_sp(GetSP());
678 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000679 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000680 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
681 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000682 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000683 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
684 return SBValue(value_sp->GetStaticValue());
Jim Ingham1b425752011-12-08 19:44:08 +0000685 }
686 }
687
688 return SBValue();
689}
690
691bool
692SBValue::IsDynamic()
693{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000694 lldb::ValueObjectSP value_sp(GetSP());
695 if (value_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000696 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000697 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
698 if (target_sp)
Jim Ingham1b425752011-12-08 19:44:08 +0000699 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000700 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
701 return value_sp->IsDynamic();
Jim Ingham1b425752011-12-08 19:44:08 +0000702 }
703 }
704 return false;
705}
706
707lldb::SBValue
Enrico Granataf7a9b142011-07-15 02:26:42 +0000708SBValue::GetValueForExpressionPath(const char* expr_path)
709{
710 lldb::ValueObjectSP child_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000711 lldb::ValueObjectSP value_sp(GetSP());
712 if (value_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000713 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000714 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
715 if (target_sp)
Enrico Granataf7a9b142011-07-15 02:26:42 +0000716 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000717 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000718 // using default values for all the fancy options, just do it if you can
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000719 child_sp = value_sp->GetValueForExpressionPath(expr_path);
Enrico Granataf7a9b142011-07-15 02:26:42 +0000720 }
721 }
722
723 SBValue sb_value (child_sp);
724
725 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
726 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000727 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000728
729 return sb_value;
730}
Chris Lattner24943d22010-06-08 16:52:24 +0000731
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000732int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000733SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
734{
Jim Ingham574c3d62011-08-12 23:34:31 +0000735 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000736 lldb::ValueObjectSP value_sp(GetSP());
737 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000738 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000739 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
740 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000741 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000742 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000743 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000744 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000745 return scalar.GetRawBits64(fail_value);
746 else
747 error.SetErrorString("could not get value");
748 }
749 else
750 error.SetErrorString("could not get target");
751 }
752 error.SetErrorString("invalid SBValue");
753 return fail_value;
754}
755
756uint64_t
757SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
758{
Jim Ingham574c3d62011-08-12 23:34:31 +0000759 error.Clear();
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000760 lldb::ValueObjectSP value_sp(GetSP());
761 if (value_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000762 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000763 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
764 if (target_sp)
Enrico Granatac92eb402011-08-04 01:41:02 +0000765 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000766 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granatac92eb402011-08-04 01:41:02 +0000767 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000768 if (value_sp->ResolveValue (scalar))
Enrico Granatac92eb402011-08-04 01:41:02 +0000769 return scalar.GetRawBits64(fail_value);
770 else
771 error.SetErrorString("could not get value");
772 }
773 else
774 error.SetErrorString("could not get target");
775 }
776 error.SetErrorString("invalid SBValue");
777 return fail_value;
778}
779
780int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000781SBValue::GetValueAsSigned(int64_t fail_value)
782{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000783 lldb::ValueObjectSP value_sp(GetSP());
784 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000785 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000786 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
787 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000788 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000789 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000790 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000791 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000792 return scalar.GetRawBits64(fail_value);
793 }
794 }
795 return fail_value;
796}
797
798uint64_t
799SBValue::GetValueAsUnsigned(uint64_t fail_value)
800{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000801 lldb::ValueObjectSP value_sp(GetSP());
802 if (value_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000803 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000804 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
805 if (target_sp)
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000806 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000807 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000808 Scalar scalar;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000809 if (value_sp->ResolveValue (scalar))
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000810 return scalar.GetRawBits64(fail_value);
811 }
812 }
813 return fail_value;
814}
815
Chris Lattner24943d22010-06-08 16:52:24 +0000816uint32_t
817SBValue::GetNumChildren ()
818{
819 uint32_t num_children = 0;
820
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000821 lldb::ValueObjectSP value_sp(GetSP());
822 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000823 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000824 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
825 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000826 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000827 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000828
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000829 num_children = value_sp->GetNumChildren();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000830 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000831 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000832
Greg Claytone005f2c2010-11-06 01:53:30 +0000833 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000834 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000835 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000836
837 return num_children;
838}
839
Chris Lattner24943d22010-06-08 16:52:24 +0000840
841SBValue
842SBValue::Dereference ()
843{
Greg Clayton49ce6822010-10-31 03:01:06 +0000844 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000845 lldb::ValueObjectSP value_sp(GetSP());
846 if (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000847 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000848 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
849 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000850 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000851 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000852
Greg Claytonb9dcc512011-06-29 18:28:50 +0000853 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000854 sb_value = value_sp->Dereference (error);
Greg Claytonb9dcc512011-06-29 18:28:50 +0000855 }
Chris Lattner24943d22010-06-08 16:52:24 +0000856 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000857 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000858 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000859 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000860
861 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000862}
863
864bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000865SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000866{
867 bool is_ptr_type = false;
868
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000869 lldb::ValueObjectSP value_sp(GetSP());
870 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000871 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000872 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
873 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000874 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000875 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000876
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000877 is_ptr_type = value_sp->IsPointerType();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000878 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000879 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000880
Greg Claytone005f2c2010-11-06 01:53:30 +0000881 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000882 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000883 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type);
Greg Clayton49ce6822010-10-31 03:01:06 +0000884
Chris Lattner24943d22010-06-08 16:52:24 +0000885
886 return is_ptr_type;
887}
888
Chris Lattner24943d22010-06-08 16:52:24 +0000889void *
890SBValue::GetOpaqueType()
891{
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000892 lldb::ValueObjectSP value_sp(GetSP());
893 if (value_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000894 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000895 TargetSP target_sp(value_sp->GetUpdatePoint().GetTargetSP());
896 if (target_sp)
Greg Claytonb9dcc512011-06-29 18:28:50 +0000897 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000898 Mutex::Locker api_locker (value_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000899
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000900 return value_sp->GetClangType();
Greg Claytonb9dcc512011-06-29 18:28:50 +0000901 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000902 }
Chris Lattner24943d22010-06-08 16:52:24 +0000903 return NULL;
904}
905
Enrico Granata979e20d2011-07-29 19:53:35 +0000906lldb::SBTarget
907SBValue::GetTarget()
908{
Greg Clayton334d33a2012-01-30 07:41:31 +0000909 SBTarget sb_target;
910 TargetSP target_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000911 lldb::ValueObjectSP value_sp(GetSP());
912 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000913 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000914 target_sp = value_sp->GetUpdatePoint().GetTargetSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000915 sb_target.SetSP (target_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000916 }
917 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
918 if (log)
919 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000920 if (target_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000921 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000922 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000923 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000924 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000925 return sb_target;
Enrico Granata979e20d2011-07-29 19:53:35 +0000926}
927
928lldb::SBProcess
929SBValue::GetProcess()
930{
Greg Clayton334d33a2012-01-30 07:41:31 +0000931 SBProcess sb_process;
932 ProcessSP process_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000933 lldb::ValueObjectSP value_sp(GetSP());
934 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000935 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000936 process_sp = value_sp->GetUpdatePoint().GetProcessSP();
Greg Clayton334d33a2012-01-30 07:41:31 +0000937 if (process_sp)
938 sb_process.SetSP (process_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000939 }
940 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
941 if (log)
942 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000943 if (process_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000944 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000945 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000946 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000947 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000948 return sb_process;
Enrico Granata979e20d2011-07-29 19:53:35 +0000949}
950
951lldb::SBThread
952SBValue::GetThread()
953{
Greg Clayton90c52142012-01-30 02:53:15 +0000954 SBThread sb_thread;
955 ThreadSP thread_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000956 lldb::ValueObjectSP value_sp(GetSP());
957 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000958 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000959 if (value_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000960 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000961 thread_sp = value_sp->GetExecutionContextScope()->CalculateThread()->shared_from_this();
Greg Clayton90c52142012-01-30 02:53:15 +0000962 sb_thread.SetThread(thread_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000963 }
964 }
965 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
966 if (log)
967 {
Greg Clayton90c52142012-01-30 02:53:15 +0000968 if (thread_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000969 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000970 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000971 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000972 }
Greg Clayton90c52142012-01-30 02:53:15 +0000973 return sb_thread;
Enrico Granata979e20d2011-07-29 19:53:35 +0000974}
975
976lldb::SBFrame
977SBValue::GetFrame()
978{
Greg Clayton334d33a2012-01-30 07:41:31 +0000979 SBFrame sb_frame;
980 StackFrameSP frame_sp;
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000981 lldb::ValueObjectSP value_sp(GetSP());
982 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000983 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000984 if (value_sp->GetExecutionContextScope())
Enrico Granata979e20d2011-07-29 19:53:35 +0000985 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000986 frame_sp = value_sp->GetExecutionContextScope()->CalculateStackFrame()->shared_from_this();
Greg Clayton334d33a2012-01-30 07:41:31 +0000987 sb_frame.SetFrameSP (frame_sp);
Enrico Granata979e20d2011-07-29 19:53:35 +0000988 }
989 }
990 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
991 if (log)
992 {
Greg Clayton334d33a2012-01-30 07:41:31 +0000993 if (frame_sp.get() == NULL)
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000994 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000995 else
Greg Clayton0a19a1b2012-02-04 02:27:34 +0000996 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +0000997 }
Greg Clayton334d33a2012-01-30 07:41:31 +0000998 return sb_frame;
Enrico Granata979e20d2011-07-29 19:53:35 +0000999}
1000
1001
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001002lldb::ValueObjectSP
1003SBValue::GetSP () const
Chris Lattner24943d22010-06-08 16:52:24 +00001004{
Greg Clayton63094e02010-06-23 01:19:29 +00001005 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001006}
1007
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001008void
1009SBValue::SetSP (const lldb::ValueObjectSP &sp)
Chris Lattner24943d22010-06-08 16:52:24 +00001010{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001011 m_opaque_sp = sp;
Chris Lattner24943d22010-06-08 16:52:24 +00001012}
Caroline Tice98f930f2010-09-20 05:20:02 +00001013
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001014
Caroline Tice98f930f2010-09-20 05:20:02 +00001015bool
Greg Clayton49ce6822010-10-31 03:01:06 +00001016SBValue::GetExpressionPath (SBStream &description)
1017{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001018 lldb::ValueObjectSP value_sp(GetSP());
1019 if (value_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +00001020 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001021 value_sp->GetExpressionPath (description.ref(), false);
Greg Claytonb01000f2011-01-17 03:46:26 +00001022 return true;
1023 }
1024 return false;
1025}
1026
1027bool
1028SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
1029{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001030 lldb::ValueObjectSP value_sp(GetSP());
1031 if (value_sp)
Greg Claytonb01000f2011-01-17 03:46:26 +00001032 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001033 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +00001034 return true;
1035 }
1036 return false;
1037}
1038
1039bool
Caroline Tice98f930f2010-09-20 05:20:02 +00001040SBValue::GetDescription (SBStream &description)
1041{
Greg Clayton96154be2011-11-13 06:57:31 +00001042 Stream &strm = description.ref();
1043
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001044 lldb::ValueObjectSP value_sp(GetSP());
1045 if (value_sp)
Caroline Tice98f930f2010-09-20 05:20:02 +00001046 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001047 ValueObject::DumpValueObject (strm, value_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +00001048 }
1049 else
Greg Clayton96154be2011-11-13 06:57:31 +00001050 strm.PutCString ("No value");
Caroline Tice98f930f2010-09-20 05:20:02 +00001051
1052 return true;
1053}
Greg Claytone179a582011-01-05 18:43:15 +00001054
1055lldb::Format
Greg Claytond68e0892011-09-09 23:04:00 +00001056SBValue::GetFormat ()
Greg Claytone179a582011-01-05 18:43:15 +00001057{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001058 lldb::ValueObjectSP value_sp(GetSP());
1059 if (value_sp)
1060 return value_sp->GetFormat();
Greg Claytone179a582011-01-05 18:43:15 +00001061 return eFormatDefault;
1062}
1063
1064void
1065SBValue::SetFormat (lldb::Format format)
1066{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001067 lldb::ValueObjectSP value_sp(GetSP());
1068 if (value_sp)
1069 value_sp->SetFormat(format);
Greg Claytone179a582011-01-05 18:43:15 +00001070}
1071
Enrico Granata979e20d2011-07-29 19:53:35 +00001072lldb::SBValue
1073SBValue::AddressOf()
1074{
1075 SBValue sb_value;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001076 lldb::ValueObjectSP value_sp(GetSP());
1077 if (value_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +00001078 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001079 Target* target = value_sp->GetUpdatePoint().GetTargetSP().get();
Enrico Granata91544802011-09-06 19:20:51 +00001080 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +00001081 {
Enrico Granata91544802011-09-06 19:20:51 +00001082 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001083 Error error;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001084 sb_value = value_sp->AddressOf (error);
Enrico Granata979e20d2011-07-29 19:53:35 +00001085 }
1086 }
1087 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1088 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001089 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get());
Enrico Granata979e20d2011-07-29 19:53:35 +00001090
1091 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001092}
Enrico Granata91544802011-09-06 19:20:51 +00001093
1094lldb::addr_t
1095SBValue::GetLoadAddress()
1096{
1097 lldb::addr_t value = LLDB_INVALID_ADDRESS;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001098 lldb::ValueObjectSP value_sp(GetSP());
1099 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001100 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001101 Target* target = value_sp->GetUpdatePoint().GetTargetSP().get();
Enrico Granata91544802011-09-06 19:20:51 +00001102 if (target)
1103 {
1104 Mutex::Locker api_locker (target->GetAPIMutex());
1105 const bool scalar_is_load_address = true;
1106 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001107 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001108 if (addr_type == eAddressTypeFile)
1109 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001110 Module* module = value_sp->GetModule();
Enrico Granata91544802011-09-06 19:20:51 +00001111 if (!module)
1112 value = LLDB_INVALID_ADDRESS;
1113 else
1114 {
1115 Address addr;
1116 module->ResolveFileAddress(value, addr);
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001117 value = addr.GetLoadAddress(value_sp->GetUpdatePoint().GetTargetSP().get());
Enrico Granata91544802011-09-06 19:20:51 +00001118 }
1119 }
1120 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1121 value = LLDB_INVALID_ADDRESS;
1122 }
1123 }
1124 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1125 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001126 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value);
Enrico Granata91544802011-09-06 19:20:51 +00001127
1128 return value;
1129}
1130
1131lldb::SBAddress
1132SBValue::GetAddress()
1133{
1134 Address addr;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001135 lldb::ValueObjectSP value_sp(GetSP());
1136 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001137 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001138 Target* target = value_sp->GetUpdatePoint().GetTargetSP().get();
Enrico Granata91544802011-09-06 19:20:51 +00001139 if (target)
1140 {
1141 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1142 Mutex::Locker api_locker (target->GetAPIMutex());
1143 const bool scalar_is_load_address = true;
1144 AddressType addr_type;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001145 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type);
Enrico Granata91544802011-09-06 19:20:51 +00001146 if (addr_type == eAddressTypeFile)
1147 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001148 Module* module = value_sp->GetModule();
Enrico Granata91544802011-09-06 19:20:51 +00001149 if (module)
1150 module->ResolveFileAddress(value, addr);
1151 }
1152 else if (addr_type == eAddressTypeLoad)
1153 {
1154 // no need to check the return value on this.. if it can actually do the resolve
1155 // addr will be in the form (section,offset), otherwise it will simply be returned
1156 // as (NULL, value)
1157 addr.SetLoadAddress(value, target);
1158 }
1159 }
1160 }
1161 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1162 if (log)
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001163 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", value_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
Enrico Granata91544802011-09-06 19:20:51 +00001164 return SBAddress(new Address(addr));
1165}
1166
1167lldb::SBData
1168SBValue::GetPointeeData (uint32_t item_idx,
1169 uint32_t item_count)
1170{
1171 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001172 lldb::ValueObjectSP value_sp(GetSP());
1173 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001174 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001175 Target* target = value_sp->GetUpdatePoint().GetTargetSP().get();
Enrico Granata91544802011-09-06 19:20:51 +00001176 if (target)
1177 {
1178 DataExtractorSP data_sp(new DataExtractor());
1179 Mutex::Locker api_locker (target->GetAPIMutex());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001180 value_sp->GetPointeeData(*data_sp, item_idx, item_count);
Enrico Granata91544802011-09-06 19:20:51 +00001181 if (data_sp->GetByteSize() > 0)
1182 *sb_data = data_sp;
1183 }
1184 }
1185 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1186 if (log)
1187 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001188 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001189 item_idx,
1190 item_count,
1191 sb_data.get());
1192
1193 return sb_data;
1194}
1195
1196lldb::SBData
1197SBValue::GetData ()
1198{
1199 lldb::SBData sb_data;
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001200 lldb::ValueObjectSP value_sp(GetSP());
1201 if (value_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001202 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001203 TargetSP target_sp (value_sp->GetUpdatePoint().GetTargetSP());
1204 if (target_sp)
Enrico Granata91544802011-09-06 19:20:51 +00001205 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001206 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Enrico Granata91544802011-09-06 19:20:51 +00001207 DataExtractorSP data_sp(new DataExtractor());
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001208 value_sp->GetData(*data_sp);
Enrico Granata91544802011-09-06 19:20:51 +00001209 if (data_sp->GetByteSize() > 0)
1210 *sb_data = data_sp;
1211 }
1212 }
1213 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1214 if (log)
1215 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001216 value_sp.get(),
Enrico Granata91544802011-09-06 19:20:51 +00001217 sb_data.get());
1218
1219 return sb_data;
1220}
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001221
1222lldb::SBWatchpoint
1223SBValue::Watch (bool resolve_location, bool read, bool write)
1224{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001225 SBWatchpoint sb_watchpoint;
1226
1227 // If the SBValue is not valid, there's no point in even trying to watch it.
1228 lldb::ValueObjectSP value_sp(GetSP());
1229 TargetSP target_sp (GetTarget().GetSP());
1230 if (value_sp && target_sp)
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001231 {
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001232 // Read and Write cannot both be false.
1233 if (!read && !write)
1234 return sb_watchpoint;
1235
1236 // If the value is not in scope, don't try and watch and invalid value
1237 if (!IsInScope())
1238 return sb_watchpoint;
1239
1240 addr_t addr = GetLoadAddress();
1241 if (addr == LLDB_INVALID_ADDRESS)
1242 return sb_watchpoint;
1243 size_t byte_size = GetByteSize();
1244 if (byte_size == 0)
1245 return sb_watchpoint;
1246
1247 uint32_t watch_type = 0;
1248 if (read)
1249 watch_type |= LLDB_WATCH_TYPE_READ;
1250 if (write)
1251 watch_type |= LLDB_WATCH_TYPE_WRITE;
1252
1253 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type);
1254
1255 if (watchpoint_sp)
1256 {
1257 sb_watchpoint.SetSP (watchpoint_sp);
1258 Declaration decl;
1259 if (value_sp->GetDeclaration (decl))
1260 {
1261 if (decl.GetFile())
1262 {
1263 StreamString ss;
1264 // True to show fullpath for declaration file.
1265 decl.DumpStopContext(&ss, true);
1266 watchpoint_sp->SetDeclInfo(ss.GetString());
1267 }
1268 }
1269 }
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001270 }
1271 return sb_watchpoint;
1272}
1273
1274lldb::SBWatchpoint
1275SBValue::WatchPointee (bool resolve_location, bool read, bool write)
1276{
Greg Clayton0a19a1b2012-02-04 02:27:34 +00001277 SBWatchpoint sb_watchpoint;
1278 if (IsInScope() && GetType().IsPointerType())
1279 sb_watchpoint = Dereference().Watch (resolve_location, read, write);
Greg Clayton1fa6b3d2011-10-13 18:08:26 +00001280 return sb_watchpoint;
1281}
1282