blob: ea7ebf8c13eb349f3ad72d78d35479d5cff22e72 [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
13#include "lldb/Core/DataExtractor.h"
Caroline Tice7826c882010-10-26 03:11:13 +000014#include "lldb/Core/Log.h"
Chris Lattner24943d22010-06-08 16:52:24 +000015#include "lldb/Core/Module.h"
Greg Clayton0fb0bcc2011-08-03 22:57:10 +000016#include "lldb/Core/Scalar.h"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamFile.h"
19#include "lldb/Core/Value.h"
20#include "lldb/Core/ValueObject.h"
Enrico Granata979e20d2011-07-29 19:53:35 +000021#include "lldb/Core/ValueObjectConstResult.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Symbol/Block.h"
23#include "lldb/Symbol/ObjectFile.h"
24#include "lldb/Symbol/Variable.h"
25#include "lldb/Target/ExecutionContext.h"
26#include "lldb/Target/Process.h"
27#include "lldb/Target/StackFrame.h"
Greg Claytonbdcda462010-12-20 20:49:23 +000028#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000029#include "lldb/Target/Thread.h"
30
Eli Friedman7a62c8b2010-06-09 07:44:37 +000031#include "lldb/API/SBProcess.h"
32#include "lldb/API/SBTarget.h"
33#include "lldb/API/SBThread.h"
34#include "lldb/API/SBFrame.h"
35#include "lldb/API/SBDebugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000036
37using namespace lldb;
38using namespace lldb_private;
39
40SBValue::SBValue () :
Greg Clayton63094e02010-06-23 01:19:29 +000041 m_opaque_sp ()
Chris Lattner24943d22010-06-08 16:52:24 +000042{
43}
44
45SBValue::SBValue (const lldb::ValueObjectSP &value_sp) :
Greg Clayton63094e02010-06-23 01:19:29 +000046 m_opaque_sp (value_sp)
Chris Lattner24943d22010-06-08 16:52:24 +000047{
48}
49
Greg Clayton538eb822010-11-05 23:17:00 +000050SBValue::SBValue(const SBValue &rhs) :
51 m_opaque_sp (rhs.m_opaque_sp)
52{
53}
54
55const SBValue &
56SBValue::operator = (const SBValue &rhs)
57{
58 if (this != &rhs)
59 m_opaque_sp = rhs.m_opaque_sp;
60 return *this;
61}
62
Chris Lattner24943d22010-06-08 16:52:24 +000063SBValue::~SBValue()
64{
65}
66
67bool
68SBValue::IsValid () const
69{
Greg Clayton49ce6822010-10-31 03:01:06 +000070 // If this function ever changes to anything that does more than just
71 // check if the opaque shared pointer is non NULL, then we need to update
72 // all "if (m_opaque_sp)" code in this file.
73 return m_opaque_sp.get() != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +000074}
75
Greg Claytonc5f728c2010-10-06 22:10:17 +000076SBError
77SBValue::GetError()
78{
79 SBError sb_error;
80
81 if (m_opaque_sp.get())
82 sb_error.SetError(m_opaque_sp->GetError());
83
84 return sb_error;
85}
86
Johnny Chen968958c2011-07-07 20:46:23 +000087user_id_t
88SBValue::GetID()
89{
90 if (m_opaque_sp)
91 return m_opaque_sp->GetID();
92 return LLDB_INVALID_UID;
93}
94
Chris Lattner24943d22010-06-08 16:52:24 +000095const char *
96SBValue::GetName()
97{
Greg Clayton49ce6822010-10-31 03:01:06 +000098
99 const char *name = NULL;
100 if (m_opaque_sp)
101 name = m_opaque_sp->GetName().GetCString();
102
Greg Claytone005f2c2010-11-06 01:53:30 +0000103 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton3f5ee7f2010-10-29 04:59:35 +0000104 if (log)
Greg Clayton49ce6822010-10-31 03:01:06 +0000105 {
106 if (name)
107 log->Printf ("SBValue(%p)::GetName () => \"%s\"", m_opaque_sp.get(), name);
108 else
109 log->Printf ("SBValue(%p)::GetName () => NULL", m_opaque_sp.get(), name);
110 }
Caroline Tice7826c882010-10-26 03:11:13 +0000111
Greg Clayton49ce6822010-10-31 03:01:06 +0000112 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000113}
114
115const char *
116SBValue::GetTypeName ()
117{
Greg Clayton49ce6822010-10-31 03:01:06 +0000118 const char *name = NULL;
119 if (m_opaque_sp)
120 name = m_opaque_sp->GetTypeName().GetCString();
Greg Claytone005f2c2010-11-06 01:53:30 +0000121 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000122 if (log)
123 {
124 if (name)
125 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", m_opaque_sp.get(), name);
126 else
127 log->Printf ("SBValue(%p)::GetTypeName () => NULL", m_opaque_sp.get());
128 }
129
130 return name;
Chris Lattner24943d22010-06-08 16:52:24 +0000131}
132
133size_t
134SBValue::GetByteSize ()
135{
136 size_t result = 0;
137
Greg Clayton49ce6822010-10-31 03:01:06 +0000138 if (m_opaque_sp)
Greg Clayton63094e02010-06-23 01:19:29 +0000139 result = m_opaque_sp->GetByteSize();
Chris Lattner24943d22010-06-08 16:52:24 +0000140
Greg Claytone005f2c2010-11-06 01:53:30 +0000141 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000142 if (log)
143 log->Printf ("SBValue(%p)::GetByteSize () => %zu", m_opaque_sp.get(), result);
144
Chris Lattner24943d22010-06-08 16:52:24 +0000145 return result;
146}
147
148bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000149SBValue::IsInScope (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000150{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000151 return IsInScope();
152}
153
154bool
155SBValue::IsInScope ()
156{
Chris Lattner24943d22010-06-08 16:52:24 +0000157 bool result = false;
158
Greg Clayton49ce6822010-10-31 03:01:06 +0000159 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000160 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000161 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000162 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000163 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000164 result = m_opaque_sp->IsInScope ();
165 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000166 }
Chris Lattner24943d22010-06-08 16:52:24 +0000167
Greg Claytone005f2c2010-11-06 01:53:30 +0000168 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000169 if (log)
170 log->Printf ("SBValue(%p)::IsInScope () => %i", m_opaque_sp.get(), result);
171
Chris Lattner24943d22010-06-08 16:52:24 +0000172 return result;
173}
174
175const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000176SBValue::GetValue (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000177{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000178 return GetValue();
179}
180
181const char *
182SBValue::GetValue ()
183{
Greg Clayton49ce6822010-10-31 03:01:06 +0000184 const char *cstr = NULL;
Greg Claytonbdcda462010-12-20 20:49:23 +0000185 if (m_opaque_sp)
186 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000187 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000188 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000189 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000190 cstr = m_opaque_sp->GetValueAsCString ();
191 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000192 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000193 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000194 if (log)
195 {
196 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000197 log->Printf ("SBValue(%p)::GetValue => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000198 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000199 log->Printf ("SBValue(%p)::GetValue => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000200 }
201
202 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000203}
204
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000205ValueType
206SBValue::GetValueType ()
207{
Greg Clayton49ce6822010-10-31 03:01:06 +0000208 ValueType result = eValueTypeInvalid;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000209 if (m_opaque_sp)
Greg Clayton49ce6822010-10-31 03:01:06 +0000210 result = m_opaque_sp->GetValueType();
Greg Claytone005f2c2010-11-06 01:53:30 +0000211 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000212 if (log)
213 {
214 switch (result)
215 {
216 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", m_opaque_sp.get()); break;
217 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", m_opaque_sp.get()); break;
218 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", m_opaque_sp.get()); break;
219 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", m_opaque_sp.get()); break;
220 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", m_opaque_sp.get()); break;
221 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", m_opaque_sp.get()); break;
222 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", m_opaque_sp.get()); break;
223 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", m_opaque_sp.get()); break;
224 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", m_opaque_sp.get(), result); break;
225 }
226 }
227 return result;
Greg Claytonf3d0b0c2010-10-27 03:32:59 +0000228}
229
Jim Ingham4ae51962010-09-10 23:12:17 +0000230const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000231SBValue::GetObjectDescription (const SBFrame &sb_frame)
Jim Ingham4ae51962010-09-10 23:12:17 +0000232{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000233 return GetObjectDescription ();
234}
235
236const char *
237SBValue::GetObjectDescription ()
238{
Greg Clayton49ce6822010-10-31 03:01:06 +0000239 const char *cstr = NULL;
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000240 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000241 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000242 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000243 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000244 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000245 cstr = m_opaque_sp->GetObjectDescription ();
246 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000247 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000248 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000249 if (log)
250 {
251 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000252 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000253 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000254 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000255 }
256 return cstr;
Jim Ingham4ae51962010-09-10 23:12:17 +0000257}
258
Chris Lattner24943d22010-06-08 16:52:24 +0000259bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000260SBValue::GetValueDidChange (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000261{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000262 return GetValueDidChange ();
263}
264
Enrico Granata979e20d2011-07-29 19:53:35 +0000265SBType
266SBValue::GetType()
267{
268 SBType result;
269 if (m_opaque_sp)
270 {
271 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
272 {
273 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000274 result = SBType(ClangASTType (m_opaque_sp->GetClangAST(), m_opaque_sp->GetClangType()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000275 }
276 }
277 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
278 if (log)
279 {
280 if (result.IsValid())
281 log->Printf ("SBValue(%p)::GetType => %p", m_opaque_sp.get(), &result);
282 else
283 log->Printf ("SBValue(%p)::GetType => NULL", m_opaque_sp.get());
284 }
285 return result;
286}
287
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000288bool
289SBValue::GetValueDidChange ()
290{
Greg Clayton49ce6822010-10-31 03:01:06 +0000291 bool result = false;
292 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000293 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000294 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000295 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000296 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000297 result = m_opaque_sp->GetValueDidChange ();
298 }
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)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000302 log->Printf ("SBValue(%p)::GetValueDidChange => %i", m_opaque_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 *
Greg Claytonbdcda462010-12-20 20:49:23 +0000308SBValue::GetSummary (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000309{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000310 return GetSummary ();
311}
312
313const char *
314SBValue::GetSummary ()
315{
Greg Clayton49ce6822010-10-31 03:01:06 +0000316 const char *cstr = NULL;
317 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000318 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000319 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000320 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000321 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000322 cstr = m_opaque_sp->GetSummaryAsCString();
323 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000324 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000325 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000326 if (log)
327 {
328 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000329 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000330 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000331 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000332 }
333 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000334}
335
336const char *
Greg Claytonbdcda462010-12-20 20:49:23 +0000337SBValue::GetLocation (const SBFrame &sb_frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000338{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000339 return GetLocation ();
340}
341
342const char *
343SBValue::GetLocation ()
344{
Greg Clayton49ce6822010-10-31 03:01:06 +0000345 const char *cstr = NULL;
346 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000347 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000348 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000349 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000350 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000351 cstr = m_opaque_sp->GetLocationAsCString();
352 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000353 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000354 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000355 if (log)
356 {
357 if (cstr)
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000358 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", m_opaque_sp.get(), cstr);
Greg Clayton49ce6822010-10-31 03:01:06 +0000359 else
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000360 log->Printf ("SBValue(%p)::GetSummary => NULL", m_opaque_sp.get());
Greg Clayton49ce6822010-10-31 03:01:06 +0000361 }
362 return cstr;
Chris Lattner24943d22010-06-08 16:52:24 +0000363}
364
365bool
Greg Claytonbdcda462010-12-20 20:49:23 +0000366SBValue::SetValueFromCString (const SBFrame &sb_frame, const char *value_str)
Chris Lattner24943d22010-06-08 16:52:24 +0000367{
Jim Inghamfa3a16a2011-03-31 00:19:25 +0000368 return SetValueFromCString (value_str);
369}
370
371bool
372SBValue::SetValueFromCString (const char *value_str)
373{
Chris Lattner24943d22010-06-08 16:52:24 +0000374 bool success = false;
Greg Clayton49ce6822010-10-31 03:01:06 +0000375 if (m_opaque_sp)
Greg Claytonbdcda462010-12-20 20:49:23 +0000376 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000377 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000378 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000379 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000380 success = m_opaque_sp->SetValueFromCString (value_str);
381 }
Greg Claytonbdcda462010-12-20 20:49:23 +0000382 }
Chris Lattner24943d22010-06-08 16:52:24 +0000383 return success;
384}
385
Enrico Granata979e20d2011-07-29 19:53:35 +0000386lldb::SBValue
387SBValue::CreateChildAtOffset (const char *name, uint32_t offset, const SBType& type)
388{
389 lldb::SBValue result;
390 if (m_opaque_sp)
391 {
392 if (type.IsValid())
393 {
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000394 result = SBValue(m_opaque_sp->GetSyntheticChildAtOffset(offset, type.m_opaque_sp->GetClangASTType(), true));
Enrico Granata979e20d2011-07-29 19:53:35 +0000395 result.m_opaque_sp->SetName(ConstString(name));
396 }
397 }
398 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
399 if (log)
400 {
401 if (result.IsValid())
402 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
403 else
404 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", m_opaque_sp.get());
405 }
406 return result;
407}
408
409lldb::SBValue
410SBValue::Cast(const SBType& type)
411{
412 return CreateChildAtOffset(m_opaque_sp->GetName().GetCString(), 0, type);
413}
414
415lldb::SBValue
416SBValue::CreateValueFromExpression (const char *name, const char* expression)
417{
418 lldb::SBValue result;
419 if (m_opaque_sp)
420 {
421 ValueObjectSP result_valobj_sp;
422 m_opaque_sp->GetUpdatePoint().GetTargetSP()->EvaluateExpression(expression,
423 m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame(),
424 true, true, eNoDynamicValues,
425 result_valobj_sp);
426 result_valobj_sp->SetName(ConstString(name));
427 result = SBValue(result_valobj_sp);
428 }
429 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
430 if (log)
431 {
432 if (result.IsValid())
433 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
434 else
435 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
436 }
437 return result;
438}
439
440lldb::SBValue
441SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, const SBType& type)
442{
443 lldb::SBValue result;
444 if (m_opaque_sp)
445 {
446
447 SBType real_type(type.GetPointerType());
448
449 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
450
Enrico Granatac9310302011-08-04 17:07:02 +0000451 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope(),
452 real_type.m_opaque_sp->GetASTContext(),
453 real_type.m_opaque_sp->GetOpaqueQualType(),
454 ConstString(name),
455 buffer,
456 lldb::endian::InlHostByteOrder(),
457 GetTarget().GetProcess().GetAddressByteSize()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000458
Enrico Granatac9310302011-08-04 17:07:02 +0000459 ValueObjectSP result_valobj_sp;
460
461 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
462 if (ptr_result_valobj_sp)
463 {
464 Error err;
465 result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
466 if (result_valobj_sp)
467 result_valobj_sp->SetName(ConstString(name));
468 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000469 result = SBValue(result_valobj_sp);
470 }
471 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
472 if (log)
473 {
474 if (result.IsValid())
475 log->Printf ("SBValue(%p)::GetChildFromAddress => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
Johnny Chena713b862011-08-09 22:38:07 +0000476 else
477 log->Printf ("SBValue(%p)::GetChildFromAddress => NULL", m_opaque_sp.get());
478 }
Enrico Granata979e20d2011-07-29 19:53:35 +0000479 return result;
480}
481
Enrico Granata91544802011-09-06 19:20:51 +0000482lldb::SBValue
483SBValue::CreateValueFromData (const char* name,
484 const SBData& data,
485 const SBType& type)
486{
487 SBValue result;
488
489 AddressType addr_of_children_priv = eAddressTypeLoad;
490
491 if (m_opaque_sp)
492 {
493 ValueObjectSP valobj_sp;
494 valobj_sp = ValueObjectConstResult::Create (m_opaque_sp->GetExecutionContextScope(),
495 type.m_opaque_sp->GetASTContext() ,
496 type.m_opaque_sp->GetOpaqueQualType(),
497 ConstString(name),
498 *data.m_opaque_sp,
499 LLDB_INVALID_ADDRESS);
500 valobj_sp->SetAddressTypeOfChildren(addr_of_children_priv);
501 result = SBValue(valobj_sp);
502 }
503 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
504 if (log)
505 {
506 if (result.IsValid())
507 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", m_opaque_sp.get(), result.m_opaque_sp.get());
508 else
509 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", m_opaque_sp.get());
510 }
511 return result;
512}
513
Chris Lattner24943d22010-06-08 16:52:24 +0000514SBValue
515SBValue::GetChildAtIndex (uint32_t idx)
516{
Greg Clayton8f64c472011-07-15 19:31:49 +0000517 const bool can_create_synthetic = false;
518 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
Johnny Chen446ccaa2011-06-29 21:19:39 +0000519 if (m_opaque_sp)
Enrico Granata979e20d2011-07-29 19:53:35 +0000520 use_dynamic = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Greg Clayton8f64c472011-07-15 19:31:49 +0000521 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic);
Jim Inghame41494a2011-04-16 00:01:13 +0000522}
523
524SBValue
Greg Clayton8f64c472011-07-15 19:31:49 +0000525SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic)
Jim Inghame41494a2011-04-16 00:01:13 +0000526{
Chris Lattner24943d22010-06-08 16:52:24 +0000527 lldb::ValueObjectSP child_sp;
528
Greg Clayton49ce6822010-10-31 03:01:06 +0000529 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000530 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000531 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000532 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000533 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Clayton8f64c472011-07-15 19:31:49 +0000534 const bool can_create = true;
535 child_sp = m_opaque_sp->GetChildAtIndex (idx, can_create);
536 if (can_create_synthetic && !child_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000537 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000538 if (m_opaque_sp->IsPointerType())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000539 {
Greg Clayton8f64c472011-07-15 19:31:49 +0000540 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromPointer(idx, can_create);
541 }
542 else if (m_opaque_sp->IsArrayType())
543 {
544 child_sp = m_opaque_sp->GetSyntheticArrayMemberFromArray(idx, can_create);
545 }
546 }
547
548 if (child_sp)
549 {
550 if (use_dynamic != lldb::eNoDynamicValues)
551 {
552 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic));
Greg Claytonb9dcc512011-06-29 18:28:50 +0000553 if (dynamic_sp)
554 child_sp = dynamic_sp;
555 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000556 }
Jim Inghame41494a2011-04-16 00:01:13 +0000557 }
558 }
559
Chris Lattner24943d22010-06-08 16:52:24 +0000560 SBValue sb_value (child_sp);
Greg Claytone005f2c2010-11-06 01:53:30 +0000561 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000562 if (log)
563 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", m_opaque_sp.get(), idx, sb_value.get());
564
Chris Lattner24943d22010-06-08 16:52:24 +0000565 return sb_value;
566}
567
568uint32_t
569SBValue::GetIndexOfChildWithName (const char *name)
570{
Greg Clayton49ce6822010-10-31 03:01:06 +0000571 uint32_t idx = UINT32_MAX;
572 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000573 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000574 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000575 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000576 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000577
Greg Claytonb9dcc512011-06-29 18:28:50 +0000578 idx = m_opaque_sp->GetIndexOfChildWithName (ConstString(name));
579 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000580 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000581 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000582 if (log)
583 {
584 if (idx == UINT32_MAX)
585 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", m_opaque_sp.get(), name, idx);
586 else
587 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", m_opaque_sp.get(), name, idx);
588 }
589 return idx;
Chris Lattner24943d22010-06-08 16:52:24 +0000590}
591
592SBValue
593SBValue::GetChildMemberWithName (const char *name)
594{
Johnny Chen446ccaa2011-06-29 21:19:39 +0000595 if (m_opaque_sp)
596 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000597 lldb::DynamicValueType use_dynamic_value = m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetPreferDynamicValue();
Johnny Chen446ccaa2011-06-29 21:19:39 +0000598 return GetChildMemberWithName (name, use_dynamic_value);
599 }
600 else
601 return GetChildMemberWithName (name, eNoDynamicValues);
Jim Inghame41494a2011-04-16 00:01:13 +0000602}
603
604SBValue
Jim Ingham10de7d12011-05-04 03:43:18 +0000605SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value)
Jim Inghame41494a2011-04-16 00:01:13 +0000606{
Chris Lattner24943d22010-06-08 16:52:24 +0000607 lldb::ValueObjectSP child_sp;
608 const ConstString str_name (name);
609
Greg Clayton905acaf2011-05-20 22:07:17 +0000610
Greg Clayton49ce6822010-10-31 03:01:06 +0000611 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000612 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000613 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Jim Inghame41494a2011-04-16 00:01:13 +0000614 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000615 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonb9dcc512011-06-29 18:28:50 +0000616 child_sp = m_opaque_sp->GetChildMemberWithName (str_name, true);
617 if (use_dynamic_value != lldb::eNoDynamicValues)
Greg Claytonfab305b2011-05-20 23:51:26 +0000618 {
Greg Claytonb9dcc512011-06-29 18:28:50 +0000619 if (child_sp)
620 {
621 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value);
622 if (dynamic_sp)
623 child_sp = dynamic_sp;
624 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000625 }
Jim Inghame41494a2011-04-16 00:01:13 +0000626 }
627 }
628
Chris Lattner24943d22010-06-08 16:52:24 +0000629 SBValue sb_value (child_sp);
Greg Clayton49ce6822010-10-31 03:01:06 +0000630
Greg Claytone005f2c2010-11-06 01:53:30 +0000631 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000632 if (log)
633 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", m_opaque_sp.get(), name, sb_value.get());
634
Chris Lattner24943d22010-06-08 16:52:24 +0000635 return sb_value;
636}
637
Enrico Granataf7a9b142011-07-15 02:26:42 +0000638lldb::SBValue
639SBValue::GetValueForExpressionPath(const char* expr_path)
640{
641 lldb::ValueObjectSP child_sp;
642 if (m_opaque_sp)
643 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000644 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Enrico Granataf7a9b142011-07-15 02:26:42 +0000645 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000646 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Enrico Granataf7a9b142011-07-15 02:26:42 +0000647 // using default values for all the fancy options, just do it if you can
648 child_sp = m_opaque_sp->GetValueForExpressionPath(expr_path);
649 }
650 }
651
652 SBValue sb_value (child_sp);
653
654 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
655 if (log)
656 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", m_opaque_sp.get(), expr_path, sb_value.get());
657
658 return sb_value;
659}
Chris Lattner24943d22010-06-08 16:52:24 +0000660
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000661int64_t
Enrico Granatac92eb402011-08-04 01:41:02 +0000662SBValue::GetValueAsSigned(SBError& error, int64_t fail_value)
663{
Jim Ingham574c3d62011-08-12 23:34:31 +0000664 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000665 if (m_opaque_sp)
666 {
667 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
668 {
669 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
670 Scalar scalar;
671 if (m_opaque_sp->ResolveValue (scalar))
672 return scalar.GetRawBits64(fail_value);
673 else
674 error.SetErrorString("could not get value");
675 }
676 else
677 error.SetErrorString("could not get target");
678 }
679 error.SetErrorString("invalid SBValue");
680 return fail_value;
681}
682
683uint64_t
684SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value)
685{
Jim Ingham574c3d62011-08-12 23:34:31 +0000686 error.Clear();
Enrico Granatac92eb402011-08-04 01:41:02 +0000687 if (m_opaque_sp)
688 {
689 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
690 {
691 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
692 Scalar scalar;
693 if (m_opaque_sp->ResolveValue (scalar))
694 return scalar.GetRawBits64(fail_value);
695 else
696 error.SetErrorString("could not get value");
697 }
698 else
699 error.SetErrorString("could not get target");
700 }
701 error.SetErrorString("invalid SBValue");
702 return fail_value;
703}
704
705int64_t
Greg Clayton0fb0bcc2011-08-03 22:57:10 +0000706SBValue::GetValueAsSigned(int64_t fail_value)
707{
708 if (m_opaque_sp)
709 {
710 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
711 {
712 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
713 Scalar scalar;
714 if (m_opaque_sp->ResolveValue (scalar))
715 return scalar.GetRawBits64(fail_value);
716 }
717 }
718 return fail_value;
719}
720
721uint64_t
722SBValue::GetValueAsUnsigned(uint64_t fail_value)
723{
724 if (m_opaque_sp)
725 {
726 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
727 {
728 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
729 Scalar scalar;
730 if (m_opaque_sp->ResolveValue (scalar))
731 return scalar.GetRawBits64(fail_value);
732 }
733 }
734 return fail_value;
735}
736
Chris Lattner24943d22010-06-08 16:52:24 +0000737uint32_t
738SBValue::GetNumChildren ()
739{
740 uint32_t num_children = 0;
741
Greg Clayton49ce6822010-10-31 03:01:06 +0000742 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000743 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000744 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000745 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000746 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000747
Greg Claytonb9dcc512011-06-29 18:28:50 +0000748 num_children = m_opaque_sp->GetNumChildren();
749 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000750 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000751
Greg Claytone005f2c2010-11-06 01:53:30 +0000752 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000753 if (log)
754 log->Printf ("SBValue(%p)::GetNumChildren () => %u", m_opaque_sp.get(), num_children);
Chris Lattner24943d22010-06-08 16:52:24 +0000755
756 return num_children;
757}
758
Chris Lattner24943d22010-06-08 16:52:24 +0000759
760SBValue
761SBValue::Dereference ()
762{
Greg Clayton49ce6822010-10-31 03:01:06 +0000763 SBValue sb_value;
764 if (m_opaque_sp)
Chris Lattner24943d22010-06-08 16:52:24 +0000765 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000766 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000767 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000768 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000769
Greg Claytonb9dcc512011-06-29 18:28:50 +0000770 Error error;
771 sb_value = m_opaque_sp->Dereference (error);
772 }
Chris Lattner24943d22010-06-08 16:52:24 +0000773 }
Greg Claytone005f2c2010-11-06 01:53:30 +0000774 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000775 if (log)
776 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
777
778 return sb_value;
Chris Lattner24943d22010-06-08 16:52:24 +0000779}
780
781bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000782SBValue::TypeIsPointerType ()
Chris Lattner24943d22010-06-08 16:52:24 +0000783{
784 bool is_ptr_type = false;
785
Greg Clayton49ce6822010-10-31 03:01:06 +0000786 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000787 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000788 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000789 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000790 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000791
Greg Claytonb9dcc512011-06-29 18:28:50 +0000792 is_ptr_type = m_opaque_sp->IsPointerType();
793 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000794 }
Greg Clayton49ce6822010-10-31 03:01:06 +0000795
Greg Claytone005f2c2010-11-06 01:53:30 +0000796 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton49ce6822010-10-31 03:01:06 +0000797 if (log)
798 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", m_opaque_sp.get(), is_ptr_type);
799
Chris Lattner24943d22010-06-08 16:52:24 +0000800
801 return is_ptr_type;
802}
803
Chris Lattner24943d22010-06-08 16:52:24 +0000804void *
805SBValue::GetOpaqueType()
806{
Greg Clayton63094e02010-06-23 01:19:29 +0000807 if (m_opaque_sp)
Greg Claytonfab305b2011-05-20 23:51:26 +0000808 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000809 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
Greg Claytonb9dcc512011-06-29 18:28:50 +0000810 {
Enrico Granata979e20d2011-07-29 19:53:35 +0000811 Mutex::Locker api_locker (m_opaque_sp->GetUpdatePoint().GetTargetSP()->GetAPIMutex());
Greg Claytonfab305b2011-05-20 23:51:26 +0000812
Greg Claytonb9dcc512011-06-29 18:28:50 +0000813 return m_opaque_sp->GetClangType();
814 }
Greg Claytonfab305b2011-05-20 23:51:26 +0000815 }
Chris Lattner24943d22010-06-08 16:52:24 +0000816 return NULL;
817}
818
Enrico Granata979e20d2011-07-29 19:53:35 +0000819lldb::SBTarget
820SBValue::GetTarget()
821{
822 SBTarget result;
823 if (m_opaque_sp)
824 {
825 if (m_opaque_sp->GetUpdatePoint().GetTargetSP())
826 {
827 result = SBTarget(lldb::TargetSP(m_opaque_sp->GetUpdatePoint().GetTargetSP()));
828 }
829 }
830 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
831 if (log)
832 {
833 if (result.get() == NULL)
834 log->Printf ("SBValue(%p)::GetTarget () => NULL", m_opaque_sp.get());
835 else
836 log->Printf ("SBValue(%p)::GetTarget () => %p", m_opaque_sp.get(), result.get());
837 }
838 return result;
839}
840
841lldb::SBProcess
842SBValue::GetProcess()
843{
844 SBProcess result;
845 if (m_opaque_sp)
846 {
Enrico Granata91544802011-09-06 19:20:51 +0000847 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
848 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +0000849 {
Enrico Granata91544802011-09-06 19:20:51 +0000850 result = SBProcess(lldb::ProcessSP(target->GetProcessSP()));
Enrico Granata979e20d2011-07-29 19:53:35 +0000851 }
852 }
853 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
854 if (log)
855 {
856 if (result.get() == NULL)
857 log->Printf ("SBValue(%p)::GetProcess () => NULL", m_opaque_sp.get());
858 else
859 log->Printf ("SBValue(%p)::GetProcess () => %p", m_opaque_sp.get(), result.get());
860 }
861 return result;
862}
863
864lldb::SBThread
865SBValue::GetThread()
866{
867 SBThread result;
868 if (m_opaque_sp)
869 {
870 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
871 {
872 result = SBThread(lldb::ThreadSP(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateThread()));
873 }
874 }
875 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
876 if (log)
877 {
878 if (result.get() == NULL)
879 log->Printf ("SBValue(%p)::GetThread () => NULL", m_opaque_sp.get());
880 else
881 log->Printf ("SBValue(%p)::GetThread () => %p", m_opaque_sp.get(), result.get());
882 }
883 return result;
884}
885
886lldb::SBFrame
887SBValue::GetFrame()
888{
889 SBFrame result;
890 if (m_opaque_sp)
891 {
892 if (m_opaque_sp->GetUpdatePoint().GetExecutionContextScope())
893 {
894 result = SBFrame(lldb::StackFrameSP(m_opaque_sp->GetUpdatePoint().GetExecutionContextScope()->CalculateStackFrame()));
895 }
896 }
897 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
898 if (log)
899 {
900 if (result.get() == NULL)
901 log->Printf ("SBValue(%p)::GetFrame () => NULL", m_opaque_sp.get());
902 else
903 log->Printf ("SBValue(%p)::GetFrame () => %p", m_opaque_sp.get(), result.get());
904 }
905 return result;
906}
907
908
Chris Lattner24943d22010-06-08 16:52:24 +0000909// Mimic shared pointer...
910lldb_private::ValueObject *
911SBValue::get() const
912{
Greg Clayton63094e02010-06-23 01:19:29 +0000913 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000914}
915
916lldb_private::ValueObject *
917SBValue::operator->() const
918{
Greg Clayton63094e02010-06-23 01:19:29 +0000919 return m_opaque_sp.get();
Chris Lattner24943d22010-06-08 16:52:24 +0000920}
921
922lldb::ValueObjectSP &
923SBValue::operator*()
924{
Greg Clayton63094e02010-06-23 01:19:29 +0000925 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000926}
927
928const lldb::ValueObjectSP &
929SBValue::operator*() const
930{
Greg Clayton63094e02010-06-23 01:19:29 +0000931 return m_opaque_sp;
Chris Lattner24943d22010-06-08 16:52:24 +0000932}
Caroline Tice98f930f2010-09-20 05:20:02 +0000933
934bool
Greg Clayton49ce6822010-10-31 03:01:06 +0000935SBValue::GetExpressionPath (SBStream &description)
936{
937 if (m_opaque_sp)
938 {
Greg Claytonb01000f2011-01-17 03:46:26 +0000939 m_opaque_sp->GetExpressionPath (description.ref(), false);
940 return true;
941 }
942 return false;
943}
944
945bool
946SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes)
947{
948 if (m_opaque_sp)
949 {
950 m_opaque_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes);
Greg Clayton49ce6822010-10-31 03:01:06 +0000951 return true;
952 }
953 return false;
954}
955
956bool
Caroline Tice98f930f2010-09-20 05:20:02 +0000957SBValue::GetDescription (SBStream &description)
958{
959 if (m_opaque_sp)
960 {
Enrico Granata19030d82011-08-15 18:01:31 +0000961 /*uint32_t ptr_depth = 0;
Greg Claytonbafc86e2011-07-06 16:49:27 +0000962 uint32_t curr_depth = 0;
963 uint32_t max_depth = UINT32_MAX;
964 bool show_types = false;
965 bool show_location = false;
966 bool use_objc = false;
967 lldb::DynamicValueType use_dynamic = eNoDynamicValues;
968 bool scope_already_checked = false;
969 bool flat_output = false;
Enrico Granatae4e3e2c2011-07-22 00:16:08 +0000970 bool use_synthetic = true;
971 uint32_t no_summary_depth = 0;
Enrico Granata19030d82011-08-15 18:01:31 +0000972 bool ignore_cap = false;*/
Greg Claytonbafc86e2011-07-06 16:49:27 +0000973 ValueObject::DumpValueObject (description.ref(),
Enrico Granata19030d82011-08-15 18:01:31 +0000974 m_opaque_sp.get());
Caroline Tice98f930f2010-09-20 05:20:02 +0000975 }
976 else
977 description.Printf ("No value");
978
979 return true;
980}
Greg Claytone179a582011-01-05 18:43:15 +0000981
982lldb::Format
983SBValue::GetFormat () const
984{
985 if (m_opaque_sp)
986 return m_opaque_sp->GetFormat();
987 return eFormatDefault;
988}
989
990void
991SBValue::SetFormat (lldb::Format format)
992{
993 if (m_opaque_sp)
994 m_opaque_sp->SetFormat(format);
995}
996
Enrico Granata979e20d2011-07-29 19:53:35 +0000997lldb::SBValue
998SBValue::AddressOf()
999{
1000 SBValue sb_value;
1001 if (m_opaque_sp)
1002 {
Enrico Granata91544802011-09-06 19:20:51 +00001003 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1004 if (target)
Enrico Granata979e20d2011-07-29 19:53:35 +00001005 {
Enrico Granata91544802011-09-06 19:20:51 +00001006 Mutex::Locker api_locker (target->GetAPIMutex());
Enrico Granata979e20d2011-07-29 19:53:35 +00001007 Error error;
1008 sb_value = m_opaque_sp->AddressOf (error);
1009 }
1010 }
1011 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1012 if (log)
1013 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", m_opaque_sp.get(), sb_value.get());
1014
1015 return sb_value;
Johnny Chena713b862011-08-09 22:38:07 +00001016}
Enrico Granata91544802011-09-06 19:20:51 +00001017
1018lldb::addr_t
1019SBValue::GetLoadAddress()
1020{
1021 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1022 if (m_opaque_sp)
1023 {
1024 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1025 if (target)
1026 {
1027 Mutex::Locker api_locker (target->GetAPIMutex());
1028 const bool scalar_is_load_address = true;
1029 AddressType addr_type;
1030 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1031 if (addr_type == eAddressTypeFile)
1032 {
1033 Module* module = m_opaque_sp->GetModule();
1034 if (!module)
1035 value = LLDB_INVALID_ADDRESS;
1036 else
1037 {
1038 Address addr;
1039 module->ResolveFileAddress(value, addr);
1040 value = addr.GetLoadAddress(m_opaque_sp->GetUpdatePoint().GetTargetSP().get());
1041 }
1042 }
1043 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid)
1044 value = LLDB_INVALID_ADDRESS;
1045 }
1046 }
1047 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1048 if (log)
1049 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", m_opaque_sp.get(), value);
1050
1051 return value;
1052}
1053
1054lldb::SBAddress
1055SBValue::GetAddress()
1056{
1057 Address addr;
1058 if (m_opaque_sp)
1059 {
1060 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1061 if (target)
1062 {
1063 lldb::addr_t value = LLDB_INVALID_ADDRESS;
1064 Mutex::Locker api_locker (target->GetAPIMutex());
1065 const bool scalar_is_load_address = true;
1066 AddressType addr_type;
1067 value = m_opaque_sp->GetAddressOf(scalar_is_load_address, &addr_type);
1068 if (addr_type == eAddressTypeFile)
1069 {
1070 Module* module = m_opaque_sp->GetModule();
1071 if (module)
1072 module->ResolveFileAddress(value, addr);
1073 }
1074 else if (addr_type == eAddressTypeLoad)
1075 {
1076 // no need to check the return value on this.. if it can actually do the resolve
1077 // addr will be in the form (section,offset), otherwise it will simply be returned
1078 // as (NULL, value)
1079 addr.SetLoadAddress(value, target);
1080 }
1081 }
1082 }
1083 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1084 if (log)
1085 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", m_opaque_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset());
1086 return SBAddress(new Address(addr));
1087}
1088
1089lldb::SBData
1090SBValue::GetPointeeData (uint32_t item_idx,
1091 uint32_t item_count)
1092{
1093 lldb::SBData sb_data;
1094 if (m_opaque_sp)
1095 {
1096 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1097 if (target)
1098 {
1099 DataExtractorSP data_sp(new DataExtractor());
1100 Mutex::Locker api_locker (target->GetAPIMutex());
1101 m_opaque_sp->GetPointeeData(*data_sp, item_idx, item_count);
1102 if (data_sp->GetByteSize() > 0)
1103 *sb_data = data_sp;
1104 }
1105 }
1106 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1107 if (log)
1108 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)",
1109 m_opaque_sp.get(),
1110 item_idx,
1111 item_count,
1112 sb_data.get());
1113
1114 return sb_data;
1115}
1116
1117lldb::SBData
1118SBValue::GetData ()
1119{
1120 lldb::SBData sb_data;
1121 if (m_opaque_sp)
1122 {
1123 Target* target = m_opaque_sp->GetUpdatePoint().GetTargetSP().get();
1124 if (target)
1125 {
1126 DataExtractorSP data_sp(new DataExtractor());
1127 Mutex::Locker api_locker (target->GetAPIMutex());
1128 m_opaque_sp->GetData(*data_sp);
1129 if (data_sp->GetByteSize() > 0)
1130 *sb_data = data_sp;
1131 }
1132 }
1133 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1134 if (log)
1135 log->Printf ("SBValue(%p)::GetData () => SBData(%p)",
1136 m_opaque_sp.get(),
1137 sb_data.get());
1138
1139 return sb_data;
1140}