blob: a30cc1306c6b6ba52d58d4ea76f5e24a2ccb5e8a [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- ValueObject.cpp -----------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/ValueObject.h"
13
14// C Includes
Greg Claytonf5e56de2010-09-14 23:36:40 +000015#include <stdlib.h>
16
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017// C++ Includes
18// Other libraries and framework includes
Chris Lattner30fdc8d2010-06-08 16:52:24 +000019#include "llvm/Support/raw_ostream.h"
Jim Ingham5a369122010-09-28 01:25:32 +000020#include "clang/AST/Type.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22// Project includes
23#include "lldb/Core/DataBufferHeap.h"
Enrico Granata4becb372011-06-29 22:27:15 +000024#include "lldb/Core/Debugger.h"
Enrico Granata6f3533f2011-07-29 19:53:35 +000025#include "lldb/Core/Log.h"
Greg Clayton1f746072012-08-29 21:13:06 +000026#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000027#include "lldb/Core/StreamString.h"
Enrico Granata21fd13f2012-10-27 02:05:48 +000028#include "lldb/Core/ValueObjectCast.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000029#include "lldb/Core/ValueObjectChild.h"
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000030#include "lldb/Core/ValueObjectConstResult.h"
Jim Ingham78a685a2011-04-16 00:01:13 +000031#include "lldb/Core/ValueObjectDynamicValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000032#include "lldb/Core/ValueObjectList.h"
Greg Claytonb2dcc362011-05-05 23:32:56 +000033#include "lldb/Core/ValueObjectMemory.h"
Enrico Granatad55546b2011-07-22 00:16:08 +000034#include "lldb/Core/ValueObjectSyntheticFilter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000035
Enrico Granata5548cb52013-01-28 23:47:25 +000036#include "lldb/DataFormatters/DataVisualization.h"
37
Greg Clayton7fb56d02011-02-01 01:31:41 +000038#include "lldb/Host/Endian.h"
39
Enrico Granata61a80ba2011-08-12 16:42:31 +000040#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000041#include "lldb/Interpreter/ScriptInterpreterPython.h"
42
Greg Claytone1a916a2010-07-21 22:12:05 +000043#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000044#include "lldb/Symbol/ClangASTContext.h"
45#include "lldb/Symbol/Type.h"
46
Jim Ingham53c47f12010-09-10 23:12:17 +000047#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000048#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000049#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050#include "lldb/Target/Process.h"
51#include "lldb/Target/RegisterContext.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000052#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55using namespace lldb;
56using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000057using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058
Greg Claytonafacd142011-09-02 01:15:17 +000059static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060
61//----------------------------------------------------------------------
62// ValueObject constructor
63//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000064ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000066 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000067 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000068 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000069 m_name (),
70 m_data (),
71 m_value (),
72 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000073 m_value_str (),
74 m_old_value_str (),
75 m_location_str (),
76 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000077 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +000078 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000079 m_children (),
80 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000081 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000082 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000083 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000084 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000085 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000086 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000087 m_type_summary_sp(),
88 m_type_format_sp(),
89 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000090 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000091 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +000092 m_value_is_valid (false),
93 m_value_did_change (false),
94 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +000095 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +000096 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +000097 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +000098 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +000099 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000100 m_is_getting_summary(false),
101 m_did_calculate_complete_objc_class_type(false)
Jim Ingham6035b672011-03-31 00:19:25 +0000102{
Jim Ingham58b59f92011-04-22 23:53:53 +0000103 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000104}
105
106//----------------------------------------------------------------------
107// ValueObject constructor
108//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000109ValueObject::ValueObject (ExecutionContextScope *exe_scope,
110 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000111 UserID (++g_value_obj_uid), // Unique identifier for every value object
112 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000113 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000114 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000115 m_name (),
116 m_data (),
117 m_value (),
118 m_error (),
119 m_value_str (),
120 m_old_value_str (),
121 m_location_str (),
122 m_summary_str (),
123 m_object_desc_str (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000124 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000125 m_children (),
126 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000127 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000128 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000129 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000130 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000131 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000132 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000133 m_type_summary_sp(),
134 m_type_format_sp(),
135 m_synthetic_children_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000136 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000137 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000138 m_value_is_valid (false),
139 m_value_did_change (false),
140 m_children_count_valid (false),
141 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000142 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000143 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000144 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000145 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000146 m_is_getting_summary(false),
147 m_did_calculate_complete_objc_class_type(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000148{
Jim Ingham58b59f92011-04-22 23:53:53 +0000149 m_manager = new ValueObjectManager();
150 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000151}
152
153//----------------------------------------------------------------------
154// Destructor
155//----------------------------------------------------------------------
156ValueObject::~ValueObject ()
157{
158}
159
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000160bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000161ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000162{
Enrico Granata4becb372011-06-29 22:27:15 +0000163
Enrico Granata9128ee22011-09-06 19:20:51 +0000164 bool did_change_formats = false;
165
Enrico Granata0a3958e2011-07-02 00:25:22 +0000166 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000167 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000168
Greg Claytonb71f3842010-10-05 03:13:51 +0000169 // If this is a constant value, then our success is predicated on whether
170 // we have an error or not
171 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000172 {
173 // if you were asked to update your formatters, but did not get a chance to do it
174 // clear your own values (this serves the purpose of faking a stop-id for frozen
175 // objects (which are regarded as constant, but could have changes behind their backs
176 // because of the frozen-pointer depth limit)
177 // TODO: decouple summary from value and then remove this code and only force-clear the summary
178 if (update_format && !did_change_formats)
Enrico Granata86cc9822012-03-19 22:58:49 +0000179 ClearUserVisibleData(eClearUserVisibleDataItemsSummary);
Greg Claytonb71f3842010-10-05 03:13:51 +0000180 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000181 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000182
Jim Ingham6035b672011-03-31 00:19:25 +0000183 bool first_update = m_update_point.IsFirstEvaluation();
184
185 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000186 {
Jim Ingham6035b672011-03-31 00:19:25 +0000187 m_update_point.SetUpdated();
188
189 // Save the old value using swap to avoid a string copy which
190 // also will clear our m_value_str
191 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000192 {
Jim Ingham6035b672011-03-31 00:19:25 +0000193 m_old_value_valid = false;
194 }
195 else
196 {
197 m_old_value_valid = true;
198 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000199 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000200 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000201
Enrico Granataf2bbf712011-07-15 02:26:42 +0000202 ClearUserVisibleData();
203
Greg Claytonefbc7d22012-03-09 04:23:44 +0000204 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000205 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000206 const bool value_was_valid = GetValueIsValid();
207 SetValueDidChange (false);
208
209 m_error.Clear();
210
211 // Call the pure virtual function to update the value
212 bool success = UpdateValue ();
213
214 SetValueIsValid (success);
215
216 if (first_update)
217 SetValueDidChange (false);
218 else if (!m_value_did_change && success == false)
219 {
220 // The value wasn't gotten successfully, so we mark this
221 // as changed if the value used to be valid and now isn't
222 SetValueDidChange (value_was_valid);
223 }
224 }
225 else
226 {
227 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000228 }
229 }
230 return m_error.Success();
231}
232
Enrico Granata9128ee22011-09-06 19:20:51 +0000233bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000234ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000235{
Greg Clayton5160ce52013-03-27 23:08:40 +0000236 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000237 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000238 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Enrico Granata6f3533f2011-07-29 19:53:35 +0000239 GetName().GetCString(),
Enrico Granatad2284832012-10-17 22:23:56 +0000240 this,
Enrico Granata4becb372011-06-29 22:27:15 +0000241 m_last_format_mgr_revision,
Enrico Granata85933ed2011-08-18 16:38:26 +0000242 DataVisualization::GetCurrentRevision());
Enrico Granata9128ee22011-09-06 19:20:51 +0000243
244 bool any_change = false;
245
Enrico Granata5548cb52013-01-28 23:47:25 +0000246 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000247 {
Enrico Granata78d06382011-09-09 23:33:14 +0000248 SetValueFormat(DataVisualization::ValueFormats::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000249 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000250#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000251 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000252#endif
Enrico Granata1490c6f2011-07-19 02:34:21 +0000253
Enrico Granata85933ed2011-08-18 16:38:26 +0000254 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
Enrico Granata855cd902011-09-06 22:59:55 +0000255
256 any_change = true;
Enrico Granata4becb372011-06-29 22:27:15 +0000257 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000258
259 return any_change;
260
Enrico Granata4becb372011-06-29 22:27:15 +0000261}
262
Jim Ingham16e0c682011-08-12 23:34:31 +0000263void
264ValueObject::SetNeedsUpdate ()
265{
266 m_update_point.SetNeedsUpdate();
267 // We have to clear the value string here so ConstResult children will notice if their values are
268 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000269 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000270}
271
Enrico Granata13ac0e22012-10-17 19:03:34 +0000272void
Enrico Granatae3e91512012-10-22 18:18:36 +0000273ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000274{
275 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000276 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000277 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000278 SetValueFormat(lldb::TypeFormatImplSP());
279 SetSummaryFormat(lldb::TypeSummaryImplSP());
280 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000281}
282
Sean Callanan72772842012-02-22 23:57:45 +0000283ClangASTType
284ValueObject::MaybeCalculateCompleteType ()
285{
Greg Clayton57ee3062013-07-11 22:46:58 +0000286 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000287
Sean Callanan72772842012-02-22 23:57:45 +0000288 if (m_did_calculate_complete_objc_class_type)
289 {
290 if (m_override_type.IsValid())
291 return m_override_type;
292 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000293 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000294 }
295
Greg Clayton57ee3062013-07-11 22:46:58 +0000296 ClangASTType class_type;
297 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000298
Greg Clayton57ee3062013-07-11 22:46:58 +0000299 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000300 {
301 is_pointer_type = true;
302 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000303 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000304 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000305 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000306 }
307 else
308 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000309 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000310 }
311
312 m_did_calculate_complete_objc_class_type = true;
313
Greg Clayton57ee3062013-07-11 22:46:58 +0000314 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000315 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000316 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000317
Greg Clayton57ee3062013-07-11 22:46:58 +0000318 if (class_name)
319 {
320 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
321
322 if (process_sp)
323 {
324 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
325
326 if (objc_language_runtime)
327 {
328 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
329
330 if (complete_objc_class_type_sp)
331 {
332 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
333
334 if (complete_class.GetCompleteType())
335 {
336 if (is_pointer_type)
337 {
338 m_override_type = complete_class.GetPointerType();
339 }
340 else
341 {
342 m_override_type = complete_class;
343 }
344
345 if (m_override_type.IsValid())
346 return m_override_type;
347 }
348 }
349 }
350 }
351 }
Sean Callanan72772842012-02-22 23:57:45 +0000352 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000353 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000354}
355
Greg Clayton57ee3062013-07-11 22:46:58 +0000356ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000357ValueObject::GetClangType ()
358{
Greg Clayton57ee3062013-07-11 22:46:58 +0000359 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000360}
361
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362DataExtractor &
363ValueObject::GetDataExtractor ()
364{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000365 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000366 return m_data;
367}
368
369const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000370ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000371{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000372 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000373 return m_error;
374}
375
376const ConstString &
377ValueObject::GetName() const
378{
379 return m_name;
380}
381
382const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000383ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000384{
Enrico Granata82fabf82013-04-30 20:45:04 +0000385 return GetLocationAsCStringImpl(m_value,
386 m_data);
387}
388
389const char *
390ValueObject::GetLocationAsCStringImpl (const Value& value,
391 const DataExtractor& data)
392{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000393 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000394 {
395 if (m_location_str.empty())
396 {
397 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000398
399 Value::ValueType value_type = value.GetValueType();
400
401 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000402 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000404 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000405 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000406 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000407 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000408 if (reg_info)
409 {
410 if (reg_info->name)
411 m_location_str = reg_info->name;
412 else if (reg_info->alt_name)
413 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000414 if (m_location_str.empty())
415 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000416 }
417 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000418 if (m_location_str.empty())
419 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 break;
421
422 case Value::eValueTypeLoadAddress:
423 case Value::eValueTypeFileAddress:
424 case Value::eValueTypeHostAddress:
425 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000426 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
427 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000428 m_location_str.swap(sstr.GetString());
429 }
430 break;
431 }
432 }
433 }
434 return m_location_str.c_str();
435}
436
437Value &
438ValueObject::GetValue()
439{
440 return m_value;
441}
442
443const Value &
444ValueObject::GetValue() const
445{
446 return m_value;
447}
448
449bool
Jim Ingham6035b672011-03-31 00:19:25 +0000450ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000451{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000452 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
453 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000454 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000455 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000456 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000457 if (scalar.IsValid())
458 {
459 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
460 if (bitfield_bit_size)
461 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
462 return true;
463 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000464 }
Greg Claytondcad5022011-12-29 01:26:56 +0000465 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000466}
467
468bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000469ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000470{
Greg Clayton288bdf92010-09-02 02:59:18 +0000471 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472}
473
474
475void
476ValueObject::SetValueIsValid (bool b)
477{
Greg Clayton288bdf92010-09-02 02:59:18 +0000478 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479}
480
481bool
Jim Ingham6035b672011-03-31 00:19:25 +0000482ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483{
Jim Ingham6035b672011-03-31 00:19:25 +0000484 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000485 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000486}
487
488void
489ValueObject::SetValueDidChange (bool value_changed)
490{
Greg Clayton288bdf92010-09-02 02:59:18 +0000491 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492}
493
494ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000495ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496{
497 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000498 // We may need to update our value if we are dynamic
499 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000500 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000501 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000502 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000503 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000504 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000505 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000506 // No we haven't created the child at this index, so lets have our
507 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000508 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000509 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000510
Enrico Granata9d60f602012-03-09 03:09:58 +0000511 ValueObject* child = m_children.GetChildAtIndex(idx);
512 if (child != NULL)
513 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000514 }
515 return child_sp;
516}
517
Enrico Granata3309d882013-01-12 01:00:22 +0000518ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000519ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
520 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000521{
522 if (idxs.size() == 0)
523 return GetSP();
524 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000525 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000526 {
527 root = root->GetChildAtIndex(idx, true);
528 if (!root)
529 {
530 if (index_of_error)
531 *index_of_error = idx;
532 return root;
533 }
534 }
535 return root;
536}
537
538ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000539ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
540 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000541{
542 if (idxs.size() == 0)
543 return GetSP();
544 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000545 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000546 {
547 root = root->GetChildAtIndex(idx.first, idx.second);
548 if (!root)
549 {
550 if (index_of_error)
551 *index_of_error = idx.first;
552 return root;
553 }
554 }
555 return root;
556}
557
558lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000559ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
560 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000561{
562 if (idxs.size() == 0)
563 return GetSP();
564 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000565 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000566 {
567 root = root->GetChildAtIndex(idx, true);
568 if (!root)
569 {
570 if (index_of_error)
571 *index_of_error = idx;
572 return root;
573 }
574 }
575 return root;
576}
577
578lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000579ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
580 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000581{
582 if (idxs.size() == 0)
583 return GetSP();
584 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000585 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000586 {
587 root = root->GetChildAtIndex(idx.first, idx.second);
588 if (!root)
589 {
590 if (index_of_error)
591 *index_of_error = idx.first;
592 return root;
593 }
594 }
595 return root;
596}
597
Greg Claytonc7bece562013-01-25 18:06:21 +0000598size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599ValueObject::GetIndexOfChildWithName (const ConstString &name)
600{
601 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000602 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603}
604
605ValueObjectSP
606ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
607{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000608 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000609 // classes (which really aren't part of the expression path), so we
610 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000612
Greg Claytondea8cb42011-06-29 22:09:02 +0000613 // We may need to update our value if we are dynamic
614 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000615 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000616
617 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000618 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000619 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
620 omit_empty_base_classes,
621 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000622 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000623 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000624 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
625 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
626
627 child_sp = GetChildAtIndex(*pos, can_create);
628 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000629 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000630 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000631 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000632 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
633 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000634 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000635 else
636 {
637 child_sp.reset();
638 }
639
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000640 }
641 }
642 return child_sp;
643}
644
645
Greg Claytonc7bece562013-01-25 18:06:21 +0000646size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000647ValueObject::GetNumChildren ()
648{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000649 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000650 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000651 {
652 SetNumChildren (CalculateNumChildren());
653 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000654 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000655}
Greg Clayton4a792072012-10-23 01:50:10 +0000656
657bool
658ValueObject::MightHaveChildren()
659{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000660 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000661 const uint32_t type_info = GetTypeInfo();
662 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000663 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000664 if (type_info & (ClangASTType::eTypeHasChildren |
665 ClangASTType::eTypeIsPointer |
666 ClangASTType::eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000667 has_children = true;
668 }
669 else
670 {
671 has_children = GetNumChildren () > 0;
672 }
673 return has_children;
674}
675
676// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000677void
Greg Claytonc7bece562013-01-25 18:06:21 +0000678ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679{
Greg Clayton288bdf92010-09-02 02:59:18 +0000680 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000681 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682}
683
684void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000685ValueObject::SetName (const ConstString &name)
686{
687 m_name = name;
688}
689
Jim Ingham58b59f92011-04-22 23:53:53 +0000690ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000691ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692{
Jim Ingham2eec4872011-05-07 00:10:58 +0000693 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000694
Greg Claytondea8cb42011-06-29 22:09:02 +0000695 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000696 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000697 std::string child_name_str;
698 uint32_t child_byte_size = 0;
699 int32_t child_byte_offset = 0;
700 uint32_t child_bitfield_bit_size = 0;
701 uint32_t child_bitfield_bit_offset = 0;
702 bool child_is_base_class = false;
703 bool child_is_deref_of_parent = false;
704
705 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000706 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000707
Greg Claytoncc4d0142012-02-17 07:49:44 +0000708 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000709
Greg Clayton57ee3062013-07-11 22:46:58 +0000710 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
711 GetName().GetCString(),
712 idx,
713 transparent_pointers,
714 omit_empty_base_classes,
715 ignore_array_bounds,
716 child_name_str,
717 child_byte_size,
718 child_byte_offset,
719 child_bitfield_bit_size,
720 child_bitfield_bit_offset,
721 child_is_base_class,
722 child_is_deref_of_parent);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000723 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000724 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000725 if (synthetic_index)
726 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000727
Greg Claytondea8cb42011-06-29 22:09:02 +0000728 ConstString child_name;
729 if (!child_name_str.empty())
730 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000731
Greg Claytondea8cb42011-06-29 22:09:02 +0000732 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000733 child_clang_type,
734 child_name,
735 child_byte_size,
736 child_byte_offset,
737 child_bitfield_bit_size,
738 child_bitfield_bit_offset,
739 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000740 child_is_deref_of_parent,
741 eAddressTypeInvalid);
742 //if (valobj)
743 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
744 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000745
Jim Ingham58b59f92011-04-22 23:53:53 +0000746 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000747}
748
Enrico Granata0c489f52012-03-01 04:24:26 +0000749bool
750ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
751 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000752{
Enrico Granata0c489f52012-03-01 04:24:26 +0000753 destination.clear();
754
755 // ideally we would like to bail out if passing NULL, but if we do so
756 // we end up not providing the summary for function pointers anymore
757 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
758 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000759
760 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000761
762 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
763 // information that we might care to see in a crash log. might be useful in very specific situations though.
764 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
765 GetTypeName().GetCString(),
766 GetName().GetCString(),
767 summary_ptr->GetDescription().c_str());*/
768
Enrico Granata0c489f52012-03-01 04:24:26 +0000769 if (UpdateValueIfNeeded (false))
770 {
771 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000773 if (HasSyntheticValue())
774 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
775 summary_ptr->FormatObject(this, destination);
Enrico Granata0c489f52012-03-01 04:24:26 +0000776 }
777 else
778 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000779 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000780
781 // Do some default printout for function pointers
782 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000783 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000784 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000785 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000786 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000787 AddressType func_ptr_address_type = eAddressTypeInvalid;
788 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
789 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000790 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000791 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000792 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000793 case eAddressTypeInvalid:
794 case eAddressTypeFile:
795 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000796
Greg Claytoncc4d0142012-02-17 07:49:44 +0000797 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000798 {
799 ExecutionContext exe_ctx (GetExecutionContextRef());
800
801 Address so_addr;
802 Target *target = exe_ctx.GetTargetPtr();
803 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000804 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000805 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000806 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000807 so_addr.Dump (&sstr,
808 exe_ctx.GetBestExecutionContextScope(),
809 Address::DumpStyleResolvedDescription,
810 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000811 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000812 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000813 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000814 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000815
Greg Claytoncc4d0142012-02-17 07:49:44 +0000816 case eAddressTypeHost:
817 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000818 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000819 }
820 if (sstr.GetSize() > 0)
821 {
822 destination.assign (1, '(');
823 destination.append (sstr.GetData(), sstr.GetSize());
824 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825 }
826 }
827 }
828 }
829 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000830 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000831 return !destination.empty();
832}
833
834const char *
835ValueObject::GetSummaryAsCString ()
836{
837 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
838 {
839 GetSummaryAsCString(GetSummaryFormat().get(),
840 m_summary_str);
841 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000842 if (m_summary_str.empty())
843 return NULL;
844 return m_summary_str.c_str();
845}
846
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000847bool
848ValueObject::IsCStringContainer(bool check_pointer)
849{
Greg Clayton57ee3062013-07-11 22:46:58 +0000850 ClangASTType pointee_or_element_clang_type;
851 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
852 bool is_char_arr_ptr (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
853 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000854 if (!is_char_arr_ptr)
855 return false;
856 if (!check_pointer)
857 return true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000858 if (type_flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000859 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000860 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000861 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000862 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000863 return (cstr_address != LLDB_INVALID_ADDRESS);
864}
865
Enrico Granata9128ee22011-09-06 19:20:51 +0000866size_t
867ValueObject::GetPointeeData (DataExtractor& data,
868 uint32_t item_idx,
869 uint32_t item_count)
870{
Greg Clayton57ee3062013-07-11 22:46:58 +0000871 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000872 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Greg Clayton57ee3062013-07-11 22:46:58 +0000873 const bool is_pointer_type = type_info & ClangASTType::eTypeIsPointer;
874 const bool is_array_type = type_info & ClangASTType::eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000875 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000876 return 0;
877
878 if (item_count == 0)
879 return 0;
880
Greg Clayton57ee3062013-07-11 22:46:58 +0000881 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000882 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000883 const uint64_t offset = item_idx * item_type_size;
884
885 if (item_idx == 0 && item_count == 1) // simply a deref
886 {
Greg Clayton2452ab72013-02-08 22:02:02 +0000887 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +0000888 {
889 Error error;
890 ValueObjectSP pointee_sp = Dereference(error);
891 if (error.Fail() || pointee_sp.get() == NULL)
892 return 0;
893 return pointee_sp->GetDataExtractor().Copy(data);
894 }
895 else
896 {
897 ValueObjectSP child_sp = GetChildAtIndex(0, true);
898 if (child_sp.get() == NULL)
899 return 0;
900 return child_sp->GetDataExtractor().Copy(data);
901 }
902 return true;
903 }
904 else /* (items > 1) */
905 {
906 Error error;
907 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
908 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
909
910 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000911 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +0000912
Enrico Granata9128ee22011-09-06 19:20:51 +0000913 switch (addr_type)
914 {
915 case eAddressTypeFile:
916 {
Greg Claytone72dfb32012-02-24 01:59:29 +0000917 ModuleSP module_sp (GetModule());
918 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +0000919 {
Enrico Granata9c2efe32012-08-07 01:49:34 +0000920 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +0000921 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +0000922 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000923 ExecutionContext exe_ctx (GetExecutionContextRef());
924 Target* target = exe_ctx.GetTargetPtr();
925 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +0000926 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000927 heap_buf_ptr->SetByteSize(bytes);
928 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
929 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +0000930 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000931 data.SetData(data_sp);
932 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +0000933 }
934 }
935 }
936 }
937 break;
938 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +0000939 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000940 ExecutionContext exe_ctx (GetExecutionContextRef());
941 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +0000942 if (process)
943 {
944 heap_buf_ptr->SetByteSize(bytes);
945 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
946 if (error.Success())
947 {
948 data.SetData(data_sp);
949 return bytes_read;
950 }
951 }
952 }
953 break;
954 case eAddressTypeHost:
955 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000956 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +0000957 if (max_bytes > offset)
958 {
959 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
960 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
961 data.SetData(data_sp);
962 return bytes_read;
963 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000964 }
965 break;
966 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +0000967 break;
968 }
969 }
970 return 0;
971}
972
Greg Claytonfaac1112013-03-14 18:31:44 +0000973uint64_t
Enrico Granata9128ee22011-09-06 19:20:51 +0000974ValueObject::GetData (DataExtractor& data)
975{
976 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +0000977 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Clayton57ee3062013-07-11 22:46:58 +0000978 Error error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +0000979 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +0000980 {
981 if (m_data.GetByteSize())
982 {
983 data = m_data;
984 return data.GetByteSize();
985 }
986 else
987 {
988 return 0;
989 }
990 }
Enrico Granata9128ee22011-09-06 19:20:51 +0000991 data.SetAddressByteSize(m_data.GetAddressByteSize());
992 data.SetByteOrder(m_data.GetByteOrder());
993 return data.GetByteSize();
994}
995
Sean Callanan389823e2013-04-13 01:21:23 +0000996bool
997ValueObject::SetData (DataExtractor &data, Error &error)
998{
999 error.Clear();
1000 // Make sure our value is up to date first so that our location and location
1001 // type is valid.
1002 if (!UpdateValueIfNeeded(false))
1003 {
1004 error.SetErrorString("unable to read value");
1005 return false;
1006 }
1007
1008 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001009 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001010
1011 const size_t byte_size = GetByteSize();
1012
1013 Value::ValueType value_type = m_value.GetValueType();
1014
1015 switch (value_type)
1016 {
1017 case Value::eValueTypeScalar:
1018 {
1019 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1020
1021 if (!set_error.Success())
1022 {
1023 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1024 return false;
1025 }
1026 }
1027 break;
1028 case Value::eValueTypeLoadAddress:
1029 {
1030 // If it is a load address, then the scalar value is the storage location
1031 // of the data, and we have to shove this value down to that load location.
1032 ExecutionContext exe_ctx (GetExecutionContextRef());
1033 Process *process = exe_ctx.GetProcessPtr();
1034 if (process)
1035 {
1036 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1037 size_t bytes_written = process->WriteMemory(target_addr,
1038 data.GetDataStart(),
1039 byte_size,
1040 error);
1041 if (!error.Success())
1042 return false;
1043 if (bytes_written != byte_size)
1044 {
1045 error.SetErrorString("unable to write value to memory");
1046 return false;
1047 }
1048 }
1049 }
1050 break;
1051 case Value::eValueTypeHostAddress:
1052 {
1053 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1054 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1055 m_data.SetData(buffer_sp, 0);
1056 data.CopyByteOrderedData (0,
1057 byte_size,
1058 const_cast<uint8_t *>(m_data.GetDataStart()),
1059 byte_size,
1060 m_data.GetByteOrder());
1061 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1062 }
1063 break;
1064 case Value::eValueTypeFileAddress:
1065 case Value::eValueTypeVector:
1066 break;
1067 }
1068
1069 // If we have reached this point, then we have successfully changed the value.
1070 SetNeedsUpdate();
1071 return true;
1072}
1073
Enrico Granata9128ee22011-09-06 19:20:51 +00001074// will compute strlen(str), but without consuming more than
1075// maxlen bytes out of str (this serves the purpose of reading
1076// chunks of a string without having to worry about
1077// missing NULL terminators in the chunk)
1078// of course, if strlen(str) > maxlen, the function will return
1079// maxlen_value (which should be != maxlen, because that allows you
1080// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1081static uint32_t
1082strlen_or_inf (const char* str,
1083 uint32_t maxlen,
1084 uint32_t maxlen_value)
1085{
1086 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001087 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001088 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001089 while(*str)
1090 {
1091 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001092 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001093 return maxlen_value;
1094 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001095 }
1096 return len;
1097}
1098
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001099size_t
Greg Claytoncc4d0142012-02-17 07:49:44 +00001100ValueObject::ReadPointedString (Stream& s,
1101 Error& error,
1102 uint32_t max_length,
1103 bool honor_array,
1104 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001105{
Greg Claytoncc4d0142012-02-17 07:49:44 +00001106 ExecutionContext exe_ctx (GetExecutionContextRef());
1107 Target* target = exe_ctx.GetTargetPtr();
1108
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001109 if (!target)
1110 {
1111 s << "<no target to read from>";
1112 error.SetErrorString("no target to read from");
1113 return 0;
1114 }
1115
1116 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001117 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001118
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001119 size_t bytes_read = 0;
1120 size_t total_bytes_read = 0;
1121
Greg Clayton57ee3062013-07-11 22:46:58 +00001122 ClangASTType clang_type = GetClangType();
1123 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001124 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Greg Clayton57ee3062013-07-11 22:46:58 +00001125 if (type_flags.AnySet (ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer) &&
1126 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001127 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001128 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1129 AddressType cstr_address_type = eAddressTypeInvalid;
1130
1131 size_t cstr_len = 0;
1132 bool capped_data = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00001133 if (type_flags.Test (ClangASTType::eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001134 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001135 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001136 uint64_t array_size = 0;
1137 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001138 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001139 cstr_len = array_size;
1140 if (cstr_len > max_length)
1141 {
1142 capped_data = true;
1143 cstr_len = max_length;
1144 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001145 }
1146 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001147 }
1148 else
1149 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001150 // We have a pointer
1151 cstr_address = GetPointerValue (&cstr_address_type);
1152 }
1153
1154 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1155 {
1156 s << "<invalid address>";
1157 error.SetErrorString("invalid address");
1158 return 0;
1159 }
1160
1161 Address cstr_so_addr (cstr_address);
1162 DataExtractor data;
1163 if (cstr_len > 0 && honor_array)
1164 {
1165 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1166 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1167 GetPointeeData(data, 0, cstr_len);
1168
1169 if ((bytes_read = data.GetByteSize()) > 0)
1170 {
1171 total_bytes_read = bytes_read;
1172 s << '"';
1173 data.Dump (&s,
1174 0, // Start offset in "data"
1175 item_format,
1176 1, // Size of item (1 byte for a char!)
1177 bytes_read, // How many bytes to print?
1178 UINT32_MAX, // num per line
1179 LLDB_INVALID_ADDRESS,// base address
1180 0, // bitfield bit size
1181 0); // bitfield bit offset
1182 if (capped_data)
1183 s << "...";
1184 s << '"';
1185 }
1186 }
1187 else
1188 {
1189 cstr_len = max_length;
1190 const size_t k_max_buf_size = 64;
1191
1192 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001193
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001194 int cstr_len_displayed = -1;
1195 bool capped_cstr = false;
1196 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1197 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1198 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001199 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001200 total_bytes_read += bytes_read;
1201 const char *cstr = data.PeekCStr(0);
1202 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1203 if (len > k_max_buf_size)
1204 len = k_max_buf_size;
1205 if (cstr && cstr_len_displayed < 0)
1206 s << '"';
1207
1208 if (cstr_len_displayed < 0)
1209 cstr_len_displayed = len;
1210
1211 if (len == 0)
1212 break;
1213 cstr_len_displayed += len;
1214 if (len > bytes_read)
1215 len = bytes_read;
1216 if (len > cstr_len)
1217 len = cstr_len;
1218
1219 data.Dump (&s,
1220 0, // Start offset in "data"
1221 item_format,
1222 1, // Size of item (1 byte for a char!)
1223 len, // How many bytes to print?
1224 UINT32_MAX, // num per line
1225 LLDB_INVALID_ADDRESS,// base address
1226 0, // bitfield bit size
1227 0); // bitfield bit offset
1228
1229 if (len < k_max_buf_size)
1230 break;
1231
1232 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001233 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001234 capped_cstr = true;
1235 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001236 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001237
1238 cstr_len -= len;
1239 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001240 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001241
1242 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001243 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001244 s << '"';
1245 if (capped_cstr)
1246 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001247 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001248 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001249 }
1250 else
1251 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001252 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001253 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001254 }
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001255 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001256}
1257
Jim Ingham53c47f12010-09-10 23:12:17 +00001258const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001259ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001260{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001261
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001262 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001263 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001264
1265 if (!m_object_desc_str.empty())
1266 return m_object_desc_str.c_str();
1267
Greg Claytoncc4d0142012-02-17 07:49:44 +00001268 ExecutionContext exe_ctx (GetExecutionContextRef());
1269 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001270 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001271 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001272
Jim Ingham53c47f12010-09-10 23:12:17 +00001273 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001274
Greg Claytonafacd142011-09-02 01:15:17 +00001275 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001276 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1277
Jim Inghama2cf2632010-12-23 02:29:54 +00001278 if (runtime == NULL)
1279 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001280 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001281 ClangASTType clang_type = GetClangType();
1282 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001283 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001284 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001285 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001286 {
Greg Claytonafacd142011-09-02 01:15:17 +00001287 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001288 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001289 }
1290 }
1291
Jim Ingham8d543de2011-03-31 23:01:21 +00001292 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001293 {
1294 m_object_desc_str.append (s.GetData());
1295 }
Sean Callanan672ad942010-10-23 00:18:49 +00001296
1297 if (m_object_desc_str.empty())
1298 return NULL;
1299 else
1300 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001301}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001302
Enrico Granata0c489f52012-03-01 04:24:26 +00001303bool
1304ValueObject::GetValueAsCString (lldb::Format format,
1305 std::string& destination)
1306{
Greg Clayton57ee3062013-07-11 22:46:58 +00001307 if (GetClangType().IsAggregateType () == false && UpdateValueIfNeeded(false))
Enrico Granata0c489f52012-03-01 04:24:26 +00001308 {
1309 const Value::ContextType context_type = m_value.GetContextType();
1310
Greg Clayton57ee3062013-07-11 22:46:58 +00001311 if (context_type == Value::eContextTypeRegisterInfo)
Enrico Granata0c489f52012-03-01 04:24:26 +00001312 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001313 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1314 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001315 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001316 ExecutionContext exe_ctx (GetExecutionContextRef());
1317
1318 StreamString reg_sstr;
1319 m_data.Dump (&reg_sstr,
1320 0,
1321 format,
1322 reg_info->byte_size,
1323 1,
1324 UINT32_MAX,
1325 LLDB_INVALID_ADDRESS,
1326 0,
1327 0,
1328 exe_ctx.GetBestExecutionContextScope());
1329 destination.swap(reg_sstr.GetString());
1330 }
1331 }
1332 else
1333 {
1334 ClangASTType clang_type = GetClangType ();
1335 if (clang_type)
1336 {
1337 // put custom bytes to display in this DataExtractor to override the default value logic
1338 lldb_private::DataExtractor special_format_data;
1339 if (format == eFormatCString)
Enrico Granata0c489f52012-03-01 04:24:26 +00001340 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001341 Flags type_flags(clang_type.GetTypeInfo(NULL));
1342 if (type_flags.Test(ClangASTType::eTypeIsPointer) && !type_flags.Test(ClangASTType::eTypeIsObjC))
Enrico Granata852cce72013-03-23 01:12:38 +00001343 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001344 // if we are dumping a pointer as a c-string, get the pointee data as a string
1345 TargetSP target_sp(GetTargetSP());
1346 if (target_sp)
Enrico Granata852cce72013-03-23 01:12:38 +00001347 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001348 size_t max_len = target_sp->GetMaximumSizeOfStringSummary();
1349 Error error;
1350 DataBufferSP buffer_sp(new DataBufferHeap(max_len+1,0));
1351 Address address(GetPointerValue());
1352 if (target_sp->ReadCStringFromMemory(address, (char*)buffer_sp->GetBytes(), max_len, error) && error.Success())
1353 special_format_data.SetData(buffer_sp);
Enrico Granata852cce72013-03-23 01:12:38 +00001354 }
1355 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001356 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001357
Greg Clayton57ee3062013-07-11 22:46:58 +00001358 StreamString sstr;
1359 ExecutionContext exe_ctx (GetExecutionContextRef());
1360 clang_type.DumpTypeValue (&sstr, // The stream to use for display
1361 format, // Format to display this type with
1362 special_format_data.GetByteSize() ?
1363 special_format_data: m_data, // Data to extract from
1364 0, // Byte offset into "m_data"
1365 GetByteSize(), // Byte size of item in "m_data"
1366 GetBitfieldBitSize(), // Bitfield bit size
1367 GetBitfieldBitOffset(), // Bitfield bit offset
1368 exe_ctx.GetBestExecutionContextScope());
1369 // Don't set the m_error to anything here otherwise
1370 // we won't be able to re-format as anything else. The
1371 // code for ClangASTType::DumpTypeValue() should always
1372 // return something, even if that something contains
1373 // an error messsage. "m_error" is used to detect errors
1374 // when reading the valid object, not for formatting errors.
1375 if (sstr.GetString().empty())
1376 destination.clear();
1377 else
1378 destination.swap(sstr.GetString());
Enrico Granata0c489f52012-03-01 04:24:26 +00001379 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001380 }
1381 return !destination.empty();
1382 }
1383 else
1384 return false;
1385}
1386
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001387const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001388ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001389{
Enrico Granatab294fd22013-05-31 19:18:19 +00001390 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001391 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001392 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001393 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001394 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001395 if (m_type_format_sp)
1396 my_format = m_type_format_sp->GetFormat();
1397 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001398 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001399 if (m_is_bitfield_for_scalar)
1400 my_format = eFormatUnsigned;
1401 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001402 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001403 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001404 {
1405 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1406 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001407 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001408 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001409 else
1410 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001411 my_format = GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001412 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001413 }
1414 }
1415 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001416 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001417 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001418 m_last_format = my_format;
1419 if (GetValueAsCString(my_format, m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001420 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001421 if (!m_value_did_change && m_old_value_valid)
1422 {
1423 // The value was gotten successfully, so we consider the
1424 // value as changed if the value string differs
1425 SetValueDidChange (m_old_value_str != m_value_str);
1426 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001427 }
1428 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429 }
1430 if (m_value_str.empty())
1431 return NULL;
1432 return m_value_str.c_str();
1433}
1434
Enrico Granatac3e320a2011-08-02 17:27:39 +00001435// if > 8bytes, 0 is returned. this method should mostly be used
1436// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001437uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001438ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001439{
1440 // If our byte size is zero this is an aggregate type that has children
Greg Clayton57ee3062013-07-11 22:46:58 +00001441 if (!GetClangType().IsAggregateType())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001442 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001443 Scalar scalar;
1444 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001445 {
1446 if (success)
1447 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001448 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001449 }
1450 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001451 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001452
1453 if (success)
1454 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001455 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001456}
1457
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001458// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1459// this call up to date by returning true for your new special cases. We will eventually move
1460// to checking this call result before trying to display special cases
1461bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001462ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1463 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001464{
Greg Clayton57ee3062013-07-11 22:46:58 +00001465 Flags flags(GetTypeInfo());
1466 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001467 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001468 {
1469 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001470 (custom_format == eFormatCString ||
1471 custom_format == eFormatCharArray ||
1472 custom_format == eFormatChar ||
1473 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001474 return true;
1475
Greg Clayton57ee3062013-07-11 22:46:58 +00001476 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001477 {
Greg Claytonafacd142011-09-02 01:15:17 +00001478 if ((custom_format == eFormatBytes) ||
1479 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001480 return true;
1481
Greg Claytonafacd142011-09-02 01:15:17 +00001482 if ((custom_format == eFormatVectorOfChar) ||
1483 (custom_format == eFormatVectorOfFloat32) ||
1484 (custom_format == eFormatVectorOfFloat64) ||
1485 (custom_format == eFormatVectorOfSInt16) ||
1486 (custom_format == eFormatVectorOfSInt32) ||
1487 (custom_format == eFormatVectorOfSInt64) ||
1488 (custom_format == eFormatVectorOfSInt8) ||
1489 (custom_format == eFormatVectorOfUInt128) ||
1490 (custom_format == eFormatVectorOfUInt16) ||
1491 (custom_format == eFormatVectorOfUInt32) ||
1492 (custom_format == eFormatVectorOfUInt64) ||
1493 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001494 return true;
1495 }
1496 }
1497 return false;
1498}
1499
Enrico Granata9fc19442011-07-06 02:13:41 +00001500bool
1501ValueObject::DumpPrintableRepresentation(Stream& s,
1502 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001503 Format custom_format,
Enrico Granata86cc9822012-03-19 22:58:49 +00001504 PrintableRepresentationSpecialCases special)
Enrico Granata9fc19442011-07-06 02:13:41 +00001505{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001506
Greg Clayton57ee3062013-07-11 22:46:58 +00001507 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001508
Enrico Granata86cc9822012-03-19 22:58:49 +00001509 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1510 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1511
1512 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001513 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001514 if (flags.AnySet(ClangASTType::eTypeIsArray | ClangASTType::eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001515 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001516 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001517 // when being asked to get a printable display an array or pointer type directly,
1518 // try to "do the right thing"
1519
1520 if (IsCStringContainer(true) &&
1521 (custom_format == eFormatCString ||
1522 custom_format == eFormatCharArray ||
1523 custom_format == eFormatChar ||
1524 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001525 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001526 Error error;
1527 ReadPointedString(s,
1528 error,
1529 0,
1530 (custom_format == eFormatVectorOfChar) ||
1531 (custom_format == eFormatCharArray));
1532 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001533 }
1534
Enrico Granata86cc9822012-03-19 22:58:49 +00001535 if (custom_format == eFormatEnum)
1536 return false;
1537
1538 // this only works for arrays, because I have no way to know when
1539 // the pointed memory ends, and no special \0 end of data marker
Greg Clayton57ee3062013-07-11 22:46:58 +00001540 if (flags.Test(ClangASTType::eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001541 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001542 if ((custom_format == eFormatBytes) ||
1543 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001544 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001545 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001546
1547 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001548 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001549 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001550
1551 if (low)
1552 s << ',';
1553
1554 ValueObjectSP child = GetChildAtIndex(low,true);
1555 if (!child.get())
1556 {
1557 s << "<invalid child>";
1558 continue;
1559 }
1560 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1561 }
1562
1563 s << ']';
1564
1565 return true;
1566 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001567
Enrico Granata86cc9822012-03-19 22:58:49 +00001568 if ((custom_format == eFormatVectorOfChar) ||
1569 (custom_format == eFormatVectorOfFloat32) ||
1570 (custom_format == eFormatVectorOfFloat64) ||
1571 (custom_format == eFormatVectorOfSInt16) ||
1572 (custom_format == eFormatVectorOfSInt32) ||
1573 (custom_format == eFormatVectorOfSInt64) ||
1574 (custom_format == eFormatVectorOfSInt8) ||
1575 (custom_format == eFormatVectorOfUInt128) ||
1576 (custom_format == eFormatVectorOfUInt16) ||
1577 (custom_format == eFormatVectorOfUInt32) ||
1578 (custom_format == eFormatVectorOfUInt64) ||
1579 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1580 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001581 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001582
1583 Format format = FormatManager::GetSingleItemFormat(custom_format);
1584
1585 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001586 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001587 {
1588
1589 if (low)
1590 s << ',';
1591
1592 ValueObjectSP child = GetChildAtIndex(low,true);
1593 if (!child.get())
1594 {
1595 s << "<invalid child>";
1596 continue;
1597 }
1598 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1599 }
1600
1601 s << ']';
1602
1603 return true;
1604 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001605 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001606
1607 if ((custom_format == eFormatBoolean) ||
1608 (custom_format == eFormatBinary) ||
1609 (custom_format == eFormatChar) ||
1610 (custom_format == eFormatCharPrintable) ||
1611 (custom_format == eFormatComplexFloat) ||
1612 (custom_format == eFormatDecimal) ||
1613 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001614 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001615 (custom_format == eFormatFloat) ||
1616 (custom_format == eFormatOctal) ||
1617 (custom_format == eFormatOSType) ||
1618 (custom_format == eFormatUnicode16) ||
1619 (custom_format == eFormatUnicode32) ||
1620 (custom_format == eFormatUnsigned) ||
1621 (custom_format == eFormatPointer) ||
1622 (custom_format == eFormatComplexInteger) ||
1623 (custom_format == eFormatComplex) ||
1624 (custom_format == eFormatDefault)) // use the [] operator
1625 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001626 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001627 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001628
1629 if (only_special)
1630 return false;
1631
Enrico Granata86cc9822012-03-19 22:58:49 +00001632 bool var_success = false;
1633
1634 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001635 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001636
1637 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1638 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1639 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001640 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001641
1642 if (custom_format != eFormatInvalid)
1643 SetFormat(custom_format);
1644
1645 switch(val_obj_display)
1646 {
1647 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001648 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001649 break;
1650
1651 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001652 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001653 break;
1654
1655 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001656 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001657 break;
1658
1659 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001660 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001661 break;
1662
1663 case eValueObjectRepresentationStyleChildrenCount:
Greg Claytonc7bece562013-01-25 18:06:21 +00001664 strm.Printf("%zu", GetNumChildren());
1665 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001666 break;
1667
1668 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001669 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001670 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001671
1672 case eValueObjectRepresentationStyleName:
1673 cstr = GetName().AsCString();
1674 break;
1675
1676 case eValueObjectRepresentationStyleExpressionPath:
1677 GetExpressionPath(strm, false);
1678 cstr = strm.GetString().c_str();
1679 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001680 }
1681
Greg Claytonc7bece562013-01-25 18:06:21 +00001682 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001683 {
1684 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001685 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001686 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1687 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001688 if (GetClangType().IsAggregateType())
Enrico Granata86cc9822012-03-19 22:58:49 +00001689 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001690 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1691 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001692 }
1693 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001694 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001695 }
1696 }
1697
Greg Claytonc7bece562013-01-25 18:06:21 +00001698 if (cstr)
1699 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001700 else
1701 {
1702 if (m_error.Fail())
1703 s.Printf("<%s>", m_error.AsCString());
1704 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1705 s.PutCString("<no summary available>");
1706 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1707 s.PutCString("<no value available>");
1708 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1709 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1710 else
1711 s.PutCString("<no printable representation>");
1712 }
1713
1714 // we should only return false here if we could not do *anything*
1715 // even if we have an error message as output, that's a success
1716 // from our callers' perspective, so return true
1717 var_success = true;
1718
1719 if (custom_format != eFormatInvalid)
1720 SetFormat(eFormatDefault);
1721 }
1722
Enrico Granataf4efecd2011-07-12 22:56:10 +00001723 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001724}
1725
Greg Clayton737b9322010-09-13 03:32:57 +00001726addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001727ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001728{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001729 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001730 return LLDB_INVALID_ADDRESS;
1731
Greg Clayton73b472d2010-10-27 03:32:59 +00001732 switch (m_value.GetValueType())
1733 {
1734 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001735 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001736 if (scalar_is_load_address)
1737 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001738 if(address_type)
1739 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001740 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1741 }
1742 break;
1743
1744 case Value::eValueTypeLoadAddress:
1745 case Value::eValueTypeFileAddress:
1746 case Value::eValueTypeHostAddress:
1747 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001748 if(address_type)
1749 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001750 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1751 }
1752 break;
1753 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001754 if (address_type)
1755 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001756 return LLDB_INVALID_ADDRESS;
1757}
1758
1759addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001760ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001761{
Greg Claytonafacd142011-09-02 01:15:17 +00001762 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001763 if(address_type)
1764 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001765
Enrico Granatac3e320a2011-08-02 17:27:39 +00001766 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001767 return address;
1768
Greg Clayton73b472d2010-10-27 03:32:59 +00001769 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001770 {
1771 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001772 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001773 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001774 break;
1775
Enrico Granata9128ee22011-09-06 19:20:51 +00001776 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001777 case Value::eValueTypeLoadAddress:
1778 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001779 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001780 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001781 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001782 }
1783 break;
1784 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001785
Enrico Granata9128ee22011-09-06 19:20:51 +00001786 if (address_type)
1787 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001788
Greg Clayton737b9322010-09-13 03:32:57 +00001789 return address;
1790}
1791
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001792bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001793ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001794{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001795 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001796 // Make sure our value is up to date first so that our location and location
1797 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001798 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001799 {
1800 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001801 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001802 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001803
Greg Claytonfaac1112013-03-14 18:31:44 +00001804 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001805 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001806
Greg Claytonb1320972010-07-14 00:18:15 +00001807 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001808
Jim Ingham16e0c682011-08-12 23:34:31 +00001809 Value::ValueType value_type = m_value.GetValueType();
1810
1811 if (value_type == Value::eValueTypeScalar)
1812 {
1813 // If the value is already a scalar, then let the scalar change itself:
1814 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1815 }
1816 else if (byte_size <= Scalar::GetMaxByteSize())
1817 {
1818 // If the value fits in a scalar, then make a new scalar and again let the
1819 // scalar code do the conversion, then figure out where to put the new value.
1820 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001821 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1822 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001823 {
Jim Ingham4b536182011-08-09 02:12:22 +00001824 switch (value_type)
1825 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001826 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001827 {
1828 // If it is a load address, then the scalar value is the storage location
1829 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001830 ExecutionContext exe_ctx (GetExecutionContextRef());
1831 Process *process = exe_ctx.GetProcessPtr();
1832 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001833 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001834 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001835 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1836 new_scalar,
1837 byte_size,
1838 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001839 if (!error.Success())
1840 return false;
1841 if (bytes_written != byte_size)
1842 {
1843 error.SetErrorString("unable to write value to memory");
1844 return false;
1845 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001846 }
1847 }
Jim Ingham4b536182011-08-09 02:12:22 +00001848 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001849 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001850 {
1851 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1852 DataExtractor new_data;
1853 new_data.SetByteOrder (m_data.GetByteOrder());
1854
1855 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1856 m_data.SetData(buffer_sp, 0);
1857 bool success = new_scalar.GetData(new_data);
1858 if (success)
1859 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001860 new_data.CopyByteOrderedData (0,
1861 byte_size,
1862 const_cast<uint8_t *>(m_data.GetDataStart()),
1863 byte_size,
1864 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001865 }
1866 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1867
1868 }
Jim Ingham4b536182011-08-09 02:12:22 +00001869 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001870 case Value::eValueTypeFileAddress:
1871 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001872 case Value::eValueTypeVector:
1873 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001874 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001875 }
1876 else
1877 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001878 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001879 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001880 }
1881 else
1882 {
1883 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001884 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001885 return false;
1886 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001887
1888 // If we have reached this point, then we have successfully changed the value.
1889 SetNeedsUpdate();
1890 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001891}
1892
Greg Clayton81e871e2012-02-04 02:27:34 +00001893bool
1894ValueObject::GetDeclaration (Declaration &decl)
1895{
1896 decl.Clear();
1897 return false;
1898}
1899
Greg Clayton84db9102012-03-26 23:03:23 +00001900ConstString
1901ValueObject::GetTypeName()
1902{
Greg Clayton57ee3062013-07-11 22:46:58 +00001903 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001904}
1905
1906ConstString
1907ValueObject::GetQualifiedTypeName()
1908{
Greg Clayton57ee3062013-07-11 22:46:58 +00001909 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00001910}
1911
1912
Greg Claytonafacd142011-09-02 01:15:17 +00001913LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00001914ValueObject::GetObjectRuntimeLanguage ()
1915{
Greg Clayton57ee3062013-07-11 22:46:58 +00001916 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00001917}
1918
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001919void
Jim Ingham58b59f92011-04-22 23:53:53 +00001920ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001921{
Jim Ingham58b59f92011-04-22 23:53:53 +00001922 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001923}
1924
1925ValueObjectSP
1926ValueObject::GetSyntheticChild (const ConstString &key) const
1927{
1928 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00001929 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001930 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00001931 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932 return synthetic_child_sp;
1933}
1934
Greg Clayton2452ab72013-02-08 22:02:02 +00001935uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00001936ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00001937{
Greg Clayton57ee3062013-07-11 22:46:58 +00001938 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00001939}
1940
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001941bool
1942ValueObject::IsPointerType ()
1943{
Greg Clayton57ee3062013-07-11 22:46:58 +00001944 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001945}
1946
Jim Inghamb7603bb2011-03-18 00:05:18 +00001947bool
Greg Claytondaf515f2011-07-09 20:12:33 +00001948ValueObject::IsArrayType ()
1949{
Greg Clayton57ee3062013-07-11 22:46:58 +00001950 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00001951}
1952
1953bool
Enrico Granata9fc19442011-07-06 02:13:41 +00001954ValueObject::IsScalarType ()
1955{
Greg Clayton57ee3062013-07-11 22:46:58 +00001956 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00001957}
1958
1959bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00001960ValueObject::IsIntegerType (bool &is_signed)
1961{
Greg Clayton57ee3062013-07-11 22:46:58 +00001962 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001963}
Greg Clayton73b472d2010-10-27 03:32:59 +00001964
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001965bool
1966ValueObject::IsPointerOrReferenceType ()
1967{
Greg Clayton57ee3062013-07-11 22:46:58 +00001968 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00001969}
1970
1971bool
Greg Claytondea8cb42011-06-29 22:09:02 +00001972ValueObject::IsPossibleDynamicType ()
1973{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00001974 ExecutionContext exe_ctx (GetExecutionContextRef());
1975 Process *process = exe_ctx.GetProcessPtr();
1976 if (process)
1977 return process->IsPossibleDynamicValue(*this);
1978 else
Greg Clayton57ee3062013-07-11 22:46:58 +00001979 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00001980}
1981
Enrico Granata9e7b3882012-12-13 23:50:33 +00001982bool
1983ValueObject::IsObjCNil ()
1984{
Greg Clayton57ee3062013-07-11 22:46:58 +00001985 const uint32_t mask = ClangASTType::eTypeIsObjC | ClangASTType::eTypeIsPointer;
1986 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00001987 if (!isObjCpointer)
1988 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001989 bool canReadValue = true;
1990 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00001991 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00001992}
1993
Greg Claytonafacd142011-09-02 01:15:17 +00001994ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00001995ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001996{
Greg Clayton2452ab72013-02-08 22:02:02 +00001997 const uint32_t type_info = GetTypeInfo ();
Greg Clayton57ee3062013-07-11 22:46:58 +00001998 if (type_info & ClangASTType::eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001999 return GetSyntheticArrayMemberFromArray(index, can_create);
2000
Greg Clayton57ee3062013-07-11 22:46:58 +00002001 if (type_info & ClangASTType::eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002002 return GetSyntheticArrayMemberFromPointer(index, can_create);
2003
2004 return ValueObjectSP();
2005
2006}
2007
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002008ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002009ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002010{
2011 ValueObjectSP synthetic_child_sp;
2012 if (IsPointerType ())
2013 {
2014 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002015 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002016 ConstString index_const_str(index_str);
2017 // Check if we have already created a synthetic array member in this
2018 // valid object. If we have we will re-use it.
2019 synthetic_child_sp = GetSyntheticChild (index_const_str);
2020 if (!synthetic_child_sp)
2021 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002022 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023 // We haven't made a synthetic array member for INDEX yet, so
2024 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002025 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002026
2027 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002028 if (synthetic_child)
2029 {
2030 AddSyntheticChild(index_const_str, synthetic_child);
2031 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002032 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002033 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002034 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002035 }
2036 }
2037 return synthetic_child_sp;
2038}
Jim Ingham22777012010-09-23 02:01:19 +00002039
Greg Claytondaf515f2011-07-09 20:12:33 +00002040// This allows you to create an array member using and index
2041// that doesn't not fall in the normal bounds of the array.
2042// Many times structure can be defined as:
2043// struct Collection
2044// {
2045// uint32_t item_count;
2046// Item item_array[0];
2047// };
2048// The size of the "item_array" is 1, but many times in practice
2049// there are more items in "item_array".
2050
2051ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002052ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002053{
2054 ValueObjectSP synthetic_child_sp;
2055 if (IsArrayType ())
2056 {
2057 char index_str[64];
Greg Claytonc7bece562013-01-25 18:06:21 +00002058 snprintf(index_str, sizeof(index_str), "[%zu]", index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002059 ConstString index_const_str(index_str);
2060 // Check if we have already created a synthetic array member in this
2061 // valid object. If we have we will re-use it.
2062 synthetic_child_sp = GetSyntheticChild (index_const_str);
2063 if (!synthetic_child_sp)
2064 {
2065 ValueObject *synthetic_child;
2066 // We haven't made a synthetic array member for INDEX yet, so
2067 // lets make one and cache it for any future reference.
2068 synthetic_child = CreateChildAtIndex(0, true, index);
2069
2070 // Cache the value if we got one back...
2071 if (synthetic_child)
2072 {
2073 AddSyntheticChild(index_const_str, synthetic_child);
2074 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002075 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002076 synthetic_child_sp->m_is_array_item_for_pointer = true;
2077 }
2078 }
2079 }
2080 return synthetic_child_sp;
2081}
2082
Enrico Granata9fc19442011-07-06 02:13:41 +00002083ValueObjectSP
2084ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2085{
2086 ValueObjectSP synthetic_child_sp;
2087 if (IsScalarType ())
2088 {
2089 char index_str[64];
2090 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2091 ConstString index_const_str(index_str);
2092 // Check if we have already created a synthetic array member in this
2093 // valid object. If we have we will re-use it.
2094 synthetic_child_sp = GetSyntheticChild (index_const_str);
2095 if (!synthetic_child_sp)
2096 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002097 // We haven't made a synthetic array member for INDEX yet, so
2098 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002099 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2100 GetClangType(),
2101 index_const_str,
2102 GetByteSize(),
2103 0,
2104 to-from+1,
2105 from,
2106 false,
2107 false,
2108 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002109
2110 // Cache the value if we got one back...
2111 if (synthetic_child)
2112 {
2113 AddSyntheticChild(index_const_str, synthetic_child);
2114 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002115 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002116 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2117 }
2118 }
2119 }
2120 return synthetic_child_sp;
2121}
2122
Greg Claytonafacd142011-09-02 01:15:17 +00002123ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002124ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2125{
2126
2127 ValueObjectSP synthetic_child_sp;
2128
2129 char name_str[64];
2130 snprintf(name_str, sizeof(name_str), "@%i", offset);
2131 ConstString name_const_str(name_str);
2132
2133 // Check if we have already created a synthetic array member in this
2134 // valid object. If we have we will re-use it.
2135 synthetic_child_sp = GetSyntheticChild (name_const_str);
2136
2137 if (synthetic_child_sp.get())
2138 return synthetic_child_sp;
2139
2140 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002141 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002142
2143 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002144 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002145 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002146 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002147 offset,
2148 0,
2149 0,
2150 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002151 false,
2152 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002153 if (synthetic_child)
2154 {
2155 AddSyntheticChild(name_const_str, synthetic_child);
2156 synthetic_child_sp = synthetic_child->GetSP();
2157 synthetic_child_sp->SetName(name_const_str);
2158 synthetic_child_sp->m_is_child_at_offset = true;
2159 }
2160 return synthetic_child_sp;
2161}
2162
Enrico Granatad55546b2011-07-22 00:16:08 +00002163// your expression path needs to have a leading . or ->
2164// (unless it somehow "looks like" an array, in which case it has
2165// a leading [ symbol). while the [ is meaningful and should be shown
2166// to the user, . and -> are just parser design, but by no means
2167// added information for the user.. strip them off
2168static const char*
2169SkipLeadingExpressionPathSeparators(const char* expression)
2170{
2171 if (!expression || !expression[0])
2172 return expression;
2173 if (expression[0] == '.')
2174 return expression+1;
2175 if (expression[0] == '-' && expression[1] == '>')
2176 return expression+2;
2177 return expression;
2178}
2179
Greg Claytonafacd142011-09-02 01:15:17 +00002180ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002181ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2182{
2183 ValueObjectSP synthetic_child_sp;
2184 ConstString name_const_string(expression);
2185 // Check if we have already created a synthetic array member in this
2186 // valid object. If we have we will re-use it.
2187 synthetic_child_sp = GetSyntheticChild (name_const_string);
2188 if (!synthetic_child_sp)
2189 {
2190 // We haven't made a synthetic array member for expression yet, so
2191 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002192 synthetic_child_sp = GetValueForExpressionPath(expression,
2193 NULL, NULL, NULL,
2194 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002195
2196 // Cache the value if we got one back...
2197 if (synthetic_child_sp.get())
2198 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002199 // FIXME: this causes a "real" child to end up with its name changed to the contents of expression
Enrico Granatad55546b2011-07-22 00:16:08 +00002200 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002201 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002202 }
2203 }
2204 return synthetic_child_sp;
2205}
2206
2207void
Enrico Granata86cc9822012-03-19 22:58:49 +00002208ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002209{
Enrico Granata86cc9822012-03-19 22:58:49 +00002210 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002211 return;
2212
Enrico Granatac5bc4122012-03-27 02:35:13 +00002213 TargetSP target_sp(GetTargetSP());
2214 if (target_sp && (target_sp->GetEnableSyntheticValue() == false || target_sp->GetSuppressSyntheticValue() == true))
2215 {
2216 m_synthetic_value = NULL;
2217 return;
2218 }
2219
Enrico Granatae3e91512012-10-22 18:18:36 +00002220 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2221
Enrico Granata5548cb52013-01-28 23:47:25 +00002222 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002223 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002224
Enrico Granata0c489f52012-03-01 04:24:26 +00002225 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002226 return;
2227
Enrico Granatae3e91512012-10-22 18:18:36 +00002228 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2229 return;
2230
Enrico Granata86cc9822012-03-19 22:58:49 +00002231 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002232}
2233
Jim Ingham78a685a2011-04-16 00:01:13 +00002234void
Greg Claytonafacd142011-09-02 01:15:17 +00002235ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002236{
Greg Claytonafacd142011-09-02 01:15:17 +00002237 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002238 return;
2239
Jim Ingham58b59f92011-04-22 23:53:53 +00002240 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002241 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002242 ExecutionContext exe_ctx (GetExecutionContextRef());
2243 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002244 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002245 {
2246 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002247 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002248 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002249 }
2250}
2251
Jim Ingham58b59f92011-04-22 23:53:53 +00002252ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002253ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002254{
Greg Claytonafacd142011-09-02 01:15:17 +00002255 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002256 return ValueObjectSP();
2257
2258 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002259 {
Jim Ingham2837b762011-05-04 03:43:18 +00002260 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002261 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002262 if (m_dynamic_value)
2263 return m_dynamic_value->GetSP();
2264 else
2265 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002266}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002267
Jim Ingham60dbabb2011-12-08 19:44:08 +00002268ValueObjectSP
2269ValueObject::GetStaticValue()
2270{
2271 return GetSP();
2272}
2273
Enrico Granata886147f2012-05-08 18:47:08 +00002274lldb::ValueObjectSP
2275ValueObject::GetNonSyntheticValue ()
2276{
2277 return GetSP();
2278}
2279
Enrico Granatad55546b2011-07-22 00:16:08 +00002280ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002281ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002282{
Enrico Granata86cc9822012-03-19 22:58:49 +00002283 if (use_synthetic == false)
2284 return ValueObjectSP();
2285
Enrico Granatad55546b2011-07-22 00:16:08 +00002286 CalculateSyntheticValue(use_synthetic);
2287
2288 if (m_synthetic_value)
2289 return m_synthetic_value->GetSP();
2290 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002291 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002292}
2293
Greg Claytone221f822011-01-21 01:59:00 +00002294bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002295ValueObject::HasSyntheticValue()
2296{
Enrico Granata5548cb52013-01-28 23:47:25 +00002297 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002298
Enrico Granata0c489f52012-03-01 04:24:26 +00002299 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002300 return false;
2301
Enrico Granata86cc9822012-03-19 22:58:49 +00002302 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002303
2304 if (m_synthetic_value)
2305 return true;
2306 else
2307 return false;
2308}
2309
2310bool
Greg Claytone221f822011-01-21 01:59:00 +00002311ValueObject::GetBaseClassPath (Stream &s)
2312{
2313 if (IsBaseClass())
2314 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002315 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002316 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002317 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002318 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002319 if (this_had_base_class)
2320 {
2321 if (parent_had_base_class)
2322 s.PutCString("::");
2323 s.PutCString(cxx_class_name.c_str());
2324 }
2325 return parent_had_base_class || this_had_base_class;
2326 }
2327 return false;
2328}
2329
2330
2331ValueObject *
2332ValueObject::GetNonBaseClassParent()
2333{
Jim Ingham78a685a2011-04-16 00:01:13 +00002334 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002335 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002336 if (GetParent()->IsBaseClass())
2337 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002338 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002339 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002340 }
2341 return NULL;
2342}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002343
2344void
Enrico Granata4becb372011-06-29 22:27:15 +00002345ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002346{
Greg Claytone221f822011-01-21 01:59:00 +00002347 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002348
Enrico Granata86cc9822012-03-19 22:58:49 +00002349 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002350 {
Enrico Granata4becb372011-06-29 22:27:15 +00002351 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2352 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2353 // the eHonorPointers mode is meant to produce strings in this latter format
2354 s.PutCString("*(");
2355 }
Greg Claytone221f822011-01-21 01:59:00 +00002356
Enrico Granata4becb372011-06-29 22:27:15 +00002357 ValueObject* parent = GetParent();
2358
2359 if (parent)
2360 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002361
2362 // if we are a deref_of_parent just because we are synthetic array
2363 // members made up to allow ptr[%d] syntax to work in variable
2364 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002365 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002366 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002367
Greg Claytone221f822011-01-21 01:59:00 +00002368 if (!IsBaseClass())
2369 {
2370 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002371 {
Greg Claytone221f822011-01-21 01:59:00 +00002372 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2373 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002374 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002375 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002376 if (non_base_class_parent_clang_type)
2377 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002378 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002379 {
2380 s.PutCString("->");
2381 }
Enrico Granata4becb372011-06-29 22:27:15 +00002382 else
2383 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002384 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2385
2386 if (non_base_class_parent_type_info & ClangASTType::eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002387 {
2388 s.PutCString("->");
2389 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002390 else if ((non_base_class_parent_type_info & ClangASTType::eTypeHasChildren) &&
2391 !(non_base_class_parent_type_info & ClangASTType::eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002392 {
2393 s.PutChar('.');
2394 }
Greg Claytone221f822011-01-21 01:59:00 +00002395 }
2396 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002397 }
Greg Claytone221f822011-01-21 01:59:00 +00002398
2399 const char *name = GetName().GetCString();
2400 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002401 {
Greg Claytone221f822011-01-21 01:59:00 +00002402 if (qualify_cxx_base_classes)
2403 {
2404 if (GetBaseClassPath (s))
2405 s.PutCString("::");
2406 }
2407 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002408 }
2409 }
2410 }
2411
Enrico Granata86cc9822012-03-19 22:58:49 +00002412 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002413 {
Greg Claytone221f822011-01-21 01:59:00 +00002414 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002415 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002416}
2417
Greg Claytonafacd142011-09-02 01:15:17 +00002418ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002419ValueObject::GetValueForExpressionPath(const char* expression,
2420 const char** first_unparsed,
2421 ExpressionPathScanEndReason* reason_to_stop,
2422 ExpressionPathEndResultType* final_value_type,
2423 const GetValueForExpressionPathOptions& options,
2424 ExpressionPathAftermath* final_task_on_target)
2425{
2426
2427 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002428 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2429 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002430 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002431
2432 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2433 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2434 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2435 final_value_type ? final_value_type : &dummy_final_value_type,
2436 options,
2437 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2438
Enrico Granata86cc9822012-03-19 22:58:49 +00002439 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002440 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002441
Enrico Granata86cc9822012-03-19 22:58:49 +00002442 if (ret_val.get() && ((final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain)) // I can only deref and takeaddress of plain objects
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002443 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002444 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002445 {
2446 Error error;
2447 ValueObjectSP final_value = ret_val->Dereference(error);
2448 if (error.Fail() || !final_value.get())
2449 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002450 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002451 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002452 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002453 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002454 return ValueObjectSP();
2455 }
2456 else
2457 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002458 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002459 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002460 return final_value;
2461 }
2462 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002463 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002464 {
2465 Error error;
2466 ValueObjectSP final_value = ret_val->AddressOf(error);
2467 if (error.Fail() || !final_value.get())
2468 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002469 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002470 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002471 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002472 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002473 return ValueObjectSP();
2474 }
2475 else
2476 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002477 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002478 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002479 return final_value;
2480 }
2481 }
2482 }
2483 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2484}
2485
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002486int
2487ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002488 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002489 const char** first_unparsed,
2490 ExpressionPathScanEndReason* reason_to_stop,
2491 ExpressionPathEndResultType* final_value_type,
2492 const GetValueForExpressionPathOptions& options,
2493 ExpressionPathAftermath* final_task_on_target)
2494{
2495 const char* dummy_first_unparsed;
2496 ExpressionPathScanEndReason dummy_reason_to_stop;
2497 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002498 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002499
2500 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2501 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2502 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2503 final_value_type ? final_value_type : &dummy_final_value_type,
2504 options,
2505 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2506
2507 if (!ret_val.get()) // if there are errors, I add nothing to the list
2508 return 0;
2509
Enrico Granata86ea8d82012-03-29 01:34:34 +00002510 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002511 {
2512 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002513 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002514 {
2515 list->Append(ret_val);
2516 return 1;
2517 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002518 if (ret_val.get() && (final_value_type ? *final_value_type : dummy_final_value_type) == eExpressionPathEndResultTypePlain) // I can only deref and takeaddress of plain objects
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002519 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002520 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002521 {
2522 Error error;
2523 ValueObjectSP final_value = ret_val->Dereference(error);
2524 if (error.Fail() || !final_value.get())
2525 {
Greg Clayton23f59502012-07-17 03:23:13 +00002526 if (reason_to_stop)
2527 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2528 if (final_value_type)
2529 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002530 return 0;
2531 }
2532 else
2533 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002534 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002535 list->Append(final_value);
2536 return 1;
2537 }
2538 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002539 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002540 {
2541 Error error;
2542 ValueObjectSP final_value = ret_val->AddressOf(error);
2543 if (error.Fail() || !final_value.get())
2544 {
Greg Clayton23f59502012-07-17 03:23:13 +00002545 if (reason_to_stop)
2546 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2547 if (final_value_type)
2548 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002549 return 0;
2550 }
2551 else
2552 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002553 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002554 list->Append(final_value);
2555 return 1;
2556 }
2557 }
2558 }
2559 }
2560 else
2561 {
2562 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2563 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2564 ret_val,
2565 list,
2566 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2567 final_value_type ? final_value_type : &dummy_final_value_type,
2568 options,
2569 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2570 }
2571 // in any non-covered case, just do the obviously right thing
2572 list->Append(ret_val);
2573 return 1;
2574}
2575
Greg Claytonafacd142011-09-02 01:15:17 +00002576ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002577ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2578 const char** first_unparsed,
2579 ExpressionPathScanEndReason* reason_to_stop,
2580 ExpressionPathEndResultType* final_result,
2581 const GetValueForExpressionPathOptions& options,
2582 ExpressionPathAftermath* what_next)
2583{
2584 ValueObjectSP root = GetSP();
2585
2586 if (!root.get())
2587 return ValueObjectSP();
2588
2589 *first_unparsed = expression_cstr;
2590
2591 while (true)
2592 {
2593
2594 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2595
Greg Clayton57ee3062013-07-11 22:46:58 +00002596 ClangASTType root_clang_type = root->GetClangType();
2597 ClangASTType pointee_clang_type;
2598 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002599
Greg Clayton57ee3062013-07-11 22:46:58 +00002600 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002601 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002602 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002603
2604 if (!expression_cstr || *expression_cstr == '\0')
2605 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002606 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002607 return root;
2608 }
2609
2610 switch (*expression_cstr)
2611 {
2612 case '-':
2613 {
2614 if (options.m_check_dot_vs_arrow_syntax &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002615 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002616 {
2617 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002618 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2619 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002620 return ValueObjectSP();
2621 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002622 if (root_clang_type_info.Test(ClangASTType::eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2623 root_clang_type_info.Test(ClangASTType::eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002624 options.m_no_fragile_ivar)
2625 {
2626 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002627 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2628 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002629 return ValueObjectSP();
2630 }
2631 if (expression_cstr[1] != '>')
2632 {
2633 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002634 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2635 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002636 return ValueObjectSP();
2637 }
2638 expression_cstr++; // skip the -
2639 }
2640 case '.': // or fallthrough from ->
2641 {
2642 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Greg Clayton57ee3062013-07-11 22:46:58 +00002643 root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 {
2645 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002646 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2647 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002648 return ValueObjectSP();
2649 }
2650 expression_cstr++; // skip .
2651 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2652 ConstString child_name;
2653 if (!next_separator) // if no other separator just expand this last layer
2654 {
2655 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002656 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2657
2658 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002659 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002660 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002661 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2662 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002663 return child_valobj_sp;
2664 }
2665 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2666 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002667 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002668 {
2669 *first_unparsed = expression_cstr;
2670 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2671 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2672 return ValueObjectSP();
2673 }
2674
2675 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002676 if (child_valobj_sp.get())
2677 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002678 }
2679
2680 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2681 // so we hit the "else" branch, and return an error
2682 if(child_valobj_sp.get()) // if it worked, just return
2683 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002684 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002685 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2686 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002687 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002688 }
2689 else
2690 {
2691 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002692 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2693 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002694 return ValueObjectSP();
2695 }
2696 }
2697 else // other layers do expand
2698 {
2699 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002700 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2701 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002702 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002703 root = child_valobj_sp;
2704 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002705 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002706 continue;
2707 }
2708 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2709 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002710 if (root->IsSynthetic())
2711 {
2712 *first_unparsed = expression_cstr;
2713 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2714 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2715 return ValueObjectSP();
2716 }
2717
Enrico Granata86cc9822012-03-19 22:58:49 +00002718 child_valobj_sp = root->GetSyntheticValue(true);
2719 if (child_valobj_sp)
2720 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002721 }
2722
2723 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2724 // so we hit the "else" branch, and return an error
2725 if(child_valobj_sp.get()) // if it worked, move on
2726 {
2727 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002728 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002729 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002730 continue;
2731 }
2732 else
2733 {
2734 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002735 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2736 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002737 return ValueObjectSP();
2738 }
2739 }
2740 break;
2741 }
2742 case '[':
2743 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002744 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && !root_clang_type_info.Test(ClangASTType::eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002745 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002746 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002747 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002748 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2749 {
2750 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002751 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2752 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002753 return ValueObjectSP();
2754 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002755 }
2756 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2757 {
2758 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002759 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2760 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002761 return ValueObjectSP();
2762 }
2763 }
2764 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2765 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002766 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002767 {
2768 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002769 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2770 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002771 return ValueObjectSP();
2772 }
2773 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2774 {
2775 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002776 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2777 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002778 return root;
2779 }
2780 }
2781 const char *separator_position = ::strchr(expression_cstr+1,'-');
2782 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2783 if (!close_bracket_position) // if there is no ], this is a syntax error
2784 {
2785 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002786 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2787 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002788 return ValueObjectSP();
2789 }
2790 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2791 {
2792 char *end = NULL;
2793 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2794 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2795 {
2796 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002797 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2798 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002799 return ValueObjectSP();
2800 }
2801 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2802 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002803 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002804 {
2805 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002806 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2807 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002808 return root;
2809 }
2810 else
2811 {
2812 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002813 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2814 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002815 return ValueObjectSP();
2816 }
2817 }
2818 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00002819 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002820 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002821 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2822 if (!child_valobj_sp)
2823 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002824 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002825 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2826 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002827 if (child_valobj_sp)
2828 {
2829 root = child_valobj_sp;
2830 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002831 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002832 continue;
2833 }
2834 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002835 {
2836 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002837 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2838 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002839 return ValueObjectSP();
2840 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002841 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002842 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002843 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002844 if (*what_next == ValueObject::eExpressionPathAftermathDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
Greg Clayton57ee3062013-07-11 22:46:58 +00002845 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002846 {
2847 Error error;
2848 root = root->Dereference(error);
2849 if (error.Fail() || !root.get())
2850 {
2851 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002852 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2853 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002854 return ValueObjectSP();
2855 }
2856 else
2857 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002858 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002859 continue;
2860 }
2861 }
2862 else
2863 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002864 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
2865 && pointee_clang_type_info.AllClear(ClangASTType::eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00002866 && root->HasSyntheticValue()
2867 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002868 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002869 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002870 }
2871 else
2872 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002873 if (!root.get())
2874 {
2875 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002876 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2877 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002878 return ValueObjectSP();
2879 }
2880 else
2881 {
2882 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002884 continue;
2885 }
2886 }
2887 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002888 else if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002889 {
2890 root = root->GetSyntheticBitFieldChild(index, index, true);
2891 if (!root.get())
2892 {
2893 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002894 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2895 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002896 return ValueObjectSP();
2897 }
2898 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
2899 {
2900 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002901 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
2902 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002903 return root;
2904 }
2905 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002906 else if (root_clang_type_info.Test(ClangASTType::eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00002907 {
2908 root = root->GetChildAtIndex(index, true);
2909 if (!root.get())
2910 {
2911 *first_unparsed = expression_cstr;
2912 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2913 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2914 return ValueObjectSP();
2915 }
2916 else
2917 {
2918 *first_unparsed = end+1; // skip ]
2919 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
2920 continue;
2921 }
2922 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002923 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00002924 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002925 if (root->HasSyntheticValue())
2926 root = root->GetSyntheticValue();
2927 else if (!root->IsSynthetic())
2928 {
2929 *first_unparsed = expression_cstr;
2930 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2931 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2932 return ValueObjectSP();
2933 }
2934 // if we are here, then root itself is a synthetic VO.. should be good to go
2935
Enrico Granata27b625e2011-08-09 01:04:56 +00002936 if (!root.get())
2937 {
2938 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002939 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
2940 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2941 return ValueObjectSP();
2942 }
2943 root = root->GetChildAtIndex(index, true);
2944 if (!root.get())
2945 {
2946 *first_unparsed = expression_cstr;
2947 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2948 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002949 return ValueObjectSP();
2950 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00002951 else
2952 {
2953 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002954 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002955 continue;
2956 }
Enrico Granata27b625e2011-08-09 01:04:56 +00002957 }
2958 else
2959 {
2960 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002961 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2962 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002963 return ValueObjectSP();
2964 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002965 }
2966 else // we have a low and a high index
2967 {
2968 char *end = NULL;
2969 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
2970 if (!end || end != separator_position) // if something weird is in our way return an error
2971 {
2972 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002973 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2974 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002975 return ValueObjectSP();
2976 }
2977 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
2978 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2979 {
2980 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002981 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2982 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002983 return ValueObjectSP();
2984 }
2985 if (index_lower > index_higher) // swap indices if required
2986 {
2987 unsigned long temp = index_lower;
2988 index_lower = index_higher;
2989 index_higher = temp;
2990 }
Greg Clayton57ee3062013-07-11 22:46:58 +00002991 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002992 {
2993 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
2994 if (!root.get())
2995 {
2996 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002997 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2998 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002999 return ValueObjectSP();
3000 }
3001 else
3002 {
3003 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003004 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3005 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003006 return root;
3007 }
3008 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003009 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
Enrico Granata86cc9822012-03-19 22:58:49 +00003010 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003011 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003012 {
3013 Error error;
3014 root = root->Dereference(error);
3015 if (error.Fail() || !root.get())
3016 {
3017 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003018 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3019 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003020 return ValueObjectSP();
3021 }
3022 else
3023 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003024 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003025 continue;
3026 }
3027 }
3028 else
3029 {
3030 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003031 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3032 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003033 return root;
3034 }
3035 }
3036 break;
3037 }
3038 default: // some non-separator is in the way
3039 {
3040 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003041 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3042 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003043 return ValueObjectSP();
3044 break;
3045 }
3046 }
3047 }
3048}
3049
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003050int
3051ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3052 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003053 ValueObjectSP root,
3054 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003055 ExpressionPathScanEndReason* reason_to_stop,
3056 ExpressionPathEndResultType* final_result,
3057 const GetValueForExpressionPathOptions& options,
3058 ExpressionPathAftermath* what_next)
3059{
3060 if (!root.get())
3061 return 0;
3062
3063 *first_unparsed = expression_cstr;
3064
3065 while (true)
3066 {
3067
3068 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3069
Greg Clayton57ee3062013-07-11 22:46:58 +00003070 ClangASTType root_clang_type = root->GetClangType();
3071 ClangASTType pointee_clang_type;
3072 Flags pointee_clang_type_info;
3073 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003074 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003075 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003076
3077 if (!expression_cstr || *expression_cstr == '\0')
3078 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003079 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003080 list->Append(root);
3081 return 1;
3082 }
3083
3084 switch (*expression_cstr)
3085 {
3086 case '[':
3087 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003088 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray) && !root_clang_type_info.Test(ClangASTType::eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003089 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003090 if (!root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003091 {
3092 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003093 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3094 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003095 return 0;
3096 }
3097 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3098 {
3099 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003100 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3101 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003102 return 0;
3103 }
3104 }
3105 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3106 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003107 if (!root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003108 {
3109 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003110 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3111 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003112 return 0;
3113 }
3114 else // expand this into list
3115 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003116 const size_t max_index = root->GetNumChildren() - 1;
3117 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003118 {
3119 ValueObjectSP child =
3120 root->GetChildAtIndex(index, true);
3121 list->Append(child);
3122 }
3123 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003124 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3125 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003126 return max_index; // tell me number of items I added to the VOList
3127 }
3128 }
3129 const char *separator_position = ::strchr(expression_cstr+1,'-');
3130 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3131 if (!close_bracket_position) // if there is no ], this is a syntax error
3132 {
3133 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003134 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3135 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003136 return 0;
3137 }
3138 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3139 {
3140 char *end = NULL;
3141 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3142 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3143 {
3144 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003145 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3146 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003147 return 0;
3148 }
3149 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3150 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003151 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003152 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003153 const size_t max_index = root->GetNumChildren() - 1;
3154 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003155 {
3156 ValueObjectSP child =
3157 root->GetChildAtIndex(index, true);
3158 list->Append(child);
3159 }
3160 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003161 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3162 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003163 return max_index; // tell me number of items I added to the VOList
3164 }
3165 else
3166 {
3167 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003168 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3169 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003170 return 0;
3171 }
3172 }
3173 // from here on we do have a valid index
Greg Clayton57ee3062013-07-11 22:46:58 +00003174 if (root_clang_type_info.Test(ClangASTType::eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003175 {
3176 root = root->GetChildAtIndex(index, true);
3177 if (!root.get())
3178 {
3179 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003180 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3181 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003182 return 0;
3183 }
3184 else
3185 {
3186 list->Append(root);
3187 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003188 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3189 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003190 return 1;
3191 }
3192 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003193 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003194 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003195 if (*what_next == ValueObject::eExpressionPathAftermathDereference && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
Greg Clayton57ee3062013-07-11 22:46:58 +00003196 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003197 {
3198 Error error;
3199 root = root->Dereference(error);
3200 if (error.Fail() || !root.get())
3201 {
3202 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003203 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3204 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003205 return 0;
3206 }
3207 else
3208 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003209 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003210 continue;
3211 }
3212 }
3213 else
3214 {
3215 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3216 if (!root.get())
3217 {
3218 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003219 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3220 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003221 return 0;
3222 }
3223 else
3224 {
3225 list->Append(root);
3226 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003227 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3228 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003229 return 1;
3230 }
3231 }
3232 }
3233 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3234 {
3235 root = root->GetSyntheticBitFieldChild(index, index, true);
3236 if (!root.get())
3237 {
3238 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003239 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3240 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003241 return 0;
3242 }
3243 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3244 {
3245 list->Append(root);
3246 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003247 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3248 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003249 return 1;
3250 }
3251 }
3252 }
3253 else // we have a low and a high index
3254 {
3255 char *end = NULL;
3256 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3257 if (!end || end != separator_position) // if something weird is in our way return an error
3258 {
3259 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003260 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3261 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003262 return 0;
3263 }
3264 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3265 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3266 {
3267 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003268 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3269 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003270 return 0;
3271 }
3272 if (index_lower > index_higher) // swap indices if required
3273 {
3274 unsigned long temp = index_lower;
3275 index_lower = index_higher;
3276 index_higher = temp;
3277 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003278 if (root_clang_type_info.Test(ClangASTType::eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003279 {
3280 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3281 if (!root.get())
3282 {
3283 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003284 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3285 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003286 return 0;
3287 }
3288 else
3289 {
3290 list->Append(root);
3291 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003292 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3293 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003294 return 1;
3295 }
3296 }
Greg Clayton57ee3062013-07-11 22:46:58 +00003297 else if (root_clang_type_info.Test(ClangASTType::eTypeIsPointer) && // if this is a ptr-to-scalar, I am accessing it by index and I would have deref'ed anyway, then do it now and use this as a bitfield
Enrico Granata86cc9822012-03-19 22:58:49 +00003298 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Greg Clayton57ee3062013-07-11 22:46:58 +00003299 pointee_clang_type_info.Test(ClangASTType::eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003300 {
3301 Error error;
3302 root = root->Dereference(error);
3303 if (error.Fail() || !root.get())
3304 {
3305 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003306 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3307 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003308 return 0;
3309 }
3310 else
3311 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003312 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003313 continue;
3314 }
3315 }
3316 else
3317 {
Johnny Chen44805302011-07-19 19:48:13 +00003318 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003319 index <= index_higher; index++)
3320 {
3321 ValueObjectSP child =
3322 root->GetChildAtIndex(index, true);
3323 list->Append(child);
3324 }
3325 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003326 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3327 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003328 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3329 }
3330 }
3331 break;
3332 }
3333 default: // some non-[ separator, or something entirely wrong, is in the way
3334 {
3335 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003336 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3337 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003338 return 0;
3339 break;
3340 }
3341 }
3342 }
3343}
3344
Enrico Granata0c489f52012-03-01 04:24:26 +00003345static void
3346DumpValueObject_Impl (Stream &s,
3347 ValueObject *valobj,
3348 const ValueObject::DumpValueObjectOptions& options,
3349 uint32_t ptr_depth,
3350 uint32_t curr_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003351{
Greg Clayton007d5be2011-05-30 00:49:24 +00003352 if (valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003353 {
Enrico Granata5548cb52013-01-28 23:47:25 +00003354 bool update_success = valobj->UpdateValueIfNeeded (true);
Greg Clayton007d5be2011-05-30 00:49:24 +00003355
Enrico Granata0c489f52012-03-01 04:24:26 +00003356 const char *root_valobj_name =
3357 options.m_root_valobj_name.empty() ?
3358 valobj->GetName().AsCString() :
3359 options.m_root_valobj_name.c_str();
3360
3361 if (update_success && options.m_use_dynamic != eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:13 +00003362 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003363 ValueObject *dynamic_value = valobj->GetDynamicValue(options.m_use_dynamic).get();
Jim Ingham78a685a2011-04-16 00:01:13 +00003364 if (dynamic_value)
3365 valobj = dynamic_value;
3366 }
3367
Greg Clayton57ee3062013-07-11 22:46:58 +00003368 ClangASTType clang_type = valobj->GetClangType();
3369 const Flags type_flags (clang_type.GetTypeInfo ());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003370 const char *err_cstr = NULL;
Greg Clayton57ee3062013-07-11 22:46:58 +00003371 const bool has_children = type_flags.Test (ClangASTType::eTypeHasChildren);
3372 const bool has_value = type_flags.Test (ClangASTType::eTypeHasValue);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003373
Enrico Granata0c489f52012-03-01 04:24:26 +00003374 const bool print_valobj = options.m_flat_output == false || has_value;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003375
3376 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003377 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003378 if (options.m_show_location)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003379 {
Jim Ingham6035b672011-03-31 00:19:25 +00003380 s.Printf("%s: ", valobj->GetLocationAsCString());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003381 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003382
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003383 s.Indent();
Enrico Granata2b2631c2012-08-09 16:51:25 +00003384
3385 bool show_type = true;
3386 // if we are at the root-level and been asked to hide the root's type, then hide it
3387 if (curr_depth == 0 && options.m_hide_root_type)
3388 show_type = false;
3389 else
3390 // otherwise decide according to the usual rules (asked to show types - always at the root level)
3391 show_type = options.m_show_types || (curr_depth == 0 && !options.m_flat_output);
3392
3393 if (show_type)
Greg Clayton0fa5c972013-04-25 01:05:15 +00003394 {
3395 // Some ValueObjects don't have types (like registers sets). Only print
3396 // the type if there is one to print
3397 ConstString qualified_type_name(valobj->GetQualifiedTypeName());
3398 if (qualified_type_name)
3399 s.Printf("(%s) ", qualified_type_name.GetCString());
3400 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003401
Enrico Granata0c489f52012-03-01 04:24:26 +00003402 if (options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003403 {
Greg Clayton6beaaa62011-01-17 03:46:26 +00003404 // If we are showing types, also qualify the C++ base classes
Enrico Granata0c489f52012-03-01 04:24:26 +00003405 const bool qualify_cxx_base_classes = options.m_show_types;
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003406 if (!options.m_hide_name)
3407 {
3408 valobj->GetExpressionPath(s, qualify_cxx_base_classes);
3409 s.PutCString(" =");
3410 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003411 }
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003412 else if (!options.m_hide_name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003413 {
3414 const char *name_cstr = root_valobj_name ? root_valobj_name : valobj->GetName().AsCString("");
3415 s.Printf ("%s =", name_cstr);
3416 }
3417
Enrico Granata0c489f52012-03-01 04:24:26 +00003418 if (!options.m_scope_already_checked && !valobj->IsInScope())
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003419 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003420 err_cstr = "out of scope";
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003421 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003422 }
3423
Enrico Granata0c489f52012-03-01 04:24:26 +00003424 std::string summary_str;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003425 std::string value_str;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003426 const char *val_cstr = NULL;
Enrico Granata4becb372011-06-29 22:27:15 +00003427 const char *sum_cstr = NULL;
Enrico Granata0c489f52012-03-01 04:24:26 +00003428 TypeSummaryImpl* entry = options.m_summary_sp ? options.m_summary_sp.get() : valobj->GetSummaryFormat().get();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003429
Enrico Granata0c489f52012-03-01 04:24:26 +00003430 if (options.m_omit_summary_depth > 0)
Enrico Granata0c5ef692011-07-16 01:22:04 +00003431 entry = NULL;
3432
Enrico Granata9e7b3882012-12-13 23:50:33 +00003433 bool is_nil = valobj->IsObjCNil();
3434
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003435 if (err_cstr == NULL)
3436 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003437 if (options.m_format != eFormatDefault && options.m_format != valobj->GetFormat())
Greg Clayton6efba4f2012-01-26 21:08:30 +00003438 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003439 valobj->GetValueAsCString(options.m_format,
3440 value_str);
Greg Clayton6efba4f2012-01-26 21:08:30 +00003441 }
Enrico Granata0c489f52012-03-01 04:24:26 +00003442 else
Greg Clayton6efba4f2012-01-26 21:08:30 +00003443 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003444 val_cstr = valobj->GetValueAsCString();
3445 if (val_cstr)
3446 value_str = val_cstr;
Greg Clayton6efba4f2012-01-26 21:08:30 +00003447 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003448 err_cstr = valobj->GetError().AsCString();
3449 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003450
3451 if (err_cstr)
3452 {
Greg Clayton007d5be2011-05-30 00:49:24 +00003453 s.Printf (" <%s>\n", err_cstr);
Greg Clayton1d3afba2010-10-05 00:00:42 +00003454 }
3455 else
3456 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003457 const bool is_ref = type_flags.Test (ClangASTType::eTypeIsReference);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003458 if (print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003459 {
Enrico Granata9e7b3882012-12-13 23:50:33 +00003460 if (is_nil)
3461 sum_cstr = "nil";
3462 else if (options.m_omit_summary_depth == 0)
Enrico Granata0c489f52012-03-01 04:24:26 +00003463 {
3464 if (options.m_summary_sp)
3465 {
3466 valobj->GetSummaryAsCString(entry, summary_str);
3467 sum_cstr = summary_str.c_str();
3468 }
3469 else
3470 sum_cstr = valobj->GetSummaryAsCString();
3471 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003472
Greg Clayton6efba4f2012-01-26 21:08:30 +00003473 // Make sure we have a value and make sure the summary didn't
Enrico Granata9e7b3882012-12-13 23:50:33 +00003474 // specify that the value should not be printed - and do not print
3475 // the value if this thing is nil
Enrico Granatac2a58d72013-03-25 19:46:48 +00003476 // (but show the value if the user passes a format explicitly)
3477 if (!is_nil && !value_str.empty() && (entry == NULL || (entry->DoesPrintValue() || options.m_format != eFormatDefault) || sum_cstr == NULL) && !options.m_hide_value)
Greg Clayton6efba4f2012-01-26 21:08:30 +00003478 s.Printf(" %s", value_str.c_str());
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003479
Enrico Granata9dd75c82011-07-15 23:30:15 +00003480 if (sum_cstr)
Enrico Granata0c489f52012-03-01 04:24:26 +00003481 s.Printf(" %s", sum_cstr);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003482
Enrico Granata9e7b3882012-12-13 23:50:33 +00003483 // let's avoid the overly verbose no description error for a nil thing
3484 if (options.m_use_objc && !is_nil)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003485 {
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003486 if (!options.m_hide_value || !options.m_hide_name)
3487 s.Printf(" ");
Jim Ingham6035b672011-03-31 00:19:25 +00003488 const char *object_desc = valobj->GetObjectDescription();
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003489 if (object_desc)
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003490 s.Printf("%s\n", object_desc);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003491 else
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003492 s.Printf ("[no Objective-C description available]\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003493 return;
Enrico Granata0a3958e2011-07-02 00:25:22 +00003494 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003495 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003496
Enrico Granata0c489f52012-03-01 04:24:26 +00003497 if (curr_depth < options.m_max_depth)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003498 {
Greg Clayton73b472d2010-10-27 03:32:59 +00003499 // We will show children for all concrete types. We won't show
3500 // pointer contents unless a pointer depth has been specified.
3501 // We won't reference contents unless the reference is the
3502 // root object (depth of zero).
3503 bool print_children = true;
3504
3505 // Use a new temporary pointer depth in case we override the
3506 // current pointer depth below...
3507 uint32_t curr_ptr_depth = ptr_depth;
3508
Greg Clayton57ee3062013-07-11 22:46:58 +00003509 const bool is_ptr = type_flags.Test (ClangASTType::eTypeIsPointer);
Greg Clayton73b472d2010-10-27 03:32:59 +00003510 if (is_ptr || is_ref)
3511 {
3512 // We have a pointer or reference whose value is an address.
3513 // Make sure that address is not NULL
Greg Claytone0d378b2011-03-24 21:19:54 +00003514 AddressType ptr_address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003515 if (valobj->GetPointerValue (&ptr_address_type) == 0)
Greg Clayton73b472d2010-10-27 03:32:59 +00003516 print_children = false;
3517
3518 else if (is_ref && curr_depth == 0)
3519 {
3520 // If this is the root object (depth is zero) that we are showing
3521 // and it is a reference, and no pointer depth has been supplied
3522 // print out what it references. Don't do this at deeper depths
3523 // otherwise we can end up with infinite recursion...
3524 curr_ptr_depth = 1;
3525 }
3526
3527 if (curr_ptr_depth == 0)
3528 print_children = false;
3529 }
Greg Clayton1d3afba2010-10-05 00:00:42 +00003530
Enrico Granata0a3958e2011-07-02 00:25:22 +00003531 if (print_children && (!entry || entry->DoesPrintChildren() || !sum_cstr))
Greg Clayton1d3afba2010-10-05 00:00:42 +00003532 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003533 ValueObjectSP synth_valobj_sp = valobj->GetSyntheticValue (options.m_use_synthetic);
Greg Clayton0fa5c972013-04-25 01:05:15 +00003534 ValueObject* synth_valobj = (synth_valobj_sp ? synth_valobj_sp.get() : valobj);
Enrico Granatac5bc4122012-03-27 02:35:13 +00003535
Greg Claytonc7bece562013-01-25 18:06:21 +00003536 size_t num_children = synth_valobj->GetNumChildren();
Enrico Granata22c55d12011-08-12 02:00:06 +00003537 bool print_dotdotdot = false;
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003538 if (num_children)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003539 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003540 if (options.m_flat_output)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003541 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003542 if (print_valobj)
3543 s.EOL();
3544 }
3545 else
3546 {
3547 if (print_valobj)
Greg Clayton93aa84e2010-10-29 04:59:35 +00003548 s.PutCString(is_ref ? ": {\n" : " {\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003549 s.IndentMore();
3550 }
Enrico Granata22c55d12011-08-12 02:00:06 +00003551
Greg Claytonc7bece562013-01-25 18:06:21 +00003552 const size_t max_num_children = valobj->GetTargetSP()->GetMaximumNumberOfChildrenToDisplay();
Enrico Granata22c55d12011-08-12 02:00:06 +00003553
Enrico Granata0c489f52012-03-01 04:24:26 +00003554 if (num_children > max_num_children && !options.m_ignore_cap)
Enrico Granata22c55d12011-08-12 02:00:06 +00003555 {
3556 num_children = max_num_children;
3557 print_dotdotdot = true;
3558 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003559
Enrico Granata0c489f52012-03-01 04:24:26 +00003560 ValueObject::DumpValueObjectOptions child_options(options);
Enrico Granatac953a6a2012-12-11 02:17:22 +00003561 child_options.SetFormat(options.m_format).SetSummary().SetRootValueObjectName();
Enrico Granata9a31ccb2013-01-29 01:35:01 +00003562 child_options.SetScopeChecked(true).SetHideName(options.m_hide_name).SetHideValue(options.m_hide_value)
Enrico Granata0c489f52012-03-01 04:24:26 +00003563 .SetOmitSummaryDepth(child_options.m_omit_summary_depth > 1 ? child_options.m_omit_summary_depth - 1 : 0);
Greg Claytonc7bece562013-01-25 18:06:21 +00003564 for (size_t idx=0; idx<num_children; ++idx)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003565 {
Enrico Granatac482a192011-08-17 22:13:59 +00003566 ValueObjectSP child_sp(synth_valobj->GetChildAtIndex(idx, true));
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003567 if (child_sp.get())
3568 {
Enrico Granata0c489f52012-03-01 04:24:26 +00003569 DumpValueObject_Impl (s,
3570 child_sp.get(),
3571 child_options,
3572 (is_ptr || is_ref) ? curr_ptr_depth - 1 : curr_ptr_depth,
3573 curr_depth + 1);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003574 }
3575 }
3576
Enrico Granata0c489f52012-03-01 04:24:26 +00003577 if (!options.m_flat_output)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003578 {
Enrico Granata22c55d12011-08-12 02:00:06 +00003579 if (print_dotdotdot)
Enrico Granata61a80ba2011-08-12 16:42:31 +00003580 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003581 ExecutionContext exe_ctx (valobj->GetExecutionContextRef());
3582 Target *target = exe_ctx.GetTargetPtr();
3583 if (target)
3584 target->GetDebugger().GetCommandInterpreter().ChildrenTruncated();
Enrico Granata22c55d12011-08-12 02:00:06 +00003585 s.Indent("...\n");
Enrico Granata61a80ba2011-08-12 16:42:31 +00003586 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003587 s.IndentLess();
3588 s.Indent("}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003589 }
3590 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003591 else if (has_children)
3592 {
3593 // Aggregate, no children...
3594 if (print_valobj)
Greg Clayton73b472d2010-10-27 03:32:59 +00003595 s.PutCString(" {}\n");
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003596 }
3597 else
3598 {
3599 if (print_valobj)
3600 s.EOL();
3601 }
3602
Greg Clayton1d3afba2010-10-05 00:00:42 +00003603 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003604 else
3605 {
Greg Clayton1d3afba2010-10-05 00:00:42 +00003606 s.EOL();
Greg Clayton1d3afba2010-10-05 00:00:42 +00003607 }
3608 }
3609 else
3610 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003611 if (has_children && print_valobj)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003612 {
Greg Clayton8f92f0a2010-10-14 22:52:14 +00003613 s.PutCString("{...}\n");
Greg Clayton1d3afba2010-10-05 00:00:42 +00003614 }
3615 }
3616 }
3617 }
3618}
3619
Enrico Granata0c489f52012-03-01 04:24:26 +00003620void
Greg Claytonf830dbb2012-03-22 18:15:37 +00003621ValueObject::LogValueObject (Log *log,
3622 ValueObject *valobj)
3623{
3624 if (log && valobj)
3625 return LogValueObject (log, valobj, DumpValueObjectOptions::DefaultOptions());
3626}
3627
3628void
3629ValueObject::LogValueObject (Log *log,
3630 ValueObject *valobj,
3631 const DumpValueObjectOptions& options)
3632{
3633 if (log && valobj)
3634 {
3635 StreamString s;
3636 ValueObject::DumpValueObject (s, valobj, options);
3637 if (s.GetSize())
3638 log->PutCString(s.GetData());
3639 }
3640}
3641
3642void
Enrico Granata0c489f52012-03-01 04:24:26 +00003643ValueObject::DumpValueObject (Stream &s,
3644 ValueObject *valobj)
3645{
3646
3647 if (!valobj)
3648 return;
3649
3650 DumpValueObject_Impl(s,
3651 valobj,
3652 DumpValueObjectOptions::DefaultOptions(),
3653 0,
3654 0);
3655}
3656
3657void
3658ValueObject::DumpValueObject (Stream &s,
3659 ValueObject *valobj,
3660 const DumpValueObjectOptions& options)
3661{
3662 DumpValueObject_Impl(s,
3663 valobj,
3664 options,
3665 options.m_max_ptr_depth, // max pointer depth allowed, we will go down from here
3666 0 // current object depth is 0 since we are just starting
3667 );
3668}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003669
3670ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003671ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003672{
3673 ValueObjectSP valobj_sp;
3674
Enrico Granatac3e320a2011-08-02 17:27:39 +00003675 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003676 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003677 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003678
3679 DataExtractor data;
3680 data.SetByteOrder (m_data.GetByteOrder());
3681 data.SetAddressByteSize(m_data.GetAddressByteSize());
3682
Enrico Granata9f1e2042012-04-24 22:15:37 +00003683 if (IsBitfield())
3684 {
3685 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003686 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003687 }
3688 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003689 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003690
3691 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003692 GetClangType(),
3693 name,
3694 data,
3695 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003696 }
Jim Ingham6035b672011-03-31 00:19:25 +00003697
3698 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003699 {
Jim Ingham58b59f92011-04-22 23:53:53 +00003700 valobj_sp = ValueObjectConstResult::Create (NULL, m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003701 }
3702 return valobj_sp;
3703}
3704
Greg Claytonafacd142011-09-02 01:15:17 +00003705ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003706ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003707{
Jim Ingham58b59f92011-04-22 23:53:53 +00003708 if (m_deref_valobj)
3709 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003710
Greg Clayton54979cd2010-12-15 05:08:08 +00003711 const bool is_pointer_type = IsPointerType();
3712 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003713 {
3714 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003715 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003716
3717 std::string child_name_str;
3718 uint32_t child_byte_size = 0;
3719 int32_t child_byte_offset = 0;
3720 uint32_t child_bitfield_bit_size = 0;
3721 uint32_t child_bitfield_bit_offset = 0;
3722 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003723 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003724 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003725 ClangASTType clang_type = GetClangType();
3726 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003727
Greg Claytoncc4d0142012-02-17 07:49:44 +00003728 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003729
Greg Clayton57ee3062013-07-11 22:46:58 +00003730 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
3731 GetName().GetCString(),
3732 0,
3733 transparent_pointers,
3734 omit_empty_base_classes,
3735 ignore_array_bounds,
3736 child_name_str,
3737 child_byte_size,
3738 child_byte_offset,
3739 child_bitfield_bit_size,
3740 child_bitfield_bit_offset,
3741 child_is_base_class,
3742 child_is_deref_of_parent);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003743 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003744 {
3745 ConstString child_name;
3746 if (!child_name_str.empty())
3747 child_name.SetCString (child_name_str.c_str());
3748
Jim Ingham58b59f92011-04-22 23:53:53 +00003749 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003750 child_clang_type,
3751 child_name,
3752 child_byte_size,
3753 child_byte_offset,
3754 child_bitfield_bit_size,
3755 child_bitfield_bit_offset,
3756 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003757 child_is_deref_of_parent,
3758 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003759 }
3760 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003761
Jim Ingham58b59f92011-04-22 23:53:53 +00003762 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003763 {
3764 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003765 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003766 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003767 else
3768 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003769 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003770 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003771
3772 if (is_pointer_type)
3773 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3774 else
3775 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003776 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003777 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003778}
3779
Greg Claytonafacd142011-09-02 01:15:17 +00003780ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003781ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003782{
Jim Ingham78a685a2011-04-16 00:01:13 +00003783 if (m_addr_of_valobj_sp)
3784 return m_addr_of_valobj_sp;
3785
Greg Claytone0d378b2011-03-24 21:19:54 +00003786 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003787 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003788 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003789 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003790 if (addr != LLDB_INVALID_ADDRESS)
3791 {
3792 switch (address_type)
3793 {
3794 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003795 {
3796 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003797 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003798 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3799 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003800 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003801
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003802 case eAddressTypeFile:
3803 case eAddressTypeLoad:
3804 case eAddressTypeHost:
3805 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003806 ClangASTType clang_type = GetClangType();
3807 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003808 {
3809 std::string name (1, '&');
3810 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003811 ExecutionContext exe_ctx (GetExecutionContextRef());
3812 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003813 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003814 ConstString (name.c_str()),
3815 addr,
3816 eAddressTypeInvalid,
3817 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003818 }
3819 }
3820 break;
3821 }
3822 }
Sean Callananed185ab2013-04-19 19:47:32 +00003823 else
3824 {
3825 StreamString expr_path_strm;
3826 GetExpressionPath(expr_path_strm, true);
3827 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3828 }
3829
Jim Ingham78a685a2011-04-16 00:01:13 +00003830 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003831}
3832
Greg Clayton9a142cf2012-02-03 05:34:10 +00003833ValueObjectSP
3834ValueObject::Cast (const ClangASTType &clang_ast_type)
3835{
Greg Clayton81e871e2012-02-04 02:27:34 +00003836 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003837}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003838
Greg Claytonafacd142011-09-02 01:15:17 +00003839ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003840ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3841{
Greg Claytonafacd142011-09-02 01:15:17 +00003842 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003843 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003844 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003845
3846 if (ptr_value != LLDB_INVALID_ADDRESS)
3847 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003848 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003849 ExecutionContext exe_ctx (GetExecutionContextRef());
3850 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003851 name,
3852 ptr_addr,
3853 clang_ast_type);
3854 }
3855 return valobj_sp;
3856}
3857
Greg Claytonafacd142011-09-02 01:15:17 +00003858ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003859ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3860{
Greg Claytonafacd142011-09-02 01:15:17 +00003861 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003862 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003863 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003864
3865 if (ptr_value != LLDB_INVALID_ADDRESS)
3866 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003867 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003868 ExecutionContext exe_ctx (GetExecutionContextRef());
3869 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003870 name,
3871 ptr_addr,
3872 type_sp);
3873 }
3874 return valobj_sp;
3875}
3876
Jim Ingham6035b672011-03-31 00:19:25 +00003877ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003878 m_mod_id(),
3879 m_exe_ctx_ref(),
3880 m_needs_update (true),
3881 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003882{
3883}
3884
3885ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003886 m_mod_id(),
3887 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003888 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003889 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003890{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003891 ExecutionContext exe_ctx(exe_scope);
3892 TargetSP target_sp (exe_ctx.GetTargetSP());
3893 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003894 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003895 m_exe_ctx_ref.SetTargetSP (target_sp);
3896 ProcessSP process_sp (exe_ctx.GetProcessSP());
3897 if (!process_sp)
3898 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003899
Greg Claytoncc4d0142012-02-17 07:49:44 +00003900 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003901 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003902 m_mod_id = process_sp->GetModID();
3903 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003904
Greg Claytoncc4d0142012-02-17 07:49:44 +00003905 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003906
Greg Claytoncc4d0142012-02-17 07:49:44 +00003907 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003908 {
3909 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003910 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003911 }
Jim Ingham6035b672011-03-31 00:19:25 +00003912
Greg Claytoncc4d0142012-02-17 07:49:44 +00003913 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003914 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003915 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003916
Greg Claytoncc4d0142012-02-17 07:49:44 +00003917 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
3918 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003919 {
3920 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003921 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003922 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003923 if (frame_sp)
3924 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003925 }
3926 }
3927 }
Jim Ingham6035b672011-03-31 00:19:25 +00003928}
3929
3930ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003931 m_mod_id(),
3932 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3933 m_needs_update (true),
3934 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003935{
3936}
3937
3938ValueObject::EvaluationPoint::~EvaluationPoint ()
3939{
3940}
3941
Jim Ingham6035b672011-03-31 00:19:25 +00003942// This function checks the EvaluationPoint against the current process state. If the current
3943// state matches the evaluation point, or the evaluation point is already invalid, then we return
3944// false, meaning "no change". If the current state is different, we update our state, and return
3945// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3946// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003947// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003948
3949bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003950ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003951{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003952
3953 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003954 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock());
Jim Ingham73ca05a2011-12-17 01:35:57 +00003955
Greg Claytoncc4d0142012-02-17 07:49:44 +00003956 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003957 return false;
3958
Jim Ingham6035b672011-03-31 00:19:25 +00003959 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003960 Process *process = exe_ctx.GetProcessPtr();
3961 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003962 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003963
Jim Ingham6035b672011-03-31 00:19:25 +00003964 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003966
Jim Ingham78a685a2011-04-16 00:01:13 +00003967 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3968 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003969 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003970 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003971
Greg Clayton23f59502012-07-17 03:23:13 +00003972 bool changed = false;
3973 const bool was_valid = m_mod_id.IsValid();
3974 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003975 {
3976 if (m_mod_id == current_mod_id)
3977 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003978 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003979 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003980 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003981 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003982 else
3983 {
3984 m_mod_id = current_mod_id;
3985 m_needs_update = true;
3986 changed = true;
3987 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003988 }
Jim Ingham6035b672011-03-31 00:19:25 +00003989
Jim Ingham73ca05a2011-12-17 01:35:57 +00003990 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3991 // That way we'll be sure to return a valid exe_scope.
3992 // If we used to have a thread or a frame but can't find it anymore, then mark ourselves as invalid.
Jim Ingham6035b672011-03-31 00:19:25 +00003993
Greg Claytoncc4d0142012-02-17 07:49:44 +00003994 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003995 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003996 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3997 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003998 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003999 if (m_exe_ctx_ref.HasFrameRef())
4000 {
4001 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
4002 if (!frame_sp)
4003 {
4004 // We used to have a frame, but now it is gone
4005 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004006 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00004007 }
4008 }
Greg Clayton262f80d2011-07-06 16:49:27 +00004009 }
Jim Ingham6035b672011-03-31 00:19:25 +00004010 else
4011 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00004012 // We used to have a thread, but now it is gone
4013 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00004014 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00004015 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00004016
Jim Ingham6035b672011-03-31 00:19:25 +00004017 }
Jim Ingham9ee01152011-12-10 01:49:43 +00004018 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00004019}
4020
Jim Ingham61be0902011-05-02 18:13:59 +00004021void
4022ValueObject::EvaluationPoint::SetUpdated ()
4023{
Greg Claytoncc4d0142012-02-17 07:49:44 +00004024 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
4025 if (process_sp)
4026 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00004027 m_first_update = false;
4028 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00004029}
4030
4031
Enrico Granataf2bbf712011-07-15 02:26:42 +00004032
4033void
Enrico Granata86cc9822012-03-19 22:58:49 +00004034ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00004035{
Enrico Granata86cc9822012-03-19 22:58:49 +00004036 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
4037 m_value_str.clear();
4038
4039 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
4040 m_location_str.clear();
4041
4042 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
4043 {
Enrico Granata86cc9822012-03-19 22:58:49 +00004044 m_summary_str.clear();
4045 }
4046
4047 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4048 m_object_desc_str.clear();
4049
4050 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4051 {
4052 if (m_synthetic_value)
4053 m_synthetic_value = NULL;
4054 }
Johnny Chen44805302011-07-19 19:48:13 +00004055}
Enrico Granata9128ee22011-09-06 19:20:51 +00004056
4057SymbolContextScope *
4058ValueObject::GetSymbolContextScope()
4059{
4060 if (m_parent)
4061 {
4062 if (!m_parent->IsPointerOrReferenceType())
4063 return m_parent->GetSymbolContextScope();
4064 }
4065 return NULL;
4066}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004067
4068lldb::ValueObjectSP
4069ValueObject::CreateValueObjectFromExpression (const char* name,
4070 const char* expression,
4071 const ExecutionContext& exe_ctx)
4072{
4073 lldb::ValueObjectSP retval_sp;
4074 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4075 if (!target_sp)
4076 return retval_sp;
4077 if (!expression || !*expression)
4078 return retval_sp;
4079 target_sp->EvaluateExpression (expression,
4080 exe_ctx.GetFrameSP().get(),
4081 retval_sp);
4082 if (retval_sp && name && *name)
4083 retval_sp->SetName(ConstString(name));
4084 return retval_sp;
4085}
4086
4087lldb::ValueObjectSP
4088ValueObject::CreateValueObjectFromAddress (const char* name,
4089 uint64_t address,
4090 const ExecutionContext& exe_ctx,
4091 ClangASTType type)
4092{
Greg Clayton57ee3062013-07-11 22:46:58 +00004093 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004094 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004095 ClangASTType pointer_type(type.GetPointerType());
4096 if (pointer_type)
4097 {
4098 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4099 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4100 pointer_type,
4101 ConstString(name),
4102 buffer,
4103 lldb::endian::InlHostByteOrder(),
4104 exe_ctx.GetAddressByteSize()));
4105 if (ptr_result_valobj_sp)
4106 {
4107 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4108 Error err;
4109 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4110 if (ptr_result_valobj_sp && name && *name)
4111 ptr_result_valobj_sp->SetName(ConstString(name));
4112 }
4113 return ptr_result_valobj_sp;
4114 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004115 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004116 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004117}
4118
4119lldb::ValueObjectSP
4120ValueObject::CreateValueObjectFromData (const char* name,
4121 DataExtractor& data,
4122 const ExecutionContext& exe_ctx,
4123 ClangASTType type)
4124{
4125 lldb::ValueObjectSP new_value_sp;
4126 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004127 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004128 ConstString(name),
4129 data,
4130 LLDB_INVALID_ADDRESS);
4131 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4132 if (new_value_sp && name && *name)
4133 new_value_sp->SetName(ConstString(name));
4134 return new_value_sp;
4135}
Enrico Granata4873e522013-04-11 22:48:58 +00004136
4137ModuleSP
4138ValueObject::GetModule ()
4139{
4140 ValueObject* root(GetRoot());
4141 if (root != this)
4142 return root->GetModule();
4143 return lldb::ModuleSP();
4144}
4145
4146ValueObject*
4147ValueObject::GetRoot ()
4148{
4149 if (m_root)
4150 return m_root;
4151 ValueObject* parent = m_parent;
4152 if (!parent)
4153 return (m_root = this);
4154 while (parent->m_parent)
4155 {
4156 if (parent->m_root)
4157 return (m_root = parent->m_root);
4158 parent = parent->m_parent;
4159 }
4160 return (m_root = parent);
4161}
4162
4163AddressType
4164ValueObject::GetAddressTypeOfChildren()
4165{
4166 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4167 {
4168 ValueObject* root(GetRoot());
4169 if (root != this)
4170 return root->GetAddressTypeOfChildren();
4171 }
4172 return m_address_type_of_ptr_or_ref_children;
4173}
4174
4175lldb::DynamicValueType
4176ValueObject::GetDynamicValueType ()
4177{
4178 ValueObject* with_dv_info = this;
4179 while (with_dv_info)
4180 {
4181 if (with_dv_info->HasDynamicValueTypeInfo())
4182 return with_dv_info->GetDynamicValueTypeImpl();
4183 with_dv_info = with_dv_info->m_parent;
4184 }
4185 return lldb::eNoDynamicValues;
4186}
Enrico Granata39d51412013-05-31 17:43:40 +00004187
Enrico Granata4873e522013-04-11 22:48:58 +00004188lldb::Format
4189ValueObject::GetFormat () const
4190{
4191 const ValueObject* with_fmt_info = this;
4192 while (with_fmt_info)
4193 {
4194 if (with_fmt_info->m_format != lldb::eFormatDefault)
4195 return with_fmt_info->m_format;
4196 with_fmt_info = with_fmt_info->m_parent;
4197 }
4198 return m_format;
4199}