blob: 624c06d5a75254e22eef3fdc15f8794790fc9dc1 [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"
Enrico Granata2206b482014-10-30 18:27:31 +000037#include "lldb/DataFormatters/StringPrinter.h"
Enrico Granata4d93b8c2013-09-30 19:11:51 +000038#include "lldb/DataFormatters/ValueObjectPrinter.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000039
Enrico Granata0c10a852014-12-08 23:13:56 +000040#include "lldb/Expression/ClangExpressionVariable.h"
41#include "lldb/Expression/ClangPersistentVariables.h"
42
Greg Clayton7fb56d02011-02-01 01:31:41 +000043#include "lldb/Host/Endian.h"
44
Enrico Granata61a80ba2011-08-12 16:42:31 +000045#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granataf2bbf712011-07-15 02:26:42 +000046#include "lldb/Interpreter/ScriptInterpreterPython.h"
47
Greg Claytone1a916a2010-07-21 22:12:05 +000048#include "lldb/Symbol/ClangASTType.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049#include "lldb/Symbol/ClangASTContext.h"
Enrico Granatac1247f52014-11-06 21:23:20 +000050#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051#include "lldb/Symbol/Type.h"
52
Jim Ingham53c47f12010-09-10 23:12:17 +000053#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000054#include "lldb/Target/LanguageRuntime.h"
Enrico Granatac3e320a2011-08-02 17:27:39 +000055#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056#include "lldb/Target/Process.h"
57#include "lldb/Target/RegisterContext.h"
Greg Claytond5944cd2013-12-06 01:12:00 +000058#include "lldb/Target/SectionLoadList.h"
Greg Claytonf5e56de2010-09-14 23:36:40 +000059#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060#include "lldb/Target/Thread.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061
62using namespace lldb;
63using namespace lldb_private;
Enrico Granataf4efecd2011-07-12 22:56:10 +000064using namespace lldb_utility;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000065
Greg Claytonafacd142011-09-02 01:15:17 +000066static user_id_t g_value_obj_uid = 0;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000067
68//----------------------------------------------------------------------
69// ValueObject constructor
70//----------------------------------------------------------------------
Jim Ingham6035b672011-03-31 00:19:25 +000071ValueObject::ValueObject (ValueObject &parent) :
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072 UserID (++g_value_obj_uid), // Unique identifier for every value object
Jim Ingham6035b672011-03-31 00:19:25 +000073 m_parent (&parent),
Enrico Granata4873e522013-04-11 22:48:58 +000074 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +000075 m_update_point (parent.GetUpdatePoint ()),
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 m_name (),
77 m_data (),
78 m_value (),
79 m_error (),
Greg Clayton288bdf92010-09-02 02:59:18 +000080 m_value_str (),
81 m_old_value_str (),
82 m_location_str (),
83 m_summary_str (),
Jim Ingham53c47f12010-09-10 23:12:17 +000084 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +000085 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +000086 m_manager(parent.GetManager()),
Greg Clayton288bdf92010-09-02 02:59:18 +000087 m_children (),
88 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +000089 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +000090 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +000091 m_deref_valobj(NULL),
Greg Clayton32c40852010-10-06 03:09:11 +000092 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +000093 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +000094 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +000095 m_type_summary_sp(),
96 m_type_format_sp(),
97 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +000098 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +000099 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000100 m_address_type_of_ptr_or_ref_children(eAddressTypeInvalid),
Greg Clayton288bdf92010-09-02 02:59:18 +0000101 m_value_is_valid (false),
102 m_value_did_change (false),
103 m_children_count_valid (false),
Greg Clayton8b2fe6d2010-12-14 02:59:59 +0000104 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000105 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000106 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000107 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000108 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000109 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000110 m_did_calculate_complete_objc_class_type(false),
111 m_is_synthetic_children_generated(parent.m_is_synthetic_children_generated)
Jim Ingham6035b672011-03-31 00:19:25 +0000112{
Jim Ingham58b59f92011-04-22 23:53:53 +0000113 m_manager->ManageObject(this);
Jim Ingham6035b672011-03-31 00:19:25 +0000114}
115
116//----------------------------------------------------------------------
117// ValueObject constructor
118//----------------------------------------------------------------------
Enrico Granata9128ee22011-09-06 19:20:51 +0000119ValueObject::ValueObject (ExecutionContextScope *exe_scope,
120 AddressType child_ptr_or_ref_addr_type) :
Jim Ingham6035b672011-03-31 00:19:25 +0000121 UserID (++g_value_obj_uid), // Unique identifier for every value object
122 m_parent (NULL),
Enrico Granata4873e522013-04-11 22:48:58 +0000123 m_root (NULL),
Stephen Wilson71c21d12011-04-11 19:41:40 +0000124 m_update_point (exe_scope),
Jim Ingham6035b672011-03-31 00:19:25 +0000125 m_name (),
126 m_data (),
127 m_value (),
128 m_error (),
129 m_value_str (),
130 m_old_value_str (),
131 m_location_str (),
132 m_summary_str (),
133 m_object_desc_str (),
Enrico Granata744794a2014-09-05 21:46:22 +0000134 m_validation_result(),
Jim Ingham58b59f92011-04-22 23:53:53 +0000135 m_manager(),
Jim Ingham6035b672011-03-31 00:19:25 +0000136 m_children (),
137 m_synthetic_children (),
Jim Ingham58b59f92011-04-22 23:53:53 +0000138 m_dynamic_value (NULL),
Enrico Granatad55546b2011-07-22 00:16:08 +0000139 m_synthetic_value(NULL),
Jim Ingham58b59f92011-04-22 23:53:53 +0000140 m_deref_valobj(NULL),
Jim Ingham6035b672011-03-31 00:19:25 +0000141 m_format (eFormatDefault),
Enrico Granatab294fd22013-05-31 19:18:19 +0000142 m_last_format (eFormatDefault),
Enrico Granata9df29e32011-07-19 20:57:44 +0000143 m_last_format_mgr_revision(0),
Enrico Granata0c489f52012-03-01 04:24:26 +0000144 m_type_summary_sp(),
145 m_type_format_sp(),
146 m_synthetic_children_sp(),
Enrico Granata744794a2014-09-05 21:46:22 +0000147 m_type_validator_sp(),
Jim Ingham4b536182011-08-09 02:12:22 +0000148 m_user_id_of_forced_summary(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000149 m_address_type_of_ptr_or_ref_children(child_ptr_or_ref_addr_type),
Jim Ingham6035b672011-03-31 00:19:25 +0000150 m_value_is_valid (false),
151 m_value_did_change (false),
152 m_children_count_valid (false),
153 m_old_value_valid (false),
Enrico Granata4becb372011-06-29 22:27:15 +0000154 m_is_deref_of_parent (false),
Enrico Granata0a3958e2011-07-02 00:25:22 +0000155 m_is_array_item_for_pointer(false),
Enrico Granata9fc19442011-07-06 02:13:41 +0000156 m_is_bitfield_for_scalar(false),
Enrico Granata6f3533f2011-07-29 19:53:35 +0000157 m_is_child_at_offset(false),
Sean Callanan72772842012-02-22 23:57:45 +0000158 m_is_getting_summary(false),
Enrico Granatae29df232014-12-09 19:51:20 +0000159 m_did_calculate_complete_objc_class_type(false),
160 m_is_synthetic_children_generated(false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000161{
Jim Ingham58b59f92011-04-22 23:53:53 +0000162 m_manager = new ValueObjectManager();
163 m_manager->ManageObject (this);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000164}
165
166//----------------------------------------------------------------------
167// Destructor
168//----------------------------------------------------------------------
169ValueObject::~ValueObject ()
170{
171}
172
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000173bool
Enrico Granata0a3958e2011-07-02 00:25:22 +0000174ValueObject::UpdateValueIfNeeded (bool update_format)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000175{
Enrico Granata4becb372011-06-29 22:27:15 +0000176
Enrico Granata9128ee22011-09-06 19:20:51 +0000177 bool did_change_formats = false;
178
Enrico Granata0a3958e2011-07-02 00:25:22 +0000179 if (update_format)
Enrico Granata5548cb52013-01-28 23:47:25 +0000180 did_change_formats = UpdateFormatsIfNeeded();
Enrico Granata4becb372011-06-29 22:27:15 +0000181
Greg Claytonb71f3842010-10-05 03:13:51 +0000182 // If this is a constant value, then our success is predicated on whether
183 // we have an error or not
184 if (GetIsConstant())
Enrico Granata9128ee22011-09-06 19:20:51 +0000185 {
Enrico Granatab1c6c482013-10-09 00:33:55 +0000186 // if you are constant, things might still have changed behind your back
187 // (e.g. you are a frozen object and things have changed deeper than you cared to freeze-dry yourself)
188 // in this case, your value has not changed, but "computed" entries might have, so you might now have
189 // a different summary, or a different object description. clear these so we will recompute them
Enrico Granata9128ee22011-09-06 19:20:51 +0000190 if (update_format && !did_change_formats)
Enrico Granatab1c6c482013-10-09 00:33:55 +0000191 ClearUserVisibleData(eClearUserVisibleDataItemsSummary | eClearUserVisibleDataItemsDescription);
Greg Claytonb71f3842010-10-05 03:13:51 +0000192 return m_error.Success();
Enrico Granata9128ee22011-09-06 19:20:51 +0000193 }
Greg Claytonb71f3842010-10-05 03:13:51 +0000194
Jim Ingham6035b672011-03-31 00:19:25 +0000195 bool first_update = m_update_point.IsFirstEvaluation();
196
197 if (m_update_point.NeedsUpdating())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000198 {
Jim Ingham6035b672011-03-31 00:19:25 +0000199 m_update_point.SetUpdated();
200
201 // Save the old value using swap to avoid a string copy which
202 // also will clear our m_value_str
203 if (m_value_str.empty())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204 {
Jim Ingham6035b672011-03-31 00:19:25 +0000205 m_old_value_valid = false;
206 }
207 else
208 {
209 m_old_value_valid = true;
210 m_old_value_str.swap (m_value_str);
Enrico Granata86cc9822012-03-19 22:58:49 +0000211 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham6035b672011-03-31 00:19:25 +0000212 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000213
Enrico Granataf2bbf712011-07-15 02:26:42 +0000214 ClearUserVisibleData();
215
Greg Claytonefbc7d22012-03-09 04:23:44 +0000216 if (IsInScope())
Jim Ingham6035b672011-03-31 00:19:25 +0000217 {
Greg Claytonefbc7d22012-03-09 04:23:44 +0000218 const bool value_was_valid = GetValueIsValid();
219 SetValueDidChange (false);
220
221 m_error.Clear();
222
223 // Call the pure virtual function to update the value
224 bool success = UpdateValue ();
225
226 SetValueIsValid (success);
227
228 if (first_update)
229 SetValueDidChange (false);
230 else if (!m_value_did_change && success == false)
231 {
232 // The value wasn't gotten successfully, so we mark this
233 // as changed if the value used to be valid and now isn't
234 SetValueDidChange (value_was_valid);
235 }
236 }
237 else
238 {
239 m_error.SetErrorString("out of scope");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000240 }
241 }
242 return m_error.Success();
243}
244
Enrico Granata9128ee22011-09-06 19:20:51 +0000245bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000246ValueObject::UpdateFormatsIfNeeded()
Enrico Granata4becb372011-06-29 22:27:15 +0000247{
Greg Clayton5160ce52013-03-27 23:08:40 +0000248 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
Enrico Granata6f3533f2011-07-29 19:53:35 +0000249 if (log)
Enrico Granatad2284832012-10-17 22:23:56 +0000250 log->Printf("[%s %p] checking for FormatManager revisions. ValueObject rev: %d - Global rev: %d",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000251 GetName().GetCString(), static_cast<void*>(this),
252 m_last_format_mgr_revision,
253 DataVisualization::GetCurrentRevision());
254
Enrico Granata9128ee22011-09-06 19:20:51 +0000255 bool any_change = false;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000256
Enrico Granata5548cb52013-01-28 23:47:25 +0000257 if ( (m_last_format_mgr_revision != DataVisualization::GetCurrentRevision()))
Enrico Granata4becb372011-06-29 22:27:15 +0000258 {
Enrico Granataa0db6ed2014-04-09 21:06:11 +0000259 m_last_format_mgr_revision = DataVisualization::GetCurrentRevision();
260 any_change = true;
261
Enrico Granata852cc952013-10-08 19:03:22 +0000262 SetValueFormat(DataVisualization::GetFormat (*this, eNoDynamicValues));
Enrico Granata5548cb52013-01-28 23:47:25 +0000263 SetSummaryFormat(DataVisualization::GetSummaryFormat (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000264#ifndef LLDB_DISABLE_PYTHON
Enrico Granata5548cb52013-01-28 23:47:25 +0000265 SetSyntheticChildren(DataVisualization::GetSyntheticChildren (*this, GetDynamicValueType()));
Jason Molenda7a9a72b2012-05-16 00:38:08 +0000266#endif
Enrico Granata744794a2014-09-05 21:46:22 +0000267 SetValidator(DataVisualization::GetValidator(*this, GetDynamicValueType()));
Enrico Granata4becb372011-06-29 22:27:15 +0000268 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000269
Enrico Granata9128ee22011-09-06 19:20:51 +0000270 return any_change;
Enrico Granata4becb372011-06-29 22:27:15 +0000271}
272
Jim Ingham16e0c682011-08-12 23:34:31 +0000273void
274ValueObject::SetNeedsUpdate ()
275{
276 m_update_point.SetNeedsUpdate();
277 // We have to clear the value string here so ConstResult children will notice if their values are
278 // changed by hand (i.e. with SetValueAsCString).
Enrico Granata86cc9822012-03-19 22:58:49 +0000279 ClearUserVisibleData(eClearUserVisibleDataItemsValue);
Jim Ingham16e0c682011-08-12 23:34:31 +0000280}
281
Enrico Granata13ac0e22012-10-17 19:03:34 +0000282void
Enrico Granatae3e91512012-10-22 18:18:36 +0000283ValueObject::ClearDynamicTypeInformation ()
Enrico Granata13ac0e22012-10-17 19:03:34 +0000284{
Enrico Granata38c54632013-10-30 00:04:29 +0000285 m_children_count_valid = false;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000286 m_did_calculate_complete_objc_class_type = false;
Enrico Granatae3e91512012-10-22 18:18:36 +0000287 m_last_format_mgr_revision = 0;
Enrico Granata13ac0e22012-10-17 19:03:34 +0000288 m_override_type = ClangASTType();
Enrico Granatae3e91512012-10-22 18:18:36 +0000289 SetValueFormat(lldb::TypeFormatImplSP());
290 SetSummaryFormat(lldb::TypeSummaryImplSP());
291 SetSyntheticChildren(lldb::SyntheticChildrenSP());
Enrico Granata13ac0e22012-10-17 19:03:34 +0000292}
293
Sean Callanan72772842012-02-22 23:57:45 +0000294ClangASTType
295ValueObject::MaybeCalculateCompleteType ()
296{
Greg Clayton57ee3062013-07-11 22:46:58 +0000297 ClangASTType clang_type(GetClangTypeImpl());
Sean Callanan356e17c2012-03-30 02:04:38 +0000298
Sean Callanan72772842012-02-22 23:57:45 +0000299 if (m_did_calculate_complete_objc_class_type)
300 {
301 if (m_override_type.IsValid())
302 return m_override_type;
303 else
Greg Clayton57ee3062013-07-11 22:46:58 +0000304 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000305 }
306
Greg Clayton57ee3062013-07-11 22:46:58 +0000307 ClangASTType class_type;
308 bool is_pointer_type = false;
Sean Callanan72772842012-02-22 23:57:45 +0000309
Greg Clayton57ee3062013-07-11 22:46:58 +0000310 if (clang_type.IsObjCObjectPointerType(&class_type))
Sean Callanan72772842012-02-22 23:57:45 +0000311 {
312 is_pointer_type = true;
313 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000314 else if (clang_type.IsObjCObjectOrInterfaceType())
Sean Callanan72772842012-02-22 23:57:45 +0000315 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000316 class_type = clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000317 }
318 else
319 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000320 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000321 }
322
323 m_did_calculate_complete_objc_class_type = true;
324
Greg Clayton57ee3062013-07-11 22:46:58 +0000325 if (class_type)
Sean Callanan72772842012-02-22 23:57:45 +0000326 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000327 ConstString class_name (class_type.GetConstTypeName());
Sean Callanan72772842012-02-22 23:57:45 +0000328
Greg Clayton57ee3062013-07-11 22:46:58 +0000329 if (class_name)
330 {
331 ProcessSP process_sp(GetUpdatePoint().GetExecutionContextRef().GetProcessSP());
332
333 if (process_sp)
334 {
335 ObjCLanguageRuntime *objc_language_runtime(process_sp->GetObjCLanguageRuntime());
336
337 if (objc_language_runtime)
338 {
339 TypeSP complete_objc_class_type_sp = objc_language_runtime->LookupInCompleteClassCache(class_name);
340
341 if (complete_objc_class_type_sp)
342 {
343 ClangASTType complete_class(complete_objc_class_type_sp->GetClangFullType());
344
345 if (complete_class.GetCompleteType())
346 {
347 if (is_pointer_type)
348 {
349 m_override_type = complete_class.GetPointerType();
350 }
351 else
352 {
353 m_override_type = complete_class;
354 }
355
356 if (m_override_type.IsValid())
357 return m_override_type;
358 }
359 }
360 }
361 }
362 }
Sean Callanan72772842012-02-22 23:57:45 +0000363 }
Greg Clayton57ee3062013-07-11 22:46:58 +0000364 return clang_type;
Sean Callanan72772842012-02-22 23:57:45 +0000365}
366
Greg Clayton57ee3062013-07-11 22:46:58 +0000367ClangASTType
Sean Callanan72772842012-02-22 23:57:45 +0000368ValueObject::GetClangType ()
369{
Greg Clayton57ee3062013-07-11 22:46:58 +0000370 return MaybeCalculateCompleteType();
Sean Callanan72772842012-02-22 23:57:45 +0000371}
372
Enrico Granatadc4db5a2013-10-29 00:28:35 +0000373TypeImpl
374ValueObject::GetTypeImpl ()
375{
376 return TypeImpl(GetClangType());
377}
378
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000379DataExtractor &
380ValueObject::GetDataExtractor ()
381{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000382 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383 return m_data;
384}
385
386const Error &
Greg Clayton262f80d2011-07-06 16:49:27 +0000387ValueObject::GetError()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000389 UpdateValueIfNeeded(false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000390 return m_error;
391}
392
393const ConstString &
394ValueObject::GetName() const
395{
396 return m_name;
397}
398
399const char *
Jim Ingham6035b672011-03-31 00:19:25 +0000400ValueObject::GetLocationAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000401{
Enrico Granata82fabf82013-04-30 20:45:04 +0000402 return GetLocationAsCStringImpl(m_value,
403 m_data);
404}
405
406const char *
407ValueObject::GetLocationAsCStringImpl (const Value& value,
408 const DataExtractor& data)
409{
Enrico Granatac3e320a2011-08-02 17:27:39 +0000410 if (UpdateValueIfNeeded(false))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000411 {
412 if (m_location_str.empty())
413 {
414 StreamString sstr;
Enrico Granata82fabf82013-04-30 20:45:04 +0000415
416 Value::ValueType value_type = value.GetValueType();
417
418 switch (value_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000420 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +0000421 case Value::eValueTypeVector:
Enrico Granata82fabf82013-04-30 20:45:04 +0000422 if (value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000423 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000424 RegisterInfo *reg_info = value.GetRegisterInfo();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 if (reg_info)
426 {
427 if (reg_info->name)
428 m_location_str = reg_info->name;
429 else if (reg_info->alt_name)
430 m_location_str = reg_info->alt_name;
Enrico Granata82fabf82013-04-30 20:45:04 +0000431 if (m_location_str.empty())
432 m_location_str = (reg_info->encoding == lldb::eEncodingVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000433 }
434 }
Enrico Granata82fabf82013-04-30 20:45:04 +0000435 if (m_location_str.empty())
436 m_location_str = (value_type == Value::eValueTypeVector) ? "vector" : "scalar";
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000437 break;
438
439 case Value::eValueTypeLoadAddress:
440 case Value::eValueTypeFileAddress:
441 case Value::eValueTypeHostAddress:
442 {
Enrico Granata82fabf82013-04-30 20:45:04 +0000443 uint32_t addr_nibble_size = data.GetAddressByteSize() * 2;
444 sstr.Printf("0x%*.*llx", addr_nibble_size, addr_nibble_size, value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 m_location_str.swap(sstr.GetString());
446 }
447 break;
448 }
449 }
450 }
451 return m_location_str.c_str();
452}
453
454Value &
455ValueObject::GetValue()
456{
457 return m_value;
458}
459
460const Value &
461ValueObject::GetValue() const
462{
463 return m_value;
464}
465
466bool
Jim Ingham6035b672011-03-31 00:19:25 +0000467ValueObject::ResolveValue (Scalar &scalar)
Greg Clayton8f343b02010-11-04 01:54:29 +0000468{
Enrico Granata6fd87d52011-08-04 01:41:02 +0000469 if (UpdateValueIfNeeded(false)) // make sure that you are up to date before returning anything
470 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000471 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Ingham16e0c682011-08-12 23:34:31 +0000472 Value tmp_value(m_value);
Greg Clayton57ee3062013-07-11 22:46:58 +0000473 scalar = tmp_value.ResolveValue(&exe_ctx);
Greg Claytondcad5022011-12-29 01:26:56 +0000474 if (scalar.IsValid())
475 {
476 const uint32_t bitfield_bit_size = GetBitfieldBitSize();
477 if (bitfield_bit_size)
478 return scalar.ExtractBitfield (bitfield_bit_size, GetBitfieldBitOffset());
479 return true;
480 }
Enrico Granata6fd87d52011-08-04 01:41:02 +0000481 }
Greg Claytondcad5022011-12-29 01:26:56 +0000482 return false;
Greg Clayton8f343b02010-11-04 01:54:29 +0000483}
484
485bool
Greg Clayton288bdf92010-09-02 02:59:18 +0000486ValueObject::GetValueIsValid () const
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Greg Clayton288bdf92010-09-02 02:59:18 +0000488 return m_value_is_valid;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489}
490
491
492void
493ValueObject::SetValueIsValid (bool b)
494{
Greg Clayton288bdf92010-09-02 02:59:18 +0000495 m_value_is_valid = b;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496}
497
498bool
Jim Ingham6035b672011-03-31 00:19:25 +0000499ValueObject::GetValueDidChange ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000500{
Jim Ingham6035b672011-03-31 00:19:25 +0000501 GetValueAsCString ();
Greg Clayton288bdf92010-09-02 02:59:18 +0000502 return m_value_did_change;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000503}
504
505void
506ValueObject::SetValueDidChange (bool value_changed)
507{
Greg Clayton288bdf92010-09-02 02:59:18 +0000508 m_value_did_change = value_changed;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000509}
510
511ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000512ValueObject::GetChildAtIndex (size_t idx, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000513{
514 ValueObjectSP child_sp;
Greg Claytondea8cb42011-06-29 22:09:02 +0000515 // We may need to update our value if we are dynamic
516 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000517 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000518 if (idx < GetNumChildren())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000520 // Check if we have already made the child value object?
Enrico Granata9d60f602012-03-09 03:09:58 +0000521 if (can_create && !m_children.HasChildAtIndex(idx))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000523 // No we haven't created the child at this index, so lets have our
524 // subclass do it and cache the result for quick future access.
Enrico Granata9d60f602012-03-09 03:09:58 +0000525 m_children.SetChildAtIndex(idx,CreateChildAtIndex (idx, false, 0));
Jim Ingham78a685a2011-04-16 00:01:13 +0000526 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000527
Enrico Granata9d60f602012-03-09 03:09:58 +0000528 ValueObject* child = m_children.GetChildAtIndex(idx);
529 if (child != NULL)
530 return child->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000531 }
532 return child_sp;
533}
534
Enrico Granata3309d882013-01-12 01:00:22 +0000535ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000536ValueObject::GetChildAtIndexPath (const std::initializer_list<size_t>& idxs,
537 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000538{
539 if (idxs.size() == 0)
540 return GetSP();
541 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000542 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000543 {
544 root = root->GetChildAtIndex(idx, true);
545 if (!root)
546 {
547 if (index_of_error)
548 *index_of_error = idx;
549 return root;
550 }
551 }
552 return root;
553}
554
555ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000556ValueObject::GetChildAtIndexPath (const std::initializer_list< std::pair<size_t, bool> >& idxs,
557 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000558{
559 if (idxs.size() == 0)
560 return GetSP();
561 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000562 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000563 {
564 root = root->GetChildAtIndex(idx.first, idx.second);
565 if (!root)
566 {
567 if (index_of_error)
568 *index_of_error = idx.first;
569 return root;
570 }
571 }
572 return root;
573}
574
575lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000576ValueObject::GetChildAtIndexPath (const std::vector<size_t> &idxs,
577 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000578{
579 if (idxs.size() == 0)
580 return GetSP();
581 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000582 for (size_t idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000583 {
584 root = root->GetChildAtIndex(idx, true);
585 if (!root)
586 {
587 if (index_of_error)
588 *index_of_error = idx;
589 return root;
590 }
591 }
592 return root;
593}
594
595lldb::ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +0000596ValueObject::GetChildAtIndexPath (const std::vector< std::pair<size_t, bool> > &idxs,
597 size_t* index_of_error)
Enrico Granata3309d882013-01-12 01:00:22 +0000598{
599 if (idxs.size() == 0)
600 return GetSP();
601 ValueObjectSP root(GetSP());
Greg Claytonc7bece562013-01-25 18:06:21 +0000602 for (std::pair<size_t, bool> idx : idxs)
Enrico Granata3309d882013-01-12 01:00:22 +0000603 {
604 root = root->GetChildAtIndex(idx.first, idx.second);
605 if (!root)
606 {
607 if (index_of_error)
608 *index_of_error = idx.first;
609 return root;
610 }
611 }
612 return root;
613}
614
Enrico Granatae2e220a2013-09-12 00:48:47 +0000615lldb::ValueObjectSP
616ValueObject::GetChildAtNamePath (const std::initializer_list<ConstString> &names,
617 ConstString* name_of_error)
618{
619 if (names.size() == 0)
620 return GetSP();
621 ValueObjectSP root(GetSP());
622 for (ConstString name : names)
623 {
624 root = root->GetChildMemberWithName(name, true);
625 if (!root)
626 {
627 if (name_of_error)
628 *name_of_error = name;
629 return root;
630 }
631 }
632 return root;
633}
634
635lldb::ValueObjectSP
636ValueObject::GetChildAtNamePath (const std::vector<ConstString> &names,
637 ConstString* name_of_error)
638{
639 if (names.size() == 0)
640 return GetSP();
641 ValueObjectSP root(GetSP());
642 for (ConstString name : names)
643 {
644 root = root->GetChildMemberWithName(name, true);
645 if (!root)
646 {
647 if (name_of_error)
648 *name_of_error = name;
649 return root;
650 }
651 }
652 return root;
653}
654
655lldb::ValueObjectSP
656ValueObject::GetChildAtNamePath (const std::initializer_list< std::pair<ConstString, bool> > &names,
657 ConstString* name_of_error)
658{
659 if (names.size() == 0)
660 return GetSP();
661 ValueObjectSP root(GetSP());
662 for (std::pair<ConstString, bool> name : names)
663 {
664 root = root->GetChildMemberWithName(name.first, name.second);
665 if (!root)
666 {
667 if (name_of_error)
668 *name_of_error = name.first;
669 return root;
670 }
671 }
672 return root;
673}
674
675lldb::ValueObjectSP
676ValueObject::GetChildAtNamePath (const std::vector< std::pair<ConstString, bool> > &names,
677 ConstString* name_of_error)
678{
679 if (names.size() == 0)
680 return GetSP();
681 ValueObjectSP root(GetSP());
682 for (std::pair<ConstString, bool> name : names)
683 {
684 root = root->GetChildMemberWithName(name.first, name.second);
685 if (!root)
686 {
687 if (name_of_error)
688 *name_of_error = name.first;
689 return root;
690 }
691 }
692 return root;
693}
694
Greg Claytonc7bece562013-01-25 18:06:21 +0000695size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000696ValueObject::GetIndexOfChildWithName (const ConstString &name)
697{
698 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000699 return GetClangType().GetIndexOfChildWithName (name.GetCString(), omit_empty_base_classes);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000700}
701
702ValueObjectSP
703ValueObject::GetChildMemberWithName (const ConstString &name, bool can_create)
704{
Greg Clayton710dd5a2011-01-08 20:28:42 +0000705 // when getting a child by name, it could be buried inside some base
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 // classes (which really aren't part of the expression path), so we
707 // need a vector of indexes that can get us down to the correct child
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000708 ValueObjectSP child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000709
Greg Claytondea8cb42011-06-29 22:09:02 +0000710 // We may need to update our value if we are dynamic
711 if (IsPossibleDynamicType ())
Enrico Granatac3e320a2011-08-02 17:27:39 +0000712 UpdateValueIfNeeded(false);
Greg Claytondea8cb42011-06-29 22:09:02 +0000713
714 std::vector<uint32_t> child_indexes;
Greg Claytondea8cb42011-06-29 22:09:02 +0000715 bool omit_empty_base_classes = true;
Greg Clayton57ee3062013-07-11 22:46:58 +0000716 const size_t num_child_indexes = GetClangType().GetIndexOfChildMemberWithName (name.GetCString(),
717 omit_empty_base_classes,
718 child_indexes);
Greg Claytondea8cb42011-06-29 22:09:02 +0000719 if (num_child_indexes > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000721 std::vector<uint32_t>::const_iterator pos = child_indexes.begin ();
722 std::vector<uint32_t>::const_iterator end = child_indexes.end ();
723
724 child_sp = GetChildAtIndex(*pos, can_create);
725 for (++pos; pos != end; ++pos)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000726 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000727 if (child_sp)
Jim Ingham78a685a2011-04-16 00:01:13 +0000728 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000729 ValueObjectSP new_child_sp(child_sp->GetChildAtIndex (*pos, can_create));
730 child_sp = new_child_sp;
Jim Ingham78a685a2011-04-16 00:01:13 +0000731 }
Greg Claytondea8cb42011-06-29 22:09:02 +0000732 else
733 {
734 child_sp.reset();
735 }
736
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000737 }
738 }
739 return child_sp;
740}
741
742
Greg Claytonc7bece562013-01-25 18:06:21 +0000743size_t
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744ValueObject::GetNumChildren ()
745{
Enrico Granatac5bc4122012-03-27 02:35:13 +0000746 UpdateValueIfNeeded();
Greg Clayton288bdf92010-09-02 02:59:18 +0000747 if (!m_children_count_valid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000748 {
749 SetNumChildren (CalculateNumChildren());
750 }
Enrico Granata9d60f602012-03-09 03:09:58 +0000751 return m_children.GetChildrenCount();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000752}
Greg Clayton4a792072012-10-23 01:50:10 +0000753
754bool
755ValueObject::MightHaveChildren()
756{
Enrico Granatadb8142b2012-10-23 02:07:54 +0000757 bool has_children = false;
Greg Clayton2452ab72013-02-08 22:02:02 +0000758 const uint32_t type_info = GetTypeInfo();
759 if (type_info)
Greg Clayton4a792072012-10-23 01:50:10 +0000760 {
Enrico Granata622be232014-10-21 20:52:14 +0000761 if (type_info & (eTypeHasChildren |
762 eTypeIsPointer |
763 eTypeIsReference))
Greg Clayton4a792072012-10-23 01:50:10 +0000764 has_children = true;
765 }
766 else
767 {
768 has_children = GetNumChildren () > 0;
769 }
770 return has_children;
771}
772
773// Should only be called by ValueObject::GetNumChildren()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000774void
Greg Claytonc7bece562013-01-25 18:06:21 +0000775ValueObject::SetNumChildren (size_t num_children)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000776{
Greg Clayton288bdf92010-09-02 02:59:18 +0000777 m_children_count_valid = true;
Enrico Granata9d60f602012-03-09 03:09:58 +0000778 m_children.SetChildrenCount(num_children);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779}
780
781void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000782ValueObject::SetName (const ConstString &name)
783{
784 m_name = name;
785}
786
Jim Ingham58b59f92011-04-22 23:53:53 +0000787ValueObject *
Greg Claytonc7bece562013-01-25 18:06:21 +0000788ValueObject::CreateChildAtIndex (size_t idx, bool synthetic_array_member, int32_t synthetic_index)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000789{
Jim Ingham2eec4872011-05-07 00:10:58 +0000790 ValueObject *valobj = NULL;
Jim Ingham78a685a2011-04-16 00:01:13 +0000791
Greg Claytondea8cb42011-06-29 22:09:02 +0000792 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +0000793 bool ignore_array_bounds = synthetic_array_member;
Greg Claytondea8cb42011-06-29 22:09:02 +0000794 std::string child_name_str;
795 uint32_t child_byte_size = 0;
796 int32_t child_byte_offset = 0;
797 uint32_t child_bitfield_bit_size = 0;
798 uint32_t child_bitfield_bit_offset = 0;
799 bool child_is_base_class = false;
800 bool child_is_deref_of_parent = false;
801
802 const bool transparent_pointers = synthetic_array_member == false;
Greg Clayton57ee3062013-07-11 22:46:58 +0000803 ClangASTType child_clang_type;
Greg Claytondea8cb42011-06-29 22:09:02 +0000804
Greg Claytoncc4d0142012-02-17 07:49:44 +0000805 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytondea8cb42011-06-29 22:09:02 +0000806
Greg Clayton57ee3062013-07-11 22:46:58 +0000807 child_clang_type = GetClangType().GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +0000808 idx,
809 transparent_pointers,
810 omit_empty_base_classes,
811 ignore_array_bounds,
812 child_name_str,
813 child_byte_size,
814 child_byte_offset,
815 child_bitfield_bit_size,
816 child_bitfield_bit_offset,
817 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +0000818 child_is_deref_of_parent,
819 this);
Greg Clayton4ef877f2012-12-06 02:33:54 +0000820 if (child_clang_type)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821 {
Greg Claytondea8cb42011-06-29 22:09:02 +0000822 if (synthetic_index)
823 child_byte_offset += child_byte_size * synthetic_index;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824
Greg Claytondea8cb42011-06-29 22:09:02 +0000825 ConstString child_name;
826 if (!child_name_str.empty())
827 child_name.SetCString (child_name_str.c_str());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000828
Greg Claytondea8cb42011-06-29 22:09:02 +0000829 valobj = new ValueObjectChild (*this,
Greg Claytondea8cb42011-06-29 22:09:02 +0000830 child_clang_type,
831 child_name,
832 child_byte_size,
833 child_byte_offset,
834 child_bitfield_bit_size,
835 child_bitfield_bit_offset,
836 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +0000837 child_is_deref_of_parent,
838 eAddressTypeInvalid);
839 //if (valobj)
840 // valobj->SetAddressTypeOfChildren(eAddressTypeInvalid);
841 }
Jim Ingham78a685a2011-04-16 00:01:13 +0000842
Jim Ingham58b59f92011-04-22 23:53:53 +0000843 return valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000844}
845
Enrico Granata0c489f52012-03-01 04:24:26 +0000846bool
847ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
848 std::string& destination)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849{
Enrico Granatac1247f52014-11-06 21:23:20 +0000850 return GetSummaryAsCString(summary_ptr, destination, TypeSummaryOptions());
851}
852
853bool
854ValueObject::GetSummaryAsCString (TypeSummaryImpl* summary_ptr,
855 std::string& destination,
856 const TypeSummaryOptions& options)
857{
Enrico Granata0c489f52012-03-01 04:24:26 +0000858 destination.clear();
859
860 // ideally we would like to bail out if passing NULL, but if we do so
861 // we end up not providing the summary for function pointers anymore
862 if (/*summary_ptr == NULL ||*/ m_is_getting_summary)
863 return false;
Greg Clayton48ca8b82012-01-07 20:58:07 +0000864
865 m_is_getting_summary = true;
Enrico Granataf18c03e2012-04-04 17:34:10 +0000866
867 // this is a hot path in code and we prefer to avoid setting this string all too often also clearing out other
868 // information that we might care to see in a crash log. might be useful in very specific situations though.
869 /*Host::SetCrashDescriptionWithFormat("Trying to fetch a summary for %s %s. Summary provider's description is %s",
870 GetTypeName().GetCString(),
871 GetName().GetCString(),
872 summary_ptr->GetDescription().c_str());*/
873
Enrico Granata0c489f52012-03-01 04:24:26 +0000874 if (UpdateValueIfNeeded (false))
875 {
876 if (summary_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000877 {
Enrico Granata86cc9822012-03-19 22:58:49 +0000878 if (HasSyntheticValue())
879 m_synthetic_value->UpdateValueIfNeeded(); // the summary might depend on the synthetic children being up-to-date (e.g. ${svar%#})
Enrico Granataf35bc632014-11-06 21:55:30 +0000880 summary_ptr->FormatObject(this, destination, options);
Enrico Granata0c489f52012-03-01 04:24:26 +0000881 }
882 else
883 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000884 ClangASTType clang_type = GetClangType();
Enrico Granata0c489f52012-03-01 04:24:26 +0000885
886 // Do some default printout for function pointers
887 if (clang_type)
Enrico Granata4becb372011-06-29 22:27:15 +0000888 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000889 if (clang_type.IsFunctionPointerType ())
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000890 {
Greg Clayton57ee3062013-07-11 22:46:58 +0000891 StreamString sstr;
Enrico Granata0c489f52012-03-01 04:24:26 +0000892 AddressType func_ptr_address_type = eAddressTypeInvalid;
893 addr_t func_ptr_address = GetPointerValue (&func_ptr_address_type);
894 if (func_ptr_address != 0 && func_ptr_address != LLDB_INVALID_ADDRESS)
Enrico Granataf2bbf712011-07-15 02:26:42 +0000895 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000896 switch (func_ptr_address_type)
Jim Ingham6035b672011-03-31 00:19:25 +0000897 {
Greg Claytoncc4d0142012-02-17 07:49:44 +0000898 case eAddressTypeInvalid:
899 case eAddressTypeFile:
900 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000901
Greg Claytoncc4d0142012-02-17 07:49:44 +0000902 case eAddressTypeLoad:
Enrico Granata0c489f52012-03-01 04:24:26 +0000903 {
904 ExecutionContext exe_ctx (GetExecutionContextRef());
905
906 Address so_addr;
907 Target *target = exe_ctx.GetTargetPtr();
908 if (target && target->GetSectionLoadList().IsEmpty() == false)
Greg Claytoncc4d0142012-02-17 07:49:44 +0000909 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000910 if (target->GetSectionLoadList().ResolveLoadAddress(func_ptr_address, so_addr))
Enrico Granataf2bbf712011-07-15 02:26:42 +0000911 {
Enrico Granata0c489f52012-03-01 04:24:26 +0000912 so_addr.Dump (&sstr,
913 exe_ctx.GetBestExecutionContextScope(),
914 Address::DumpStyleResolvedDescription,
915 Address::DumpStyleSectionNameOffset);
Enrico Granataf2bbf712011-07-15 02:26:42 +0000916 }
Enrico Granataf2bbf712011-07-15 02:26:42 +0000917 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000918 }
Greg Claytoncc4d0142012-02-17 07:49:44 +0000919 break;
Enrico Granata0c489f52012-03-01 04:24:26 +0000920
Greg Claytoncc4d0142012-02-17 07:49:44 +0000921 case eAddressTypeHost:
922 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +0000923 }
Enrico Granata0c489f52012-03-01 04:24:26 +0000924 }
925 if (sstr.GetSize() > 0)
926 {
927 destination.assign (1, '(');
928 destination.append (sstr.GetData(), sstr.GetSize());
929 destination.append (1, ')');
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000930 }
931 }
932 }
933 }
934 }
Greg Clayton48ca8b82012-01-07 20:58:07 +0000935 m_is_getting_summary = false;
Enrico Granata0c489f52012-03-01 04:24:26 +0000936 return !destination.empty();
937}
938
939const char *
940ValueObject::GetSummaryAsCString ()
941{
942 if (UpdateValueIfNeeded(true) && m_summary_str.empty())
943 {
944 GetSummaryAsCString(GetSummaryFormat().get(),
Enrico Granatac1247f52014-11-06 21:23:20 +0000945 m_summary_str,
Enrico Granata49bfafb2014-11-18 23:36:25 +0000946 TypeSummaryOptions());
Enrico Granata0c489f52012-03-01 04:24:26 +0000947 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000948 if (m_summary_str.empty())
949 return NULL;
950 return m_summary_str.c_str();
951}
952
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000953bool
Enrico Granata49bfafb2014-11-18 23:36:25 +0000954ValueObject::GetSummaryAsCString (std::string& destination,
955 const TypeSummaryOptions& options)
956{
957 return GetSummaryAsCString(GetSummaryFormat().get(),
958 destination,
959 options);
960}
961
962bool
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000963ValueObject::IsCStringContainer(bool check_pointer)
964{
Greg Clayton57ee3062013-07-11 22:46:58 +0000965 ClangASTType pointee_or_element_clang_type;
966 const Flags type_flags (GetTypeInfo (&pointee_or_element_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +0000967 bool is_char_arr_ptr (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +0000968 pointee_or_element_clang_type.IsCharType ());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000969 if (!is_char_arr_ptr)
970 return false;
971 if (!check_pointer)
972 return true;
Enrico Granata622be232014-10-21 20:52:14 +0000973 if (type_flags.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000974 return true;
Greg Claytonafacd142011-09-02 01:15:17 +0000975 addr_t cstr_address = LLDB_INVALID_ADDRESS;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000976 AddressType cstr_address_type = eAddressTypeInvalid;
Enrico Granata9128ee22011-09-06 19:20:51 +0000977 cstr_address = GetAddressOf (true, &cstr_address_type);
Enrico Granataf9fa6ee2011-07-12 00:18:11 +0000978 return (cstr_address != LLDB_INVALID_ADDRESS);
979}
980
Enrico Granata9128ee22011-09-06 19:20:51 +0000981size_t
982ValueObject::GetPointeeData (DataExtractor& data,
983 uint32_t item_idx,
984 uint32_t item_count)
985{
Greg Clayton57ee3062013-07-11 22:46:58 +0000986 ClangASTType pointee_or_element_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +0000987 const uint32_t type_info = GetTypeInfo (&pointee_or_element_clang_type);
Enrico Granata622be232014-10-21 20:52:14 +0000988 const bool is_pointer_type = type_info & eTypeIsPointer;
989 const bool is_array_type = type_info & eTypeIsArray;
Greg Clayton2452ab72013-02-08 22:02:02 +0000990 if (!(is_pointer_type || is_array_type))
Enrico Granata9128ee22011-09-06 19:20:51 +0000991 return 0;
992
993 if (item_count == 0)
994 return 0;
995
Greg Clayton57ee3062013-07-11 22:46:58 +0000996 const uint64_t item_type_size = pointee_or_element_clang_type.GetByteSize();
Enrico Granata9128ee22011-09-06 19:20:51 +0000997 const uint64_t bytes = item_count * item_type_size;
Enrico Granata9128ee22011-09-06 19:20:51 +0000998 const uint64_t offset = item_idx * item_type_size;
999
1000 if (item_idx == 0 && item_count == 1) // simply a deref
1001 {
Greg Clayton2452ab72013-02-08 22:02:02 +00001002 if (is_pointer_type)
Enrico Granata9128ee22011-09-06 19:20:51 +00001003 {
1004 Error error;
1005 ValueObjectSP pointee_sp = Dereference(error);
1006 if (error.Fail() || pointee_sp.get() == NULL)
1007 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001008 return pointee_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001009 }
1010 else
1011 {
1012 ValueObjectSP child_sp = GetChildAtIndex(0, true);
1013 if (child_sp.get() == NULL)
1014 return 0;
Sean Callanan866e91c2014-02-28 22:27:53 +00001015 Error error;
1016 return child_sp->GetData(data, error);
Enrico Granata9128ee22011-09-06 19:20:51 +00001017 }
1018 return true;
1019 }
1020 else /* (items > 1) */
1021 {
1022 Error error;
1023 lldb_private::DataBufferHeap* heap_buf_ptr = NULL;
1024 lldb::DataBufferSP data_sp(heap_buf_ptr = new lldb_private::DataBufferHeap());
1025
1026 AddressType addr_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001027 lldb::addr_t addr = is_pointer_type ? GetPointerValue(&addr_type) : GetAddressOf(true, &addr_type);
Enrico Granata9128ee22011-09-06 19:20:51 +00001028
Enrico Granata9128ee22011-09-06 19:20:51 +00001029 switch (addr_type)
1030 {
1031 case eAddressTypeFile:
1032 {
Greg Claytone72dfb32012-02-24 01:59:29 +00001033 ModuleSP module_sp (GetModule());
1034 if (module_sp)
Enrico Granata9128ee22011-09-06 19:20:51 +00001035 {
Enrico Granata9c2efe32012-08-07 01:49:34 +00001036 addr = addr + offset;
Enrico Granata9128ee22011-09-06 19:20:51 +00001037 Address so_addr;
Greg Claytone72dfb32012-02-24 01:59:29 +00001038 module_sp->ResolveFileAddress(addr, so_addr);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001039 ExecutionContext exe_ctx (GetExecutionContextRef());
1040 Target* target = exe_ctx.GetTargetPtr();
1041 if (target)
Enrico Granata9128ee22011-09-06 19:20:51 +00001042 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001043 heap_buf_ptr->SetByteSize(bytes);
1044 size_t bytes_read = target->ReadMemory(so_addr, false, heap_buf_ptr->GetBytes(), bytes, error);
1045 if (error.Success())
Enrico Granata9128ee22011-09-06 19:20:51 +00001046 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001047 data.SetData(data_sp);
1048 return bytes_read;
Enrico Granata9128ee22011-09-06 19:20:51 +00001049 }
1050 }
1051 }
1052 }
1053 break;
1054 case eAddressTypeLoad:
Enrico Granata9128ee22011-09-06 19:20:51 +00001055 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001056 ExecutionContext exe_ctx (GetExecutionContextRef());
1057 Process *process = exe_ctx.GetProcessPtr();
Enrico Granata9128ee22011-09-06 19:20:51 +00001058 if (process)
1059 {
1060 heap_buf_ptr->SetByteSize(bytes);
1061 size_t bytes_read = process->ReadMemory(addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
Enrico Granata5e1480c2013-10-30 17:52:44 +00001062 if (error.Success() || bytes_read > 0)
Enrico Granata9128ee22011-09-06 19:20:51 +00001063 {
1064 data.SetData(data_sp);
1065 return bytes_read;
1066 }
1067 }
1068 }
1069 break;
1070 case eAddressTypeHost:
1071 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001072 const uint64_t max_bytes = GetClangType().GetByteSize();
Greg Clayton2452ab72013-02-08 22:02:02 +00001073 if (max_bytes > offset)
1074 {
1075 size_t bytes_read = std::min<uint64_t>(max_bytes - offset, bytes);
1076 heap_buf_ptr->CopyData((uint8_t*)(addr + offset), bytes_read);
1077 data.SetData(data_sp);
1078 return bytes_read;
1079 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001080 }
1081 break;
1082 case eAddressTypeInvalid:
Enrico Granata9128ee22011-09-06 19:20:51 +00001083 break;
1084 }
1085 }
1086 return 0;
1087}
1088
Greg Claytonfaac1112013-03-14 18:31:44 +00001089uint64_t
Sean Callanan866e91c2014-02-28 22:27:53 +00001090ValueObject::GetData (DataExtractor& data, Error &error)
Enrico Granata9128ee22011-09-06 19:20:51 +00001091{
1092 UpdateValueIfNeeded(false);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001093 ExecutionContext exe_ctx (GetExecutionContextRef());
Sean Callanan866e91c2014-02-28 22:27:53 +00001094 error = m_value.GetValueAsData(&exe_ctx, data, 0, GetModule().get());
Enrico Granata9128ee22011-09-06 19:20:51 +00001095 if (error.Fail())
Sean Callananed185ab2013-04-19 19:47:32 +00001096 {
1097 if (m_data.GetByteSize())
1098 {
1099 data = m_data;
1100 return data.GetByteSize();
1101 }
1102 else
1103 {
1104 return 0;
1105 }
1106 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001107 data.SetAddressByteSize(m_data.GetAddressByteSize());
1108 data.SetByteOrder(m_data.GetByteOrder());
1109 return data.GetByteSize();
1110}
1111
Sean Callanan389823e2013-04-13 01:21:23 +00001112bool
1113ValueObject::SetData (DataExtractor &data, Error &error)
1114{
1115 error.Clear();
1116 // Make sure our value is up to date first so that our location and location
1117 // type is valid.
1118 if (!UpdateValueIfNeeded(false))
1119 {
1120 error.SetErrorString("unable to read value");
1121 return false;
1122 }
1123
1124 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001125 const Encoding encoding = GetClangType().GetEncoding(count);
Sean Callanan389823e2013-04-13 01:21:23 +00001126
1127 const size_t byte_size = GetByteSize();
1128
1129 Value::ValueType value_type = m_value.GetValueType();
1130
1131 switch (value_type)
1132 {
1133 case Value::eValueTypeScalar:
1134 {
1135 Error set_error = m_value.GetScalar().SetValueFromData(data, encoding, byte_size);
1136
1137 if (!set_error.Success())
1138 {
1139 error.SetErrorStringWithFormat("unable to set scalar value: %s", set_error.AsCString());
1140 return false;
1141 }
1142 }
1143 break;
1144 case Value::eValueTypeLoadAddress:
1145 {
1146 // If it is a load address, then the scalar value is the storage location
1147 // of the data, and we have to shove this value down to that load location.
1148 ExecutionContext exe_ctx (GetExecutionContextRef());
1149 Process *process = exe_ctx.GetProcessPtr();
1150 if (process)
1151 {
1152 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1153 size_t bytes_written = process->WriteMemory(target_addr,
1154 data.GetDataStart(),
1155 byte_size,
1156 error);
1157 if (!error.Success())
1158 return false;
1159 if (bytes_written != byte_size)
1160 {
1161 error.SetErrorString("unable to write value to memory");
1162 return false;
1163 }
1164 }
1165 }
1166 break;
1167 case Value::eValueTypeHostAddress:
1168 {
1169 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1170 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1171 m_data.SetData(buffer_sp, 0);
1172 data.CopyByteOrderedData (0,
1173 byte_size,
1174 const_cast<uint8_t *>(m_data.GetDataStart()),
1175 byte_size,
1176 m_data.GetByteOrder());
1177 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1178 }
1179 break;
1180 case Value::eValueTypeFileAddress:
1181 case Value::eValueTypeVector:
1182 break;
1183 }
1184
1185 // If we have reached this point, then we have successfully changed the value.
1186 SetNeedsUpdate();
1187 return true;
1188}
1189
Enrico Granata9128ee22011-09-06 19:20:51 +00001190// will compute strlen(str), but without consuming more than
1191// maxlen bytes out of str (this serves the purpose of reading
1192// chunks of a string without having to worry about
1193// missing NULL terminators in the chunk)
1194// of course, if strlen(str) > maxlen, the function will return
1195// maxlen_value (which should be != maxlen, because that allows you
1196// to know whether strlen(str) == maxlen or strlen(str) > maxlen)
1197static uint32_t
1198strlen_or_inf (const char* str,
1199 uint32_t maxlen,
1200 uint32_t maxlen_value)
1201{
1202 uint32_t len = 0;
Greg Clayton8dd5c172011-10-05 22:19:51 +00001203 if (str)
Enrico Granata9128ee22011-09-06 19:20:51 +00001204 {
Greg Clayton8dd5c172011-10-05 22:19:51 +00001205 while(*str)
1206 {
1207 len++;str++;
Greg Clayton2452ab72013-02-08 22:02:02 +00001208 if (len >= maxlen)
Greg Clayton8dd5c172011-10-05 22:19:51 +00001209 return maxlen_value;
1210 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001211 }
1212 return len;
1213}
1214
Enrico Granata2206b482014-10-30 18:27:31 +00001215static bool
1216CopyStringDataToBufferSP(const StreamString& source,
1217 lldb::DataBufferSP& destination)
1218{
1219 destination.reset(new DataBufferHeap(source.GetSize()+1,0));
1220 memcpy(destination->GetBytes(), source.GetString().c_str(), source.GetSize());
1221 return true;
1222}
1223
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001224size_t
Enrico Granata2206b482014-10-30 18:27:31 +00001225ValueObject::ReadPointedString (lldb::DataBufferSP& buffer_sp,
Greg Claytoncc4d0142012-02-17 07:49:44 +00001226 Error& error,
1227 uint32_t max_length,
1228 bool honor_array,
1229 Format item_format)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001230{
Enrico Granata2206b482014-10-30 18:27:31 +00001231 StreamString s;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001232 ExecutionContext exe_ctx (GetExecutionContextRef());
1233 Target* target = exe_ctx.GetTargetPtr();
Enrico Granata2206b482014-10-30 18:27:31 +00001234
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001235 if (!target)
1236 {
1237 s << "<no target to read from>";
1238 error.SetErrorString("no target to read from");
Enrico Granata2206b482014-10-30 18:27:31 +00001239 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001240 return 0;
1241 }
1242
1243 if (max_length == 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001244 max_length = target->GetMaximumSizeOfStringSummary();
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001245
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001246 size_t bytes_read = 0;
1247 size_t total_bytes_read = 0;
1248
Greg Clayton57ee3062013-07-11 22:46:58 +00001249 ClangASTType clang_type = GetClangType();
1250 ClangASTType elem_or_pointee_clang_type;
Greg Clayton2452ab72013-02-08 22:02:02 +00001251 const Flags type_flags (GetTypeInfo (&elem_or_pointee_clang_type));
Enrico Granata622be232014-10-21 20:52:14 +00001252 if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer) &&
Greg Clayton57ee3062013-07-11 22:46:58 +00001253 elem_or_pointee_clang_type.IsCharType ())
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001254 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001255 addr_t cstr_address = LLDB_INVALID_ADDRESS;
1256 AddressType cstr_address_type = eAddressTypeInvalid;
1257
1258 size_t cstr_len = 0;
1259 bool capped_data = false;
Enrico Granata622be232014-10-21 20:52:14 +00001260 if (type_flags.Test (eTypeIsArray))
Greg Claytoncc4d0142012-02-17 07:49:44 +00001261 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001262 // We have an array
Greg Clayton57ee3062013-07-11 22:46:58 +00001263 uint64_t array_size = 0;
1264 if (clang_type.IsArrayType(NULL, &array_size, NULL))
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001265 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001266 cstr_len = array_size;
1267 if (cstr_len > max_length)
1268 {
1269 capped_data = true;
1270 cstr_len = max_length;
1271 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001272 }
1273 cstr_address = GetAddressOf (true, &cstr_address_type);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001274 }
1275 else
1276 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001277 // We have a pointer
1278 cstr_address = GetPointerValue (&cstr_address_type);
1279 }
1280
1281 if (cstr_address == 0 || cstr_address == LLDB_INVALID_ADDRESS)
1282 {
1283 s << "<invalid address>";
1284 error.SetErrorString("invalid address");
Enrico Granata2206b482014-10-30 18:27:31 +00001285 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001286 return 0;
1287 }
Enrico Granata2206b482014-10-30 18:27:31 +00001288
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001289 Address cstr_so_addr (cstr_address);
1290 DataExtractor data;
1291 if (cstr_len > 0 && honor_array)
1292 {
1293 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1294 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1295 GetPointeeData(data, 0, cstr_len);
Enrico Granata2206b482014-10-30 18:27:31 +00001296
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001297 if ((bytes_read = data.GetByteSize()) > 0)
1298 {
1299 total_bytes_read = bytes_read;
Enrico Granata2206b482014-10-30 18:27:31 +00001300 for (size_t offset = 0; offset < bytes_read; offset++)
1301 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001302 if (capped_data)
1303 s << "...";
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001304 }
1305 }
1306 else
1307 {
1308 cstr_len = max_length;
1309 const size_t k_max_buf_size = 64;
Enrico Granata2206b482014-10-30 18:27:31 +00001310
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001311 size_t offset = 0;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001312
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001313 int cstr_len_displayed = -1;
1314 bool capped_cstr = false;
1315 // I am using GetPointeeData() here to abstract the fact that some ValueObjects are actually frozen pointers in the host
1316 // but the pointed-to data lives in the debuggee, and GetPointeeData() automatically takes care of this
1317 while ((bytes_read = GetPointeeData(data, offset, k_max_buf_size)) > 0)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001318 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001319 total_bytes_read += bytes_read;
1320 const char *cstr = data.PeekCStr(0);
1321 size_t len = strlen_or_inf (cstr, k_max_buf_size, k_max_buf_size+1);
1322 if (len > k_max_buf_size)
1323 len = k_max_buf_size;
Enrico Granata2206b482014-10-30 18:27:31 +00001324
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001325 if (cstr_len_displayed < 0)
1326 cstr_len_displayed = len;
Enrico Granata2206b482014-10-30 18:27:31 +00001327
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001328 if (len == 0)
1329 break;
1330 cstr_len_displayed += len;
1331 if (len > bytes_read)
1332 len = bytes_read;
1333 if (len > cstr_len)
1334 len = cstr_len;
1335
Enrico Granata2206b482014-10-30 18:27:31 +00001336 for (size_t offset = 0; offset < bytes_read; offset++)
1337 s.Printf("%c", *data.PeekData(offset, 1));
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001338
1339 if (len < k_max_buf_size)
1340 break;
1341
1342 if (len >= cstr_len)
Enrico Granata6f3533f2011-07-29 19:53:35 +00001343 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001344 capped_cstr = true;
1345 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001346 }
Enrico Granata2206b482014-10-30 18:27:31 +00001347
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001348 cstr_len -= len;
1349 offset += len;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001350 }
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001351
1352 if (cstr_len_displayed >= 0)
Greg Claytoncc4d0142012-02-17 07:49:44 +00001353 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001354 if (capped_cstr)
1355 s << "...";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001356 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00001357 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001358 }
1359 else
1360 {
Enrico Granata7e0db2a2013-02-28 22:01:33 +00001361 error.SetErrorString("not a string object");
Enrico Granata6f3533f2011-07-29 19:53:35 +00001362 s << "<not a string object>";
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001363 }
Enrico Granata2206b482014-10-30 18:27:31 +00001364 CopyStringDataToBufferSP(s, buffer_sp);
Enrico Granataea2bc0f2013-02-21 19:57:10 +00001365 return total_bytes_read;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001366}
1367
Enrico Granata744794a2014-09-05 21:46:22 +00001368std::pair<TypeValidatorResult, std::string>
1369ValueObject::GetValidationStatus ()
1370{
1371 if (!UpdateValueIfNeeded(true))
1372 return {TypeValidatorResult::Success,""}; // not the validator's job to discuss update problems
1373
1374 if (m_validation_result.hasValue())
1375 return m_validation_result.getValue();
1376
1377 if (!m_type_validator_sp)
1378 return {TypeValidatorResult::Success,""}; // no validator no failure
1379
1380 auto outcome = m_type_validator_sp->FormatObject(this);
1381
1382 return (m_validation_result = {outcome.m_result,outcome.m_message}).getValue();
1383}
1384
Jim Ingham53c47f12010-09-10 23:12:17 +00001385const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001386ValueObject::GetObjectDescription ()
Jim Ingham53c47f12010-09-10 23:12:17 +00001387{
Enrico Granata0a3958e2011-07-02 00:25:22 +00001388
Enrico Granatad8b5fce2011-08-02 23:12:24 +00001389 if (!UpdateValueIfNeeded (true))
Jim Ingham53c47f12010-09-10 23:12:17 +00001390 return NULL;
Enrico Granata0a3958e2011-07-02 00:25:22 +00001391
1392 if (!m_object_desc_str.empty())
1393 return m_object_desc_str.c_str();
1394
Greg Claytoncc4d0142012-02-17 07:49:44 +00001395 ExecutionContext exe_ctx (GetExecutionContextRef());
1396 Process *process = exe_ctx.GetProcessPtr();
Jim Ingham5a369122010-09-28 01:25:32 +00001397 if (process == NULL)
Jim Ingham53c47f12010-09-10 23:12:17 +00001398 return NULL;
Jim Ingham5a369122010-09-28 01:25:32 +00001399
Jim Ingham53c47f12010-09-10 23:12:17 +00001400 StreamString s;
Jim Ingham5a369122010-09-28 01:25:32 +00001401
Greg Claytonafacd142011-09-02 01:15:17 +00001402 LanguageType language = GetObjectRuntimeLanguage();
Jim Ingham5a369122010-09-28 01:25:32 +00001403 LanguageRuntime *runtime = process->GetLanguageRuntime(language);
1404
Jim Inghama2cf2632010-12-23 02:29:54 +00001405 if (runtime == NULL)
1406 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001407 // Aw, hell, if the things a pointer, or even just an integer, let's try ObjC anyway...
Greg Clayton57ee3062013-07-11 22:46:58 +00001408 ClangASTType clang_type = GetClangType();
1409 if (clang_type)
Jim Inghama2cf2632010-12-23 02:29:54 +00001410 {
Jim Inghamb7603bb2011-03-18 00:05:18 +00001411 bool is_signed;
Greg Clayton57ee3062013-07-11 22:46:58 +00001412 if (clang_type.IsIntegerType (is_signed) || clang_type.IsPointerType ())
Jim Inghamb7603bb2011-03-18 00:05:18 +00001413 {
Greg Claytonafacd142011-09-02 01:15:17 +00001414 runtime = process->GetLanguageRuntime(eLanguageTypeObjC);
Jim Inghamb7603bb2011-03-18 00:05:18 +00001415 }
Jim Inghama2cf2632010-12-23 02:29:54 +00001416 }
1417 }
1418
Jim Ingham8d543de2011-03-31 23:01:21 +00001419 if (runtime && runtime->GetObjectDescription(s, *this))
Jim Ingham53c47f12010-09-10 23:12:17 +00001420 {
1421 m_object_desc_str.append (s.GetData());
1422 }
Sean Callanan672ad942010-10-23 00:18:49 +00001423
1424 if (m_object_desc_str.empty())
1425 return NULL;
1426 else
1427 return m_object_desc_str.c_str();
Jim Ingham53c47f12010-09-10 23:12:17 +00001428}
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001429
Enrico Granata0c489f52012-03-01 04:24:26 +00001430bool
Enrico Granata4939b982013-12-22 09:24:22 +00001431ValueObject::GetValueAsCString (const lldb_private::TypeFormatImpl& format,
1432 std::string& destination)
1433{
1434 if (UpdateValueIfNeeded(false))
1435 return format.FormatObject(this,destination);
1436 else
1437 return false;
1438}
1439
1440bool
Enrico Granata0c489f52012-03-01 04:24:26 +00001441ValueObject::GetValueAsCString (lldb::Format format,
1442 std::string& destination)
1443{
Enrico Granata30f287f2013-12-28 08:44:02 +00001444 return GetValueAsCString(TypeFormatImpl_Format(format),destination);
Enrico Granata0c489f52012-03-01 04:24:26 +00001445}
1446
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001447const char *
Jim Ingham6035b672011-03-31 00:19:25 +00001448ValueObject::GetValueAsCString ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001449{
Enrico Granatab294fd22013-05-31 19:18:19 +00001450 if (UpdateValueIfNeeded(true))
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001451 {
Enrico Granata4939b982013-12-22 09:24:22 +00001452 lldb::TypeFormatImplSP format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001453 lldb::Format my_format = GetFormat();
Enrico Granatac953a6a2012-12-11 02:17:22 +00001454 if (my_format == lldb::eFormatDefault)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001455 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001456 if (m_type_format_sp)
Enrico Granata4939b982013-12-22 09:24:22 +00001457 format_sp = m_type_format_sp;
Enrico Granata0c489f52012-03-01 04:24:26 +00001458 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001459 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001460 if (m_is_bitfield_for_scalar)
1461 my_format = eFormatUnsigned;
1462 else
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001463 {
Enrico Granata0c489f52012-03-01 04:24:26 +00001464 if (m_value.GetContextType() == Value::eContextTypeRegisterInfo)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001465 {
1466 const RegisterInfo *reg_info = m_value.GetRegisterInfo();
1467 if (reg_info)
Enrico Granata0c489f52012-03-01 04:24:26 +00001468 my_format = reg_info->format;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001469 }
Enrico Granata0c489f52012-03-01 04:24:26 +00001470 else
1471 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001472 my_format = GetValue().GetClangType().GetFormat();
Enrico Granata0c489f52012-03-01 04:24:26 +00001473 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001474 }
1475 }
1476 }
Enrico Granatab294fd22013-05-31 19:18:19 +00001477 if (my_format != m_last_format || m_value_str.empty())
Enrico Granata297e69f2012-03-06 23:21:16 +00001478 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001479 m_last_format = my_format;
Enrico Granata4939b982013-12-22 09:24:22 +00001480 if (!format_sp)
Enrico Granata30f287f2013-12-28 08:44:02 +00001481 format_sp.reset(new TypeFormatImpl_Format(my_format));
Enrico Granata4939b982013-12-22 09:24:22 +00001482 if (GetValueAsCString(*format_sp.get(), m_value_str))
Enrico Granata297e69f2012-03-06 23:21:16 +00001483 {
Enrico Granatab294fd22013-05-31 19:18:19 +00001484 if (!m_value_did_change && m_old_value_valid)
1485 {
1486 // The value was gotten successfully, so we consider the
1487 // value as changed if the value string differs
1488 SetValueDidChange (m_old_value_str != m_value_str);
1489 }
Enrico Granata297e69f2012-03-06 23:21:16 +00001490 }
1491 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001492 }
1493 if (m_value_str.empty())
1494 return NULL;
1495 return m_value_str.c_str();
1496}
1497
Enrico Granatac3e320a2011-08-02 17:27:39 +00001498// if > 8bytes, 0 is returned. this method should mostly be used
1499// to read address values out of pointers
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001500uint64_t
Johnny Chen3f476c42012-06-05 19:37:43 +00001501ValueObject::GetValueAsUnsigned (uint64_t fail_value, bool *success)
Enrico Granatac3e320a2011-08-02 17:27:39 +00001502{
1503 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001504 if (CanProvideValue())
Enrico Granatac3e320a2011-08-02 17:27:39 +00001505 {
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001506 Scalar scalar;
1507 if (ResolveValue (scalar))
Johnny Chen3f476c42012-06-05 19:37:43 +00001508 {
1509 if (success)
1510 *success = true;
Enrico Granata48ea80f2012-10-24 20:24:39 +00001511 return scalar.ULongLong(fail_value);
Johnny Chen3f476c42012-06-05 19:37:43 +00001512 }
1513 // fallthrough, otherwise...
Enrico Granatac3e320a2011-08-02 17:27:39 +00001514 }
Johnny Chen3f476c42012-06-05 19:37:43 +00001515
1516 if (success)
1517 *success = false;
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001518 return fail_value;
Enrico Granatac3e320a2011-08-02 17:27:39 +00001519}
1520
Enrico Granatad7373f62013-10-31 18:57:50 +00001521int64_t
1522ValueObject::GetValueAsSigned (int64_t fail_value, bool *success)
1523{
1524 // If our byte size is zero this is an aggregate type that has children
Enrico Granatad07cfd32014-10-08 18:27:36 +00001525 if (CanProvideValue())
Enrico Granatad7373f62013-10-31 18:57:50 +00001526 {
1527 Scalar scalar;
1528 if (ResolveValue (scalar))
1529 {
1530 if (success)
1531 *success = true;
1532 return scalar.SLongLong(fail_value);
1533 }
1534 // fallthrough, otherwise...
1535 }
1536
1537 if (success)
1538 *success = false;
1539 return fail_value;
1540}
1541
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001542// if any more "special cases" are added to ValueObject::DumpPrintableRepresentation() please keep
1543// this call up to date by returning true for your new special cases. We will eventually move
1544// to checking this call result before trying to display special cases
1545bool
Enrico Granata86cc9822012-03-19 22:58:49 +00001546ValueObject::HasSpecialPrintableRepresentation(ValueObjectRepresentationStyle val_obj_display,
1547 Format custom_format)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001548{
Greg Clayton57ee3062013-07-11 22:46:58 +00001549 Flags flags(GetTypeInfo());
Enrico Granata622be232014-10-21 20:52:14 +00001550 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001551 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001552 {
1553 if (IsCStringContainer(true) &&
Greg Claytonafacd142011-09-02 01:15:17 +00001554 (custom_format == eFormatCString ||
1555 custom_format == eFormatCharArray ||
1556 custom_format == eFormatChar ||
1557 custom_format == eFormatVectorOfChar))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001558 return true;
1559
Enrico Granata622be232014-10-21 20:52:14 +00001560 if (flags.Test(eTypeIsArray))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001561 {
Greg Claytonafacd142011-09-02 01:15:17 +00001562 if ((custom_format == eFormatBytes) ||
1563 (custom_format == eFormatBytesWithASCII))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001564 return true;
1565
Greg Claytonafacd142011-09-02 01:15:17 +00001566 if ((custom_format == eFormatVectorOfChar) ||
1567 (custom_format == eFormatVectorOfFloat32) ||
1568 (custom_format == eFormatVectorOfFloat64) ||
1569 (custom_format == eFormatVectorOfSInt16) ||
1570 (custom_format == eFormatVectorOfSInt32) ||
1571 (custom_format == eFormatVectorOfSInt64) ||
1572 (custom_format == eFormatVectorOfSInt8) ||
1573 (custom_format == eFormatVectorOfUInt128) ||
1574 (custom_format == eFormatVectorOfUInt16) ||
1575 (custom_format == eFormatVectorOfUInt32) ||
1576 (custom_format == eFormatVectorOfUInt64) ||
1577 (custom_format == eFormatVectorOfUInt8))
Enrico Granatad64d0bc2011-08-19 21:13:46 +00001578 return true;
1579 }
1580 }
1581 return false;
1582}
1583
Enrico Granata9fc19442011-07-06 02:13:41 +00001584bool
1585ValueObject::DumpPrintableRepresentation(Stream& s,
1586 ValueObjectRepresentationStyle val_obj_display,
Greg Claytonafacd142011-09-02 01:15:17 +00001587 Format custom_format,
Enrico Granata0dba9b32014-01-08 01:36:59 +00001588 PrintableRepresentationSpecialCases special,
1589 bool do_dump_error)
Enrico Granata9fc19442011-07-06 02:13:41 +00001590{
Enrico Granataf4efecd2011-07-12 22:56:10 +00001591
Greg Clayton57ee3062013-07-11 22:46:58 +00001592 Flags flags(GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001593
Enrico Granata86cc9822012-03-19 22:58:49 +00001594 bool allow_special = ((special & ePrintableRepresentationSpecialCasesAllow) == ePrintableRepresentationSpecialCasesAllow);
1595 bool only_special = ((special & ePrintableRepresentationSpecialCasesOnly) == ePrintableRepresentationSpecialCasesOnly);
1596
1597 if (allow_special)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001598 {
Enrico Granata622be232014-10-21 20:52:14 +00001599 if (flags.AnySet(eTypeIsArray | eTypeIsPointer)
Enrico Granata86cc9822012-03-19 22:58:49 +00001600 && val_obj_display == ValueObject::eValueObjectRepresentationStyleValue)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001601 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001602 // when being asked to get a printable display an array or pointer type directly,
1603 // try to "do the right thing"
1604
1605 if (IsCStringContainer(true) &&
1606 (custom_format == eFormatCString ||
1607 custom_format == eFormatCharArray ||
1608 custom_format == eFormatChar ||
1609 custom_format == eFormatVectorOfChar)) // print char[] & char* directly
Enrico Granataf4efecd2011-07-12 22:56:10 +00001610 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001611 Error error;
Enrico Granata2206b482014-10-30 18:27:31 +00001612 lldb::DataBufferSP buffer_sp;
1613 ReadPointedString(buffer_sp,
Enrico Granata86cc9822012-03-19 22:58:49 +00001614 error,
1615 0,
1616 (custom_format == eFormatVectorOfChar) ||
1617 (custom_format == eFormatCharArray));
Enrico Granataebdc1ac2014-11-05 21:20:48 +00001618 lldb_private::formatters::ReadBufferAndDumpToStreamOptions options(*this);
Enrico Granata2206b482014-10-30 18:27:31 +00001619 options.SetData(DataExtractor(buffer_sp, lldb::eByteOrderInvalid, 8)); // none of this matters for a string - pass some defaults
1620 options.SetStream(&s);
1621 options.SetPrefixToken(0);
1622 options.SetQuote('"');
1623 options.SetSourceSize(buffer_sp->GetByteSize());
Enrico Granata2206b482014-10-30 18:27:31 +00001624 lldb_private::formatters::ReadBufferAndDumpToStream<lldb_private::formatters::StringElementType::ASCII>(options);
Enrico Granata86cc9822012-03-19 22:58:49 +00001625 return !error.Fail();
Enrico Granataf4efecd2011-07-12 22:56:10 +00001626 }
1627
Enrico Granata86cc9822012-03-19 22:58:49 +00001628 if (custom_format == eFormatEnum)
1629 return false;
1630
1631 // this only works for arrays, because I have no way to know when
1632 // the pointed memory ends, and no special \0 end of data marker
Enrico Granata622be232014-10-21 20:52:14 +00001633 if (flags.Test(eTypeIsArray))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001634 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001635 if ((custom_format == eFormatBytes) ||
1636 (custom_format == eFormatBytesWithASCII))
Enrico Granataf4efecd2011-07-12 22:56:10 +00001637 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001638 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001639
1640 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001641 for (size_t low = 0; low < count; low++)
Enrico Granataf4efecd2011-07-12 22:56:10 +00001642 {
Enrico Granata86cc9822012-03-19 22:58:49 +00001643
1644 if (low)
1645 s << ',';
1646
1647 ValueObjectSP child = GetChildAtIndex(low,true);
1648 if (!child.get())
1649 {
1650 s << "<invalid child>";
1651 continue;
1652 }
1653 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, custom_format);
1654 }
1655
1656 s << ']';
1657
1658 return true;
1659 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001660
Enrico Granata86cc9822012-03-19 22:58:49 +00001661 if ((custom_format == eFormatVectorOfChar) ||
1662 (custom_format == eFormatVectorOfFloat32) ||
1663 (custom_format == eFormatVectorOfFloat64) ||
1664 (custom_format == eFormatVectorOfSInt16) ||
1665 (custom_format == eFormatVectorOfSInt32) ||
1666 (custom_format == eFormatVectorOfSInt64) ||
1667 (custom_format == eFormatVectorOfSInt8) ||
1668 (custom_format == eFormatVectorOfUInt128) ||
1669 (custom_format == eFormatVectorOfUInt16) ||
1670 (custom_format == eFormatVectorOfUInt32) ||
1671 (custom_format == eFormatVectorOfUInt64) ||
1672 (custom_format == eFormatVectorOfUInt8)) // arrays of bytes, bytes with ASCII or any vector format should be printed directly
1673 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001674 const size_t count = GetNumChildren();
Enrico Granata86cc9822012-03-19 22:58:49 +00001675
1676 Format format = FormatManager::GetSingleItemFormat(custom_format);
1677
1678 s << '[';
Greg Claytonc7bece562013-01-25 18:06:21 +00001679 for (size_t low = 0; low < count; low++)
Enrico Granata86cc9822012-03-19 22:58:49 +00001680 {
1681
1682 if (low)
1683 s << ',';
1684
1685 ValueObjectSP child = GetChildAtIndex(low,true);
1686 if (!child.get())
1687 {
1688 s << "<invalid child>";
1689 continue;
1690 }
1691 child->DumpPrintableRepresentation(s, ValueObject::eValueObjectRepresentationStyleValue, format);
1692 }
1693
1694 s << ']';
1695
1696 return true;
1697 }
Enrico Granataf4efecd2011-07-12 22:56:10 +00001698 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001699
1700 if ((custom_format == eFormatBoolean) ||
1701 (custom_format == eFormatBinary) ||
1702 (custom_format == eFormatChar) ||
1703 (custom_format == eFormatCharPrintable) ||
1704 (custom_format == eFormatComplexFloat) ||
1705 (custom_format == eFormatDecimal) ||
1706 (custom_format == eFormatHex) ||
Enrico Granata7ec18e32012-08-09 19:33:34 +00001707 (custom_format == eFormatHexUppercase) ||
Enrico Granata86cc9822012-03-19 22:58:49 +00001708 (custom_format == eFormatFloat) ||
1709 (custom_format == eFormatOctal) ||
1710 (custom_format == eFormatOSType) ||
1711 (custom_format == eFormatUnicode16) ||
1712 (custom_format == eFormatUnicode32) ||
1713 (custom_format == eFormatUnsigned) ||
1714 (custom_format == eFormatPointer) ||
1715 (custom_format == eFormatComplexInteger) ||
1716 (custom_format == eFormatComplex) ||
1717 (custom_format == eFormatDefault)) // use the [] operator
1718 return false;
Enrico Granataf4efecd2011-07-12 22:56:10 +00001719 }
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00001720 }
Enrico Granata85933ed2011-08-18 16:38:26 +00001721
1722 if (only_special)
1723 return false;
1724
Enrico Granata86cc9822012-03-19 22:58:49 +00001725 bool var_success = false;
1726
1727 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001728 const char *cstr = NULL;
Enrico Granata2c75f112013-06-21 00:04:51 +00001729
1730 // this is a local stream that we are using to ensure that the data pointed to by cstr survives
1731 // long enough for us to copy it to its destination - it is necessary to have this temporary storage
1732 // area for cases where our desired output is not backed by some other longer-term storage
Greg Claytonc7bece562013-01-25 18:06:21 +00001733 StreamString strm;
Enrico Granata86cc9822012-03-19 22:58:49 +00001734
Enrico Granata465f4bc2014-02-15 01:24:44 +00001735 if (custom_format != eFormatInvalid)
Enrico Granata86cc9822012-03-19 22:58:49 +00001736 SetFormat(custom_format);
1737
1738 switch(val_obj_display)
1739 {
1740 case eValueObjectRepresentationStyleValue:
Greg Claytonc7bece562013-01-25 18:06:21 +00001741 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001742 break;
1743
1744 case eValueObjectRepresentationStyleSummary:
Greg Claytonc7bece562013-01-25 18:06:21 +00001745 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001746 break;
1747
1748 case eValueObjectRepresentationStyleLanguageSpecific:
Greg Claytonc7bece562013-01-25 18:06:21 +00001749 cstr = GetObjectDescription();
Enrico Granata86cc9822012-03-19 22:58:49 +00001750 break;
1751
1752 case eValueObjectRepresentationStyleLocation:
Greg Claytonc7bece562013-01-25 18:06:21 +00001753 cstr = GetLocationAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001754 break;
1755
1756 case eValueObjectRepresentationStyleChildrenCount:
Deepak Panickal99fbc072014-03-03 15:39:47 +00001757 strm.Printf("%" PRIu64 "", (uint64_t)GetNumChildren());
Greg Claytonc7bece562013-01-25 18:06:21 +00001758 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001759 break;
1760
1761 case eValueObjectRepresentationStyleType:
Greg Claytonc7bece562013-01-25 18:06:21 +00001762 cstr = GetTypeName().AsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001763 break;
Enrico Granata2c75f112013-06-21 00:04:51 +00001764
1765 case eValueObjectRepresentationStyleName:
1766 cstr = GetName().AsCString();
1767 break;
1768
1769 case eValueObjectRepresentationStyleExpressionPath:
1770 GetExpressionPath(strm, false);
1771 cstr = strm.GetString().c_str();
1772 break;
Enrico Granata86cc9822012-03-19 22:58:49 +00001773 }
1774
Greg Claytonc7bece562013-01-25 18:06:21 +00001775 if (!cstr)
Enrico Granata86cc9822012-03-19 22:58:49 +00001776 {
1777 if (val_obj_display == eValueObjectRepresentationStyleValue)
Greg Claytonc7bece562013-01-25 18:06:21 +00001778 cstr = GetSummaryAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001779 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1780 {
Enrico Granatad07cfd32014-10-08 18:27:36 +00001781 if (!CanProvideValue())
Enrico Granata86cc9822012-03-19 22:58:49 +00001782 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001783 strm.Printf("%s @ %s", GetTypeName().AsCString(), GetLocationAsCString());
1784 cstr = strm.GetString().c_str();
Enrico Granata86cc9822012-03-19 22:58:49 +00001785 }
1786 else
Greg Claytonc7bece562013-01-25 18:06:21 +00001787 cstr = GetValueAsCString();
Enrico Granata86cc9822012-03-19 22:58:49 +00001788 }
1789 }
1790
Greg Claytonc7bece562013-01-25 18:06:21 +00001791 if (cstr)
1792 s.PutCString(cstr);
Enrico Granata86cc9822012-03-19 22:58:49 +00001793 else
1794 {
1795 if (m_error.Fail())
Enrico Granata0dba9b32014-01-08 01:36:59 +00001796 {
1797 if (do_dump_error)
1798 s.Printf("<%s>", m_error.AsCString());
1799 else
1800 return false;
1801 }
Enrico Granata86cc9822012-03-19 22:58:49 +00001802 else if (val_obj_display == eValueObjectRepresentationStyleSummary)
1803 s.PutCString("<no summary available>");
1804 else if (val_obj_display == eValueObjectRepresentationStyleValue)
1805 s.PutCString("<no value available>");
1806 else if (val_obj_display == eValueObjectRepresentationStyleLanguageSpecific)
1807 s.PutCString("<not a valid Objective-C object>"); // edit this if we have other runtimes that support a description
1808 else
1809 s.PutCString("<no printable representation>");
1810 }
1811
1812 // we should only return false here if we could not do *anything*
1813 // even if we have an error message as output, that's a success
1814 // from our callers' perspective, so return true
1815 var_success = true;
Enrico Granata465f4bc2014-02-15 01:24:44 +00001816
1817 if (custom_format != eFormatInvalid)
1818 SetFormat(eFormatDefault);
Enrico Granata86cc9822012-03-19 22:58:49 +00001819 }
1820
Enrico Granataf4efecd2011-07-12 22:56:10 +00001821 return var_success;
Enrico Granata9fc19442011-07-06 02:13:41 +00001822}
1823
Greg Clayton737b9322010-09-13 03:32:57 +00001824addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001825ValueObject::GetAddressOf (bool scalar_is_load_address, AddressType *address_type)
Greg Clayton73b472d2010-10-27 03:32:59 +00001826{
Enrico Granatac3e320a2011-08-02 17:27:39 +00001827 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001828 return LLDB_INVALID_ADDRESS;
1829
Greg Clayton73b472d2010-10-27 03:32:59 +00001830 switch (m_value.GetValueType())
1831 {
1832 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001833 case Value::eValueTypeVector:
Greg Clayton73b472d2010-10-27 03:32:59 +00001834 if (scalar_is_load_address)
1835 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001836 if(address_type)
1837 *address_type = eAddressTypeLoad;
Greg Clayton73b472d2010-10-27 03:32:59 +00001838 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1839 }
1840 break;
1841
1842 case Value::eValueTypeLoadAddress:
1843 case Value::eValueTypeFileAddress:
1844 case Value::eValueTypeHostAddress:
1845 {
Enrico Granata9128ee22011-09-06 19:20:51 +00001846 if(address_type)
1847 *address_type = m_value.GetValueAddressType ();
Greg Clayton73b472d2010-10-27 03:32:59 +00001848 return m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
1849 }
1850 break;
1851 }
Enrico Granata9128ee22011-09-06 19:20:51 +00001852 if (address_type)
1853 *address_type = eAddressTypeInvalid;
Greg Clayton73b472d2010-10-27 03:32:59 +00001854 return LLDB_INVALID_ADDRESS;
1855}
1856
1857addr_t
Enrico Granata9128ee22011-09-06 19:20:51 +00001858ValueObject::GetPointerValue (AddressType *address_type)
Greg Clayton737b9322010-09-13 03:32:57 +00001859{
Greg Claytonafacd142011-09-02 01:15:17 +00001860 addr_t address = LLDB_INVALID_ADDRESS;
Enrico Granata9128ee22011-09-06 19:20:51 +00001861 if(address_type)
1862 *address_type = eAddressTypeInvalid;
Jim Ingham78a685a2011-04-16 00:01:13 +00001863
Enrico Granatac3e320a2011-08-02 17:27:39 +00001864 if (!UpdateValueIfNeeded(false))
Jim Ingham78a685a2011-04-16 00:01:13 +00001865 return address;
1866
Greg Clayton73b472d2010-10-27 03:32:59 +00001867 switch (m_value.GetValueType())
Greg Clayton737b9322010-09-13 03:32:57 +00001868 {
1869 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001870 case Value::eValueTypeVector:
Enrico Granata9128ee22011-09-06 19:20:51 +00001871 address = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Clayton737b9322010-09-13 03:32:57 +00001872 break;
1873
Enrico Granata9128ee22011-09-06 19:20:51 +00001874 case Value::eValueTypeHostAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001875 case Value::eValueTypeLoadAddress:
1876 case Value::eValueTypeFileAddress:
Greg Clayton737b9322010-09-13 03:32:57 +00001877 {
Greg Claytonc7bece562013-01-25 18:06:21 +00001878 lldb::offset_t data_offset = 0;
Greg Clayton737b9322010-09-13 03:32:57 +00001879 address = m_data.GetPointer(&data_offset);
Greg Clayton737b9322010-09-13 03:32:57 +00001880 }
1881 break;
1882 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001883
Enrico Granata9128ee22011-09-06 19:20:51 +00001884 if (address_type)
1885 *address_type = GetAddressTypeOfChildren();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00001886
Greg Clayton737b9322010-09-13 03:32:57 +00001887 return address;
1888}
1889
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001890bool
Enrico Granata07a4ac22012-05-08 21:25:06 +00001891ValueObject::SetValueFromCString (const char *value_str, Error& error)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001892{
Enrico Granata07a4ac22012-05-08 21:25:06 +00001893 error.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001894 // Make sure our value is up to date first so that our location and location
1895 // type is valid.
Enrico Granatac3e320a2011-08-02 17:27:39 +00001896 if (!UpdateValueIfNeeded(false))
Enrico Granata07a4ac22012-05-08 21:25:06 +00001897 {
1898 error.SetErrorString("unable to read value");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001899 return false;
Enrico Granata07a4ac22012-05-08 21:25:06 +00001900 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001901
Greg Claytonfaac1112013-03-14 18:31:44 +00001902 uint64_t count = 0;
Greg Clayton57ee3062013-07-11 22:46:58 +00001903 const Encoding encoding = GetClangType().GetEncoding (count);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001904
Greg Claytonb1320972010-07-14 00:18:15 +00001905 const size_t byte_size = GetByteSize();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001906
Jim Ingham16e0c682011-08-12 23:34:31 +00001907 Value::ValueType value_type = m_value.GetValueType();
1908
1909 if (value_type == Value::eValueTypeScalar)
1910 {
1911 // If the value is already a scalar, then let the scalar change itself:
1912 m_value.GetScalar().SetValueFromCString (value_str, encoding, byte_size);
1913 }
1914 else if (byte_size <= Scalar::GetMaxByteSize())
1915 {
1916 // If the value fits in a scalar, then make a new scalar and again let the
1917 // scalar code do the conversion, then figure out where to put the new value.
1918 Scalar new_scalar;
Jim Ingham16e0c682011-08-12 23:34:31 +00001919 error = new_scalar.SetValueFromCString (value_str, encoding, byte_size);
1920 if (error.Success())
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001921 {
Jim Ingham4b536182011-08-09 02:12:22 +00001922 switch (value_type)
1923 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001924 case Value::eValueTypeLoadAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001925 {
1926 // If it is a load address, then the scalar value is the storage location
1927 // of the data, and we have to shove this value down to that load location.
Greg Claytoncc4d0142012-02-17 07:49:44 +00001928 ExecutionContext exe_ctx (GetExecutionContextRef());
1929 Process *process = exe_ctx.GetProcessPtr();
1930 if (process)
Jim Ingham16e0c682011-08-12 23:34:31 +00001931 {
Enrico Granata48ea80f2012-10-24 20:24:39 +00001932 addr_t target_addr = m_value.GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
Greg Claytoncc4d0142012-02-17 07:49:44 +00001933 size_t bytes_written = process->WriteScalarToMemory (target_addr,
1934 new_scalar,
1935 byte_size,
1936 error);
Enrico Granata07a4ac22012-05-08 21:25:06 +00001937 if (!error.Success())
1938 return false;
1939 if (bytes_written != byte_size)
1940 {
1941 error.SetErrorString("unable to write value to memory");
1942 return false;
1943 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001944 }
1945 }
Jim Ingham4b536182011-08-09 02:12:22 +00001946 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001947 case Value::eValueTypeHostAddress:
Jim Ingham16e0c682011-08-12 23:34:31 +00001948 {
1949 // If it is a host address, then we stuff the scalar as a DataBuffer into the Value's data.
1950 DataExtractor new_data;
1951 new_data.SetByteOrder (m_data.GetByteOrder());
1952
1953 DataBufferSP buffer_sp (new DataBufferHeap(byte_size, 0));
1954 m_data.SetData(buffer_sp, 0);
1955 bool success = new_scalar.GetData(new_data);
1956 if (success)
1957 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00001958 new_data.CopyByteOrderedData (0,
1959 byte_size,
1960 const_cast<uint8_t *>(m_data.GetDataStart()),
1961 byte_size,
1962 m_data.GetByteOrder());
Jim Ingham16e0c682011-08-12 23:34:31 +00001963 }
1964 m_value.GetScalar() = (uintptr_t)m_data.GetDataStart();
1965
1966 }
Jim Ingham4b536182011-08-09 02:12:22 +00001967 break;
Greg Claytoncc4d0142012-02-17 07:49:44 +00001968 case Value::eValueTypeFileAddress:
1969 case Value::eValueTypeScalar:
Greg Clayton0665a0f2012-10-30 18:18:43 +00001970 case Value::eValueTypeVector:
1971 break;
Jim Ingham4b536182011-08-09 02:12:22 +00001972 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001973 }
1974 else
1975 {
Jim Ingham16e0c682011-08-12 23:34:31 +00001976 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001977 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001978 }
1979 else
1980 {
1981 // We don't support setting things bigger than a scalar at present.
Enrico Granata07a4ac22012-05-08 21:25:06 +00001982 error.SetErrorString("unable to write aggregate data type");
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001983 return false;
1984 }
Jim Ingham16e0c682011-08-12 23:34:31 +00001985
1986 // If we have reached this point, then we have successfully changed the value.
1987 SetNeedsUpdate();
1988 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001989}
1990
Greg Clayton81e871e2012-02-04 02:27:34 +00001991bool
1992ValueObject::GetDeclaration (Declaration &decl)
1993{
1994 decl.Clear();
1995 return false;
1996}
1997
Greg Clayton84db9102012-03-26 23:03:23 +00001998ConstString
1999ValueObject::GetTypeName()
2000{
Greg Clayton57ee3062013-07-11 22:46:58 +00002001 return GetClangType().GetConstTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002002}
2003
2004ConstString
Enrico Granatae8daa2f2014-05-17 19:14:17 +00002005ValueObject::GetDisplayTypeName()
2006{
2007 return GetTypeName();
2008}
2009
2010ConstString
Greg Clayton84db9102012-03-26 23:03:23 +00002011ValueObject::GetQualifiedTypeName()
2012{
Greg Clayton57ee3062013-07-11 22:46:58 +00002013 return GetClangType().GetConstQualifiedTypeName();
Greg Clayton84db9102012-03-26 23:03:23 +00002014}
2015
2016
Greg Claytonafacd142011-09-02 01:15:17 +00002017LanguageType
Jim Ingham5a369122010-09-28 01:25:32 +00002018ValueObject::GetObjectRuntimeLanguage ()
2019{
Greg Clayton57ee3062013-07-11 22:46:58 +00002020 return GetClangType().GetMinimumLanguage ();
Jim Ingham5a369122010-09-28 01:25:32 +00002021}
2022
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002023void
Jim Ingham58b59f92011-04-22 23:53:53 +00002024ValueObject::AddSyntheticChild (const ConstString &key, ValueObject *valobj)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002025{
Jim Ingham58b59f92011-04-22 23:53:53 +00002026 m_synthetic_children[key] = valobj;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002027}
2028
2029ValueObjectSP
2030ValueObject::GetSyntheticChild (const ConstString &key) const
2031{
2032 ValueObjectSP synthetic_child_sp;
Jim Ingham58b59f92011-04-22 23:53:53 +00002033 std::map<ConstString, ValueObject *>::const_iterator pos = m_synthetic_children.find (key);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002034 if (pos != m_synthetic_children.end())
Jim Ingham58b59f92011-04-22 23:53:53 +00002035 synthetic_child_sp = pos->second->GetSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002036 return synthetic_child_sp;
2037}
2038
Greg Clayton2452ab72013-02-08 22:02:02 +00002039uint32_t
Greg Clayton57ee3062013-07-11 22:46:58 +00002040ValueObject::GetTypeInfo (ClangASTType *pointee_or_element_clang_type)
Greg Clayton2452ab72013-02-08 22:02:02 +00002041{
Greg Clayton57ee3062013-07-11 22:46:58 +00002042 return GetClangType().GetTypeInfo (pointee_or_element_clang_type);
Greg Clayton2452ab72013-02-08 22:02:02 +00002043}
2044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002045bool
2046ValueObject::IsPointerType ()
2047{
Greg Clayton57ee3062013-07-11 22:46:58 +00002048 return GetClangType().IsPointerType();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002049}
2050
Jim Inghamb7603bb2011-03-18 00:05:18 +00002051bool
Greg Claytondaf515f2011-07-09 20:12:33 +00002052ValueObject::IsArrayType ()
2053{
Greg Clayton57ee3062013-07-11 22:46:58 +00002054 return GetClangType().IsArrayType (NULL, NULL, NULL);
Greg Claytondaf515f2011-07-09 20:12:33 +00002055}
2056
2057bool
Enrico Granata9fc19442011-07-06 02:13:41 +00002058ValueObject::IsScalarType ()
2059{
Greg Clayton57ee3062013-07-11 22:46:58 +00002060 return GetClangType().IsScalarType ();
Enrico Granata9fc19442011-07-06 02:13:41 +00002061}
2062
2063bool
Jim Inghamb7603bb2011-03-18 00:05:18 +00002064ValueObject::IsIntegerType (bool &is_signed)
2065{
Greg Clayton57ee3062013-07-11 22:46:58 +00002066 return GetClangType().IsIntegerType (is_signed);
Jim Inghamb7603bb2011-03-18 00:05:18 +00002067}
Greg Clayton73b472d2010-10-27 03:32:59 +00002068
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002069bool
2070ValueObject::IsPointerOrReferenceType ()
2071{
Greg Clayton57ee3062013-07-11 22:46:58 +00002072 return GetClangType().IsPointerOrReferenceType ();
Greg Clayton007d5be2011-05-30 00:49:24 +00002073}
2074
2075bool
Greg Claytondea8cb42011-06-29 22:09:02 +00002076ValueObject::IsPossibleDynamicType ()
2077{
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002078 ExecutionContext exe_ctx (GetExecutionContextRef());
2079 Process *process = exe_ctx.GetProcessPtr();
2080 if (process)
2081 return process->IsPossibleDynamicValue(*this);
2082 else
Greg Clayton57ee3062013-07-11 22:46:58 +00002083 return GetClangType().IsPossibleDynamicType (NULL, true, true);
Greg Claytondea8cb42011-06-29 22:09:02 +00002084}
2085
Enrico Granata9e7b3882012-12-13 23:50:33 +00002086bool
2087ValueObject::IsObjCNil ()
2088{
Enrico Granata622be232014-10-21 20:52:14 +00002089 const uint32_t mask = eTypeIsObjC | eTypeIsPointer;
Greg Clayton57ee3062013-07-11 22:46:58 +00002090 bool isObjCpointer = (((GetClangType().GetTypeInfo(NULL)) & mask) == mask);
Enrico Granata7277d202013-03-15 23:33:15 +00002091 if (!isObjCpointer)
2092 return false;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002093 bool canReadValue = true;
2094 bool isZero = GetValueAsUnsigned(0,&canReadValue) == 0;
Enrico Granata7277d202013-03-15 23:33:15 +00002095 return canReadValue && isZero;
Enrico Granata9e7b3882012-12-13 23:50:33 +00002096}
2097
Greg Claytonafacd142011-09-02 01:15:17 +00002098ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002099ValueObject::GetSyntheticArrayMember (size_t index, bool can_create)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002100{
Greg Clayton2452ab72013-02-08 22:02:02 +00002101 const uint32_t type_info = GetTypeInfo ();
Enrico Granata622be232014-10-21 20:52:14 +00002102 if (type_info & eTypeIsArray)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002103 return GetSyntheticArrayMemberFromArray(index, can_create);
2104
Enrico Granata622be232014-10-21 20:52:14 +00002105 if (type_info & eTypeIsPointer)
Enrico Granatad64d0bc2011-08-19 21:13:46 +00002106 return GetSyntheticArrayMemberFromPointer(index, can_create);
2107
2108 return ValueObjectSP();
2109
2110}
2111
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002112ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002113ValueObject::GetSyntheticArrayMemberFromPointer (size_t index, bool can_create)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002114{
2115 ValueObjectSP synthetic_child_sp;
2116 if (IsPointerType ())
2117 {
2118 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002119 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002120 ConstString index_const_str(index_str);
2121 // Check if we have already created a synthetic array member in this
2122 // valid object. If we have we will re-use it.
2123 synthetic_child_sp = GetSyntheticChild (index_const_str);
2124 if (!synthetic_child_sp)
2125 {
Jim Ingham58b59f92011-04-22 23:53:53 +00002126 ValueObject *synthetic_child;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002127 // We haven't made a synthetic array member for INDEX yet, so
2128 // lets make one and cache it for any future reference.
Jim Ingham58b59f92011-04-22 23:53:53 +00002129 synthetic_child = CreateChildAtIndex(0, true, index);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002130
2131 // Cache the value if we got one back...
Jim Ingham58b59f92011-04-22 23:53:53 +00002132 if (synthetic_child)
2133 {
2134 AddSyntheticChild(index_const_str, synthetic_child);
2135 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002136 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata0a3958e2011-07-02 00:25:22 +00002137 synthetic_child_sp->m_is_array_item_for_pointer = true;
Jim Ingham58b59f92011-04-22 23:53:53 +00002138 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00002139 }
2140 }
2141 return synthetic_child_sp;
2142}
Jim Ingham22777012010-09-23 02:01:19 +00002143
Greg Claytondaf515f2011-07-09 20:12:33 +00002144// This allows you to create an array member using and index
2145// that doesn't not fall in the normal bounds of the array.
2146// Many times structure can be defined as:
2147// struct Collection
2148// {
2149// uint32_t item_count;
2150// Item item_array[0];
2151// };
2152// The size of the "item_array" is 1, but many times in practice
2153// there are more items in "item_array".
2154
2155ValueObjectSP
Greg Claytonc7bece562013-01-25 18:06:21 +00002156ValueObject::GetSyntheticArrayMemberFromArray (size_t index, bool can_create)
Greg Claytondaf515f2011-07-09 20:12:33 +00002157{
2158 ValueObjectSP synthetic_child_sp;
2159 if (IsArrayType ())
2160 {
2161 char index_str[64];
Deepak Panickal99fbc072014-03-03 15:39:47 +00002162 snprintf(index_str, sizeof(index_str), "[%" PRIu64 "]", (uint64_t)index);
Greg Claytondaf515f2011-07-09 20:12:33 +00002163 ConstString index_const_str(index_str);
2164 // Check if we have already created a synthetic array member in this
2165 // valid object. If we have we will re-use it.
2166 synthetic_child_sp = GetSyntheticChild (index_const_str);
2167 if (!synthetic_child_sp)
2168 {
2169 ValueObject *synthetic_child;
2170 // We haven't made a synthetic array member for INDEX yet, so
2171 // lets make one and cache it for any future reference.
2172 synthetic_child = CreateChildAtIndex(0, true, index);
2173
2174 // Cache the value if we got one back...
2175 if (synthetic_child)
2176 {
2177 AddSyntheticChild(index_const_str, synthetic_child);
2178 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002179 synthetic_child_sp->SetName(ConstString(index_str));
Greg Claytondaf515f2011-07-09 20:12:33 +00002180 synthetic_child_sp->m_is_array_item_for_pointer = true;
2181 }
2182 }
2183 }
2184 return synthetic_child_sp;
2185}
2186
Enrico Granata9fc19442011-07-06 02:13:41 +00002187ValueObjectSP
2188ValueObject::GetSyntheticBitFieldChild (uint32_t from, uint32_t to, bool can_create)
2189{
2190 ValueObjectSP synthetic_child_sp;
2191 if (IsScalarType ())
2192 {
2193 char index_str[64];
2194 snprintf(index_str, sizeof(index_str), "[%i-%i]", from, to);
2195 ConstString index_const_str(index_str);
2196 // Check if we have already created a synthetic array member in this
2197 // valid object. If we have we will re-use it.
2198 synthetic_child_sp = GetSyntheticChild (index_const_str);
2199 if (!synthetic_child_sp)
2200 {
Enrico Granata9fc19442011-07-06 02:13:41 +00002201 // We haven't made a synthetic array member for INDEX yet, so
2202 // lets make one and cache it for any future reference.
Greg Clayton57ee3062013-07-11 22:46:58 +00002203 ValueObjectChild *synthetic_child = new ValueObjectChild (*this,
2204 GetClangType(),
2205 index_const_str,
2206 GetByteSize(),
2207 0,
2208 to-from+1,
2209 from,
2210 false,
2211 false,
2212 eAddressTypeInvalid);
Enrico Granata9fc19442011-07-06 02:13:41 +00002213
2214 // Cache the value if we got one back...
2215 if (synthetic_child)
2216 {
2217 AddSyntheticChild(index_const_str, synthetic_child);
2218 synthetic_child_sp = synthetic_child->GetSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002219 synthetic_child_sp->SetName(ConstString(index_str));
Enrico Granata9fc19442011-07-06 02:13:41 +00002220 synthetic_child_sp->m_is_bitfield_for_scalar = true;
2221 }
2222 }
2223 }
2224 return synthetic_child_sp;
2225}
2226
Greg Claytonafacd142011-09-02 01:15:17 +00002227ValueObjectSP
Enrico Granata6f3533f2011-07-29 19:53:35 +00002228ValueObject::GetSyntheticChildAtOffset(uint32_t offset, const ClangASTType& type, bool can_create)
2229{
2230
2231 ValueObjectSP synthetic_child_sp;
2232
2233 char name_str[64];
2234 snprintf(name_str, sizeof(name_str), "@%i", offset);
2235 ConstString name_const_str(name_str);
2236
2237 // Check if we have already created a synthetic array member in this
2238 // valid object. If we have we will re-use it.
2239 synthetic_child_sp = GetSyntheticChild (name_const_str);
2240
2241 if (synthetic_child_sp.get())
2242 return synthetic_child_sp;
2243
2244 if (!can_create)
Greg Claytonafacd142011-09-02 01:15:17 +00002245 return ValueObjectSP();
Enrico Granata6f3533f2011-07-29 19:53:35 +00002246
2247 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
Greg Clayton57ee3062013-07-11 22:46:58 +00002248 type,
Enrico Granata6f3533f2011-07-29 19:53:35 +00002249 name_const_str,
Greg Clayton57ee3062013-07-11 22:46:58 +00002250 type.GetByteSize(),
Enrico Granata6f3533f2011-07-29 19:53:35 +00002251 offset,
2252 0,
2253 0,
2254 false,
Enrico Granata9128ee22011-09-06 19:20:51 +00002255 false,
2256 eAddressTypeInvalid);
Enrico Granata6f3533f2011-07-29 19:53:35 +00002257 if (synthetic_child)
2258 {
2259 AddSyntheticChild(name_const_str, synthetic_child);
2260 synthetic_child_sp = synthetic_child->GetSP();
2261 synthetic_child_sp->SetName(name_const_str);
2262 synthetic_child_sp->m_is_child_at_offset = true;
2263 }
2264 return synthetic_child_sp;
2265}
2266
Enrico Granata32556cd2014-08-26 20:54:04 +00002267ValueObjectSP
Enrico Granata59953f02014-08-26 21:35:30 +00002268ValueObject::GetSyntheticBase (uint32_t offset, const ClangASTType& type, bool can_create)
Enrico Granata32556cd2014-08-26 20:54:04 +00002269{
2270 ValueObjectSP synthetic_child_sp;
2271
2272 char name_str[64];
2273 snprintf(name_str, sizeof(name_str), "%s", type.GetTypeName().AsCString("<unknown>"));
2274 ConstString name_const_str(name_str);
2275
2276 // Check if we have already created a synthetic array member in this
2277 // valid object. If we have we will re-use it.
2278 synthetic_child_sp = GetSyntheticChild (name_const_str);
2279
2280 if (synthetic_child_sp.get())
2281 return synthetic_child_sp;
2282
2283 if (!can_create)
2284 return ValueObjectSP();
2285
Enrico Granata32556cd2014-08-26 20:54:04 +00002286 const bool is_base_class = true;
2287
2288 ValueObjectChild *synthetic_child = new ValueObjectChild(*this,
2289 type,
2290 name_const_str,
2291 type.GetByteSize(),
2292 offset,
2293 0,
2294 0,
2295 is_base_class,
2296 false,
2297 eAddressTypeInvalid);
2298 if (synthetic_child)
2299 {
2300 AddSyntheticChild(name_const_str, synthetic_child);
2301 synthetic_child_sp = synthetic_child->GetSP();
2302 synthetic_child_sp->SetName(name_const_str);
2303 }
2304 return synthetic_child_sp;
2305}
2306
2307
Enrico Granatad55546b2011-07-22 00:16:08 +00002308// your expression path needs to have a leading . or ->
2309// (unless it somehow "looks like" an array, in which case it has
2310// a leading [ symbol). while the [ is meaningful and should be shown
2311// to the user, . and -> are just parser design, but by no means
2312// added information for the user.. strip them off
2313static const char*
2314SkipLeadingExpressionPathSeparators(const char* expression)
2315{
2316 if (!expression || !expression[0])
2317 return expression;
2318 if (expression[0] == '.')
2319 return expression+1;
2320 if (expression[0] == '-' && expression[1] == '>')
2321 return expression+2;
2322 return expression;
2323}
2324
Greg Claytonafacd142011-09-02 01:15:17 +00002325ValueObjectSP
Enrico Granatad55546b2011-07-22 00:16:08 +00002326ValueObject::GetSyntheticExpressionPathChild(const char* expression, bool can_create)
2327{
2328 ValueObjectSP synthetic_child_sp;
2329 ConstString name_const_string(expression);
2330 // Check if we have already created a synthetic array member in this
2331 // valid object. If we have we will re-use it.
2332 synthetic_child_sp = GetSyntheticChild (name_const_string);
2333 if (!synthetic_child_sp)
2334 {
2335 // We haven't made a synthetic array member for expression yet, so
2336 // lets make one and cache it for any future reference.
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002337 synthetic_child_sp = GetValueForExpressionPath(expression,
2338 NULL, NULL, NULL,
2339 GetValueForExpressionPathOptions().DontAllowSyntheticChildren());
Enrico Granatad55546b2011-07-22 00:16:08 +00002340
2341 // Cache the value if we got one back...
2342 if (synthetic_child_sp.get())
2343 {
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002344 // 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 +00002345 AddSyntheticChild(name_const_string, synthetic_child_sp.get());
Enrico Granata6f3533f2011-07-29 19:53:35 +00002346 synthetic_child_sp->SetName(ConstString(SkipLeadingExpressionPathSeparators(expression)));
Enrico Granatad55546b2011-07-22 00:16:08 +00002347 }
2348 }
2349 return synthetic_child_sp;
2350}
2351
2352void
Enrico Granata86cc9822012-03-19 22:58:49 +00002353ValueObject::CalculateSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002354{
Enrico Granata86cc9822012-03-19 22:58:49 +00002355 if (use_synthetic == false)
Enrico Granatad55546b2011-07-22 00:16:08 +00002356 return;
2357
Enrico Granatac5bc4122012-03-27 02:35:13 +00002358 TargetSP target_sp(GetTargetSP());
Enrico Granata5d5f60c2013-09-24 22:58:37 +00002359 if (target_sp && target_sp->GetEnableSyntheticValue() == false)
Enrico Granatac5bc4122012-03-27 02:35:13 +00002360 {
2361 m_synthetic_value = NULL;
2362 return;
2363 }
2364
Enrico Granatae3e91512012-10-22 18:18:36 +00002365 lldb::SyntheticChildrenSP current_synth_sp(m_synthetic_children_sp);
2366
Enrico Granata5548cb52013-01-28 23:47:25 +00002367 if (!UpdateFormatsIfNeeded() && m_synthetic_value)
Enrico Granata86cc9822012-03-19 22:58:49 +00002368 return;
Enrico Granatad55546b2011-07-22 00:16:08 +00002369
Enrico Granata0c489f52012-03-01 04:24:26 +00002370 if (m_synthetic_children_sp.get() == NULL)
Enrico Granatad55546b2011-07-22 00:16:08 +00002371 return;
2372
Enrico Granatae3e91512012-10-22 18:18:36 +00002373 if (current_synth_sp == m_synthetic_children_sp && m_synthetic_value)
2374 return;
2375
Enrico Granata86cc9822012-03-19 22:58:49 +00002376 m_synthetic_value = new ValueObjectSynthetic(*this, m_synthetic_children_sp);
Enrico Granatad55546b2011-07-22 00:16:08 +00002377}
2378
Jim Ingham78a685a2011-04-16 00:01:13 +00002379void
Greg Claytonafacd142011-09-02 01:15:17 +00002380ValueObject::CalculateDynamicValue (DynamicValueType use_dynamic)
Jim Ingham22777012010-09-23 02:01:19 +00002381{
Greg Claytonafacd142011-09-02 01:15:17 +00002382 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002383 return;
2384
Jim Ingham58b59f92011-04-22 23:53:53 +00002385 if (!m_dynamic_value && !IsDynamic())
Jim Ingham78a685a2011-04-16 00:01:13 +00002386 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00002387 ExecutionContext exe_ctx (GetExecutionContextRef());
2388 Process *process = exe_ctx.GetProcessPtr();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002389 if (process && process->IsPossibleDynamicValue(*this))
Enrico Granatae3e91512012-10-22 18:18:36 +00002390 {
2391 ClearDynamicTypeInformation ();
Enrico Granatafd4c84e2012-05-21 16:51:35 +00002392 m_dynamic_value = new ValueObjectDynamicValue (*this, use_dynamic);
Enrico Granatae3e91512012-10-22 18:18:36 +00002393 }
Jim Ingham78a685a2011-04-16 00:01:13 +00002394 }
2395}
2396
Jim Ingham58b59f92011-04-22 23:53:53 +00002397ValueObjectSP
Jim Ingham2837b762011-05-04 03:43:18 +00002398ValueObject::GetDynamicValue (DynamicValueType use_dynamic)
Jim Ingham78a685a2011-04-16 00:01:13 +00002399{
Greg Claytonafacd142011-09-02 01:15:17 +00002400 if (use_dynamic == eNoDynamicValues)
Jim Ingham2837b762011-05-04 03:43:18 +00002401 return ValueObjectSP();
2402
2403 if (!IsDynamic() && m_dynamic_value == NULL)
Jim Ingham78a685a2011-04-16 00:01:13 +00002404 {
Jim Ingham2837b762011-05-04 03:43:18 +00002405 CalculateDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:13 +00002406 }
Jim Ingham58b59f92011-04-22 23:53:53 +00002407 if (m_dynamic_value)
2408 return m_dynamic_value->GetSP();
2409 else
2410 return ValueObjectSP();
Jim Ingham22777012010-09-23 02:01:19 +00002411}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002412
Jim Ingham60dbabb2011-12-08 19:44:08 +00002413ValueObjectSP
2414ValueObject::GetStaticValue()
2415{
2416 return GetSP();
2417}
2418
Enrico Granata886147f2012-05-08 18:47:08 +00002419lldb::ValueObjectSP
2420ValueObject::GetNonSyntheticValue ()
2421{
2422 return GetSP();
2423}
2424
Enrico Granatad55546b2011-07-22 00:16:08 +00002425ValueObjectSP
Enrico Granata86cc9822012-03-19 22:58:49 +00002426ValueObject::GetSyntheticValue (bool use_synthetic)
Enrico Granatad55546b2011-07-22 00:16:08 +00002427{
Enrico Granata86cc9822012-03-19 22:58:49 +00002428 if (use_synthetic == false)
2429 return ValueObjectSP();
2430
Enrico Granatad55546b2011-07-22 00:16:08 +00002431 CalculateSyntheticValue(use_synthetic);
2432
2433 if (m_synthetic_value)
2434 return m_synthetic_value->GetSP();
2435 else
Enrico Granata86cc9822012-03-19 22:58:49 +00002436 return ValueObjectSP();
Enrico Granatad55546b2011-07-22 00:16:08 +00002437}
2438
Greg Claytone221f822011-01-21 01:59:00 +00002439bool
Enrico Granata27b625e2011-08-09 01:04:56 +00002440ValueObject::HasSyntheticValue()
2441{
Enrico Granata5548cb52013-01-28 23:47:25 +00002442 UpdateFormatsIfNeeded();
Enrico Granata27b625e2011-08-09 01:04:56 +00002443
Enrico Granata0c489f52012-03-01 04:24:26 +00002444 if (m_synthetic_children_sp.get() == NULL)
Enrico Granata27b625e2011-08-09 01:04:56 +00002445 return false;
2446
Enrico Granata86cc9822012-03-19 22:58:49 +00002447 CalculateSyntheticValue(true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002448
2449 if (m_synthetic_value)
2450 return true;
2451 else
2452 return false;
2453}
2454
2455bool
Greg Claytone221f822011-01-21 01:59:00 +00002456ValueObject::GetBaseClassPath (Stream &s)
2457{
2458 if (IsBaseClass())
2459 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002460 bool parent_had_base_class = GetParent() && GetParent()->GetBaseClassPath (s);
Greg Clayton57ee3062013-07-11 22:46:58 +00002461 ClangASTType clang_type = GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002462 std::string cxx_class_name;
Greg Clayton57ee3062013-07-11 22:46:58 +00002463 bool this_had_base_class = clang_type.GetCXXClassName (cxx_class_name);
Greg Claytone221f822011-01-21 01:59:00 +00002464 if (this_had_base_class)
2465 {
2466 if (parent_had_base_class)
2467 s.PutCString("::");
2468 s.PutCString(cxx_class_name.c_str());
2469 }
2470 return parent_had_base_class || this_had_base_class;
2471 }
2472 return false;
2473}
2474
2475
2476ValueObject *
2477ValueObject::GetNonBaseClassParent()
2478{
Jim Ingham78a685a2011-04-16 00:01:13 +00002479 if (GetParent())
Greg Claytone221f822011-01-21 01:59:00 +00002480 {
Jim Ingham78a685a2011-04-16 00:01:13 +00002481 if (GetParent()->IsBaseClass())
2482 return GetParent()->GetNonBaseClassParent();
Greg Claytone221f822011-01-21 01:59:00 +00002483 else
Jim Ingham78a685a2011-04-16 00:01:13 +00002484 return GetParent();
Greg Claytone221f822011-01-21 01:59:00 +00002485 }
2486 return NULL;
2487}
Greg Clayton1d3afba2010-10-05 00:00:42 +00002488
Enrico Granataa3c8f042014-08-19 22:29:08 +00002489
2490bool
2491ValueObject::IsBaseClass (uint32_t& depth)
2492{
2493 if (!IsBaseClass())
2494 {
2495 depth = 0;
2496 return false;
2497 }
2498 if (GetParent())
2499 {
2500 GetParent()->IsBaseClass(depth);
2501 depth = depth + 1;
2502 return true;
2503 }
2504 // TODO: a base of no parent? weird..
2505 depth = 1;
2506 return true;
2507}
2508
Greg Clayton1d3afba2010-10-05 00:00:42 +00002509void
Enrico Granata4becb372011-06-29 22:27:15 +00002510ValueObject::GetExpressionPath (Stream &s, bool qualify_cxx_base_classes, GetExpressionPathFormat epformat)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002511{
Greg Claytone221f822011-01-21 01:59:00 +00002512 const bool is_deref_of_parent = IsDereferenceOfParent ();
Greg Claytone221f822011-01-21 01:59:00 +00002513
Enrico Granata86cc9822012-03-19 22:58:49 +00002514 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002515 {
Enrico Granata4becb372011-06-29 22:27:15 +00002516 // this is the original format of GetExpressionPath() producing code like *(a_ptr).memberName, which is entirely
2517 // fine, until you put this into StackFrame::GetValueForVariableExpressionPath() which prefers to see a_ptr->memberName.
2518 // the eHonorPointers mode is meant to produce strings in this latter format
2519 s.PutCString("*(");
2520 }
Greg Claytone221f822011-01-21 01:59:00 +00002521
Enrico Granata4becb372011-06-29 22:27:15 +00002522 ValueObject* parent = GetParent();
2523
2524 if (parent)
2525 parent->GetExpressionPath (s, qualify_cxx_base_classes, epformat);
Enrico Granata0a3958e2011-07-02 00:25:22 +00002526
2527 // if we are a deref_of_parent just because we are synthetic array
2528 // members made up to allow ptr[%d] syntax to work in variable
2529 // printing, then add our name ([%d]) to the expression path
Enrico Granata86cc9822012-03-19 22:58:49 +00002530 if (m_is_array_item_for_pointer && epformat == eGetExpressionPathFormatHonorPointers)
Enrico Granata0a3958e2011-07-02 00:25:22 +00002531 s.PutCString(m_name.AsCString());
Enrico Granata4becb372011-06-29 22:27:15 +00002532
Greg Claytone221f822011-01-21 01:59:00 +00002533 if (!IsBaseClass())
2534 {
2535 if (!is_deref_of_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002536 {
Greg Claytone221f822011-01-21 01:59:00 +00002537 ValueObject *non_base_class_parent = GetNonBaseClassParent();
2538 if (non_base_class_parent)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002539 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002540 ClangASTType non_base_class_parent_clang_type = non_base_class_parent->GetClangType();
Greg Claytone221f822011-01-21 01:59:00 +00002541 if (non_base_class_parent_clang_type)
2542 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002543 if (parent && parent->IsDereferenceOfParent() && epformat == eGetExpressionPathFormatHonorPointers)
Greg Claytone221f822011-01-21 01:59:00 +00002544 {
2545 s.PutCString("->");
2546 }
Enrico Granata4becb372011-06-29 22:27:15 +00002547 else
2548 {
Greg Clayton57ee3062013-07-11 22:46:58 +00002549 const uint32_t non_base_class_parent_type_info = non_base_class_parent_clang_type.GetTypeInfo();
2550
Enrico Granata622be232014-10-21 20:52:14 +00002551 if (non_base_class_parent_type_info & eTypeIsPointer)
Enrico Granata4becb372011-06-29 22:27:15 +00002552 {
2553 s.PutCString("->");
2554 }
Enrico Granata622be232014-10-21 20:52:14 +00002555 else if ((non_base_class_parent_type_info & eTypeHasChildren) &&
2556 !(non_base_class_parent_type_info & eTypeIsArray))
Enrico Granata4becb372011-06-29 22:27:15 +00002557 {
2558 s.PutChar('.');
2559 }
Greg Claytone221f822011-01-21 01:59:00 +00002560 }
2561 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002562 }
Greg Claytone221f822011-01-21 01:59:00 +00002563
2564 const char *name = GetName().GetCString();
2565 if (name)
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002566 {
Greg Claytone221f822011-01-21 01:59:00 +00002567 if (qualify_cxx_base_classes)
2568 {
2569 if (GetBaseClassPath (s))
2570 s.PutCString("::");
2571 }
2572 s.PutCString(name);
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002573 }
2574 }
2575 }
2576
Enrico Granata86cc9822012-03-19 22:58:49 +00002577 if (is_deref_of_parent && epformat == eGetExpressionPathFormatDereferencePointers)
Enrico Granata85933ed2011-08-18 16:38:26 +00002578 {
Greg Claytone221f822011-01-21 01:59:00 +00002579 s.PutChar(')');
Enrico Granata4becb372011-06-29 22:27:15 +00002580 }
Greg Clayton8f92f0a2010-10-14 22:52:14 +00002581}
2582
Greg Claytonafacd142011-09-02 01:15:17 +00002583ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002584ValueObject::GetValueForExpressionPath(const char* expression,
2585 const char** first_unparsed,
2586 ExpressionPathScanEndReason* reason_to_stop,
2587 ExpressionPathEndResultType* final_value_type,
2588 const GetValueForExpressionPathOptions& options,
2589 ExpressionPathAftermath* final_task_on_target)
2590{
2591
2592 const char* dummy_first_unparsed;
Enrico Granataea2bc0f2013-02-21 19:57:10 +00002593 ExpressionPathScanEndReason dummy_reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnknown;
2594 ExpressionPathEndResultType dummy_final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata86cc9822012-03-19 22:58:49 +00002595 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002596
2597 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2598 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2599 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2600 final_value_type ? final_value_type : &dummy_final_value_type,
2601 options,
2602 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2603
Enrico Granata86cc9822012-03-19 22:58:49 +00002604 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002605 return ret_val;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002606
Enrico Granata86cc9822012-03-19 22:58:49 +00002607 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 +00002608 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002609 if ( (final_task_on_target ? *final_task_on_target : dummy_final_task_on_target) == ValueObject::eExpressionPathAftermathDereference)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002610 {
2611 Error error;
2612 ValueObjectSP final_value = ret_val->Dereference(error);
2613 if (error.Fail() || !final_value.get())
2614 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002615 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002616 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002617 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002618 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002619 return ValueObjectSP();
2620 }
2621 else
2622 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002623 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002624 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002625 return final_value;
2626 }
2627 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002628 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002629 {
2630 Error error;
2631 ValueObjectSP final_value = ret_val->AddressOf(error);
2632 if (error.Fail() || !final_value.get())
2633 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002634 if (reason_to_stop)
Enrico Granata86cc9822012-03-19 22:58:49 +00002635 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
Enrico Granata385ad4e2012-03-03 00:45:57 +00002636 if (final_value_type)
Enrico Granata86cc9822012-03-19 22:58:49 +00002637 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002638 return ValueObjectSP();
2639 }
2640 else
2641 {
Enrico Granata385ad4e2012-03-03 00:45:57 +00002642 if (final_task_on_target)
Enrico Granata86cc9822012-03-19 22:58:49 +00002643 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002644 return final_value;
2645 }
2646 }
2647 }
2648 return ret_val; // final_task_on_target will still have its original value, so you know I did not do it
2649}
2650
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002651int
2652ValueObject::GetValuesForExpressionPath(const char* expression,
Greg Claytonafacd142011-09-02 01:15:17 +00002653 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002654 const char** first_unparsed,
2655 ExpressionPathScanEndReason* reason_to_stop,
2656 ExpressionPathEndResultType* final_value_type,
2657 const GetValueForExpressionPathOptions& options,
2658 ExpressionPathAftermath* final_task_on_target)
2659{
2660 const char* dummy_first_unparsed;
2661 ExpressionPathScanEndReason dummy_reason_to_stop;
2662 ExpressionPathEndResultType dummy_final_value_type;
Enrico Granata86cc9822012-03-19 22:58:49 +00002663 ExpressionPathAftermath dummy_final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002664
2665 ValueObjectSP ret_val = GetValueForExpressionPath_Impl(expression,
2666 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2667 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2668 final_value_type ? final_value_type : &dummy_final_value_type,
2669 options,
2670 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2671
2672 if (!ret_val.get()) // if there are errors, I add nothing to the list
2673 return 0;
2674
Enrico Granata86ea8d82012-03-29 01:34:34 +00002675 if ( (reason_to_stop ? *reason_to_stop : dummy_reason_to_stop) != eExpressionPathScanEndReasonArrayRangeOperatorMet)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002676 {
2677 // I need not expand a range, just post-process the final value and return
Enrico Granata86cc9822012-03-19 22:58:49 +00002678 if (!final_task_on_target || *final_task_on_target == ValueObject::eExpressionPathAftermathNothing)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002679 {
2680 list->Append(ret_val);
2681 return 1;
2682 }
Enrico Granata86ea8d82012-03-29 01:34:34 +00002683 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 +00002684 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002685 if (*final_task_on_target == ValueObject::eExpressionPathAftermathDereference)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002686 {
2687 Error error;
2688 ValueObjectSP final_value = ret_val->Dereference(error);
2689 if (error.Fail() || !final_value.get())
2690 {
Greg Clayton23f59502012-07-17 03:23:13 +00002691 if (reason_to_stop)
2692 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
2693 if (final_value_type)
2694 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002695 return 0;
2696 }
2697 else
2698 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002699 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002700 list->Append(final_value);
2701 return 1;
2702 }
2703 }
Enrico Granata86cc9822012-03-19 22:58:49 +00002704 if (*final_task_on_target == ValueObject::eExpressionPathAftermathTakeAddress)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002705 {
2706 Error error;
2707 ValueObjectSP final_value = ret_val->AddressOf(error);
2708 if (error.Fail() || !final_value.get())
2709 {
Greg Clayton23f59502012-07-17 03:23:13 +00002710 if (reason_to_stop)
2711 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonTakingAddressFailed;
2712 if (final_value_type)
2713 *final_value_type = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002714 return 0;
2715 }
2716 else
2717 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002718 *final_task_on_target = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002719 list->Append(final_value);
2720 return 1;
2721 }
2722 }
2723 }
2724 }
2725 else
2726 {
2727 return ExpandArraySliceExpression(first_unparsed ? *first_unparsed : dummy_first_unparsed,
2728 first_unparsed ? first_unparsed : &dummy_first_unparsed,
2729 ret_val,
2730 list,
2731 reason_to_stop ? reason_to_stop : &dummy_reason_to_stop,
2732 final_value_type ? final_value_type : &dummy_final_value_type,
2733 options,
2734 final_task_on_target ? final_task_on_target : &dummy_final_task_on_target);
2735 }
2736 // in any non-covered case, just do the obviously right thing
2737 list->Append(ret_val);
2738 return 1;
2739}
2740
Greg Claytonafacd142011-09-02 01:15:17 +00002741ValueObjectSP
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002742ValueObject::GetValueForExpressionPath_Impl(const char* expression_cstr,
2743 const char** first_unparsed,
2744 ExpressionPathScanEndReason* reason_to_stop,
2745 ExpressionPathEndResultType* final_result,
2746 const GetValueForExpressionPathOptions& options,
2747 ExpressionPathAftermath* what_next)
2748{
2749 ValueObjectSP root = GetSP();
2750
2751 if (!root.get())
2752 return ValueObjectSP();
2753
2754 *first_unparsed = expression_cstr;
2755
2756 while (true)
2757 {
2758
2759 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
2760
Greg Clayton57ee3062013-07-11 22:46:58 +00002761 ClangASTType root_clang_type = root->GetClangType();
2762 ClangASTType pointee_clang_type;
2763 Flags pointee_clang_type_info;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002764
Greg Clayton57ee3062013-07-11 22:46:58 +00002765 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00002766 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00002767 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002768
2769 if (!expression_cstr || *expression_cstr == '\0')
2770 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002771 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002772 return root;
2773 }
2774
2775 switch (*expression_cstr)
2776 {
2777 case '-':
2778 {
2779 if (options.m_check_dot_vs_arrow_syntax &&
Enrico Granata622be232014-10-21 20:52:14 +00002780 root_clang_type_info.Test(eTypeIsPointer) ) // if you are trying to use -> on a non-pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002781 {
2782 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002783 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrowInsteadOfDot;
2784 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002785 return ValueObjectSP();
2786 }
Enrico Granata622be232014-10-21 20:52:14 +00002787 if (root_clang_type_info.Test(eTypeIsObjC) && // if yo are trying to extract an ObjC IVar when this is forbidden
2788 root_clang_type_info.Test(eTypeIsPointer) &&
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002789 options.m_no_fragile_ivar)
2790 {
2791 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002792 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonFragileIVarNotAllowed;
2793 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002794 return ValueObjectSP();
2795 }
2796 if (expression_cstr[1] != '>')
2797 {
2798 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002799 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2800 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002801 return ValueObjectSP();
2802 }
2803 expression_cstr++; // skip the -
2804 }
2805 case '.': // or fallthrough from ->
2806 {
2807 if (options.m_check_dot_vs_arrow_syntax && *expression_cstr == '.' &&
Enrico Granata622be232014-10-21 20:52:14 +00002808 root_clang_type_info.Test(eTypeIsPointer)) // if you are trying to use . on a pointer and I must catch the error
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002809 {
2810 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002811 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDotInsteadOfArrow;
2812 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002813 return ValueObjectSP();
2814 }
2815 expression_cstr++; // skip .
2816 const char *next_separator = strpbrk(expression_cstr+1,"-.[");
2817 ConstString child_name;
2818 if (!next_separator) // if no other separator just expand this last layer
2819 {
2820 child_name.SetCString (expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002821 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2822
2823 if (child_valobj_sp.get()) // we know we are done, so just return
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002824 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002825 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002826 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2827 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002828 return child_valobj_sp;
2829 }
2830 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2831 {
Enrico Granata86cc9822012-03-19 22:58:49 +00002832 if (root->IsSynthetic())
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002833 {
2834 *first_unparsed = expression_cstr;
Enrico Granatad07cfd32014-10-08 18:27:36 +00002835 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchSyntheticChild;
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002836 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2837 return ValueObjectSP();
2838 }
2839
2840 child_valobj_sp = root->GetSyntheticValue();
Enrico Granata86cc9822012-03-19 22:58:49 +00002841 if (child_valobj_sp.get())
2842 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002843 }
2844
2845 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2846 // so we hit the "else" branch, and return an error
2847 if(child_valobj_sp.get()) // if it worked, just return
2848 {
Daniel Maleaa85e6b62012-12-07 22:21:08 +00002849 *first_unparsed = "";
Enrico Granata86cc9822012-03-19 22:58:49 +00002850 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
2851 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002852 return child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002853 }
2854 else
2855 {
2856 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002857 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2858 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002859 return ValueObjectSP();
2860 }
2861 }
2862 else // other layers do expand
2863 {
2864 child_name.SetCStringWithLength(expression_cstr, next_separator - expression_cstr);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002865 ValueObjectSP child_valobj_sp = root->GetChildMemberWithName(child_name, true);
2866 if (child_valobj_sp.get()) // store the new root and move on
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002867 {
Enrico Granata8c9d3562011-08-11 17:08:01 +00002868 root = child_valobj_sp;
2869 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002870 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00002871 continue;
2872 }
2873 else if (options.m_no_synthetic_children == false) // let's try with synthetic children
2874 {
Enrico Granatadf31a8a2012-08-02 17:34:05 +00002875 if (root->IsSynthetic())
2876 {
2877 *first_unparsed = expression_cstr;
2878 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2879 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
2880 return ValueObjectSP();
2881 }
2882
Enrico Granata86cc9822012-03-19 22:58:49 +00002883 child_valobj_sp = root->GetSyntheticValue(true);
2884 if (child_valobj_sp)
2885 child_valobj_sp = child_valobj_sp->GetChildMemberWithName(child_name, true);
Enrico Granata8c9d3562011-08-11 17:08:01 +00002886 }
2887
2888 // if we are here and options.m_no_synthetic_children is true, child_valobj_sp is going to be a NULL SP,
2889 // so we hit the "else" branch, and return an error
2890 if(child_valobj_sp.get()) // if it worked, move on
2891 {
2892 root = child_valobj_sp;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002893 *first_unparsed = next_separator;
Enrico Granata86cc9822012-03-19 22:58:49 +00002894 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002895 continue;
2896 }
2897 else
2898 {
2899 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002900 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
2901 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002902 return ValueObjectSP();
2903 }
2904 }
2905 break;
2906 }
2907 case '[':
2908 {
Enrico Granata622be232014-10-21 20:52:14 +00002909 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer) && !root_clang_type_info.Test(eTypeIsVector)) // if this is not a T[] nor a T*
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002910 {
Enrico Granata622be232014-10-21 20:52:14 +00002911 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar...
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002912 {
Enrico Granata27b625e2011-08-09 01:04:56 +00002913 if (options.m_no_synthetic_children) // ...only chance left is synthetic
2914 {
2915 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002916 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
2917 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00002918 return ValueObjectSP();
2919 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002920 }
2921 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
2922 {
2923 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002924 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
2925 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002926 return ValueObjectSP();
2927 }
2928 }
2929 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
2930 {
Enrico Granata622be232014-10-21 20:52:14 +00002931 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002932 {
2933 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002934 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2935 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002936 return ValueObjectSP();
2937 }
2938 else // even if something follows, we cannot expand unbounded ranges, just let the caller do it
2939 {
2940 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002941 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2942 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002943 return root;
2944 }
2945 }
2946 const char *separator_position = ::strchr(expression_cstr+1,'-');
2947 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
2948 if (!close_bracket_position) // if there is no ], this is a syntax error
2949 {
2950 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002951 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2952 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002953 return ValueObjectSP();
2954 }
2955 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
2956 {
2957 char *end = NULL;
2958 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
2959 if (!end || end != close_bracket_position) // if something weird is in our way return an error
2960 {
2961 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002962 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
2963 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002964 return ValueObjectSP();
2965 }
2966 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
2967 {
Enrico Granata622be232014-10-21 20:52:14 +00002968 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002969 {
2970 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00002971 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
2972 *final_result = ValueObject::eExpressionPathEndResultTypeUnboundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002973 return root;
2974 }
2975 else
2976 {
2977 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00002978 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
2979 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002980 return ValueObjectSP();
2981 }
2982 }
2983 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00002984 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00002985 {
Greg Claytondaf515f2011-07-09 20:12:33 +00002986 ValueObjectSP child_valobj_sp = root->GetChildAtIndex(index, true);
2987 if (!child_valobj_sp)
2988 child_valobj_sp = root->GetSyntheticArrayMemberFromArray(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00002989 if (!child_valobj_sp)
Enrico Granata86cc9822012-03-19 22:58:49 +00002990 if (root->HasSyntheticValue() && root->GetSyntheticValue()->GetNumChildren() > index)
2991 child_valobj_sp = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Greg Claytondaf515f2011-07-09 20:12:33 +00002992 if (child_valobj_sp)
2993 {
2994 root = child_valobj_sp;
2995 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00002996 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Greg Claytondaf515f2011-07-09 20:12:33 +00002997 continue;
2998 }
2999 else
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003000 {
3001 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003002 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3003 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003004 return ValueObjectSP();
3005 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003006 }
Enrico Granata622be232014-10-21 20:52:14 +00003007 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003008 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003009 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
Enrico Granata622be232014-10-21 20:52:14 +00003010 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003011 {
3012 Error error;
3013 root = root->Dereference(error);
3014 if (error.Fail() || !root.get())
3015 {
3016 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003017 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3018 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003019 return ValueObjectSP();
3020 }
3021 else
3022 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003023 *what_next = eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003024 continue;
3025 }
3026 }
3027 else
3028 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003029 if (root->GetClangType().GetMinimumLanguage() == eLanguageTypeObjC
Enrico Granata622be232014-10-21 20:52:14 +00003030 && pointee_clang_type_info.AllClear(eTypeIsPointer)
Greg Clayton84db9102012-03-26 23:03:23 +00003031 && root->HasSyntheticValue()
3032 && options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003033 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003034 root = root->GetSyntheticValue()->GetChildAtIndex(index, true);
Enrico Granata27b625e2011-08-09 01:04:56 +00003035 }
3036 else
3037 root = root->GetSyntheticArrayMemberFromPointer(index, true);
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003038 if (!root.get())
3039 {
3040 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003041 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3042 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003043 return ValueObjectSP();
3044 }
3045 else
3046 {
3047 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003048 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003049 continue;
3050 }
3051 }
3052 }
Enrico Granata622be232014-10-21 20:52:14 +00003053 else if (root_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003054 {
3055 root = root->GetSyntheticBitFieldChild(index, index, true);
3056 if (!root.get())
3057 {
3058 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003059 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3060 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003061 return ValueObjectSP();
3062 }
3063 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3064 {
3065 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003066 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3067 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003068 return root;
3069 }
3070 }
Enrico Granata622be232014-10-21 20:52:14 +00003071 else if (root_clang_type_info.Test(eTypeIsVector))
Enrico Granata08a1bb82013-06-19 00:00:45 +00003072 {
3073 root = root->GetChildAtIndex(index, true);
3074 if (!root.get())
3075 {
3076 *first_unparsed = expression_cstr;
3077 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3078 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3079 return ValueObjectSP();
3080 }
3081 else
3082 {
3083 *first_unparsed = end+1; // skip ]
3084 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
3085 continue;
3086 }
3087 }
Enrico Granata86cc9822012-03-19 22:58:49 +00003088 else if (options.m_no_synthetic_children == false)
Enrico Granata27b625e2011-08-09 01:04:56 +00003089 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003090 if (root->HasSyntheticValue())
3091 root = root->GetSyntheticValue();
3092 else if (!root->IsSynthetic())
3093 {
3094 *first_unparsed = expression_cstr;
3095 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3096 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3097 return ValueObjectSP();
3098 }
3099 // if we are here, then root itself is a synthetic VO.. should be good to go
3100
Enrico Granata27b625e2011-08-09 01:04:56 +00003101 if (!root.get())
3102 {
3103 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003104 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonSyntheticValueMissing;
3105 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
3106 return ValueObjectSP();
3107 }
3108 root = root->GetChildAtIndex(index, true);
3109 if (!root.get())
3110 {
3111 *first_unparsed = expression_cstr;
3112 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3113 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003114 return ValueObjectSP();
3115 }
Enrico Granata8c9d3562011-08-11 17:08:01 +00003116 else
3117 {
3118 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003119 *final_result = ValueObject::eExpressionPathEndResultTypePlain;
Enrico Granata8c9d3562011-08-11 17:08:01 +00003120 continue;
3121 }
Enrico Granata27b625e2011-08-09 01:04:56 +00003122 }
3123 else
3124 {
3125 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003126 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3127 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granata27b625e2011-08-09 01:04:56 +00003128 return ValueObjectSP();
3129 }
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003130 }
3131 else // we have a low and a high index
3132 {
3133 char *end = NULL;
3134 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3135 if (!end || end != separator_position) // if something weird is in our way return an error
3136 {
3137 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003138 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3139 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003140 return ValueObjectSP();
3141 }
3142 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3143 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3144 {
3145 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003146 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3147 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003148 return ValueObjectSP();
3149 }
3150 if (index_lower > index_higher) // swap indices if required
3151 {
3152 unsigned long temp = index_lower;
3153 index_lower = index_higher;
3154 index_higher = temp;
3155 }
Enrico Granata622be232014-10-21 20:52:14 +00003156 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003157 {
3158 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3159 if (!root.get())
3160 {
3161 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003162 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3163 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003164 return ValueObjectSP();
3165 }
3166 else
3167 {
3168 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003169 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonBitfieldRangeOperatorMet;
3170 *final_result = ValueObject::eExpressionPathEndResultTypeBitfield;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003171 return root;
3172 }
3173 }
Enrico Granata622be232014-10-21 20:52:14 +00003174 else if (root_clang_type_info.Test(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 +00003175 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003176 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003177 {
3178 Error error;
3179 root = root->Dereference(error);
3180 if (error.Fail() || !root.get())
3181 {
3182 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003183 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3184 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003185 return ValueObjectSP();
3186 }
3187 else
3188 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003189 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003190 continue;
3191 }
3192 }
3193 else
3194 {
3195 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003196 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonArrayRangeOperatorMet;
3197 *final_result = ValueObject::eExpressionPathEndResultTypeBoundedRange;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003198 return root;
3199 }
3200 }
3201 break;
3202 }
3203 default: // some non-separator is in the way
3204 {
3205 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003206 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3207 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granatafc7a7f32011-07-08 02:51:01 +00003208 return ValueObjectSP();
3209 break;
3210 }
3211 }
3212 }
3213}
3214
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003215int
3216ValueObject::ExpandArraySliceExpression(const char* expression_cstr,
3217 const char** first_unparsed,
Greg Claytonafacd142011-09-02 01:15:17 +00003218 ValueObjectSP root,
3219 ValueObjectListSP& list,
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003220 ExpressionPathScanEndReason* reason_to_stop,
3221 ExpressionPathEndResultType* final_result,
3222 const GetValueForExpressionPathOptions& options,
3223 ExpressionPathAftermath* what_next)
3224{
3225 if (!root.get())
3226 return 0;
3227
3228 *first_unparsed = expression_cstr;
3229
3230 while (true)
3231 {
3232
3233 const char* expression_cstr = *first_unparsed; // hide the top level expression_cstr
3234
Greg Clayton57ee3062013-07-11 22:46:58 +00003235 ClangASTType root_clang_type = root->GetClangType();
3236 ClangASTType pointee_clang_type;
3237 Flags pointee_clang_type_info;
3238 Flags root_clang_type_info(root_clang_type.GetTypeInfo(&pointee_clang_type));
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003239 if (pointee_clang_type)
Greg Clayton57ee3062013-07-11 22:46:58 +00003240 pointee_clang_type_info.Reset(pointee_clang_type.GetTypeInfo());
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003241
3242 if (!expression_cstr || *expression_cstr == '\0')
3243 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003244 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEndOfString;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003245 list->Append(root);
3246 return 1;
3247 }
3248
3249 switch (*expression_cstr)
3250 {
3251 case '[':
3252 {
Enrico Granata622be232014-10-21 20:52:14 +00003253 if (!root_clang_type_info.Test(eTypeIsArray) && !root_clang_type_info.Test(eTypeIsPointer)) // if this is not a T[] nor a T*
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003254 {
Enrico Granata622be232014-10-21 20:52:14 +00003255 if (!root_clang_type_info.Test(eTypeIsScalar)) // if this is not even a scalar, this syntax is just plain wrong!
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003256 {
3257 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003258 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorInvalid;
3259 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003260 return 0;
3261 }
3262 else if (!options.m_allow_bitfields_syntax) // if this is a scalar, check that we can expand bitfields
3263 {
3264 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003265 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorNotAllowed;
3266 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003267 return 0;
3268 }
3269 }
3270 if (*(expression_cstr+1) == ']') // if this is an unbounded range it only works for arrays
3271 {
Enrico Granata622be232014-10-21 20:52:14 +00003272 if (!root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003273 {
3274 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003275 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3276 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003277 return 0;
3278 }
3279 else // expand this into list
3280 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003281 const size_t max_index = root->GetNumChildren() - 1;
3282 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003283 {
3284 ValueObjectSP child =
3285 root->GetChildAtIndex(index, true);
3286 list->Append(child);
3287 }
3288 *first_unparsed = expression_cstr+2;
Enrico Granata86cc9822012-03-19 22:58:49 +00003289 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3290 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003291 return max_index; // tell me number of items I added to the VOList
3292 }
3293 }
3294 const char *separator_position = ::strchr(expression_cstr+1,'-');
3295 const char *close_bracket_position = ::strchr(expression_cstr+1,']');
3296 if (!close_bracket_position) // if there is no ], this is a syntax error
3297 {
3298 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003299 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3300 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003301 return 0;
3302 }
3303 if (!separator_position || separator_position > close_bracket_position) // if no separator, this is either [] or [N]
3304 {
3305 char *end = NULL;
3306 unsigned long index = ::strtoul (expression_cstr+1, &end, 0);
3307 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3308 {
3309 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003310 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3311 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003312 return 0;
3313 }
3314 if (end - expression_cstr == 1) // if this is [], only return a valid value for arrays
3315 {
Enrico Granata622be232014-10-21 20:52:14 +00003316 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003317 {
Greg Claytonc7bece562013-01-25 18:06:21 +00003318 const size_t max_index = root->GetNumChildren() - 1;
3319 for (size_t index = 0; index < max_index; index++)
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003320 {
3321 ValueObjectSP child =
3322 root->GetChildAtIndex(index, true);
3323 list->Append(child);
3324 }
3325 *first_unparsed = expression_cstr+2;
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 max_index; // tell me number of items I added to the VOList
3329 }
3330 else
3331 {
3332 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003333 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonEmptyRangeNotAllowed;
3334 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003335 return 0;
3336 }
3337 }
3338 // from here on we do have a valid index
Enrico Granata622be232014-10-21 20:52:14 +00003339 if (root_clang_type_info.Test(eTypeIsArray))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003340 {
3341 root = root->GetChildAtIndex(index, true);
3342 if (!root.get())
3343 {
3344 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003345 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3346 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003347 return 0;
3348 }
3349 else
3350 {
3351 list->Append(root);
3352 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003353 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3354 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003355 return 1;
3356 }
3357 }
Enrico Granata622be232014-10-21 20:52:14 +00003358 else if (root_clang_type_info.Test(eTypeIsPointer))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003359 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003360 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
Enrico Granata622be232014-10-21 20:52:14 +00003361 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003362 {
3363 Error error;
3364 root = root->Dereference(error);
3365 if (error.Fail() || !root.get())
3366 {
3367 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003368 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3369 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003370 return 0;
3371 }
3372 else
3373 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003374 *what_next = eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003375 continue;
3376 }
3377 }
3378 else
3379 {
3380 root = root->GetSyntheticArrayMemberFromPointer(index, true);
3381 if (!root.get())
3382 {
3383 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003384 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3385 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003386 return 0;
3387 }
3388 else
3389 {
3390 list->Append(root);
3391 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003392 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3393 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003394 return 1;
3395 }
3396 }
3397 }
3398 else /*if (ClangASTContext::IsScalarType(root_clang_type))*/
3399 {
3400 root = root->GetSyntheticBitFieldChild(index, index, true);
3401 if (!root.get())
3402 {
3403 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003404 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3405 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003406 return 0;
3407 }
3408 else // we do not know how to expand members of bitfields, so we just return and let the caller do any further processing
3409 {
3410 list->Append(root);
3411 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003412 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3413 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003414 return 1;
3415 }
3416 }
3417 }
3418 else // we have a low and a high index
3419 {
3420 char *end = NULL;
3421 unsigned long index_lower = ::strtoul (expression_cstr+1, &end, 0);
3422 if (!end || end != separator_position) // if something weird is in our way return an error
3423 {
3424 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003425 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3426 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003427 return 0;
3428 }
3429 unsigned long index_higher = ::strtoul (separator_position+1, &end, 0);
3430 if (!end || end != close_bracket_position) // if something weird is in our way return an error
3431 {
3432 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003433 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3434 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003435 return 0;
3436 }
3437 if (index_lower > index_higher) // swap indices if required
3438 {
3439 unsigned long temp = index_lower;
3440 index_lower = index_higher;
3441 index_higher = temp;
3442 }
Enrico Granata622be232014-10-21 20:52:14 +00003443 if (root_clang_type_info.Test(eTypeIsScalar)) // expansion only works for scalars
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003444 {
3445 root = root->GetSyntheticBitFieldChild(index_lower, index_higher, true);
3446 if (!root.get())
3447 {
3448 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003449 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonNoSuchChild;
3450 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003451 return 0;
3452 }
3453 else
3454 {
3455 list->Append(root);
3456 *first_unparsed = end+1; // skip ]
Enrico Granata86cc9822012-03-19 22:58:49 +00003457 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3458 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003459 return 1;
3460 }
3461 }
Enrico Granata622be232014-10-21 20:52:14 +00003462 else if (root_clang_type_info.Test(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 +00003463 *what_next == ValueObject::eExpressionPathAftermathDereference &&
Enrico Granata622be232014-10-21 20:52:14 +00003464 pointee_clang_type_info.Test(eTypeIsScalar))
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003465 {
3466 Error error;
3467 root = root->Dereference(error);
3468 if (error.Fail() || !root.get())
3469 {
3470 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003471 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonDereferencingFailed;
3472 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003473 return 0;
3474 }
3475 else
3476 {
Enrico Granata86cc9822012-03-19 22:58:49 +00003477 *what_next = ValueObject::eExpressionPathAftermathNothing;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003478 continue;
3479 }
3480 }
3481 else
3482 {
Johnny Chen44805302011-07-19 19:48:13 +00003483 for (unsigned long index = index_lower;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003484 index <= index_higher; index++)
3485 {
3486 ValueObjectSP child =
3487 root->GetChildAtIndex(index, true);
3488 list->Append(child);
3489 }
3490 *first_unparsed = end+1;
Enrico Granata86cc9822012-03-19 22:58:49 +00003491 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonRangeOperatorExpanded;
3492 *final_result = ValueObject::eExpressionPathEndResultTypeValueObjectList;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003493 return index_higher-index_lower+1; // tell me number of items I added to the VOList
3494 }
3495 }
3496 break;
3497 }
3498 default: // some non-[ separator, or something entirely wrong, is in the way
3499 {
3500 *first_unparsed = expression_cstr;
Enrico Granata86cc9822012-03-19 22:58:49 +00003501 *reason_to_stop = ValueObject::eExpressionPathScanEndReasonUnexpectedSymbol;
3502 *final_result = ValueObject::eExpressionPathEndResultTypeInvalid;
Enrico Granataf9fa6ee2011-07-12 00:18:11 +00003503 return 0;
3504 break;
3505 }
3506 }
3507 }
3508}
3509
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003510void
3511ValueObject::LogValueObject (Log *log)
Greg Clayton1d3afba2010-10-05 00:00:42 +00003512{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003513 if (log)
3514 return LogValueObject (log, DumpValueObjectOptions::DefaultOptions());
Greg Clayton1d3afba2010-10-05 00:00:42 +00003515}
3516
Enrico Granata0c489f52012-03-01 04:24:26 +00003517void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003518ValueObject::LogValueObject (Log *log, const DumpValueObjectOptions& options)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003519{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003520 if (log)
Greg Claytonf830dbb2012-03-22 18:15:37 +00003521 {
3522 StreamString s;
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003523 Dump (s, options);
Greg Claytonf830dbb2012-03-22 18:15:37 +00003524 if (s.GetSize())
3525 log->PutCString(s.GetData());
3526 }
3527}
3528
3529void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003530ValueObject::Dump (Stream &s)
Enrico Granata0c489f52012-03-01 04:24:26 +00003531{
3532
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003533 ValueObjectPrinter printer(this,&s,DumpValueObjectOptions::DefaultOptions());
3534 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003535}
3536
3537void
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003538ValueObject::Dump (Stream &s,
3539 const DumpValueObjectOptions& options)
Enrico Granata0c489f52012-03-01 04:24:26 +00003540{
Enrico Granata4d93b8c2013-09-30 19:11:51 +00003541 ValueObjectPrinter printer(this,&s,options);
3542 printer.PrintValueObject();
Enrico Granata0c489f52012-03-01 04:24:26 +00003543}
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003544
3545ValueObjectSP
Jim Ingham6035b672011-03-31 00:19:25 +00003546ValueObject::CreateConstantValue (const ConstString &name)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003547{
3548 ValueObjectSP valobj_sp;
3549
Enrico Granatac3e320a2011-08-02 17:27:39 +00003550 if (UpdateValueIfNeeded(false) && m_error.Success())
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003551 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003552 ExecutionContext exe_ctx (GetExecutionContextRef());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003553
3554 DataExtractor data;
3555 data.SetByteOrder (m_data.GetByteOrder());
3556 data.SetAddressByteSize(m_data.GetAddressByteSize());
3557
Enrico Granata9f1e2042012-04-24 22:15:37 +00003558 if (IsBitfield())
3559 {
3560 Value v(Scalar(GetValueAsUnsigned(UINT64_MAX)));
Greg Clayton57ee3062013-07-11 22:46:58 +00003561 m_error = v.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Enrico Granata9f1e2042012-04-24 22:15:37 +00003562 }
3563 else
Greg Clayton57ee3062013-07-11 22:46:58 +00003564 m_error = m_value.GetValueAsData (&exe_ctx, data, 0, GetModule().get());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003565
3566 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003567 GetClangType(),
3568 name,
3569 data,
3570 GetAddressOf());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003571 }
Jim Ingham6035b672011-03-31 00:19:25 +00003572
3573 if (!valobj_sp)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003574 {
Greg Claytoneeb15652013-12-10 23:16:40 +00003575 ExecutionContext exe_ctx (GetExecutionContextRef());
3576 valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), m_error);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003577 }
3578 return valobj_sp;
3579}
3580
Enrico Granata538a88a2014-10-09 18:24:30 +00003581ValueObjectSP
3582ValueObject::GetQualifiedRepresentationIfAvailable (lldb::DynamicValueType dynValue,
3583 bool synthValue)
3584{
3585 ValueObjectSP result_sp(GetSP());
3586
3587 switch (dynValue)
3588 {
3589 case lldb::eDynamicCanRunTarget:
3590 case lldb::eDynamicDontRunTarget:
3591 {
3592 if (!result_sp->IsDynamic())
3593 {
3594 if (result_sp->GetDynamicValue(dynValue))
3595 result_sp = result_sp->GetDynamicValue(dynValue);
3596 }
3597 }
3598 break;
3599 case lldb::eNoDynamicValues:
Enrico Granata538a88a2014-10-09 18:24:30 +00003600 {
3601 if (result_sp->IsDynamic())
3602 {
3603 if (result_sp->GetStaticValue())
3604 result_sp = result_sp->GetStaticValue();
3605 }
3606 }
3607 break;
3608 }
3609
3610 if (synthValue)
3611 {
3612 if (!result_sp->IsSynthetic())
3613 {
3614 if (result_sp->GetSyntheticValue())
3615 result_sp = result_sp->GetSyntheticValue();
3616 }
3617 }
3618 else
3619 {
3620 if (result_sp->IsSynthetic())
3621 {
3622 if (result_sp->GetNonSyntheticValue())
3623 result_sp = result_sp->GetNonSyntheticValue();
3624 }
3625 }
3626
3627 return result_sp;
3628}
3629
Greg Clayton759e7442014-07-19 00:12:57 +00003630lldb::addr_t
3631ValueObject::GetCPPVTableAddress (AddressType &address_type)
3632{
3633 ClangASTType pointee_type;
3634 ClangASTType this_type(GetClangType());
3635 uint32_t type_info = this_type.GetTypeInfo(&pointee_type);
3636 if (type_info)
3637 {
3638 bool ptr_or_ref = false;
Enrico Granata622be232014-10-21 20:52:14 +00003639 if (type_info & (eTypeIsPointer | eTypeIsReference))
Greg Clayton759e7442014-07-19 00:12:57 +00003640 {
3641 ptr_or_ref = true;
3642 type_info = pointee_type.GetTypeInfo();
3643 }
3644
Enrico Granata622be232014-10-21 20:52:14 +00003645 const uint32_t cpp_class = eTypeIsClass | eTypeIsCPlusPlus;
Greg Clayton759e7442014-07-19 00:12:57 +00003646 if ((type_info & cpp_class) == cpp_class)
3647 {
3648 if (ptr_or_ref)
3649 {
3650 address_type = GetAddressTypeOfChildren();
3651 return GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
3652 }
3653 else
3654 return GetAddressOf (false, &address_type);
3655 }
3656 }
3657
3658 address_type = eAddressTypeInvalid;
3659 return LLDB_INVALID_ADDRESS;
3660}
3661
Greg Claytonafacd142011-09-02 01:15:17 +00003662ValueObjectSP
Greg Claytonaf67cec2010-12-20 20:49:23 +00003663ValueObject::Dereference (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003664{
Jim Ingham58b59f92011-04-22 23:53:53 +00003665 if (m_deref_valobj)
3666 return m_deref_valobj->GetSP();
Jim Ingham78a685a2011-04-16 00:01:13 +00003667
Greg Clayton54979cd2010-12-15 05:08:08 +00003668 const bool is_pointer_type = IsPointerType();
3669 if (is_pointer_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003670 {
3671 bool omit_empty_base_classes = true;
Greg Claytondaf515f2011-07-09 20:12:33 +00003672 bool ignore_array_bounds = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003673
3674 std::string child_name_str;
3675 uint32_t child_byte_size = 0;
3676 int32_t child_byte_offset = 0;
3677 uint32_t child_bitfield_bit_size = 0;
3678 uint32_t child_bitfield_bit_offset = 0;
3679 bool child_is_base_class = false;
Greg Claytone221f822011-01-21 01:59:00 +00003680 bool child_is_deref_of_parent = false;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003681 const bool transparent_pointers = false;
Greg Clayton57ee3062013-07-11 22:46:58 +00003682 ClangASTType clang_type = GetClangType();
3683 ClangASTType child_clang_type;
Jim Inghamd555bac2011-06-24 22:03:24 +00003684
Greg Claytoncc4d0142012-02-17 07:49:44 +00003685 ExecutionContext exe_ctx (GetExecutionContextRef());
Jim Inghamd555bac2011-06-24 22:03:24 +00003686
Greg Clayton57ee3062013-07-11 22:46:58 +00003687 child_clang_type = clang_type.GetChildClangTypeAtIndex (&exe_ctx,
Greg Clayton57ee3062013-07-11 22:46:58 +00003688 0,
3689 transparent_pointers,
3690 omit_empty_base_classes,
3691 ignore_array_bounds,
3692 child_name_str,
3693 child_byte_size,
3694 child_byte_offset,
3695 child_bitfield_bit_size,
3696 child_bitfield_bit_offset,
3697 child_is_base_class,
Greg Clayton759e7442014-07-19 00:12:57 +00003698 child_is_deref_of_parent,
3699 this);
Greg Clayton3e06bd92011-01-09 21:07:35 +00003700 if (child_clang_type && child_byte_size)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003701 {
3702 ConstString child_name;
3703 if (!child_name_str.empty())
3704 child_name.SetCString (child_name_str.c_str());
3705
Jim Ingham58b59f92011-04-22 23:53:53 +00003706 m_deref_valobj = new ValueObjectChild (*this,
Jim Ingham58b59f92011-04-22 23:53:53 +00003707 child_clang_type,
3708 child_name,
3709 child_byte_size,
3710 child_byte_offset,
3711 child_bitfield_bit_size,
3712 child_bitfield_bit_offset,
3713 child_is_base_class,
Enrico Granata9128ee22011-09-06 19:20:51 +00003714 child_is_deref_of_parent,
3715 eAddressTypeInvalid);
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003716 }
3717 }
Greg Clayton54979cd2010-12-15 05:08:08 +00003718
Jim Ingham58b59f92011-04-22 23:53:53 +00003719 if (m_deref_valobj)
Greg Clayton54979cd2010-12-15 05:08:08 +00003720 {
3721 error.Clear();
Jim Ingham58b59f92011-04-22 23:53:53 +00003722 return m_deref_valobj->GetSP();
Greg Clayton54979cd2010-12-15 05:08:08 +00003723 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003724 else
3725 {
Greg Clayton54979cd2010-12-15 05:08:08 +00003726 StreamString strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003727 GetExpressionPath(strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003728
3729 if (is_pointer_type)
3730 error.SetErrorStringWithFormat("dereference failed: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
3731 else
3732 error.SetErrorStringWithFormat("not a pointer type: (%s) %s", GetTypeName().AsCString("<invalid type>"), strm.GetString().c_str());
Jim Ingham58b59f92011-04-22 23:53:53 +00003733 return ValueObjectSP();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003734 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003735}
3736
Greg Claytonafacd142011-09-02 01:15:17 +00003737ValueObjectSP
Greg Clayton54979cd2010-12-15 05:08:08 +00003738ValueObject::AddressOf (Error &error)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003739{
Jim Ingham78a685a2011-04-16 00:01:13 +00003740 if (m_addr_of_valobj_sp)
3741 return m_addr_of_valobj_sp;
3742
Greg Claytone0d378b2011-03-24 21:19:54 +00003743 AddressType address_type = eAddressTypeInvalid;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003744 const bool scalar_is_load_address = false;
Enrico Granata9128ee22011-09-06 19:20:51 +00003745 addr_t addr = GetAddressOf (scalar_is_load_address, &address_type);
Greg Clayton54979cd2010-12-15 05:08:08 +00003746 error.Clear();
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003747 if (addr != LLDB_INVALID_ADDRESS)
3748 {
3749 switch (address_type)
3750 {
3751 case eAddressTypeInvalid:
Greg Clayton54979cd2010-12-15 05:08:08 +00003752 {
3753 StreamString expr_path_strm;
Greg Clayton6beaaa62011-01-17 03:46:26 +00003754 GetExpressionPath(expr_path_strm, true);
Greg Clayton54979cd2010-12-15 05:08:08 +00003755 error.SetErrorStringWithFormat("'%s' is not in memory", expr_path_strm.GetString().c_str());
3756 }
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003757 break;
Greg Clayton54979cd2010-12-15 05:08:08 +00003758
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003759 case eAddressTypeFile:
3760 case eAddressTypeLoad:
3761 case eAddressTypeHost:
3762 {
Greg Clayton57ee3062013-07-11 22:46:58 +00003763 ClangASTType clang_type = GetClangType();
3764 if (clang_type)
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003765 {
3766 std::string name (1, '&');
3767 name.append (m_name.AsCString(""));
Greg Claytoncc4d0142012-02-17 07:49:44 +00003768 ExecutionContext exe_ctx (GetExecutionContextRef());
3769 m_addr_of_valobj_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00003770 clang_type.GetPointerType(),
Jim Ingham58b59f92011-04-22 23:53:53 +00003771 ConstString (name.c_str()),
3772 addr,
3773 eAddressTypeInvalid,
3774 m_data.GetAddressByteSize());
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003775 }
3776 }
3777 break;
3778 }
3779 }
Sean Callananed185ab2013-04-19 19:47:32 +00003780 else
3781 {
3782 StreamString expr_path_strm;
3783 GetExpressionPath(expr_path_strm, true);
3784 error.SetErrorStringWithFormat("'%s' doesn't have a valid address", expr_path_strm.GetString().c_str());
3785 }
3786
Jim Ingham78a685a2011-04-16 00:01:13 +00003787 return m_addr_of_valobj_sp;
Greg Clayton8b2fe6d2010-12-14 02:59:59 +00003788}
3789
Greg Clayton9a142cf2012-02-03 05:34:10 +00003790ValueObjectSP
3791ValueObject::Cast (const ClangASTType &clang_ast_type)
3792{
Greg Clayton81e871e2012-02-04 02:27:34 +00003793 return ValueObjectCast::Create (*this, GetName(), clang_ast_type);
Greg Clayton9a142cf2012-02-03 05:34:10 +00003794}
Greg Claytonb2dcc362011-05-05 23:32:56 +00003795
Greg Claytonafacd142011-09-02 01:15:17 +00003796ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003797ValueObject::CastPointerType (const char *name, ClangASTType &clang_ast_type)
3798{
Greg Claytonafacd142011-09-02 01:15:17 +00003799 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003800 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003801 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003802
3803 if (ptr_value != LLDB_INVALID_ADDRESS)
3804 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003805 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003806 ExecutionContext exe_ctx (GetExecutionContextRef());
3807 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003808 name,
3809 ptr_addr,
3810 clang_ast_type);
3811 }
3812 return valobj_sp;
3813}
3814
Greg Claytonafacd142011-09-02 01:15:17 +00003815ValueObjectSP
Greg Claytonb2dcc362011-05-05 23:32:56 +00003816ValueObject::CastPointerType (const char *name, TypeSP &type_sp)
3817{
Greg Claytonafacd142011-09-02 01:15:17 +00003818 ValueObjectSP valobj_sp;
Greg Claytonb2dcc362011-05-05 23:32:56 +00003819 AddressType address_type;
Enrico Granata9128ee22011-09-06 19:20:51 +00003820 addr_t ptr_value = GetPointerValue (&address_type);
Greg Claytonb2dcc362011-05-05 23:32:56 +00003821
3822 if (ptr_value != LLDB_INVALID_ADDRESS)
3823 {
Greg Claytone72dfb32012-02-24 01:59:29 +00003824 Address ptr_addr (ptr_value);
Greg Claytoncc4d0142012-02-17 07:49:44 +00003825 ExecutionContext exe_ctx (GetExecutionContextRef());
3826 valobj_sp = ValueObjectMemory::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Claytonb2dcc362011-05-05 23:32:56 +00003827 name,
3828 ptr_addr,
3829 type_sp);
3830 }
3831 return valobj_sp;
3832}
3833
Jim Ingham6035b672011-03-31 00:19:25 +00003834ValueObject::EvaluationPoint::EvaluationPoint () :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003835 m_mod_id(),
3836 m_exe_ctx_ref(),
3837 m_needs_update (true),
3838 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003839{
3840}
3841
3842ValueObject::EvaluationPoint::EvaluationPoint (ExecutionContextScope *exe_scope, bool use_selected):
Greg Claytoncc4d0142012-02-17 07:49:44 +00003843 m_mod_id(),
3844 m_exe_ctx_ref(),
Jim Ingham6035b672011-03-31 00:19:25 +00003845 m_needs_update (true),
Greg Claytoncc4d0142012-02-17 07:49:44 +00003846 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003847{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003848 ExecutionContext exe_ctx(exe_scope);
3849 TargetSP target_sp (exe_ctx.GetTargetSP());
3850 if (target_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003851 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003852 m_exe_ctx_ref.SetTargetSP (target_sp);
3853 ProcessSP process_sp (exe_ctx.GetProcessSP());
3854 if (!process_sp)
3855 process_sp = target_sp->GetProcessSP();
Jim Ingham6035b672011-03-31 00:19:25 +00003856
Greg Claytoncc4d0142012-02-17 07:49:44 +00003857 if (process_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003858 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003859 m_mod_id = process_sp->GetModID();
3860 m_exe_ctx_ref.SetProcessSP (process_sp);
Jim Ingham4b536182011-08-09 02:12:22 +00003861
Greg Claytoncc4d0142012-02-17 07:49:44 +00003862 ThreadSP thread_sp (exe_ctx.GetThreadSP());
Jim Ingham6035b672011-03-31 00:19:25 +00003863
Greg Claytoncc4d0142012-02-17 07:49:44 +00003864 if (!thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003865 {
3866 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003867 thread_sp = process_sp->GetThreadList().GetSelectedThread();
Jim Ingham6035b672011-03-31 00:19:25 +00003868 }
Jim Ingham6035b672011-03-31 00:19:25 +00003869
Greg Claytoncc4d0142012-02-17 07:49:44 +00003870 if (thread_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003871 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003872 m_exe_ctx_ref.SetThreadSP(thread_sp);
Greg Claytonc14ee322011-09-22 04:58:26 +00003873
Jason Molendab57e4a12013-11-04 09:33:30 +00003874 StackFrameSP frame_sp (exe_ctx.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003875 if (!frame_sp)
Jim Ingham6035b672011-03-31 00:19:25 +00003876 {
3877 if (use_selected)
Greg Claytoncc4d0142012-02-17 07:49:44 +00003878 frame_sp = thread_sp->GetSelectedFrame();
Jim Ingham6035b672011-03-31 00:19:25 +00003879 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003880 if (frame_sp)
3881 m_exe_ctx_ref.SetFrameSP(frame_sp);
Jim Ingham6035b672011-03-31 00:19:25 +00003882 }
3883 }
3884 }
Jim Ingham6035b672011-03-31 00:19:25 +00003885}
3886
3887ValueObject::EvaluationPoint::EvaluationPoint (const ValueObject::EvaluationPoint &rhs) :
Greg Claytoncc4d0142012-02-17 07:49:44 +00003888 m_mod_id(),
3889 m_exe_ctx_ref(rhs.m_exe_ctx_ref),
3890 m_needs_update (true),
3891 m_first_update (true)
Jim Ingham6035b672011-03-31 00:19:25 +00003892{
3893}
3894
3895ValueObject::EvaluationPoint::~EvaluationPoint ()
3896{
3897}
3898
Jim Ingham6035b672011-03-31 00:19:25 +00003899// This function checks the EvaluationPoint against the current process state. If the current
3900// state matches the evaluation point, or the evaluation point is already invalid, then we return
3901// false, meaning "no change". If the current state is different, we update our state, and return
3902// true meaning "yes, change". If we did see a change, we also set m_needs_update to true, so
3903// future calls to NeedsUpdate will return true.
Jim Ingham9ee01152011-12-10 01:49:43 +00003904// exe_scope will be set to the current execution context scope.
Jim Ingham6035b672011-03-31 00:19:25 +00003905
3906bool
Greg Claytoncc4d0142012-02-17 07:49:44 +00003907ValueObject::EvaluationPoint::SyncWithProcessState()
Jim Ingham6035b672011-03-31 00:19:25 +00003908{
Jim Ingham73ca05a2011-12-17 01:35:57 +00003909
3910 // Start with the target, if it is NULL, then we're obviously not going to get any further:
Greg Clayton44d93782014-01-27 23:43:24 +00003911 const bool thread_and_frame_only_if_stopped = true;
3912 ExecutionContext exe_ctx(m_exe_ctx_ref.Lock(thread_and_frame_only_if_stopped));
Jim Ingham73ca05a2011-12-17 01:35:57 +00003913
Greg Claytoncc4d0142012-02-17 07:49:44 +00003914 if (exe_ctx.GetTargetPtr() == NULL)
Jim Ingham73ca05a2011-12-17 01:35:57 +00003915 return false;
3916
Jim Ingham6035b672011-03-31 00:19:25 +00003917 // If we don't have a process nothing can change.
Greg Claytoncc4d0142012-02-17 07:49:44 +00003918 Process *process = exe_ctx.GetProcessPtr();
3919 if (process == NULL)
Jim Ingham6035b672011-03-31 00:19:25 +00003920 return false;
Jim Ingham73ca05a2011-12-17 01:35:57 +00003921
Jim Ingham6035b672011-03-31 00:19:25 +00003922 // If our stop id is the current stop ID, nothing has changed:
Greg Claytoncc4d0142012-02-17 07:49:44 +00003923 ProcessModID current_mod_id = process->GetModID();
Jim Ingham4b536182011-08-09 02:12:22 +00003924
Jim Ingham78a685a2011-04-16 00:01:13 +00003925 // If the current stop id is 0, either we haven't run yet, or the process state has been cleared.
3926 // In either case, we aren't going to be able to sync with the process state.
Jim Ingham4b536182011-08-09 02:12:22 +00003927 if (current_mod_id.GetStopID() == 0)
Jim Ingham78a685a2011-04-16 00:01:13 +00003928 return false;
Jim Ingham9ee01152011-12-10 01:49:43 +00003929
Greg Clayton23f59502012-07-17 03:23:13 +00003930 bool changed = false;
3931 const bool was_valid = m_mod_id.IsValid();
3932 if (was_valid)
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003933 {
3934 if (m_mod_id == current_mod_id)
3935 {
Jim Ingham5cfbe4a2012-01-12 22:42:34 +00003936 // Everything is already up to date in this object, no need to
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003937 // update the execution context scope.
Jim Ingham9ee01152011-12-10 01:49:43 +00003938 changed = false;
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003939 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003940 else
3941 {
3942 m_mod_id = current_mod_id;
3943 m_needs_update = true;
3944 changed = true;
3945 }
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00003946 }
Jim Ingham6035b672011-03-31 00:19:25 +00003947
Jim Ingham73ca05a2011-12-17 01:35:57 +00003948 // Now re-look up the thread and frame in case the underlying objects have gone away & been recreated.
3949 // That way we'll be sure to return a valid exe_scope.
3950 // 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 +00003951
Greg Claytoncc4d0142012-02-17 07:49:44 +00003952 if (m_exe_ctx_ref.HasThreadRef())
Jim Ingham6035b672011-03-31 00:19:25 +00003953 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003954 ThreadSP thread_sp (m_exe_ctx_ref.GetThreadSP());
3955 if (thread_sp)
Greg Clayton262f80d2011-07-06 16:49:27 +00003956 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003957 if (m_exe_ctx_ref.HasFrameRef())
3958 {
Jason Molendab57e4a12013-11-04 09:33:30 +00003959 StackFrameSP frame_sp (m_exe_ctx_ref.GetFrameSP());
Greg Claytoncc4d0142012-02-17 07:49:44 +00003960 if (!frame_sp)
3961 {
3962 // We used to have a frame, but now it is gone
3963 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003964 changed = was_valid;
Greg Claytoncc4d0142012-02-17 07:49:44 +00003965 }
3966 }
Greg Clayton262f80d2011-07-06 16:49:27 +00003967 }
Jim Ingham6035b672011-03-31 00:19:25 +00003968 else
3969 {
Greg Claytoncc4d0142012-02-17 07:49:44 +00003970 // We used to have a thread, but now it is gone
3971 SetInvalid();
Greg Clayton23f59502012-07-17 03:23:13 +00003972 changed = was_valid;
Jim Ingham6035b672011-03-31 00:19:25 +00003973 }
Greg Claytoncc4d0142012-02-17 07:49:44 +00003974
Jim Ingham6035b672011-03-31 00:19:25 +00003975 }
Jim Ingham9ee01152011-12-10 01:49:43 +00003976 return changed;
Jim Ingham6035b672011-03-31 00:19:25 +00003977}
3978
Jim Ingham61be0902011-05-02 18:13:59 +00003979void
3980ValueObject::EvaluationPoint::SetUpdated ()
3981{
Greg Claytoncc4d0142012-02-17 07:49:44 +00003982 ProcessSP process_sp(m_exe_ctx_ref.GetProcessSP());
3983 if (process_sp)
3984 m_mod_id = process_sp->GetModID();
Jim Ingham61be0902011-05-02 18:13:59 +00003985 m_first_update = false;
3986 m_needs_update = false;
Jim Ingham61be0902011-05-02 18:13:59 +00003987}
3988
3989
Enrico Granataf2bbf712011-07-15 02:26:42 +00003990
3991void
Enrico Granata86cc9822012-03-19 22:58:49 +00003992ValueObject::ClearUserVisibleData(uint32_t clear_mask)
Enrico Granataf2bbf712011-07-15 02:26:42 +00003993{
Enrico Granata86cc9822012-03-19 22:58:49 +00003994 if ((clear_mask & eClearUserVisibleDataItemsValue) == eClearUserVisibleDataItemsValue)
3995 m_value_str.clear();
3996
3997 if ((clear_mask & eClearUserVisibleDataItemsLocation) == eClearUserVisibleDataItemsLocation)
3998 m_location_str.clear();
3999
4000 if ((clear_mask & eClearUserVisibleDataItemsSummary) == eClearUserVisibleDataItemsSummary)
Enrico Granata86cc9822012-03-19 22:58:49 +00004001 m_summary_str.clear();
Enrico Granata86cc9822012-03-19 22:58:49 +00004002
4003 if ((clear_mask & eClearUserVisibleDataItemsDescription) == eClearUserVisibleDataItemsDescription)
4004 m_object_desc_str.clear();
4005
4006 if ((clear_mask & eClearUserVisibleDataItemsSyntheticChildren) == eClearUserVisibleDataItemsSyntheticChildren)
4007 {
4008 if (m_synthetic_value)
4009 m_synthetic_value = NULL;
4010 }
Enrico Granata744794a2014-09-05 21:46:22 +00004011
4012 if ((clear_mask & eClearUserVisibleDataItemsValidator) == eClearUserVisibleDataItemsValidator)
4013 m_validation_result.reset();
Johnny Chen44805302011-07-19 19:48:13 +00004014}
Enrico Granata9128ee22011-09-06 19:20:51 +00004015
4016SymbolContextScope *
4017ValueObject::GetSymbolContextScope()
4018{
4019 if (m_parent)
4020 {
4021 if (!m_parent->IsPointerOrReferenceType())
4022 return m_parent->GetSymbolContextScope();
4023 }
4024 return NULL;
4025}
Enrico Granatab2698cd2012-09-13 18:27:09 +00004026
4027lldb::ValueObjectSP
4028ValueObject::CreateValueObjectFromExpression (const char* name,
4029 const char* expression,
4030 const ExecutionContext& exe_ctx)
4031{
4032 lldb::ValueObjectSP retval_sp;
4033 lldb::TargetSP target_sp(exe_ctx.GetTargetSP());
4034 if (!target_sp)
4035 return retval_sp;
4036 if (!expression || !*expression)
4037 return retval_sp;
4038 target_sp->EvaluateExpression (expression,
4039 exe_ctx.GetFrameSP().get(),
4040 retval_sp);
4041 if (retval_sp && name && *name)
4042 retval_sp->SetName(ConstString(name));
4043 return retval_sp;
4044}
4045
4046lldb::ValueObjectSP
4047ValueObject::CreateValueObjectFromAddress (const char* name,
4048 uint64_t address,
4049 const ExecutionContext& exe_ctx,
4050 ClangASTType type)
4051{
Greg Clayton57ee3062013-07-11 22:46:58 +00004052 if (type)
Enrico Granatab2698cd2012-09-13 18:27:09 +00004053 {
Greg Clayton57ee3062013-07-11 22:46:58 +00004054 ClangASTType pointer_type(type.GetPointerType());
4055 if (pointer_type)
4056 {
4057 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t)));
4058 lldb::ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
4059 pointer_type,
4060 ConstString(name),
4061 buffer,
4062 lldb::endian::InlHostByteOrder(),
4063 exe_ctx.GetAddressByteSize()));
4064 if (ptr_result_valobj_sp)
4065 {
4066 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress);
4067 Error err;
4068 ptr_result_valobj_sp = ptr_result_valobj_sp->Dereference(err);
4069 if (ptr_result_valobj_sp && name && *name)
4070 ptr_result_valobj_sp->SetName(ConstString(name));
4071 }
4072 return ptr_result_valobj_sp;
4073 }
Enrico Granatab2698cd2012-09-13 18:27:09 +00004074 }
Greg Clayton57ee3062013-07-11 22:46:58 +00004075 return lldb::ValueObjectSP();
Enrico Granatab2698cd2012-09-13 18:27:09 +00004076}
4077
4078lldb::ValueObjectSP
4079ValueObject::CreateValueObjectFromData (const char* name,
Enrico Granata7ca1c762014-03-31 23:02:25 +00004080 const DataExtractor& data,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004081 const ExecutionContext& exe_ctx,
4082 ClangASTType type)
4083{
4084 lldb::ValueObjectSP new_value_sp;
4085 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(),
Greg Clayton57ee3062013-07-11 22:46:58 +00004086 type,
Enrico Granatab2698cd2012-09-13 18:27:09 +00004087 ConstString(name),
4088 data,
4089 LLDB_INVALID_ADDRESS);
4090 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad);
4091 if (new_value_sp && name && *name)
4092 new_value_sp->SetName(ConstString(name));
4093 return new_value_sp;
4094}
Enrico Granata4873e522013-04-11 22:48:58 +00004095
4096ModuleSP
4097ValueObject::GetModule ()
4098{
4099 ValueObject* root(GetRoot());
4100 if (root != this)
4101 return root->GetModule();
4102 return lldb::ModuleSP();
4103}
4104
4105ValueObject*
4106ValueObject::GetRoot ()
4107{
4108 if (m_root)
4109 return m_root;
4110 ValueObject* parent = m_parent;
4111 if (!parent)
4112 return (m_root = this);
4113 while (parent->m_parent)
4114 {
4115 if (parent->m_root)
4116 return (m_root = parent->m_root);
4117 parent = parent->m_parent;
4118 }
4119 return (m_root = parent);
4120}
4121
4122AddressType
4123ValueObject::GetAddressTypeOfChildren()
4124{
4125 if (m_address_type_of_ptr_or_ref_children == eAddressTypeInvalid)
4126 {
4127 ValueObject* root(GetRoot());
4128 if (root != this)
4129 return root->GetAddressTypeOfChildren();
4130 }
4131 return m_address_type_of_ptr_or_ref_children;
4132}
4133
4134lldb::DynamicValueType
4135ValueObject::GetDynamicValueType ()
4136{
4137 ValueObject* with_dv_info = this;
4138 while (with_dv_info)
4139 {
4140 if (with_dv_info->HasDynamicValueTypeInfo())
4141 return with_dv_info->GetDynamicValueTypeImpl();
4142 with_dv_info = with_dv_info->m_parent;
4143 }
4144 return lldb::eNoDynamicValues;
4145}
Enrico Granata39d51412013-05-31 17:43:40 +00004146
Enrico Granata4873e522013-04-11 22:48:58 +00004147lldb::Format
4148ValueObject::GetFormat () const
4149{
4150 const ValueObject* with_fmt_info = this;
4151 while (with_fmt_info)
4152 {
4153 if (with_fmt_info->m_format != lldb::eFormatDefault)
4154 return with_fmt_info->m_format;
4155 with_fmt_info = with_fmt_info->m_parent;
4156 }
4157 return m_format;
4158}
Enrico Granatad07cfd32014-10-08 18:27:36 +00004159
Enrico Granatac1247f52014-11-06 21:23:20 +00004160lldb::LanguageType
4161ValueObject::GetPreferredDisplayLanguage ()
4162{
4163 lldb::LanguageType type = lldb::eLanguageTypeUnknown;
4164 if (GetRoot())
4165 {
4166 if (GetRoot() == this)
4167 {
4168 if (StackFrameSP frame_sp = GetFrameSP())
4169 {
4170 const SymbolContext& sc(frame_sp->GetSymbolContext(eSymbolContextCompUnit));
4171 if (CompileUnit* cu = sc.comp_unit)
4172 type = cu->GetLanguage();
4173 }
4174 }
4175 else
4176 {
4177 type = GetRoot()->GetPreferredDisplayLanguage();
4178 }
4179 }
4180 return type;
4181}
4182
Enrico Granatad07cfd32014-10-08 18:27:36 +00004183bool
4184ValueObject::CanProvideValue ()
4185{
4186 return (false == GetClangType().IsAggregateType());
4187}
Enrico Granata0c10a852014-12-08 23:13:56 +00004188
4189ValueObjectSP
4190ValueObject::Persist ()
4191{
4192 if (!UpdateValueIfNeeded())
4193 return nullptr;
4194
4195 TargetSP target_sp(GetTargetSP());
4196 if (!target_sp)
4197 return nullptr;
4198
4199 ConstString name(target_sp->GetPersistentVariables().GetNextPersistentVariableName());
4200
4201 ClangExpressionVariableSP clang_var_sp(new ClangExpressionVariable(target_sp.get(), GetValue(), name));
4202 if (clang_var_sp)
4203 {
4204 clang_var_sp->m_live_sp = clang_var_sp->m_frozen_sp;
4205 clang_var_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
4206 target_sp->GetPersistentVariables().AddVariable(clang_var_sp);
4207 }
4208
4209 return clang_var_sp->GetValueObject();
4210}
Enrico Granatae29df232014-12-09 19:51:20 +00004211
4212bool
4213ValueObject::IsSyntheticChildrenGenerated ()
4214{
4215 return m_is_synthetic_children_generated;
4216}
4217
4218void
4219ValueObject::SetSyntheticChildrenGenerated (bool b)
4220{
4221 m_is_synthetic_children_generated = b;
4222}